Page 1 of 1

How to embedded SQLite into program

Posted: Tue 28 Dec 2010 17:00
by Soida
Hi!
I'm trying to embedded SQLite like Synopse SQLite3 Database Framework (no use SQlite3.dll).
I modified file LiteCallUni.pas:

Code: Select all

  {$L sqlite3.obj}       // link SQlite3 database engine

  // functions

  function sqlite3_open(
    filename: PAnsiChar;    // Database filename (UTF-8)
    out ppDb: Tsqlite3      // OUT: SQLite db handle
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF} external;

  function sqlite3_open16(
    filename: PWideChar;    // Database filename (UTF-16)
    out ppDb: Tsqlite3      // OUT: SQLite db handle
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF} external;

  function sqlite3_open_v2(
    filename: PAnsiChar;    // Database filename (UTF-8)
    out ppDb: Tsqlite3;     // OUT: SQLite db handle
    flags: integer;         // Flags
    zVfs: PAnsiChar         // Name of VFS module to use
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF} external;

  function sqlite3_close(
    pDb: Tsqlite3
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_errmsg(
    pDb: Tsqlite3
  ): PAnsiChar; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_last_insert_rowid(
    pDb: Tsqlite3
  ): int64; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_changes(
    pDb: Tsqlite3
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_prepare_v2(
    db: Tsqlite3;           // Database handle
    zSql: PAnsiChar;        // SQL statement, UTF-8 encoded
    nByte: integer;         // Maximum length of zSql in bytes.
    out ppStmt: Tsqlite3_stmt;  // OUT: Statement handle
    pzTail: IntPtr          // OUT: Pointer to unused portion of zSql
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_step(
    pStmt: Tsqlite3_stmt
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_reset(
    pStmt: Tsqlite3_stmt
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_finalize(
    pStmt: Tsqlite3_stmt
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_count(
    pStmt: Tsqlite3_stmt
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_type(
    pStmt: Tsqlite3_stmt; iCol: integer
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_name(
    pStmt: Tsqlite3_stmt; iCol: integer
  ): PAnsiChar; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_origin_name(
    pStmt: Tsqlite3_stmt; iCol: integer
  ): PAnsiChar; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_table_name(
    pStmt: Tsqlite3_stmt; iCol: integer
  ): PAnsiChar; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_database_name(
    pStmt: Tsqlite3_stmt; iCol: integer
  ): PAnsiChar; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_decltype(
    pStmt: Tsqlite3_stmt; iCol: integer
  ): PAnsiChar; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_blob(
    pStmt: Tsqlite3_stmt; iCol: integer
  ): IntPtr; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_bytes(
    pStmt: Tsqlite3_stmt; iCol: integer
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_double(
    pStmt: Tsqlite3_stmt; iCol: integer
  ): double; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_int(
    pStmt: Tsqlite3_stmt; iCol: integer
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_int64(
    pStmt: Tsqlite3_stmt; iCol: integer
  ): int64; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_column_text(
    pStmt: Tsqlite3_stmt; iCol: integer
  ): PAnsiChar; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_bind_parameter_count(
    pStmt: Tsqlite3_stmt
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_bind_blob(
    pStmt: Tsqlite3_stmt; index: integer; value: IntPtr; size: integer; destr: IntPtr
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_bind_double(
    pStmt: Tsqlite3_stmt; index: integer; value: double
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_bind_int(
    pStmt: Tsqlite3_stmt; index: integer; value: integer
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_bind_int64(
    pStmt: Tsqlite3_stmt; index: integer; value: int64
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_bind_null(
    pStmt: Tsqlite3_stmt; index: integer
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_bind_text(
    pStmt: Tsqlite3_stmt; index: integer; value: PAnsiChar; size: integer; destr: IntPtr
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_libversion(
  ): PAnsiChar; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_libversion_number(
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_create_collation(
    pSQLite: Tsqlite3; zName: PAnsiChar; eTextRep: Integer; userData: IntPtr; func: IntPtr
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_create_collation16(
    pSQLite: Tsqlite3; zName: PWideChar; eTextRep: Integer; userData: IntPtr; func: IntPtr
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_key(
    pSQLite: Tsqlite3; key: PAnsiChar; size: integer
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;

  function sqlite3_rekey(
    pSQLite: Tsqlite3; newkey: PAnsiChar; size: integer
  ): integer; {$IFNDEF CLR}cdecl;{$ENDIF}external;
But it show these messages:
[DCC Error] LiteCallUni.pas(252): E2065 Unsatisfied forward or external declaration: 'sqlite3_key'
[DCC Error] LiteCallUni.pas(256): E2065 Unsatisfied forward or external declaration: 'sqlite3_rekey'
Can you help me???
Ps: I'm woking with UniDac 3.50.0.14.
Thank you very much!!!

Posted: Wed 29 Dec 2010 08:25
by AlexP
Hello,

The sqlite3_key and the sqlite3_rekey functions added to the support of SQLite encryption.
Maybe Synopse SQLite3 Database Framework doesn't support the encryption, if it is so then you should remove declaration of these functions.

Posted: Wed 29 Dec 2010 08:37
by Soida
AlexP wrote:Hello,

The sqlite3_key and the sqlite3_rekey functions added to the support of SQLite encryption.
Maybe Synopse SQLite3 Database Framework doesn't support the encryption, if it is so then you should remove declaration of these functions.
I downloaded the lastest source of SQLite (sqlite.org) and build it into Sqlite3.obj, but the source code don't support SQLite encryption while the Sqlite3.dll has sqlite3_key and sqlite3_rekey function :(
I don't know "why"???

Posted: Wed 29 Dec 2010 09:09
by AlexP
Hello,

This is a declaration of the sqlite_key and the sqlite_rekey functions

/*
** Specify the key for an encrypted database. This routine should be
** called right after sqlite3_open().
**
** The code to implement this API is not available in the public release
** of SQLite.
*/
SQLITE_API int sqlite3_key(
sqlite3 *db, /* Database to be rekeyed */
const void *pKey, int nKey /* The key */
);

/*
** Change the key on an open database. If the current database is not
** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
** database is decrypted.
**
** The code to implement this API is not available in the public release
** of SQLite.
*/
SQLITE_API int sqlite3_rekey(
sqlite3 *db, /* Database to be rekeyed */
const void *pKey, int nKey /* The new key */
);


As you can see these functions are not available in the public release of SQLite:

** The code to implement this API is not available in the public release
** of SQLite.

Posted: Wed 29 Dec 2010 09:13
by Soida
Thank you very much :D