-
Notifications
You must be signed in to change notification settings - Fork 44
/
SQLite3.pas
604 lines (537 loc) · 29.5 KB
/
SQLite3.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
unit SQLite3;
{
Simplified interface for SQLite.
Updated for Sqlite 3 by Tim Anderson ([email protected])
Note: NOT COMPLETE for version 3, just minimal functionality
Adapted from file created by Pablo Pissanetzky ([email protected])
which was based on SQLite.pas by Ben Hochstrasser ([email protected])
}
{$IFDEF FPC}
{$MODE DELPHI}
{$H+} (* use AnsiString *)
{$PACKENUM 4} (* use 4-byte enums *)
{$PACKRECORDS C} (* C/C++-compatible record packing *)
{$ELSE}
{$MINENUMSIZE 4} (* use 4-byte enums *)
{$ENDIF}
interface
var
merdadll: string;
// Return values for sqlite3_exec() and sqlite3_step()
const
SQLITE_OK = 0; // Successful result
(* beginning-of-error-codes *)
SQLITE_ERROR = 1; // SQL error or missing database
SQLITE_INTERNAL = 2; // An internal logic error in SQLite
SQLITE_PERM = 3; // Access permission denied
SQLITE_ABORT = 4; // Callback routine requested an abort
SQLITE_BUSY = 5; // The database file is locked
SQLITE_LOCKED = 6; // A table in the database is locked
SQLITE_NOMEM = 7; // A malloc() failed
SQLITE_READONLY = 8; // Attempt to write a readonly database
SQLITE_INTERRUPT = 9; // Operation terminated by sqlite3_interrupt()
SQLITE_IOERR = 10; // Some kind of disk I/O error occurred
SQLITE_CORRUPT = 11; // The database disk image is malformed
SQLITE_NOTFOUND = 12; // (Internal Only) Table or record not found
SQLITE_FULL = 13; // Insertion failed because database is full
SQLITE_CANTOPEN = 14; // Unable to open the database file
SQLITE_PROTOCOL = 15; // Database lock protocol error
SQLITE_EMPTY = 16; // Database is empty
SQLITE_SCHEMA = 17; // The database schema changed
SQLITE_TOOBIG = 18; // Too much data for one row of a table
SQLITE_CONSTRAINT = 19; // Abort due to contraint violation
SQLITE_MISMATCH = 20; // Data type mismatch
SQLITE_MISUSE = 21; // Library used incorrectly
SQLITE_NOLFS = 22; // Uses OS features not supported on host
SQLITE_AUTH = 23; // Authorization denied
SQLITE_FORMAT = 24; // Auxiliary database format error
SQLITE_RANGE = 25; // 2nd parameter to sqlite3_bind out of range
SQLITE_NOTADB = 26; // File opened that is not a database file
SQLITE_ROW = 100; // sqlite3_step() has another row ready
SQLITE_DONE = 101; // sqlite3_step() has finished executing
SQLITE_INTEGER = 1;
SQLITE_FLOAT = 2;
SQLITE_TEXT = 3;
SQLITE_BLOB = 4;
SQLITE_NULL = 5;
SQLITE_UTF8 = 1;
SQLITE_UTF16 = 2;
SQLITE_UTF16BE = 3;
SQLITE_UTF16LE = 4;
SQLITE_ANY = 5;
SQLITE_STATIC {: TSQLite3Destructor} = Pointer(0);
SQLITE_TRANSIENT {: TSQLite3Destructor} = Pointer(-1);
type
TSQLiteDB = Pointer;
TSQLiteResult = ^PAnsiChar;
TSQLiteStmt = Pointer;
type
PPAnsiCharArray = ^TPAnsiCharArray;
TPAnsiCharArray = array[0 .. (MaxInt div SizeOf(PAnsiChar))-1] of PAnsiChar;
type
TSQLiteExecCallback = function(UserData: Pointer; NumCols: integer; ColValues:
PPAnsiCharArray; ColNames: PPAnsiCharArray): integer; cdecl;
TSQLiteBusyHandlerCallback = function(UserData: Pointer; P2: integer): integer; cdecl;
//function prototype for define own collate
TCollateXCompare = function(UserData: pointer; Buf1Len: integer; Buf1: pointer;
Buf2Len: integer; Buf2: pointer): integer; cdecl;
{
function SQLite3_Open(filename: PAnsiChar; var db: TSQLiteDB): integer; cdecl; external SQLiteDLL name 'sqlite3_open';
function SQLite3_Close(db: TSQLiteDB): integer; cdecl; external SQLiteDLL name 'sqlite3_close';
function SQLite3_Exec(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer; cdecl; external SQLiteDLL name 'sqlite3_exec';
function SQLite3_Version(): PAnsiChar; cdecl; external SQLiteDLL name 'sqlite3_libversion';
function SQLite3_ErrMsg(db: TSQLiteDB): PAnsiChar; cdecl; external SQLiteDLL name 'sqlite3_errmsg';
function SQLite3_ErrCode(db: TSQLiteDB): integer; cdecl; external SQLiteDLL name 'sqlite3_errcode';
procedure SQlite3_Free(P: PAnsiChar); cdecl; external SQLiteDLL name 'sqlite3_free';
function SQLite3_GetTable(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer; cdecl; external SQLiteDLL name 'sqlite3_get_table';
procedure SQLite3_FreeTable(Table: TSQLiteResult); cdecl; external SQLiteDLL name 'sqlite3_free_table';
function SQLite3_Complete(P: PAnsiChar): boolean; cdecl; external SQLiteDLL name 'sqlite3_complete';
function SQLite3_LastInsertRowID(db: TSQLiteDB): int64; cdecl; external SQLiteDLL name 'sqlite3_last_insert_rowid';
procedure SQLite3_Interrupt(db: TSQLiteDB); cdecl; external SQLiteDLL name 'sqlite3_interrupt';
procedure SQLite3_BusyHandler(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer); cdecl; external SQLiteDLL name 'sqlite3_busy_handler';
procedure SQLite3_BusyTimeout(db: TSQLiteDB; TimeOut: integer); cdecl; external SQLiteDLL name 'sqlite3_busy_timeout';
function SQLite3_Changes(db: TSQLiteDB): integer; cdecl; external SQLiteDLL name 'sqlite3_changes';
function SQLite3_TotalChanges(db: TSQLiteDB): integer; cdecl; external SQLiteDLL name 'sqlite3_total_changes';
function SQLite3_Prepare(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl; external SQLiteDLL name 'sqlite3_prepare';
function SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl; external SQLiteDLL name 'sqlite3_prepare_v2';
function SQLite3_ColumnCount(hStmt: TSqliteStmt): integer; cdecl; external SQLiteDLL name 'sqlite3_column_count';
function SQLite3_ColumnName(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl; external SQLiteDLL name 'sqlite3_column_name';
function SQLite3_ColumnDeclType(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl; external SQLiteDLL name 'sqlite3_column_decltype';
function SQLite3_Step(hStmt: TSqliteStmt): integer; cdecl; external SQLiteDLL name 'sqlite3_step';
function SQLite3_DataCount(hStmt: TSqliteStmt): integer; cdecl; external SQLiteDLL name 'sqlite3_data_count';
function SQLite3_ColumnBlob(hStmt: TSqliteStmt; ColNum: integer): pointer; cdecl; external SQLiteDLL name 'sqlite3_column_blob';
function SQLite3_ColumnBytes(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl; external SQLiteDLL name 'sqlite3_column_bytes';
function SQLite3_ColumnDouble(hStmt: TSqliteStmt; ColNum: integer): double; cdecl; external SQLiteDLL name 'sqlite3_column_double';
function SQLite3_ColumnInt(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl; external SQLiteDLL name 'sqlite3_column_int';
function SQLite3_ColumnText(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl; external SQLiteDLL name 'sqlite3_column_text';
function SQLite3_ColumnType(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl; external SQLiteDLL name 'sqlite3_column_type';
function SQLite3_ColumnInt64(hStmt: TSqliteStmt; ColNum: integer): Int64; cdecl; external SQLiteDLL name 'sqlite3_column_int64';
function SQLite3_Finalize(hStmt: TSqliteStmt): integer; cdecl; external SQLiteDLL name 'sqlite3_finalize';
function SQLite3_Reset(hStmt: TSqliteStmt): integer; cdecl; external SQLiteDLL name 'sqlite3_reset';
}
function SQLite3_Open(filename: PAnsiChar; var db: TSQLiteDB): integer; cdecl;
function SQLite3_Close(db: TSQLiteDB): integer; cdecl;
function SQLite3_Exec(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer; cdecl;
function SQLite3_Version(): PAnsiChar; cdecl;
function SQLite3_ErrMsg(db: TSQLiteDB): PAnsiChar; cdecl;
function SQLite3_ErrCode(db: TSQLiteDB): integer; cdecl;
procedure SQlite3_Free(P: PAnsiChar); cdecl;
function SQLite3_GetTable(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer; cdecl;
procedure SQLite3_FreeTable(Table: TSQLiteResult); cdecl;
function SQLite3_Complete(P: PAnsiChar): boolean; cdecl;
function SQLite3_LastInsertRowID(db: TSQLiteDB): int64; cdecl;
procedure SQLite3_Interrupt(db: TSQLiteDB); cdecl;
procedure SQLite3_BusyHandler(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer); cdecl;
procedure SQLite3_BusyTimeout(db: TSQLiteDB; TimeOut: integer); cdecl;
function SQLite3_Changes(db: TSQLiteDB): integer; cdecl;
function SQLite3_TotalChanges(db: TSQLiteDB): integer; cdecl;
function SQLite3_Prepare(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl;
function SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl;
function SQLite3_ColumnCount(hStmt: TSqliteStmt): integer; cdecl;
function SQLite3_ColumnName(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
function SQLite3_ColumnDeclType(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
function SQLite3_Step(hStmt: TSqliteStmt): integer; cdecl;
function SQLite3_DataCount(hStmt: TSqliteStmt): integer; cdecl;
function SQLite3_ColumnBlob(hStmt: TSqliteStmt; ColNum: integer): pointer; cdecl;
function SQLite3_ColumnBytes(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
function SQLite3_ColumnDouble(hStmt: TSqliteStmt; ColNum: integer): double; cdecl;
function SQLite3_ColumnInt(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
function SQLite3_ColumnText(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
function SQLite3_ColumnType(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
function SQLite3_ColumnInt64(hStmt: TSqliteStmt; ColNum: integer): Int64; cdecl;
function SQLite3_Finalize(hStmt: TSqliteStmt): integer; cdecl;
function SQLite3_Reset(hStmt: TSqliteStmt): integer; cdecl;
//
// In the SQL strings input to sqlite3_prepare() and sqlite3_prepare16(),
// one or more literals can be replace by a wildcard "?" or ":N:" where
// N is an integer. These value of these wildcard literals can be set
// using the routines listed below.
//
// In every case, the first parameter is a pointer to the sqlite3_stmt
// structure returned from sqlite3_prepare(). The second parameter is the
// index of the wildcard. The first "?" has an index of 1. ":N:" wildcards
// use the index N.
//
// The fifth parameter to sqlite3_bind_blob(), sqlite3_bind_text(), and
//sqlite3_bind_text16() is a destructor used to dispose of the BLOB or
//text after SQLite has finished with it. If the fifth argument is the
// special value SQLITE_STATIC, then the library assumes that the information
// is in static, unmanaged space and does not need to be freed. If the
// fifth argument has the value SQLITE_TRANSIENT, then SQLite makes its
// own private copy of the data.
//
// The sqlite3_bind_* routine must be called before sqlite3_step() after
// an sqlite3_prepare() or sqlite3_reset(). Unbound wildcards are interpreted
// as NULL.
//
type
TSQLite3Destructor = procedure(Ptr: Pointer); cdecl;
{
function sqlite3_bind_blob(hStmt: TSqliteStmt; ParamNum: integer; ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer; cdecl; external SQLiteDLL name 'sqlite3_bind_blob';
function sqlite3_bind_text(hStmt: TSqliteStmt; ParamNum: integer; Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer; cdecl; external SQLiteDLL name 'sqlite3_bind_text';
function sqlite3_bind_double(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer; cdecl; external SQLiteDLL name 'sqlite3_bind_double';
function sqlite3_bind_int(hStmt: TSqLiteStmt; ParamNum: integer; Data: integer): integer; cdecl; external SQLiteDLL name 'sqlite3_bind_int';
function sqlite3_bind_int64(hStmt: TSqliteStmt; ParamNum: integer; Data: int64): integer; cdecl; external SQLiteDLL name 'sqlite3_bind_int64';
function sqlite3_bind_null(hStmt: TSqliteStmt; ParamNum: integer): integer; cdecl; external SQLiteDLL name 'sqlite3_bind_null';
function sqlite3_bind_parameter_index(hStmt: TSqliteStmt; zName: PAnsiChar): integer; cdecl; external SQLiteDLL name 'sqlite3_bind_parameter_index';
function sqlite3_enable_shared_cache(Value: integer): integer; cdecl; external SQLiteDLL name 'sqlite3_enable_shared_cache';
function SQLite3_create_collation(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer; UserData: pointer; xCompare: TCollateXCompare): integer; cdecl; external SQLiteDLL name 'sqlite3_create_collation';
}
function sqlite3_bind_blob(hStmt: TSqliteStmt; ParamNum: integer; ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer; cdecl;
function sqlite3_bind_text(hStmt: TSqliteStmt; ParamNum: integer; Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer; cdecl;
function sqlite3_bind_double(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer; cdecl;
function sqlite3_bind_int(hStmt: TSqLiteStmt; ParamNum: integer; Data: integer): integer; cdecl;
function sqlite3_bind_int64(hStmt: TSqliteStmt; ParamNum: integer; Data: int64): integer; cdecl;
function sqlite3_bind_null(hStmt: TSqliteStmt; ParamNum: integer): integer; cdecl;
function sqlite3_bind_parameter_index(hStmt: TSqliteStmt; zName: PAnsiChar): integer; cdecl;
function sqlite3_enable_shared_cache(Value: integer): integer; cdecl;
function SQLite3_create_collation(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer; UserData: pointer; xCompare: TCollateXCompare): integer; cdecl;
function SQLiteFieldType(SQLiteFieldTypeCode: Integer): AnsiString;
function SQLiteErrorStr(SQLiteErrorCode: Integer): AnsiString;
implementation
uses
SysUtils,
windows;
function sqlite3_bind_blob(hStmt: TSqliteStmt; ParamNum: integer; ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
var
xsqlite3_bind_blob: function(hStmt: TSqliteStmt; ParamNum: integer; ptrData: pointer; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer; cdecl;
begin
xsqlite3_bind_blob := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_bind_blob'));
Result := xsqlite3_bind_blob(hStmt, ParamNum, ptrData, numBytes, ptrDestructor);
end;
function sqlite3_bind_text(hStmt: TSqliteStmt; ParamNum: integer; Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer;
var
xsqlite3_bind_text: function(hStmt: TSqliteStmt; ParamNum: integer; Text: PAnsiChar; numBytes: integer; ptrDestructor: TSQLite3Destructor): integer; cdecl;
begin
xsqlite3_bind_text := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_bind_text'));
Result := xsqlite3_bind_text(hStmt, ParamNum, Text, numBytes, ptrDestructor);
end;
function sqlite3_bind_double(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer;
var
xsqlite3_bind_double: function(hStmt: TSqliteStmt; ParamNum: integer; Data: Double): integer; cdecl;
begin
xsqlite3_bind_double := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_bind_double'));
Result := xsqlite3_bind_double(hStmt, ParamNum, Data);
end;
function sqlite3_bind_int(hStmt: TSqLiteStmt; ParamNum: integer; Data: integer): integer;
var
xsqlite3_bind_int: function(hStmt: TSqLiteStmt; ParamNum: integer; Data: integer): integer; cdecl;
begin
xsqlite3_bind_int := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_bind_int'));
Result := xsqlite3_bind_int(hStmt, ParamNum, Data);
end;
function sqlite3_bind_int64(hStmt: TSqliteStmt; ParamNum: integer; Data: int64): integer;
var
xsqlite3_bind_int64: function(hStmt: TSqliteStmt; ParamNum: integer; Data: int64): integer; cdecl;
begin
xsqlite3_bind_int64 := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_bind_int64'));
Result := xsqlite3_bind_int64(hStmt, ParamNum, Data);
end;
function sqlite3_bind_null(hStmt: TSqliteStmt; ParamNum: integer): integer;
var
xsqlite3_bind_null: function(hStmt: TSqliteStmt; ParamNum: integer): integer; cdecl;
begin
xsqlite3_bind_null := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_bind_null'));
Result := xsqlite3_bind_null(hStmt, ParamNum);
end;
function sqlite3_bind_parameter_index(hStmt: TSqliteStmt; zName: PAnsiChar): integer;
var
xsqlite3_bind_parameter_index: function(hStmt: TSqliteStmt; zName: PAnsiChar): integer; cdecl;
begin
xsqlite3_bind_parameter_index := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_bind_parameter_index'));
Result := xsqlite3_bind_parameter_index(hStmt, zName);
end;
function sqlite3_enable_shared_cache(Value: integer): integer;
var
xsqlite3_enable_shared_cache: function(Value: integer): integer; cdecl;
begin
xsqlite3_enable_shared_cache := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_enable_shared_cache'));
Result := xsqlite3_enable_shared_cache(Value);
end;
function SQLite3_create_collation(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer; UserData: pointer; xCompare: TCollateXCompare): integer;
var
xSQLite3_create_collation: function(db: TSQLiteDB; Name: PAnsiChar; eTextRep: integer; UserData: pointer; xCompare: TCollateXCompare): integer; cdecl;
begin
xSQLite3_create_collation := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_create_collation'));
Result := xSQLite3_create_collation(db, Name, eTextRep, UserData, xCompare);
end;
function SQLite3_Open(filename: PAnsiChar; var db: TSQLiteDB): integer;
var
xSQLite3_Open: function(filename: PAnsiChar; var db: TSQLiteDB): integer; cdecl;
begin
xSQLite3_Open := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_open'));
Result := xSQLite3_Open(filename, db);
end;
function SQLite3_Close(db: TSQLiteDB): integer;
var
xSQLite3_Close: function(db: TSQLiteDB): integer; cdecl;
begin
xSQLite3_Close := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_close'));
Result := xSQLite3_Close(db);
end;
function SQLite3_Exec(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer;
var
xSQLite3_Exec: function(db: TSQLiteDB; SQLStatement: PAnsiChar; CallbackPtr: TSQLiteExecCallback; UserData: Pointer; var ErrMsg: PAnsiChar): integer; cdecl;
begin
xSQLite3_Exec := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_exec'));
Result := xSQLite3_Exec(db, SQLStatement, CallbackPtr, UserData, ErrMsg);
end;
function SQLite3_Version(): PAnsiChar;
var
xSQLite3_Version: function(): PAnsiChar; cdecl;
begin
xSQLite3_Version := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_libversion'));
Result := xSQLite3_Version();
end;
function SQLite3_ErrMsg(db: TSQLiteDB): PAnsiChar;
var
xSQLite3_ErrMsg: function(db: TSQLiteDB): PAnsiChar; cdecl;
begin
xSQLite3_ErrMsg := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_errmsg'));
Result := xSQLite3_ErrMsg(db);
end;
function SQLite3_ErrCode(db: TSQLiteDB): integer;
var
xSQLite3_ErrCode: function(db: TSQLiteDB): integer; cdecl;
begin
xSQLite3_ErrCode := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_errcode'));
Result := xSQLite3_ErrCode(db);
end;
procedure SQlite3_Free(P: PAnsiChar);
var
xSQlite3_Free: procedure(P: PAnsiChar); cdecl;
begin
xSQlite3_Free := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_free'));
xSQlite3_Free(P);
end;
function SQLite3_GetTable(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer;
var
xSQLite3_GetTable: function(db: TSQLiteDB; SQLStatement: PAnsiChar; var ResultPtr: TSQLiteResult; var RowCount: Cardinal; var ColCount: Cardinal; var ErrMsg: PAnsiChar): integer; cdecl;
begin
xSQLite3_GetTable := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_get_table'));
Result := xSQLite3_GetTable(db, SQLStatement, ResultPtr, RowCount, ColCount, ErrMsg);
end;
procedure SQLite3_FreeTable(Table: TSQLiteResult);
var
xSQLite3_FreeTable: procedure(Table: TSQLiteResult); cdecl;
begin
xSQLite3_FreeTable := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_free_table'));
xSQLite3_FreeTable(Table);
end;
function SQLite3_Complete(P: PAnsiChar): boolean;
var
xSQLite3_Complete: function(P: PAnsiChar): boolean; cdecl;
begin
xSQLite3_Complete := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_complete'));
Result := xSQLite3_Complete(P);
end;
function SQLite3_LastInsertRowID(db: TSQLiteDB): int64;
var
xSQLite3_LastInsertRowID: function(db: TSQLiteDB): int64; cdecl;
begin
xSQLite3_LastInsertRowID := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_last_insert_rowid'));
Result := xSQLite3_LastInsertRowID(db);
end;
procedure SQLite3_Interrupt(db: TSQLiteDB);
var
xSQLite3_Interrupt: procedure(db: TSQLiteDB); cdecl;
begin
xSQLite3_Interrupt := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_interrupt'));
xSQLite3_Interrupt(db);
end;
procedure SQLite3_BusyHandler(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer);
var
xSQLite3_BusyHandler: procedure(db: TSQLiteDB; CallbackPtr: TSQLiteBusyHandlerCallback; UserData: Pointer); cdecl;
begin
xSQLite3_BusyHandler := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_busy_handler'));
xSQLite3_BusyHandler(db, CallbackPtr, UserData);
end;
procedure SQLite3_BusyTimeout(db: TSQLiteDB; TimeOut: integer);
var
xSQLite3_BusyTimeout: procedure(db: TSQLiteDB; TimeOut: integer); cdecl;
begin
xSQLite3_BusyTimeout := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_busy_timeout'));
xSQLite3_BusyTimeout(db, TimeOut);
end;
function SQLite3_Changes(db: TSQLiteDB): integer;
var
xSQLite3_Changes: function(db: TSQLiteDB): integer; cdecl;
begin
xSQLite3_Changes := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_changes'));
Result := xSQLite3_Changes(db);
end;
function SQLite3_TotalChanges(db: TSQLiteDB): integer;
var
xSQLite3_TotalChanges: function(db: TSQLiteDB): integer; cdecl;
begin
xSQLite3_TotalChanges := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_total_changes'));
Result := xSQLite3_TotalChanges(db);
end;
function SQLite3_Prepare(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
var
xSQLite3_Prepare: function(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl;
begin
xSQLite3_Prepare := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_prepare'));
Result := xSQLite3_Prepare(db, SQLStatement, nBytes, hStmt, pzTail);
end;
function SQLite3_Prepare_v2(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer;
var
xSQLite3_Prepare_v2: function(db: TSQLiteDB; SQLStatement: PAnsiChar; nBytes: integer; var hStmt: TSqliteStmt; var pzTail: PAnsiChar): integer; cdecl;
begin
xSQLite3_Prepare_v2 := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_prepare_v2'));
Result := xSQLite3_Prepare_v2(db, SQLStatement, nBytes, hStmt, pzTail);
end;
function SQLite3_ColumnCount(hStmt: TSqliteStmt): integer;
var
xSQLite3_ColumnCount: function(hStmt: TSqliteStmt): integer; cdecl;
begin
xSQLite3_ColumnCount := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_column_count'));
Result := xSQLite3_ColumnCount(hStmt);
end;
function SQLite3_ColumnName(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
var
xSQLite3_ColumnName: function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
begin
xSQLite3_ColumnName := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_column_name'));
Result := xSQLite3_ColumnName(hStmt, ColNum);
end;
function SQLite3_ColumnDeclType(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
var
xSQLite3_ColumnDeclType: function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
begin
xSQLite3_ColumnDeclType := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_column_decltype'));
Result := xSQLite3_ColumnDeclType(hStmt, ColNum);
end;
function SQLite3_Step(hStmt: TSqliteStmt): integer;
var
xSQLite3_Step: function(hStmt: TSqliteStmt): integer; cdecl;
begin
xSQLite3_Step := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_step'));
Result := xSQLite3_Step(hStmt);
end;
function SQLite3_DataCount(hStmt: TSqliteStmt): integer;
var
xSQLite3_DataCount: function(hStmt: TSqliteStmt): integer; cdecl;
begin
xSQLite3_DataCount := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_data_count'));
Result := xSQLite3_DataCount(hStmt);
end;
function SQLite3_ColumnBlob(hStmt: TSqliteStmt; ColNum: integer): pointer;
var
xSQLite3_ColumnBlob: function(hStmt: TSqliteStmt; ColNum: integer): pointer; cdecl;
begin
xSQLite3_ColumnBlob := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_column_blob'));
Result := xSQLite3_ColumnBlob(hStmt, ColNum);
end;
function SQLite3_ColumnBytes(hStmt: TSqliteStmt; ColNum: integer): integer;
var
xSQLite3_ColumnBytes: function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
begin
xSQLite3_ColumnBytes := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_column_bytes'));
Result := xSQLite3_ColumnBytes(hStmt, ColNum);
end;
function SQLite3_ColumnDouble(hStmt: TSqliteStmt; ColNum: integer): double;
var
xSQLite3_ColumnDouble: function(hStmt: TSqliteStmt; ColNum: integer): double; cdecl;
begin
xSQLite3_ColumnDouble := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_column_double'));
Result := xSQLite3_ColumnDouble(hStmt, ColNum);
end;
function SQLite3_ColumnInt(hStmt: TSqliteStmt; ColNum: integer): integer;
var
xSQLite3_ColumnInt: function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
begin
xSQLite3_ColumnInt := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_column_int'));
Result := xSQLite3_ColumnInt(hStmt, ColNum);
end;
function SQLite3_ColumnText(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar;
var
xSQLite3_ColumnText: function(hStmt: TSqliteStmt; ColNum: integer): PAnsiChar; cdecl;
begin
xSQLite3_ColumnText := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_column_text'));
Result := xSQLite3_ColumnText(hStmt, ColNum);
end;
function SQLite3_ColumnType(hStmt: TSqliteStmt; ColNum: integer): integer;
var
xSQLite3_ColumnType: function(hStmt: TSqliteStmt; ColNum: integer): integer; cdecl;
begin
xSQLite3_ColumnType := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_column_type'));
Result := xSQLite3_ColumnType(hStmt, ColNum);
end;
function SQLite3_ColumnInt64(hStmt: TSqliteStmt; ColNum: integer): Int64;
var
xSQLite3_ColumnInt64: function(hStmt: TSqliteStmt; ColNum: integer): Int64; cdecl;
begin
xSQLite3_ColumnInt64 := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_column_int64'));
Result := xSQLite3_ColumnInt64(hStmt, ColNum);
end;
function SQLite3_Finalize(hStmt: TSqliteStmt): integer;
var
xSQLite3_Finalize: function(hStmt: TSqliteStmt): integer; cdecl;
begin
xSQLite3_Finalize := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_finalize'));
Result := xSQLite3_Finalize(hStmt);
end;
function SQLite3_Reset(hStmt: TSqliteStmt): integer;
var
xSQLite3_Reset: function(hStmt: TSqliteStmt): integer; cdecl;
begin
xSQLite3_Reset := GetProcAddress(LoadLibrary(pchar(MerdaDLL)), pchar('sqlite3_reset'));
Result := xSQLite3_Reset(hStmt);
end;
function SQLiteFieldType(SQLiteFieldTypeCode: Integer): AnsiString;
begin
case SQLiteFieldTypeCode of
SQLITE_INTEGER: Result := 'Integer';
SQLITE_FLOAT: Result := 'Float';
SQLITE_TEXT: Result := 'Text';
SQLITE_BLOB: Result := 'Blob';
SQLITE_NULL: Result := 'Null';
else
Result := 'Unknown SQLite Field Type Code "' + IntToStr(SQLiteFieldTypeCode) + '"';
end;
end;
function SQLiteErrorStr(SQLiteErrorCode: Integer): AnsiString;
begin
case SQLiteErrorCode of
SQLITE_OK: Result := 'Successful result';
SQLITE_ERROR: Result := 'SQL error or missing database';
SQLITE_INTERNAL: Result := 'An internal logic error in SQLite';
SQLITE_PERM: Result := 'Access permission denied';
SQLITE_ABORT: Result := 'Callback routine requested an abort';
SQLITE_BUSY: Result := 'The database file is locked';
SQLITE_LOCKED: Result := 'A table in the database is locked';
SQLITE_NOMEM: Result := 'A malloc() failed';
SQLITE_READONLY: Result := 'Attempt to write a readonly database';
SQLITE_INTERRUPT: Result := 'Operation terminated by sqlite3_interrupt()';
SQLITE_IOERR: Result := 'Some kind of disk I/O error occurred';
SQLITE_CORRUPT: Result := 'The database disk image is malformed';
SQLITE_NOTFOUND: Result := '(Internal Only) Table or record not found';
SQLITE_FULL: Result := 'Insertion failed because database is full';
SQLITE_CANTOPEN: Result := 'Unable to open the database file';
SQLITE_PROTOCOL: Result := 'Database lock protocol error';
SQLITE_EMPTY: Result := 'Database is empty';
SQLITE_SCHEMA: Result := 'The database schema changed';
SQLITE_TOOBIG: Result := 'Too much data for one row of a table';
SQLITE_CONSTRAINT: Result := 'Abort due to contraint violation';
SQLITE_MISMATCH: Result := 'Data type mismatch';
SQLITE_MISUSE: Result := 'Library used incorrectly';
SQLITE_NOLFS: Result := 'Uses OS features not supported on host';
SQLITE_AUTH: Result := 'Authorization denied';
SQLITE_FORMAT: Result := 'Auxiliary database format error';
SQLITE_RANGE: Result := '2nd parameter to sqlite3_bind out of range';
SQLITE_NOTADB: Result := 'File opened that is not a database file';
SQLITE_ROW: Result := 'sqlite3_step() has another row ready';
SQLITE_DONE: Result := 'sqlite3_step() has finished executing';
else
Result := 'Unknown SQLite Error Code "' + IntToStr(SQLiteErrorCode) + '"';
end;
end;
function ColValueToStr(Value: PAnsiChar): AnsiString;
begin
if (Value = nil) then
Result := 'NULL'
else
Result := Value;
end;
end.