-
-
Notifications
You must be signed in to change notification settings - Fork 324
/
SynSQLite3.pas
5979 lines (5526 loc) · 270 KB
/
SynSQLite3.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
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/// SQLite3 Database engine direct access
// - this unit is a part of the freeware Synopse mORMot framework,
// licensed under a MPL/GPL/LGPL tri-license; version 1.18
unit SynSQLite3;
{
This file is part of Synopse mORMot framework.
Synopse mORMot framework. Copyright (c) Arnaud Bouchez
Synopse Informatique - https://synopse.info
*** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.
The Original Code is Synopse mORMot framework.
The Initial Developer of the Original Code is Arnaud Bouchez.
Portions created by the Initial Developer are Copyright (c)
the Initial Developer. All Rights Reserved.
Contributor(s):
- Alfred Glaenzer (alf)
- Eric Grange
- Vaclav
Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****
SQLite3 3.46.1 database engine
********************************
Brand new SQLite3 library to be used with Delphi/FPC
- FLEXIBLE: in process, local or remote access (JSON RESTFUL HTTP server)
- STANDARD: full UTF-8 and Unicode, SQLite3 engine (enhanced but not hacked)
- SECURE: tested, multi-thread oriented, atomic commit, encryption ready
- SIMPLE: staticaly linked into a single Delphi unit (via SynSQLite3Static)
or standard external dll - via TSQLite3LibraryDynamic
- LIGHT: use native classes, not TDataSet nor TDataSource
- SMART: queries share a JSON-based memory cache for immediate response
- FAST: tuned pascal and i386 assembler code with use of FastMM4/SynScaleMM
- FREE: full source code provided, with permissive licence
- unitary tested with provided regression tests
- includes RTREE extension for doing very fast range queries
- can include FTS3 full text search engine (MATCH operator) after sqlite3.c
recompile (by default, FTS3 is not compiled, saving more than 50KB of code)
- uses only newest API (sqlite3_prepare_v2) and follow SQLite3 official documentation
- uses purely UTF-8 encoded strings: Ansi/Unicode conversion routines included,
Delphi 2009 ready (but Unicode works very well with older Delphi versions)
- optional on the fly fast encryption of the data on disk
- use an optional and efficient caching mechanism (TSynCache based) for the
most used SELECT statements, using our TSQLTableJSON as fast data source
- record retrieval from its ID is speed up via SQL statement preparation
- uses ISO 8601:2004 format to properly handle date/time values in TEXT field
- can be easily updated from official SQLite3 source code (see comments in
the source code of this unit)
- compiled without thread mutex: the caller has to be thread-safe aware
(this is faster on most configuration, since mutex has to be acquired once):
low level sqlite3_*() functions are not thread-safe, as TSQLRequest and
TSQLBlobStream which just wrap them; but TSQLDataBase is thread-safe, as
mORMot's TSQLTableDB/TSQLRestServerDB/TSQLRestClientDB which use TSQLDataBase
- compiled with SQLITE_OMIT_SHARED_CACHE define
- compatible with our LVCL 'Very LIGHT VCL routines' framework
for building light but fast GUI servers software
}
{$I Synopse.inc} // define HASINLINE CPU32 CPU64 OWNNORMTOUPPER
interface
uses
{$ifdef MSWINDOWS}
Windows,
{$ifdef FPC}
dynlibs,
{$endif}
{$else}
{$ifdef KYLIX3}
LibC,
SyncObjs,
SynKylix,
{$endif}
{$ifdef FPC}
{$ifdef Linux}
SynFPCLinux,
{$ifdef BSDNOTDARWIN}
dl,
{$else}
DynLibs,
{$endif}
{$endif}
{$endif}
{$endif}
SysUtils,
Classes,
{$ifndef LVCL}
Contnrs,
{$endif}
SynCommons,
SynTable,
SynLog;
{ ************ direct access to sqlite3.c / sqlite3.obj consts and functions }
{$ifdef BSD}
{$linklib c}
{$linklib pthread}
{$endif}
{$ifdef FPC}
{$packrecords C}
{$packenum 4}
{$endif}
type
/// internaly store the SQLite3 database handle
TSQLite3DB = type PtrUInt;
/// internaly store the SQLite3 statement handle
// - This object is variously known as a "prepared statement" or a "compiled
// SQL statement" or simply as a "statement".
// - Create the object using sqlite3.prepare_v2() or a related function.
// - Bind values to host parameters using the sqlite3.bind_*() interfaces.
// - Run the SQL by calling sqlite3.step() one or more times.
// - Reset the statement using sqlite3.reset() then go back to "Bind" step.
// Do this zero or more times.
// - Destroy the object using sqlite3.finalize().
TSQLite3Statement = type PtrUInt;
/// internaly store the SQLite3 blob handle
TSQLite3Blob = type PtrUInt;
/// internaly store a SQLite3 Dynamically Typed Value Object
// - SQLite uses the sqlite3.value object to represent all values that
// can be stored in a database table, which are mapped to this TSQLite3Value type
// - SQLite uses dynamic typing for the values it stores
// - Values stored in sqlite3.value objects can be integers, floating point
// values, strings, BLOBs, or NULL
TSQLite3Value = type PtrUInt;
/// internal store a SQLite3 Function Context Object
// - The context in which an SQL function executes is stored in an sqlite3.context
// object, which is mapped to this TSQLite3FunctionContext type
// - A pointer to an sqlite3.context object is always first parameter to
// application-defined SQL functions, i.e. a TSQLFunctionFunc prototype
TSQLite3FunctionContext = type PtrUInt;
/// internaly store a SQLite3 Backup process handle
TSQLite3Backup = type PtrUInt;
/// internaly store of SQLite3 values, as used by TSQLFunctionFunc
TSQLite3ValueArray = array[0..63] of TSQLite3Value;
const
{$ifdef MSWINDOWS}
{$ifdef CPU64}
// see https://synopse.info/files/SQLite3-64.7z
SQLITE_LIBRARY_DEFAULT_NAME = 'sqlite3-64.dll';
{$else}
SQLITE_LIBRARY_DEFAULT_NAME = 'sqlite3.dll';
{$endif}
{$else}
{$ifdef Linux}
{$ifdef Android}
SQLITE_LIBRARY_DEFAULT_NAME = 'libsqlite.so';
{$else}
{$ifdef Darwin}
SQLITE_LIBRARY_DEFAULT_NAME = 'libsqlite3.dylib';
{$else}
SQLITE_LIBRARY_DEFAULT_NAME = 'libsqlite3.so.0';
{$endif}
{$endif}
{$else}
SQLITE_LIBRARY_DEFAULT_NAME = 'libsqlite3.so';
{$endif}
{$endif}
/// internal SQLite3 type as Integer
SQLITE_INTEGER = 1;
/// internal SQLite3 type as Floating point value
SQLITE_FLOAT = 2;
/// internal SQLite3 type as Text
SQLITE_TEXT = 3;
/// internal SQLite3 type as Blob
SQLITE_BLOB = 4;
/// internal SQLite3 type as NULL
SQLITE_NULL = 5;
/// text is UTF-8 encoded
SQLITE_UTF8 = 1;
/// text is UTF-16 LE encoded
SQLITE_UTF16LE = 2;
/// text is UTF-16 BE encoded
SQLITE_UTF16BE = 3;
/// text is UTF-16 encoded, using the system native byte order
SQLITE_UTF16 = 4;
/// sqlite3.create_function don't care about text encoding
SQLITE_ANY = 5;
/// used by sqlite3.create_collation() only
SQLITE_UTF16_ALIGNED = 8;
/// sqlite_exec() return code: no error occured
SQLITE_OK = 0;
/// sqlite_exec() return code: SQL error or missing database - legacy generic code
SQLITE_ERROR = 1;
/// sqlite_exec() return code: An internal logic error in SQLite
SQLITE_INTERNAL = 2;
/// sqlite_exec() return code: Access permission denied
SQLITE_PERM = 3;
/// sqlite_exec() return code: Callback routine requested an abort
SQLITE_ABORT = 4;
/// sqlite_exec() return code: The database file is locked
SQLITE_BUSY = 5;
/// sqlite_exec() return code: A table in the database is locked
SQLITE_LOCKED = 6;
/// sqlite_exec() return code: A malloc() failed
SQLITE_NOMEM = 7;
/// sqlite_exec() return code: Attempt to write a readonly database
SQLITE_READONLY = 8;
/// sqlite_exec() return code: Operation terminated by sqlite3.interrupt()
SQLITE_INTERRUPT = 9;
/// sqlite_exec() return code: Some kind of disk I/O error occurred
SQLITE_IOERR = 10;
/// sqlite_exec() return code: The database disk image is malformed
SQLITE_CORRUPT = 11;
/// sqlite_exec() return code: (Internal Only) Table or record not found
SQLITE_NOTFOUND = 12;
/// sqlite_exec() return code: Insertion failed because database is full
SQLITE_FULL = 13;
/// sqlite_exec() return code: Unable to open the database file
SQLITE_CANTOPEN = 14;
/// sqlite_exec() return code: (Internal Only) Database lock protocol error
SQLITE_PROTOCOL = 15;
/// sqlite_exec() return code: Database is empty
SQLITE_EMPTY = 16;
/// sqlite_exec() return code: The database schema changed, and unable to be recompiled
SQLITE_SCHEMA = 17;
/// sqlite_exec() return code: Too much data for one row of a table
SQLITE_TOOBIG = 18;
/// sqlite_exec() return code: Abort due to contraint violation
SQLITE_CONSTRAINT = 19;
/// sqlite_exec() return code: Data type mismatch
SQLITE_MISMATCH = 20;
/// sqlite_exec() return code: Library used incorrectly
SQLITE_MISUSE = 21;
/// sqlite_exec() return code: Uses OS features not supported on host
SQLITE_NOLFS = 22;
/// sqlite_exec() return code: Authorization denied
SQLITE_AUTH = 23;
/// sqlite_exec() return code: Auxiliary database format error
SQLITE_FORMAT = 24;
/// sqlite_exec() return code: 2nd parameter to sqlite3.bind out of range
SQLITE_RANGE = 25;
/// sqlite_exec() return code: File opened that is not a database file
SQLITE_NOTADB = 26;
/// sqlite3.step() return code: another result row is ready
SQLITE_ROW = 100;
/// sqlite3.step() return code: has finished executing
SQLITE_DONE = 101;
/// possible error codes for sqlite_exec() and sqlite3.step()
// - as verified by sqlite3_check()
SQLITE_ERRORS = [SQLITE_ERROR..SQLITE_ROW-1];
/// The database is opened in read-only mode
// - if the database does not already exist, an error is returned
// - Ok for sqlite3.open_v2()
SQLITE_OPEN_READONLY = $00000001;
/// The database is opened for reading and writing if possible, or reading
// only if the file is write protected by the operating system
// - In either case the database must already exist, otherwise an error is
// returned
// - Ok for sqlite3.open_v2()
SQLITE_OPEN_READWRITE = $00000002;
/// In conjunction with SQLITE_OPEN_READWRITE, optionally create the database
// file if it does not exist
// - The database is opened for reading and writing if possible, or reading
// only if the file is write protected by the operating system
// - In either case the database must already exist, otherwise an error is returned
SQLITE_OPEN_CREATE = $00000004;
/// URI filename interpretation is enabled if the SQLITE_OPEN_URI flag is set
// in the fourth argument to sqlite3.open_v2(), or if it has been enabled
// globally using the SQLITE_CONFIG_URI option with the sqlite3.config() method
// or by the SQLITE_USE_URI compile-time option.
// - As of SQLite version 3.7.7, URI filename interpretation is turned off by
// default, but future releases of SQLite might enable URI filename
// interpretation by default
// - Ok for sqlite3.open_v2(), in conjuction with SQLITE_OPEN_READONLY,
// SQLITE_OPEN_READWRITE, (SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE)
SQLITE_OPEN_URI = $00000040; // Ok for sqlite3_open_v2()
/// If the SQLITE_OPEN_NOMUTEX flag is set, then the database will remain in
// memory
// - Ok for sqlite3.open_v2(), in conjuction with SQLITE_OPEN_READONLY,
// SQLITE_OPEN_READWRITE, (SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE)
SQLITE_OPEN_MEMORY = $00000080; // Ok for sqlite3_open_v2()
/// If the SQLITE_OPEN_NOMUTEX flag is set, then the database connection opens
// in the multi-thread threading mode as long as the single-thread mode has
// not been set at compile-time or start-time
// - Ok for sqlite3.open_v2(), in conjuction with SQLITE_OPEN_READONLY,
// SQLITE_OPEN_READWRITE, (SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE)
SQLITE_OPEN_NOMUTEX = $00008000; // Ok for sqlite3_open_v2()
/// If the SQLITE_OPEN_FULLMUTEX flag is set then the database connection opens
// in the serialized threading mode unless single-thread was previously selected
// at compile-time or start-time
// - Ok for sqlite3.open_v2(), in conjuction with SQLITE_OPEN_READONLY,
// SQLITE_OPEN_READWRITE, (SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE)
SQLITE_OPEN_FULLMUTEX = $00010000; // Ok for sqlite3_open_v2()
/// The SQLITE_OPEN_SHAREDCACHE flag causes the database connection to be
// eligible to use shared cache mode, regardless of whether or not shared
// cache is enabled using sqlite3.enable_shared_cache()
// - Ok for sqlite3.open_v2(), in conjuction with SQLITE_OPEN_READONLY,
// SQLITE_OPEN_READWRITE, (SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE)
SQLITE_OPEN_SHAREDCACHE = $00020000; // Ok for sqlite3_open_v2()
/// The SQLITE_OPEN_PRIVATECACHE flag causes the database connection to not
// participate in shared cache mode even if it is enabled
// - Ok for sqlite3.open_v2(), in conjuction with SQLITE_OPEN_READONLY,
// SQLITE_OPEN_READWRITE, (SQLITE_OPEN_READWRITE or SQLITE_OPEN_CREATE)
SQLITE_OPEN_PRIVATECACHE = $00040000;
{
SQLITE_OPEN_DELETEONCLOSE = $00000008; // VFS only
SQLITE_OPEN_EXCLUSIVE = $00000010; // VFS only
SQLITE_OPEN_AUTOPROXY = $00000020; // VFS only
SQLITE_OPEN_MAIN_DB = $00000100; // VFS only
SQLITE_OPEN_TEMP_DB = $00000200; // VFS only
SQLITE_OPEN_TRANSIENT_DB = $00000400; // VFS only
SQLITE_OPEN_MAIN_JOURNAL = $00000800; // VFS only
SQLITE_OPEN_TEMP_JOURNAL = $00001000; // VFS only
SQLITE_OPEN_SUBJOURNAL = $00002000; // VFS only
SQLITE_OPEN_MASTER_JOURNAL = $00004000; // VFS only
SQLITE_OPEN_WAL = $00080000; // VFS only
}
/// DestroyPtr set to SQLITE_STATIC if data is constant and will never change
// - SQLite assumes that the text or BLOB result is in constant space and
// does not copy the content of the parameter nor call a destructor on the
// content when it has finished using that result
SQLITE_STATIC = pointer(0);
/// DestroyPtr set to SQLITE_TRANSIENT for SQLite3 to make a private copy of
// the data into space obtained from from sqlite3.malloc() before it returns
// - this is the default behavior in our framework
// - note that we discovered that under Win64, sqlite3.result_text() expects
// SQLITE_TRANSIENT_VIRTUALTABLE=pointer(integer(-1)) and not pointer(-1)
SQLITE_TRANSIENT = pointer(-1);
/// DestroyPtr set to SQLITE_TRANSIENT_VIRTUALTABLE for setting results to
// SQlite3 virtual tables columns
// - due to a bug of the SQlite3 engine under Win64
SQLITE_TRANSIENT_VIRTUALTABLE = pointer(integer(-1));
/// pseudo database file name used to create an in-memory database
// - an SQLite database is normally stored in a single ordinary disk file -
// however, in certain circumstances, the database might be stored in memory,
// if you pass SQLITE_MEMORY_DATABASE_NAME to TSQLDatabase.Create() instead of
// a real disk file name
// - this instance will cease to exist as soon as the database connection
// is closed, i.e. when calling TSQLDatabase.Free
// - every ':memory:' database is distinct from every other - so, creating two
// TSQLDatabase instances each with the filename SQLITE_MEMORY_DATABASE_NAME
// will create two independent in-memory databases
SQLITE_MEMORY_DATABASE_NAME = ':memory:';
SQLITE_CONFIG_SINGLETHREAD = 1;
SQLITE_CONFIG_MULTITHREAD = 2;
SQLITE_CONFIG_SERIALIZED = 3;
SQLITE_CONFIG_MALLOC = 4;
SQLITE_CONFIG_GETMALLOC = 5;
SQLITE_CONFIG_SCRATCH = 6;
SQLITE_CONFIG_PAGECACHE = 7;
SQLITE_CONFIG_HEAP = 8;
SQLITE_CONFIG_MEMSTATUS = 9;
SQLITE_CONFIG_MUTEX = 10;
SQLITE_CONFIG_GETMUTEX = 11;
SQLITE_CONFIG_LOOKASIDE = 13;
SQLITE_CONFIG_PCACHE = 14;
SQLITE_CONFIG_GETPCACHE = 15;
SQLITE_CONFIG_LOG = 16;
SQLITE_CONFIG_URI = 17;
SQLITE_CONFIG_PCACHE2 = 18;
SQLITE_CONFIG_GETPCACHE2 = 19;
SQLITE_CONFIG_COVERING_INDEX_SCAN = 20;
SQLITE_CONFIG_SQLLOG = 21;
SQLITE_CONFIG_MMAP_SIZE = 22;
SQLITE_CONFIG_WIN32_HEAPSIZE = 23;
SQLITE_DBCONFIG_LOOKASIDE = 1001;
SQLITE_DBCONFIG_ENABLE_FKEY = 1002;
SQLITE_DBCONFIG_ENABLE_TRIGGER = 1003;
SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER = 1004;
SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION = 1005;
type
/// type for a custom destructor for the text or BLOB content
// - set to @sqlite3InternalFree if a Value must be released via Freemem()
// - set to @sqlite3InternalFreeObject if a Value must be released via
// TObject(p).Free
TSQLDestroyPtr = procedure(p: pointer); cdecl;
/// SQLite3 collation (i.e. sort and comparison) function prototype
// - this function MUST use s1Len and s2Len parameters during the comparison:
// s1 and s2 are not zero-terminated
// - used by sqlite3.create_collation low-level function
TSQLCollateFunc = function(CollateParam: pointer; s1Len: integer; s1: pointer;
s2Len: integer; s2: pointer) : integer; cdecl;
/// SQLite3 user function or aggregate callback prototype
// - argc is the number of supplied parameters, which are available in argv[]
// (you can call ErrorWrongNumberOfArgs(Context) in case of unexpected number)
// - use sqlite3.value_*(argv[*]) functions to retrieve a parameter value
// - then set the result using sqlite3.result_*(Context,*) functions
TSQLFunctionFunc = procedure(Context: TSQLite3FunctionContext;
argc: integer; var argv: TSQLite3ValueArray); cdecl;
/// SQLite3 user final aggregate callback prototype
TSQLFunctionFinal = procedure(Context: TSQLite3FunctionContext); cdecl;
/// SQLite3 callback prototype to handle SQLITE_BUSY errors
// - The first argument to the busy handler is a copy of the user pointer which
// is the third argument to sqlite3.busy_handler().
// - The second argument to the busy handler callback is the number of times
// that the busy handler has been invoked for this locking event.
// - If the busy callback returns 0, then no additional attempts are made to
// access the database and SQLITE_BUSY or SQLITE_IOERR_BLOCKED is returned.
// - If the callback returns non-zero, then another attempt is made to open
// the database for reading and the cycle repeats.
TSQLBusyHandler = function(user: pointer; count: integer): integer;
cdecl;
PFTSMatchInfo = ^TFTSMatchInfo;
/// map the matchinfo function returned BLOB value
// - i.e. the default 'pcx' layout, for both FTS3 and FTS4
// - see http://www.sqlite.org/fts3.html#matchinfo
// - used for the FTS3/FTS4 ranking of results by TSQLRest.FTSMatch method
// and the internal RANK() function as proposed in
// http://www.sqlite.org/fts3.html#appendix_a
TFTSMatchInfo = packed record
nPhrase: integer;
nCol: integer;
hits: array[1..9] of record
this_row: integer;
all_rows: integer;
docs_with_hits: integer;
end;
end;
PSQLite3Module = ^TSQLite3Module;
PSQLite3VTab = ^TSQLite3VTab;
PSQLite3VTabCursor = ^TSQLite3VTabCursor;
/// records WHERE clause constraints of the form "column OP expr"
// - Where "column" is a column in the virtual table, OP is an operator like
// "=" or "<", and EXPR is an arbitrary expression
// - So, for example, if the WHERE clause contained a term like this:
// $ a = 5
// Then one of the constraints would be on the "a" column with operator "="
// and an expression of "5"
// - For example, if the WHERE clause contained something like this:
// $ x BETWEEN 10 AND 100 AND 999>y
// The query optimizer might translate this into three separate constraints:
// ! x >= 10
// ! x <= 100
// ! y < 999
TSQLite3IndexConstraint = record
/// Column on left-hand side of constraint
// - The first column of the virtual table is column 0
// - The ROWID of the virtual table is column -1
// - Hidden columns are counted when determining the column index.
iColumn: integer;
/// Constraint operator
// - OP is =, <, <=, >, or >= using one of the SQLITE_INDEX_CONSTRAINT_* values
op: byte;
/// True if this constraint is usable
// - The aConstraint[] array contains information about all constraints that
// apply to the virtual table. But some of the constraints might not be usable
// because of the way tables are ordered in a join. The xBestIndex method
// must therefore only consider constraints that have a usable flag which is
// true, and just ignore contraints with usable set to false
usable: bytebool;
/// Used internally - xBestIndex() should ignore this field
iTermOffset: integer;
end;
PSQLite3IndexConstraintArray = ^TSQLite3IndexConstraintArray;
TSQLite3IndexConstraintArray = array[0..MaxInt div SizeOf(TSQLite3IndexConstraint)-1] of TSQLite3IndexConstraint;
/// ORDER BY clause, one item per column
TSQLite3IndexOrderBy = record
/// Column number
// - The first column of the virtual table is column 0
// - The ROWID of the virtual table is column -1
// - Hidden columns are counted when determining the column index.
iColumn: integer;
/// True for DESC. False for ASC.
desc: bytebool;
end;
PSQLite3IndexOrderByArray = ^TSQLite3IndexOrderByArray;
TSQLite3IndexOrderByArray = array[0..MaxInt div SizeOf(TSQLite3IndexOrderBy)-1] of TSQLite3IndexOrderBy;
/// define what information is to be passed to xFilter() for a given WHERE
// clause constraint of the form "column OP expr"
TSQLite3IndexConstraintUsage = record
/// If argvIndex>0 then the right-hand side of the corresponding
// aConstraint[] is evaluated and becomes the argvIndex-th entry in argv
// - Exactly one entry should be set to 1, another to 2, another to 3, and
// so forth up to as many or as few as the xBestIndex() method wants.
// - The EXPR of the corresponding constraints will then be passed in as
// the argv[] parameters to xFilter()
// - For example, if the aConstraint[3].argvIndex is set to 1, then when
// xFilter() is called, the argv[0] passed to xFilter will have the EXPR
// value of the aConstraint[3] constraint.
argvIndex: Integer;
/// If omit is true, then the constraint is assumed to be fully handled
// by the virtual table and is not checked again by SQLite
// - By default, the SQLite core double checks all constraints on each
// row of the virtual table that it receives. If such a check is redundant,
// xBestFilter() method can suppress that double-check by setting this field
omit: bytebool;
end;
PSQLite3IndexConstraintUsageArray = ^TSQLite3IndexConstraintUsageArray;
TSQLite3IndexConstraintUsageArray = array[0..MaxInt div SizeOf(TSQLite3IndexConstraintUsage) - 1] of TSQLite3IndexConstraintUsage;
/// Structure used as part of the virtual table interface to pass information
// into and receive the reply from the xBestIndex() method of a virtual table module
// - Outputs fields will be passed as parameter to the xFilter() method, and
// will be initialized to zero by SQLite
// - For instance, xBestIndex() method fills the idxNum and idxStr fields with
// information that communicates an indexing strategy to the xFilter method.
// The information in idxNum and idxStr is arbitrary as far as the SQLite core
// is concerned. The SQLite core just copies the information through to the
// xFilter() method. Any desired meaning can be assigned to idxNum and idxStr
// as long as xBestIndex() and xFilter() agree on what that meaning is.
// Use the SetInfo() method of this object in order to make a temporary copy
// of any needed data.
TSQLite3IndexInfo = record
/// input: Number of entries in aConstraint array
nConstraint: integer;
/// input: List of WHERE clause constraints of the form "column OP expr"
aConstraint: PSQLite3IndexConstraintArray;
/// input: Number of terms in the aOrderBy array
nOrderBy: integer;
/// input: List of ORDER BY clause, one per column
aOrderBy: PSQLite3IndexOrderByArray;
/// output: filled by xBestIndex() method with information about what
// parameters to pass to xFilter() method
// - has the same number of items than the aConstraint[] array
// - should set the aConstraintUsage[].argvIndex to have the corresponding
// argument in xFilter() argc/argv[] expression list
aConstraintUsage: PSQLite3IndexConstraintUsageArray;
/// output: Number used to identify the index
idxNum: integer;
/// output: String, possibly obtained from sqlite3.malloc()
// - may contain any variable-length data or class/record content, as
// necessary
idxStr: PAnsiChar;
/// output: Free idxStr using sqlite3.free() if true (=1)
needToFreeIdxStr: integer;
/// output: True (=1) if output is already ordered
// - i.e. if the virtual table will output rows in the order specified
// by the ORDER BY clause
// - if False (=0), will indicate to the SQLite core that it will need to
// do a separate sorting pass over the data after it comes out
// of the virtual table
orderByConsumed: integer;
/// output: Estimated cost of using this index
// - Should be set to the estimated number of disk access operations
// required to execute this query against the virtual table
// - The SQLite core will often call xBestIndex() multiple times with
// different constraints, obtain multiple cost estimates, then choose the
// query plan that gives the lowest estimate
estimatedCost: Double;
/// output: Estimated number of rows returned (since 3.8.2)
// - may be set to an estimate of the number of rows returned by the
// proposed query plan. If this value is not explicitly set, the default
// estimate of 25 rows is used
estimatedRows: Int64;
/// output: Mask of SQLITE_INDEX_SCAN_* flags (since 3.9.0)
// - may be set to SQLITE_INDEX_SCAN_UNIQUE to indicate that the virtual
// table will return only zero or one rows given the input constraints.
// Additional bits of the idxFlags field might be understood in later
// versions of SQLite
idxFlags: Integer;
/// input: Mask of columns used by statement (since 3.10.0)
// - indicates which fields of the virtual table are actually used by the
// statement being prepared. If the lowest bit of colUsed is set, that means
// that the first column is used. The second lowest bit corresponds to the
// second column. And so forth. If the most significant bit of colUsed is
// set, that means that one or more columns other than the first 63 columns
// are used.
// - If column usage information is needed by the xFilter method, then the
// required bits must be encoded into either the idxNum or idxStr output fields
colUsed: UInt64;
end;
/// Virtual Table Instance Object
// - Every virtual table module implementation uses a subclass of this object
// to describe a particular instance of the virtual table.
// - Each subclass will be tailored to the specific needs of the module
// implementation. The purpose of this superclass is to define certain fields
// that are common to all module implementations. This structure therefore
// contains a pInstance field, which will be used to store a class instance
// handling the virtual table as a pure Delphi class: the TSQLVirtualTableModule
// class will use it internaly
TSQLite3VTab = record
/// The module for this virtual table
pModule: PSQLite3Module;
/// no longer used
nRef: integer;
/// Error message from sqlite3.mprintf()
// - Virtual tables methods can set an error message by assigning a string
// obtained from sqlite3.mprintf() to zErrMsg.
// - The method should take care that any prior string is freed by a call
// to sqlite3.free() prior to assigning a new string to zErrMsg.
// - After the error message is delivered up to the client application,
// the string will be automatically freed by sqlite3.free() and the zErrMsg
// field will be zeroed.
zErrMsg: PUTF8Char;
/// this will be used to store a Delphi class instance handling the Virtual Table
pInstance: TObject;
end;
/// Virtual Table Cursor Object
// - Every virtual table module implementation uses a subclass of the following
// structure to describe cursors that point into the virtual table and are
// used to loop through the virtual table.
// - Cursors are created using the xOpen method of the module and are destroyed
// by the xClose method. Cursors are used by the xFilter, xNext, xEof, xColumn,
// and xRowid methods of the module.
// - Each module implementation will define the content of a cursor structure
// to suit its own needs.
// - This superclass exists in order to define fields of the cursor that are
// common to all implementationsThis structure therefore contains a pInstance
// field, which will be used to store a class instance handling the virtual
// table as a pure Delphi class: the TSQLVirtualTableModule class will use
// it internaly
TSQLite3VTabCursor = record
/// Virtual table of this cursor
pVtab: PSQLite3VTab;
/// this will be used to store a Delphi class instance handling the cursor
pInstance: TObject;
end;
/// defines a module object used to implement a virtual table.
// - Think of a module as a class from which one can construct multiple virtual
// tables having similar properties. For example, one might have a module that
// provides read-only access to comma-separated-value (CSV) files on disk.
// That one module can then be used to create several virtual tables where each
// virtual table refers to a different CSV file.
// - The module structure contains methods that are invoked by SQLite to perform
// various actions on the virtual table such as creating new instances of a
// virtual table or destroying old ones, reading and writing data, searching
// for and deleting, updating, or inserting rows.
TSQLite3Module = record
/// defines the particular edition of the module table structure
// - Currently, handled iVersion is 2, but in future releases of SQLite the
// module structure definition might be extended with additional methods and
// in that case the iVersion value will be increased
iVersion: integer;
/// called to create a new instance of a virtual table in response to a
// CREATE VIRTUAL TABLE statement
// - The job of this method is to construct the new virtual table object (an
// PSQLite3VTab object) and return a pointer to it in ppVTab
// - The DB parameter is a pointer to the SQLite database connection that is
// executing the CREATE VIRTUAL TABLE statement
// - The pAux argument is the copy of the client data pointer that was the
// fourth argument to the sqlite3.create_module_v2() call that registered
// the virtual table module
// - The argv parameter is an array of argc pointers to null terminated strings
// - The first string, argv[0], is the name of the module being invoked. The
// module name is the name provided as the second argument to sqlite3.create_module()
// and as the argument to the USING clause of the CREATE VIRTUAL TABLE
// statement that is running.
// - The second, argv[1], is the name of the database in which the new virtual
// table is being created. The database name is "main" for the primary
// database, or "temp" for TEMP database, or the name given at the end of
// the ATTACH statement for attached databases.
// - The third element of the array, argv[2], is the name of the new virtual
// table, as specified following the TABLE keyword in the CREATE VIRTUAL
// TABLE statement
// - If present, the fourth and subsequent strings in the argv[] array report
// the arguments to the module name in the CREATE VIRTUAL TABLE statement
// - As part of the task of creating a new PSQLite3VTab structure, this method
// must invoke sqlite3.declare_vtab() to tell the SQLite core about the
// columns and datatypes in the virtual table
xCreate: function(DB: TSQLite3DB; pAux: Pointer;
argc: Integer; const argv: PPUTF8CharArray;
var ppVTab: PSQLite3VTab; var pzErr: PUTF8Char): Integer; cdecl;
/// xConnect is called to establish a new connection to an existing virtual table,
// whereas xCreate is called to create a new virtual table from scratch
// - It has the same parameters and constructs a new PSQLite3VTab structure
// - xCreate and xConnect methods are only different when the virtual table
// has some kind of backing store that must be initialized the first time the
// virtual table is created. The xCreate method creates and initializes the
// backing store. The xConnect method just connects to an existing backing store.
xConnect: function(DB: TSQLite3DB; pAux: Pointer;
argc: Integer; const argv: PPUTF8CharArray;
var ppVTab: PSQLite3VTab; var pzErr: PUTF8Char): Integer; cdecl;
/// Used to determine the best way to access the virtual table
// - The pInfo parameter is used for input and output parameters
// - The SQLite core calls the xBestIndex() method when it is compiling a query
// that involves a virtual table. In other words, SQLite calls this method when
// it is running sqlite3.prepare() or the equivalent.
// - By calling this method, the SQLite core is saying to the virtual table
// that it needs to access some subset of the rows in the virtual table and
// it wants to know the most efficient way to do that access. The xBestIndex
// method replies with information that the SQLite core can then use to
// conduct an efficient search of the virtual table, via the xFilter() method.
// - While compiling a single SQL query, the SQLite core might call xBestIndex
// multiple times with different settings in pInfo. The SQLite
// core will then select the combination that appears to give the best performance.
// - The information in the pInfo structure is ephemeral and may be overwritten
// or deallocated as soon as the xBestIndex() method returns. If the
// xBestIndex() method needs to remember any part of the pInfo structure,
// it should make a copy. Care must be taken to store the copy in a place
// where it will be deallocated, such as in the idxStr field with
// needToFreeIdxStr set to 1.
xBestIndex: function(var pVTab: TSQLite3VTab; var pInfo: TSQLite3IndexInfo): Integer;
cdecl;
/// Releases a connection to a virtual table
// - Only the pVTab object is destroyed. The virtual table is not destroyed and
// any backing store associated with the virtual table persists. This method
// undoes the work of xConnect.
xDisconnect: function(pVTab: PSQLite3VTab): Integer; cdecl;
/// Releases a connection to a virtual table, just like the xDisconnect method,
// and it also destroys the underlying table implementation.
// - This method undoes the work of xCreate
// - The xDisconnect method is called whenever a database connection that uses
// a virtual table is closed. The xDestroy method is only called when a
// DROP TABLE statement is executed against the virtual table.
xDestroy: function(pVTab: PSQLite3VTab): Integer; cdecl;
/// Creates a new cursor used for accessing (read and/or writing) a virtual table
// - A successful invocation of this method will allocate the memory for the
// TPSQLite3VTabCursor (or a subclass), initialize the new object, and
// make ppCursor point to the new object. The successful call then returns SQLITE_OK.
// - For every successful call to this method, the SQLite core will later
// invoke the xClose method to destroy the allocated cursor.
// - The xOpen method need not initialize the pVtab field of the ppCursor structure.
// The SQLite core will take care of that chore automatically.
// - A virtual table implementation must be able to support an arbitrary number
// of simultaneously open cursors.
// - When initially opened, the cursor is in an undefined state. The SQLite core
// will invoke the xFilter method on the cursor prior to any attempt to
// position or read from the cursor.
xOpen: function(var pVTab: TSQLite3VTab; var ppCursor: PSQLite3VTabCursor): Integer;
cdecl;
/// Closes a cursor previously opened by xOpen
// - The SQLite core will always call xClose once for each cursor opened using xOpen.
// - This method must release all resources allocated by the corresponding xOpen call.
// - The routine will not be called again even if it returns an error. The
// SQLite core will not use the pVtabCursor again after it has been closed.
xClose: function(pVtabCursor: PSQLite3VTabCursor): Integer; cdecl;
/// Begins a search of a virtual table
// - The first argument is a cursor opened by xOpen.
// - The next two arguments define a particular search index previously chosen
// by xBestIndex(). The specific meanings of idxNum and idxStr are unimportant
// as long as xFilter() and xBestIndex() agree on what that meaning is.
// - The xBestIndex() function may have requested the values of certain
// expressions using the aConstraintUsage[].argvIndex values of its pInfo
// structure. Those values are passed to xFilter() using the argc and argv
// parameters.
// - If the virtual table contains one or more rows that match the search criteria,
// then the cursor must be left point at the first row. Subsequent calls to
// xEof must return false (zero). If there are no rows match, then the cursor
// must be left in a state that will cause the xEof to return true (non-zero).
// The SQLite engine will use the xColumn and xRowid methods to access that row content.
// The xNext method will be used to advance to the next row.
// - This method must return SQLITE_OK if successful, or an sqlite error code
// if an error occurs.
xFilter: function(var pVtabCursor: TSQLite3VTabCursor; idxNum: Integer; const idxStr: PAnsiChar;
argc: Integer; var argv: TSQLite3ValueArray): Integer; cdecl;
/// Advances a virtual table cursor to the next row of a result set initiated by xFilter
// - If the cursor is already pointing at the last row when this routine is called,
// then the cursor no longer points to valid data and a subsequent call to the
// xEof method must return true (non-zero).
// - If the cursor is successfully advanced to another row of content, then
// subsequent calls to xEof must return false (zero).
// - This method must return SQLITE_OK if successful, or an sqlite error code
// if an error occurs.
xNext: function(var pVtabCursor: TSQLite3VTabCursor): Integer; cdecl;
/// Checks if cursor reached end of rows
// - Must return false (zero) if the specified cursor currently points to a
// valid row of data, or true (non-zero) otherwise
xEof: function(var pVtabCursor: TSQLite3VTabCursor): Integer; cdecl;
/// The SQLite core invokes this method in order to find the value for the
// N-th column of the current row
// - N is zero-based so the first column is numbered 0.
// - The xColumn method may return its result back to SQLite using one of the
// standard sqlite3.result_*() functions with the specified sContext
// - If the xColumn method implementation calls none of the sqlite3.result_*()
// functions, then the value of the column defaults to an SQL NULL.
// - The xColumn method must return SQLITE_OK on success.
// - To raise an error, the xColumn method should use one of the result_text()
// methods to set the error message text, then return an appropriate error code.
xColumn: function(var pVtabCursor: TSQLite3VTabCursor; sContext: TSQLite3FunctionContext;
N: Integer): Integer; cdecl;
/// Should fill pRowid with the rowid of row that the virtual table cursor
// pVtabCursor is currently pointing at
xRowid: function(var pVtabCursor: TSQLite3VTabCursor; var pRowid: Int64): Integer;
cdecl;
/// Makes a change to a virtual table content (insert/delete/update)
// - The nArg parameter specifies the number of entries in the ppArg[] array
// - The value of nArg will be 1 for a pure delete operation or N+2 for an
// insert or replace or update where N is the number of columns in the table
// (including any hidden columns)
// - The ppArg[0] parameter is the rowid of a row in the virtual table to be deleted.
// If ppArg[0] is an SQL NULL, then no deletion occurs
// - The ppArg[1] parameter is the rowid of a new row to be inserted into the
// virtual table. If ppArg[1] is an SQL NULL, then the implementation must
// choose a rowid for the newly inserted row. Subsequent ppArg[] entries
// contain values of the columns of the virtual table, in the order that
// the columns were declared. The number of columns will match the table
// declaration that the xConnect or xCreate method made using the
// sqlite3.declare_vtab() call. All hidden columns are included.
// - When doing an insert without a rowid (nArg>1, ppArg[1] is an SQL NULL),
// the implementation must set pRowid to the rowid of the newly inserted row;
// this will become the value returned by the sqlite3.last_insert_rowid()
// function. Setting this value in all the other cases is a harmless no-op;
// the SQLite engine ignores the pRowid return value if nArg=1 or ppArg[1]
// is not an SQL NULL.
// - Each call to xUpdate() will fall into one of cases shown below. Note
// that references to ppArg[i] mean the SQL value held within the ppArg[i]
// object, not the ppArg[i] object itself:
// $ nArg = 1
// The single row with rowid equal to ppArg[0] is deleted. No insert occurs.
// $ nArg > 1
// $ ppArg[0] = NULL
// A new row is inserted with a rowid ppArg[1] and column values in ppArg[2]
// and following. If ppArg[1] is an SQL NULL, the a new unique rowid is
// generated automatically.
// $ nArg > 1
// $ ppArg[0] <> NULL
// $ ppArg[0] = ppArg[1]
// The row with rowid ppArg[0] is updated with new values in ppArg[2] and
// following parameters.
// $ nArg > 1
// $ ppArg[0] <> NULL
// $ ppArg[0] <> ppArg[1]
// The row with rowid ppArg[0] is updated with rowid ppArg[1] and new values
// in ppArg[2] and following parameters. This will occur when an SQL statement
// updates a rowid, as in the statement:
// $ UPDATE table SET rowid=rowid+1 WHERE ...;
// - The xUpdate() method must return SQLITE_OK if and only if it is successful.
// If a failure occurs, the xUpdate() must return an appropriate error code.
// On a failure, the pVTab.zErrMsg element may optionally be replaced with
// a custom error message text.
// - If the xUpdate() method violates some constraint of the virtual table
// (including, but not limited to, attempting to store a value of the
// wrong datatype, attempting to store a value that is too large or too small,
// or attempting to change a read-only value) then the xUpdate() must fail
// with an appropriate error code.
// - There might be one or more TSQLite3VTabCursor objects open and in use on
// the virtual table instance and perhaps even on the row of the virtual
// table when the xUpdate() method is invoked. The implementation of xUpdate()
// must be prepared for attempts to delete or modify rows of the table out
// from other existing cursors. If the virtual table cannot accommodate such
// changes, the xUpdate() method must return an error code.
xUpdate: function(var pVTab: TSQLite3VTab; nArg: Integer;
var ppArg: TSQLite3ValueArray; var pRowid: Int64): Integer; cdecl;
/// Begins a transaction on a virtual table
// - This method is always followed by one call to either the xCommit or
// xRollback method.
// - Virtual table transactions do not nest, so the xBegin method will not be
// invoked more than once on a single virtual table without an intervening
// call to either xCommit or xRollback. For nested transactions, use
// xSavepoint, xRelease and xRollBackTo methods.
// - Multiple calls to other methods can and likely will occur in between the
// xBegin and the corresponding xCommit or xRollback.
xBegin: function(var pVTab: TSQLite3VTab): Integer; cdecl;
/// Signals the start of a two-phase commit on a virtual table
// - This method is only invoked after call to the xBegin method and prior
// to an xCommit or xRollback.
// - In order to implement two-phase commit, the xSync method on all virtual
// tables is invoked prior to invoking the xCommit method on any virtual table.
// - If any of the xSync methods fail, the entire transaction is rolled back.
xSync: function(var pVTab: TSQLite3VTab): Integer; cdecl;
/// Causes a virtual table transaction to commit
xCommit: function(var pVTab: TSQLite3VTab): Integer; cdecl;
/// Causes a virtual table transaction to rollback
xRollback: function(var pVTab: TSQLite3VTab): Integer; cdecl;
/// Called during sqlite3.prepare() to give the virtual table implementation
// an opportunity to overload SQL functions
// - When a function uses a column from a virtual table as its first argument,
// this method is called to see if the virtual table would like to overload
// the function. The first three parameters are inputs: the virtual table,
// the number of arguments to the function, and the name of the function.
// If no overloading is desired, this method returns 0. To overload the
// function, this method writes the new function implementation into pxFunc
// and writes user data into ppArg and returns 1.
// - Note that infix functions (LIKE, GLOB, REGEXP, and MATCH) reverse the
// order of their arguments. So "like(A,B)" is equivalent to "B like A".
// For the form "B like A" the B term is considered the first argument to the
// function. But for "like(A,B)" the A term is considered the first argument.
// - The function pointer returned by this routine must be valid for the
// lifetime of the pVTab object given in the first parameter.
xFindFunction: function(var pVTab: TSQLite3VTab; nArg: Integer; const zName: PAnsiChar;
var pxFunc: TSQLFunctionFunc; var ppArg: Pointer): Integer; cdecl;
/// Provides notification that the virtual table implementation that the
// virtual table will be given a new name
// - If this method returns SQLITE_OK then SQLite renames the table.
// - If this method returns an error code then the renaming is prevented.
xRename: function(var pVTab: TSQLite3VTab; const zNew: PAnsiChar): Integer;
cdecl;
/// Starts a new transaction with the virtual table
// - SAVEPOINTs are a method of creating transactions, similar to BEGIN and
// COMMIT, except that the SAVEPOINT and RELEASE commands are named and
// may be nested. See @http://www.sqlite.org/lang_savepoint.html
// - iSavepoint parameter indicates the unique name of the SAVEPOINT
xSavepoint: function(var pVTab: TSQLite3VTab; iSavepoint: integer): Integer;
cdecl;
/// Merges a transaction into its parent transaction, so that the specified
// transaction and its parent become the same transaction
// - Causes all savepoints back to and including the most recent savepoint
// with a matching identifier to be removed from the transaction stack
// - Some people view RELEASE as the equivalent of COMMIT for a SAVEPOINT.
// This is an acceptable point of view as long as one remembers that the
// changes committed by an inner transaction might later be undone by a
// rollback in an outer transaction.
// - iSavepoint parameter indicates the unique name of the SAVEPOINT
xRelease: function(var pVTab: TSQLite3VTab; iSavepoint: integer): Integer;
cdecl;
/// Reverts the state of the virtual table content back to what it was just
// after the corresponding SAVEPOINT
// - iSavepoint parameter indicates the unique name of the SAVEPOINT
xRollbackTo: function(var pVTab: TSQLite3VTab; iSavepoint: integer): Integer;
cdecl;
end;
/// Compile-Time Authorization Callback prototype
// - The authorizer callback is invoked as SQL statements are being compiled by
// sqlite3.prepare2() e.g.
// - The authorizer callback should return SQLITE_OK to allow the action,
// SQLITE_IGNORE to disallow the specific action but allow the SQL statement
// to continue to be compiled, or SQLITE_DENY to cause the entire SQL statement
// to be rejected with an error.
// - If the authorizer callback returns any value other than SQLITE_IGNORE,
// SQLITE_OK, or SQLITE_DENY then the sqlite3.prepare_v2() or equivalent call
// that triggered the authorizer will fail with an error message.
// - The first pUserData parameter to the authorizer callback is a copy of the
// third parameter to the sqlite3.set_authorizer() interface
// - The second parameter to the callback is an integer action code that
// specifies the particular action to be authorized:
// - The third through sixth parameters to the callback are zero-terminated
// strings that contain additional details about the action to be authorized.
// - Here is a list of handled code constant, and their associated zTab / zCol
// parameters:
// ! const zTab zCol
// $ SQLITE_CREATE_INDEX Index Name Table Name
// $ SQLITE_CREATE_TABLE Table Name nil
// $ SQLITE_CREATE_TEMP_INDEX Index Name Table Name
// $ SQLITE_CREATE_TEMP_TABLE Table Name nil
// $ SQLITE_CREATE_TEMP_TRIGGER Trigger Name Table Name
// $ SQLITE_CREATE_TEMP_VIEW View Name nil
// $ SQLITE_CREATE_TRIGGER Trigger Name Table Name
// $ SQLITE_CREATE_VIEW View Name nil
// $ SQLITE_DELETE Table Name nil
// $ SQLITE_DROP_INDEX Index Name Table Name
// $ SQLITE_DROP_TABLE Table Name nil
// $ SQLITE_DROP_TEMP_INDEX Index Name Table Name
// $ SQLITE_DROP_TEMP_TABLE Table Name nil
// $ SQLITE_DROP_TEMP_TRIGGER Trigger Name Table Name
// $ SQLITE_DROP_TEMP_VIEW View Name nil
// $ SQLITE_DROP_TRIGGER Trigger Name Table Name
// $ SQLITE_DROP_VIEW View Name nil
// $ SQLITE_INSERT Table Name nil
// $ SQLITE_PRAGMA Pragma Name 1st arg or nil
// $ SQLITE_READ Table Name Column Name
// $ SQLITE_SELECT nil nil
// $ SQLITE_TRANSACTION Operation nil
// $ SQLITE_UPDATE Table Name Column Name
// $ SQLITE_ATTACH Filename nil
// $ SQLITE_DETACH Database Name nil
// $ SQLITE_ALTER_TABLE Database Name Table Name
// $ SQLITE_REINDEX Index Name nil
// $ SQLITE_ANALYZE Table Name nil
// $ SQLITE_CREATE_VTABLE Table Name Module Name