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