00001 {@********************************************************}
00002 { Copyright (c) 1999-2006 Zeos Development Group }
00003 { }
00004 { License Agreement: }
00005 { }
00006 { This library is distributed in the hope that it will be }
00007 { useful, but WITHOUT ANY WARRANTY; without even the }
00008 { implied warranty of MERCHANTABILITY or FITNESS FOR }
00009 { A PARTICULAR PURPOSE. See the GNU Lesser General }
00010 { Public License for more details. }
00011 { }
00012 { The source code of the ZEOS Libraries and packages are }
00013 { distributed under the Library GNU General Public }
00014 { License (see the file COPYING / COPYING.ZEOS) }
00015 { with the following modification: }
00016 { As a special exception, the copyright holders of this }
00017 { library give you permission to link this library with }
00018 { independent modules to produce an executable, }
00019 { regardless of the license terms of these independent }
00020 { modules, and to copy and distribute the resulting }
00021 { executable under terms of your choice, provided that }
00022 { you also meet, for each linked independent module, }
00023 { the terms and conditions of the license of that module. }
00024 { An independent module is a module which is not derived }
00025 { from or based on this library. If you modify this }
00026 { library, you may extend this exception to your version }
00027 { of the library, but you are not obligated to do so. }
00028 { If you do not wish to do so, delete this exception }
00029 { statement from your version. }
00030 { }
00031 { }
00032 { The project web site is located on: }
00033 { http:
00034 { http:
00035 { svn:
00036 { }
00037 { http:
00038 { http:
00039 { }
00040 { }
00041 { }
00042 { Zeos Development Group. }
00043 {********************************************************@}
00044
00045 unit ZPlainSqLite3;
00046
00047 interface
00048
00049 {$I ZPlain.inc}
00050
00051 {$J+}
00052 {$Z4}
00053
00054 uses Classes, ZPlainLoader, ZCompatibility;
00055
00056 { ***************** Plain API Constants definition **************** }
00057
00058 const
00059 WINDOWS_DLL_LOCATION = 'sqlite3.dll';
00060 LINUX_DLL_LOCATION = 'libsqlite3.so';
00061
00062 SQLITE_ISO8859 = 1;
00063 MASTER_NAME = 'sqlite_master';
00064 TEMP_MASTER_NAME = 'sqlite_temp_master';
00065 SQLITE_VERSION = '3.5.4';
00066
00067 { Return values for sqlite_exec() and sqlite_step() }
00068 SQLITE_OK = 0;
00069 SQLITE_ERROR = 1;
00070 SQLITE_INTERNAL = 2;
00071 SQLITE_PERM = 3;
00072 SQLITE_ABORT = 4;
00073 SQLITE_BUSY = 5;
00074 SQLITE_LOCKED = 6;
00075 SQLITE_NOMEM = 7;
00076 SQLITE_READONLY = 8;
00077 _SQLITE_INTERRUPT = 9;
00078 SQLITE_IOERR = 10;
00079 SQLITE_CORRUPT = 11;
00080 SQLITE_NOTFOUND = 12;
00081 SQLITE_FULL = 13;
00082 SQLITE_CANTOPEN = 14;
00083 SQLITE_PROTOCOL = 15;
00084 SQLITE_EMPTY = 16;
00085 SQLITE_SCHEMA = 17;
00086 SQLITE_TOOBIG = 18;
00087 SQLITE_CONSTRAINT = 19;
00088 SQLITE_MISMATCH = 20;
00089 SQLITE_MISUSE = 21;
00090 SQLITE_NOLFS = 22;
00091 SQLITE_AUTH = 23;
00092 SQLITE_FORMAT = 24;
00093 SQLITE_RANGE = 25;
00094 SQLITE_NOTADB = 26;
00095 SQLITE_ROW = 100;
00096 SQLITE_DONE = 101;
00097
00098 SQLITE_NUMERIC = -1;
00099 SQLITE_TEXT = -2;
00100 SQLITE_ARGS = -3;
00101
00102 {
00103 The second parameter to the access authorization function above will
00104 be one of the values below. These values signify what kind of operation
00105 is to be authorized. The 3rd and 4th parameters to the authorization
00106 function will be parameters or NULL depending on which of the following
00107 codes is used as the second parameter. The 5th parameter is the name
00108 of the database ("main", "temp", etc.) if applicable. The 6th parameter
00109 is the name of the inner-most trigger or view that is responsible for
00110 the access attempt or NULL if this access attempt is directly from
00111 input SQL code.
00112
00113 Arg-3 Arg-4
00114 }
00115 SQLITE_COPY = 0;
00116 SQLITE_CREATE_INDEX = 1;
00117 SQLITE_CREATE_TABLE = 2;
00118 SQLITE_CREATE_TEMP_INDEX = 3;
00119 SQLITE_CREATE_TEMP_TABLE = 4;
00120 SQLITE_CREATE_TEMP_TRIGGER = 5;
00121 SQLITE_CREATE_TEMP_VIEW = 6;
00122 SQLITE_CREATE_TRIGGER = 7;
00123 SQLITE_CREATE_VIEW = 8;
00124 SQLITE_DELETE = 9;
00125 SQLITE_DROP_INDEX = 10;
00126 SQLITE_DROP_TABLE = 11;
00127 SQLITE_DROP_TEMP_INDEX = 12;
00128 SQLITE_DROP_TEMP_TABLE = 13;
00129 SQLITE_DROP_TEMP_TRIGGER = 14;
00130 SQLITE_DROP_TEMP_VIEW = 15;
00131 SQLITE_DROP_TRIGGER = 16;
00132 SQLITE_DROP_VIEW = 17;
00133 SQLITE_INSERT = 18;
00134 SQLITE_PRAGMA = 19;
00135 SQLITE_READ = 20;
00136 SQLITE_SELECT = 21;
00137 SQLITE_TRANSACTION = 22;
00138 SQLITE_UPDATE = 23;
00139
00140 { The return value of the authorization function should be one of the
00141 following constants: }
00142 SQLITE_DENY = 1;
00143 SQLITE_IGNORE = 2;
00144
00145 type
00146 Psqlite = Pointer;
00147 Psqlite_func = Pointer;
00148 Psqlite_vm = Pointer;
00149
00150 { ************** Plain API Function types definition ************* }
00151
00152 Tsqlite_callback = function(p1: Pointer; p2: Integer; var p3: PChar;
00153 var p4: PChar): Integer; cdecl;
00154 Tsqlite_simple_callback = function(p1: Pointer): Integer; cdecl;
00155 Tsqlite_simple_callback0 = function(p1: Pointer): Pointer; cdecl;
00156 Tsqlite_busy_callback = function(p1: Pointer; const p2: PChar;
00157 p3: Integer): Integer; cdecl;
00158
00159 Tsqlite_function_callback = procedure(p1: Psqlite_func; p2: Integer;
00160 const p3: PPChar); cdecl;
00161 Tsqlite_finalize_callback = procedure(p1: Psqlite_func); cdecl;
00162 Tsqlite_auth_callback = function(p1: Pointer; p2: Integer; const p3: PChar;
00163 const p4: PChar; const p5: PChar; const p6: PChar): Integer; cdecl;
00164 Tsqlite_trace_callback = procedure(p1: Pointer; const p2: PChar); cdecl;
00165
00166 Tsqlite_open = function(const filename: PChar;var Qsqlite: Psqlite):
00167 Integer; cdecl;
00168 Tsqlite_close = procedure(db: Psqlite); cdecl;
00169 Tsqlite_column_count = function(db: Psqlite): Integer; cdecl;
00170 Tsqlite_column_bytes = function(db: Psqlite; iCol: Integer): Pchar; cdecl;
00171 Tsqlite_column_name = function(db: Psqlite; iCol: Integer): Pchar; cdecl;
00172 Tsqlite_column_decltype = function(db: Psqlite; iCol: Integer): Pchar; cdecl;
00173 Tsqlite_exec = function(db: Psqlite; const sql: PChar;
00174 sqlite_callback: Tsqlite_callback; arg: Pointer;
00175 var errmsg: PChar): Integer; cdecl;
00176 Tsqlite_errmsg = function(db: Psqlite): PChar; cdecl;
00177 Tsqlite_last_insert_rowid = function(db: Psqlite): Integer; cdecl;
00178 Tsqlite_changes = function(db: Psqlite): Integer; cdecl;
00179 Tsqlite_last_statement_changes = function(db: Psqlite): Integer; cdecl;
00180 Tsqlite_error_string = function(code: Integer): PChar; cdecl;
00181 Tsqlite_interrupt = procedure(db: Psqlite); cdecl;
00182 Tsqlite_complete = function(const sql: PChar): Integer; cdecl;
00183 Tsqlite_busy_handler = procedure(db: Psqlite;
00184 callback: Tsqlite_busy_callback; ptr: Pointer); cdecl;
00185 Tsqlite_busy_timeout = procedure(db: Psqlite; ms: Integer); cdecl;
00186 Tsqlite_get_table = function(db: Psqlite; const sql: PChar;
00187 var resultp: PPChar; var nrow: Integer; var ncolumn: Integer;
00188 var errmsg: PChar): Integer; cdecl;
00189 Tsqlite_free_table = procedure(var result: PChar); cdecl;
00190 Tsqlite_freemem = procedure(ptr: Pointer); cdecl;
00191 Tsqlite_libversion = function: PChar; cdecl;
00192 Tsqlite_libencoding = function: PChar; cdecl;
00193
00194 Tsqlite_create_function = function(db: Psqlite; const zName: PChar;
00195 nArg: Integer; callback: Tsqlite_function_callback;
00196 pUserData: Pointer): Integer; cdecl;
00197 Tsqlite_create_aggregate = function(db: Psqlite; const zName: PChar;
00198 nArg: Integer; callback: Tsqlite_function_callback;
00199 finalize: Tsqlite_finalize_callback; pUserData: Pointer): Integer; cdecl;
00200 Tsqlite_function_type = function(db: Psqlite; const zName: PChar;
00201 datatype: Integer): Integer; cdecl;
00202 Tsqlite_set_result_string = function(func: Psqlite_func; const arg: PChar;
00203 len: Integer; UN: Tsqlite_simple_callback): PChar; cdecl;
00204 Tsqlite_set_result_int = procedure(func: Psqlite_func; arg: Integer); cdecl;
00205 Tsqlite_set_result_double = procedure(func: Psqlite_func; arg: Double); cdecl;
00206 Tsqlite_set_result_error = procedure(func: Psqlite_func; const arg: PChar;
00207 len: Integer); cdecl;
00208 Tsqlite_user_data = function(func: Psqlite_func): Pointer; cdecl;
00209 Tsqlite_aggregate_context = function(func: Psqlite_func;
00210 nBytes: Integer): Pointer; cdecl;
00211 Tsqlite_aggregate_count = function(func: Psqlite_func): Integer; cdecl;
00212
00213 Tsqlite_set_authorizer = function(db: Psqlite;
00214 callback: Tsqlite_auth_callback; pUserData: Pointer): Integer; cdecl;
00215 Tsqlite_trace = function(db: Psqlite; callback: Tsqlite_trace_callback;
00216 ptr: Pointer): Pointer; cdecl;
00217
00218 Tsqlite_compile = function(db: Psqlite; const zSql: PChar; nBytes: Integer;
00219 var ppVm: Psqlite_vm; pzTail: PChar): Integer; cdecl;
00220 Tsqlite_step = function(pVm: Psqlite_vm): Integer; cdecl;
00221 Tsqlite_finalize = function(vm: Psqlite_vm): Integer; cdecl;
00222 Tsqlite_reset = function(vm: Psqlite_vm): Integer; cdecl;
00223 Tsqlite_bind = function(vm: Psqlite_vm; idx: Integer; const value: PChar;
00224 len: Integer; copy: Integer): Integer; cdecl;
00225 { Tsqlite_bind_double = function(vm: Psqlite_vm; idx: Integer; const value: PChar;
00226 len: Integer; copy: Integer): Integer; cdecl;
00227 Tsqlite_bind_int = function(vm: Psqlite_vm; idx: Integer; const value: PChar;
00228 len: Integer; copy: Integer): Integer; cdecl;
00229 Tsqlite_bind_int64 = function(vm: Psqlite_vm; idx: Integer; const value: PChar;
00230 len: Integer; copy: Integer): Integer; cdecl;
00231 Tsqlite_bind_null = function(vm: Psqlite_vm; idx: Integer; const value: PChar;
00232 len: Integer; copy: Integer): Integer; cdecl;
00233 Tsqlite_bind_text = function(vm: Psqlite_vm; idx: Integer; const value: PChar;
00234 len: Integer; copy: Integer): Integer; cdecl;}
00235
00236 Tsqlite_progress_handler = procedure(db: Psqlite; p1: Integer;
00237 callback: Tsqlite_simple_callback; ptr: Pointer); cdecl;
00238 Tsqlite_commit_hook = function(db: Psqlite; callback: Tsqlite_simple_callback;
00239 ptr: Pointer): Pointer; cdecl;
00240
00241 Tsqlite_open_encrypted = function(const zFilename: PChar;
00242 const pKey: PChar; nKey: Integer; var pErrcode: Integer;
00243 var pzErrmsg: PChar): Psqlite; cdecl;
00244 Tsqlite_rekey = function(db: Psqlite; const pKey: Pointer;
00245 nKey: Integer): Integer; cdecl;
00246 Tsqlite_key = function(db: Psqlite; const pKey: Pointer;
00247 nKey: Integer): Integer; cdecl;
00248
00249 var
00250
00251 { ************* Plain API Function variables definition ************ }
00252
00253 sqlite_open: Tsqlite_open;
00254 sqlite_close: Tsqlite_close;
00255 sqlite_column_count: Tsqlite_column_count;
00256 sqlite_column_bytes: Tsqlite_column_bytes;
00257 sqlite_column_name: Tsqlite_column_name;
00258 sqlite_column_decltype: Tsqlite_column_decltype;
00259 sqlite_exec: Tsqlite_exec;
00260 sqlite_errmsg: Tsqlite_errmsg;
00261 sqlite_last_insert_rowid: Tsqlite_last_insert_rowid;
00262 sqlite_changes: Tsqlite_changes;
00263 sqlite_last_statement_changes: Tsqlite_last_statement_changes;
00264 sqlite_error_string: Tsqlite_error_string;
00265 sqlite_interrupt: Tsqlite_interrupt;
00266 sqlite_complete: Tsqlite_complete;
00267 sqlite_busy_handler: Tsqlite_busy_handler;
00268 sqlite_busy_timeout: Tsqlite_busy_timeout;
00269 sqlite_get_table: Tsqlite_get_table;
00270 sqlite_free_table: Tsqlite_free_table;
00271 sqlite_freemem: Tsqlite_freemem;
00272 sqlite_libversion: Tsqlite_libversion;
00273 sqlite_libencoding: Tsqlite_libencoding;
00274 sqlite_create_function: Tsqlite_create_function;
00275 sqlite_create_aggregate: Tsqlite_create_aggregate;
00276 sqlite_function_type: Tsqlite_function_type;
00277 sqlite_set_result_string: Tsqlite_set_result_string;
00278 sqlite_set_result_int: Tsqlite_set_result_int;
00279 sqlite_set_result_double: Tsqlite_set_result_double;
00280 sqlite_set_result_error: Tsqlite_set_result_error;
00281 sqlite_user_data: Tsqlite_user_data;
00282 sqlite_aggregate_context: Tsqlite_aggregate_context;
00283 sqlite_aggregate_count: Tsqlite_aggregate_count;
00284 sqlite_set_authorizer: Tsqlite_set_authorizer;
00285 sqlite_trace: Tsqlite_trace;
00286 sqlite_compile: Tsqlite_compile;
00287 sqlite_step: Tsqlite_step;
00288 sqlite_finalize: Tsqlite_finalize;
00289 sqlite_reset: Tsqlite_reset;
00290 sqlite_bind: Tsqlite_bind;
00291 sqlite_progress_handler: Tsqlite_progress_handler;
00292 sqlite_commit_hook: Tsqlite_commit_hook;
00293 sqlite_open_encrypted: Tsqlite_open_encrypted;
00294 sqlite_rekey: Tsqlite_rekey;
00295 sqlite_key: Tsqlite_key;
00296
00297 var
00298 LibraryLoader: TZNativeLibraryLoader;
00299
00300 implementation
00301
00302 type
00303 {** Implements a loader for SQLite native library. }
00304 TZSQLiteNativeLibraryLoader = class (TZNativeLibraryLoader)
00305 public
00306 function Load: Boolean; override;
00307 end;
00308
00309 { TZSQLiteNativeLibraryLoader }
00310
00311 {**
00312 Loads a library module.
00313 @return <code>True</code> if library was successfully loaded.
00314 }
00315 function TZSQLiteNativeLibraryLoader.Load: Boolean;
00316 begin
00317 Result := inherited Load;
00318
00319 {!} @sqlite_open := GetAddress('sqlite3_open');
00320 {!} @sqlite_close := GetAddress('sqlite3_close');
00321 {!} @sqlite_column_count := GetAddress('sqlite3_column_count');
00322 {!} @sqlite_column_bytes := GetAddress('sqlite3_column_text');
00323 {!} @sqlite_column_name := GetAddress('sqlite3_column_name');
00324 {!} @sqlite_column_decltype := GetAddress('sqlite3_column_decltype');
00325 {!} @sqlite_exec := GetAddress('sqlite3_exec');
00326 {!} @sqlite_last_insert_rowid := GetAddress('sqlite3_last_insert_rowid');
00327 {!} @sqlite_changes := GetAddress('sqlite3_changes');
00328 {!} @sqlite_errmsg := GetAddress('sqlite3_errmsg');
00329 { ?- @sqlite_last_statement_changes := GetAddress('sqlite3_last_statement_changes');}
00330 {!} @sqlite_interrupt := GetAddress('sqlite3_interrupt');
00331 {!} @sqlite_complete := GetAddress('sqlite3_complete');
00332 {!} @sqlite_busy_handler := GetAddress('sqlite3_busy_handler');
00333 {!} @sqlite_busy_timeout := GetAddress('sqlite3_busy_timeout');
00334 {!} @sqlite_get_table := GetAddress('sqlite3_get_table');
00335 {!} @sqlite_free_table := GetAddress('sqlite3_free_table');
00336 {!} @sqlite_freemem := GetAddress('sqlite3_free');
00337 {!} @sqlite_libversion := GetAddress('sqlite3_libversion');
00338 { ?- @sqlite_libencoding := GetAddress('sqlite3_libencoding');
00339 { ?- @sqlite_create_function := GetAddress('sqlite3_create_function');}
00340 { ?- @sqlite_create_aggregate := GetAddress('sqlite3_create_collation');}
00341 { ?- @sqlite_function_type := GetAddress('sqlite3_function_type');
00342 {!} @sqlite_set_result_string := GetAddress('sqlite3_result_string');
00343 {!} @sqlite_set_result_int := GetAddress('sqlite3_result_int');
00344 {!} @sqlite_set_result_double := GetAddress('sqlite3_result_double');
00345 {!} @sqlite_set_result_error := GetAddress('sqlite3_result_error');
00346 {!} @sqlite_user_data := GetAddress('sqlite3_user_data');
00347 {!} @sqlite_aggregate_context := GetAddress('sqlite3_aggregate_context');
00348 {!} @sqlite_aggregate_count := GetAddress('sqlite3_aggregate_count');
00349 {!} @sqlite_set_authorizer := GetAddress('sqlite3_set_authorizer');
00350 {!} @sqlite_trace := GetAddress('sqlite3_trace');
00351 {!} @sqlite_compile := GetAddress('sqlite3_prepare');
00352 {!} @sqlite_step := GetAddress('sqlite3_step');
00353 {!} @sqlite_finalize := GetAddress('sqlite3_finalize');
00354 {!} @sqlite_reset := GetAddress('sqlite3_reset');
00355 { ?- @sqlite_bind := GetAddress('sqlite3_bind');}
00356 {!} @sqlite_progress_handler := GetAddress('sqlite3_progress_handler');
00357 {!} @sqlite_commit_hook := GetAddress('sqlite3_commit_hook');
00358 { ?- @sqlite_open_encrypted := GetAddress('sqlite3_open_encrypted');}
00359 {!} @sqlite_rekey := GetAddress('sqlite3_rekey');
00360 {!} @sqlite_key := GetAddress('sqlite3_key');
00361
00362 end;
00363
00364 initialization
00365 {$IFNDEF UNIX}
00366 LibraryLoader := TZSQLiteNativeLibraryLoader.Create(
00367 [WINDOWS_DLL_LOCATION]);
00368 {$ELSE}
00369 LibraryLoader := TZSQLiteNativeLibraryLoader.Create(
00370 [LINUX_DLL_LOCATION]);
00371 {$ENDIF}
00372 finalization
00373 if Assigned(LibraryLoader) then
00374 LibraryLoader.Free;
00375 end.
00376