[yunqa.de] Re: SQLite metadata

  • From: Delphi Inspiration <delphi@xxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Thu, 04 Jun 2009 18:23:29 +0200

At 09:45 04.06.2009, Radovan Antloga wrote:

>You would probably add this to DISQLite3 to in next release.
>I have done it already so I created new function:
>
>function sqlite3_prepare(Db: sqlite3; const zSQL: PAnsiChar; nByte: integer;
> ppStmt: sqlite3_stmt_ptr; const pzTail: PPUtf8Char): Integer;
>var
> Retries: integer;
>begin
> Retries := 0;
> repeat
>   Inc(Retries);
>   Result := sqlite3_prepare_v2(DB, zSQL, nByte, ppStmt, pzTail);
> until (Retries > 1) or (Result <> SQLITE_SCHEMA);
>end;
>
>and replaced all sqlite3_prepare_v2 with new sqlite3_prepare.

Yes, but I can not redefine sqlite3_prepare (and similar functions) because 
this would break the original SQLite API.

Instead, I will add two new functions (see below) to DISQLite3Api.pas and call 
them throughout the DISQLite3 library wherever appropriate. They wrap around 
the recommended sqlite3_prepare_v2(). As the name suggests, they should be seen 
as "internal" functions only which could change without notice.

Ralf

//------------------------------------------------------------------------------

function sqlite3_prepare_internal(
  DB: sqlite3; // Database handle.
  const zSql: PUtf8Char; // SQL statement, UTF-8 encoded.
  nByte: Integer; // Maximum length of zSql in bytes.
  ppStmt: sqlite3_stmt_ptr; // OUT: Statement handle.
  const pzTail: PPUtf8Char // OUT: Pointer to unused portion of zSql.
  ): Integer;
var
  Retries: Cardinal;
begin
  Retries := 0;
  repeat
    Inc(Retries);
    Result := sqlite3_prepare_v2(DB, zSql, nByte, ppStmt, pzTail);
  until (Result <> SQLITE_SCHEMA) or (Retries > 1);
end;

//------------------------------------------------------------------------------

{$IFNDEF SQLITE_OMIT_UTF16}

function sqlite3_prepare16_internal(
  DB: sqlite3; // Database handle.
  const zSql: PWideChar; // SQL statement, UTF-16 encoded.
  nByte: Integer; // Maximum length of zSql in bytes.
  ppStmt: sqlite3_stmt_ptr; // OUT: Statement handle.
  const pzTail: PPWideChar // OUT: Pointer to unused portion of zSql.
  ): Integer;
var
  Retries: Cardinal;
begin
  Retries := 0;
  repeat
    Inc(Retries);
    Result := sqlite3_prepare16_v2(DB, zSql, nByte, ppStmt, pzTail);
  until (Result <> SQLITE_SCHEMA) or (Retries > 1);
end;

_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa



Other related posts: