-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathraw.cs
1332 lines (1141 loc) · 50.6 KB
/
raw.cs
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
/*
Copyright 2014-2019 SourceGear, LLC
Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Copyright © Microsoft Open Technologies, Inc.
// All Rights Reserved
// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
//
// See the Apache 2 License for the specific language governing permissions and limitations under the License.
namespace SQLitePCL
{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public delegate int strdelegate_collation(object user_data, string s1, string s2);
public delegate void strdelegate_update(object user_data, int type, string database, string table, long rowid);
public delegate void strdelegate_log(object user_data, int errorCode, string msg);
public delegate int strdelegate_authorizer(object user_data, int action_code, string param0, string param1, string dbName, string inner_most_trigger_or_view);
public delegate void strdelegate_trace(object user_data, string s);
public delegate void strdelegate_profile(object user_data, string statement, long ns);
public delegate int strdelegate_exec(object user_data, string[] values, string[] names);
public static class raw
{
private static ISQLite3Provider _imp;
private static bool _frozen;
static raw()
{
_frozen = false;
}
static public void SetProvider(ISQLite3Provider imp)
{
if (_frozen) return;
int version = imp.sqlite3_libversion_number();
#if not // don't do this, because it ends up calling sqlite3_initialize
IntPtr db;
int rc;
rc = imp.sqlite3_open(":memory:", out db);
if (rc != 0) throw new Exception();
rc = imp.sqlite3_close(db);
if (rc != 0) throw new Exception();
#endif
_imp = imp;
}
static public void FreezeProvider(bool b = true)
{
_frozen = b;
}
private static ISQLite3Provider Provider
{
get
{
if (_imp == null) throw new Exception("You need to call SQLitePCL.raw.SetProvider(). If you are using a bundle package, this is done by calling SQLitePCL.Batteries.Init().");
return _imp;
}
}
static public string GetNativeLibraryName()
{
return Provider.GetNativeLibraryName();
}
public const int SQLITE_UTF8 = 1;
public const int SQLITE_UTF16LE = 2;
public const int SQLITE_UTF16BE = 3;
public const int SQLITE_UTF16 = 4; /* Use native byte order */
public const int SQLITE_ANY = 5; /* sqlite3_create_function only */
public const int SQLITE_UTF16_ALIGNED = 8; /* sqlite3_create_function only */
public const int SQLITE_DETERMINISTIC = 0x800;
public const int SQLITE_CONFIG_SINGLETHREAD = 1; /* nil */
public const int SQLITE_CONFIG_MULTITHREAD = 2; /* nil */
public const int SQLITE_CONFIG_SERIALIZED = 3; /* nil */
public const int SQLITE_CONFIG_MALLOC = 4; /* sqlite3_mem_methods* */
public const int SQLITE_CONFIG_GETMALLOC = 5; /* sqlite3_mem_methods* */
public const int SQLITE_CONFIG_SCRATCH = 6; /* void*, int utf8z, int N */
public const int SQLITE_CONFIG_PAGECACHE = 7; /* void*, int utf8z, int N */
public const int SQLITE_CONFIG_HEAP = 8; /* void*, int nByte, int min */
public const int SQLITE_CONFIG_MEMSTATUS = 9; /* boolean */
public const int SQLITE_CONFIG_MUTEX = 10; /* sqlite3_mutex_methods* */
public const int SQLITE_CONFIG_GETMUTEX = 11; /* sqlite3_mutex_methods* */
/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */
public const int SQLITE_CONFIG_LOOKASIDE = 13; /* int int */
public const int SQLITE_CONFIG_PCACHE = 14; /* no-op */
public const int SQLITE_CONFIG_GETPCACHE = 15; /* no-op */
public const int SQLITE_CONFIG_LOG = 16; /* xFunc, void* */
public const int SQLITE_CONFIG_URI = 17; /* int */
public const int SQLITE_CONFIG_PCACHE2 = 18; /* sqlite3_pcache_methods2* */
public const int SQLITE_CONFIG_GETPCACHE2 = 19; /* sqlite3_pcache_methods2* */
public const int SQLITE_CONFIG_COVERING_INDEX_SCAN = 20; /* int */
public const int SQLITE_CONFIG_SQLLOG = 21; /* xSqllog, void* */
public const int SQLITE_OPEN_READONLY = 0x00000001; /* Ok for sqlite3_open_v2() */
public const int SQLITE_OPEN_READWRITE = 0x00000002; /* Ok for sqlite3_open_v2() */
public const int SQLITE_OPEN_CREATE = 0x00000004; /* Ok for sqlite3_open_v2() */
public const int SQLITE_OPEN_DELETEONCLOSE = 0x00000008; /* VFS only */
public const int SQLITE_OPEN_EXCLUSIVE = 0x00000010; /* VFS only */
public const int SQLITE_OPEN_AUTOPROXY = 0x00000020; /* VFS only */
public const int SQLITE_OPEN_URI = 0x00000040; /* Ok for sqlite3_open_v2() */
public const int SQLITE_OPEN_MEMORY = 0x00000080; /* Ok for sqlite3_open_v2() */
public const int SQLITE_OPEN_MAIN_DB = 0x00000100; /* VFS only */
public const int SQLITE_OPEN_TEMP_DB = 0x00000200; /* VFS only */
public const int SQLITE_OPEN_TRANSIENT_DB = 0x00000400; /* VFS only */
public const int SQLITE_OPEN_MAIN_JOURNAL = 0x00000800; /* VFS only */
public const int SQLITE_OPEN_TEMP_JOURNAL = 0x00001000; /* VFS only */
public const int SQLITE_OPEN_SUBJOURNAL = 0x00002000; /* VFS only */
public const int SQLITE_OPEN_MASTER_JOURNAL = 0x00004000; /* VFS only */
public const int SQLITE_OPEN_NOMUTEX = 0x00008000; /* Ok for sqlite3_open_v2() */
public const int SQLITE_OPEN_FULLMUTEX = 0x00010000; /* Ok for sqlite3_open_v2() */
public const int SQLITE_OPEN_SHAREDCACHE = 0x00020000; /* Ok for sqlite3_open_v2() */
public const int SQLITE_OPEN_PRIVATECACHE = 0x00040000; /* Ok for sqlite3_open_v2() */
public const int SQLITE_OPEN_WAL = 0x00080000; /* VFS only */
public const int SQLITE_PREPARE_PERSISTENT = 0x01;
public const int SQLITE_PREPARE_NORMALIZE = 0x02;
public const int SQLITE_PREPARE_NO_VTAB = 0x04;
public const int SQLITE_INTEGER = 1;
public const int SQLITE_FLOAT = 2;
public const int SQLITE_TEXT = 3;
public const int SQLITE_BLOB = 4;
public const int SQLITE_NULL = 5;
public const int SQLITE_OK = 0;
public const int SQLITE_ERROR = 1;
public const int SQLITE_INTERNAL = 2;
public const int SQLITE_PERM = 3;
public const int SQLITE_ABORT = 4;
public const int SQLITE_BUSY = 5;
public const int SQLITE_LOCKED = 6;
public const int SQLITE_NOMEM = 7;
public const int SQLITE_READONLY = 8;
public const int SQLITE_INTERRUPT = 9;
public const int SQLITE_IOERR = 10;
public const int SQLITE_CORRUPT = 11;
public const int SQLITE_NOTFOUND = 12;
public const int SQLITE_FULL = 13;
public const int SQLITE_CANTOPEN = 14;
public const int SQLITE_PROTOCOL = 15;
public const int SQLITE_EMPTY = 16;
public const int SQLITE_SCHEMA = 17;
public const int SQLITE_TOOBIG = 18;
public const int SQLITE_CONSTRAINT = 19;
public const int SQLITE_MISMATCH = 20;
public const int SQLITE_MISUSE = 21;
public const int SQLITE_NOLFS = 22;
public const int SQLITE_AUTH = 23;
public const int SQLITE_FORMAT = 24;
public const int SQLITE_RANGE = 25;
public const int SQLITE_NOTADB = 26;
public const int SQLITE_NOTICE = 27;
public const int SQLITE_WARNING = 28;
public const int SQLITE_ROW = 100;
public const int SQLITE_DONE = 101;
public const int SQLITE_IOERR_READ = (SQLITE_IOERR | (1 << 8));
public const int SQLITE_IOERR_SHORT_READ = (SQLITE_IOERR | (2 << 8));
public const int SQLITE_IOERR_WRITE = (SQLITE_IOERR | (3 << 8));
public const int SQLITE_IOERR_FSYNC = (SQLITE_IOERR | (4 << 8));
public const int SQLITE_IOERR_DIR_FSYNC = (SQLITE_IOERR | (5 << 8));
public const int SQLITE_IOERR_TRUNCATE = (SQLITE_IOERR | (6 << 8));
public const int SQLITE_IOERR_FSTAT = (SQLITE_IOERR | (7 << 8));
public const int SQLITE_IOERR_UNLOCK = (SQLITE_IOERR | (8 << 8));
public const int SQLITE_IOERR_RDLOCK = (SQLITE_IOERR | (9 << 8));
public const int SQLITE_IOERR_DELETE = (SQLITE_IOERR | (10 << 8));
public const int SQLITE_IOERR_BLOCKED = (SQLITE_IOERR | (11 << 8));
public const int SQLITE_IOERR_NOMEM = (SQLITE_IOERR | (12 << 8));
public const int SQLITE_IOERR_ACCESS = (SQLITE_IOERR | (13 << 8));
public const int SQLITE_IOERR_CHECKRESERVEDLOCK = (SQLITE_IOERR | (14 << 8));
public const int SQLITE_IOERR_LOCK = (SQLITE_IOERR | (15 << 8));
public const int SQLITE_IOERR_CLOSE = (SQLITE_IOERR | (16 << 8));
public const int SQLITE_IOERR_DIR_CLOSE = (SQLITE_IOERR | (17 << 8));
public const int SQLITE_IOERR_SHMOPEN = (SQLITE_IOERR | (18 << 8));
public const int SQLITE_IOERR_SHMSIZE = (SQLITE_IOERR | (19 << 8));
public const int SQLITE_IOERR_SHMLOCK = (SQLITE_IOERR | (20 << 8));
public const int SQLITE_IOERR_SHMMAP = (SQLITE_IOERR | (21 << 8));
public const int SQLITE_IOERR_SEEK = (SQLITE_IOERR | (22 << 8));
public const int SQLITE_IOERR_DELETE_NOENT = (SQLITE_IOERR | (23 << 8));
public const int SQLITE_IOERR_MMAP = (SQLITE_IOERR | (24 << 8));
public const int SQLITE_IOERR_GETTEMPPATH = (SQLITE_IOERR | (25 << 8));
public const int SQLITE_IOERR_CONVPATH = (SQLITE_IOERR | (26 << 8));
public const int SQLITE_LOCKED_SHAREDCACHE = (SQLITE_LOCKED | (1 << 8));
public const int SQLITE_BUSY_RECOVERY = (SQLITE_BUSY | (1 << 8));
public const int SQLITE_BUSY_SNAPSHOT = (SQLITE_BUSY | (2 << 8));
public const int SQLITE_CANTOPEN_NOTEMPDIR = (SQLITE_CANTOPEN | (1 << 8));
public const int SQLITE_CANTOPEN_ISDIR = (SQLITE_CANTOPEN | (2 << 8));
public const int SQLITE_CANTOPEN_FULLPATH = (SQLITE_CANTOPEN | (3 << 8));
public const int SQLITE_CANTOPEN_CONVPATH = (SQLITE_CANTOPEN | (4 << 8));
public const int SQLITE_CORRUPT_VTAB = (SQLITE_CORRUPT | (1 << 8));
public const int SQLITE_READONLY_RECOVERY = (SQLITE_READONLY | (1 << 8));
public const int SQLITE_READONLY_CANTLOCK = (SQLITE_READONLY | (2 << 8));
public const int SQLITE_READONLY_ROLLBACK = (SQLITE_READONLY | (3 << 8));
public const int SQLITE_READONLY_DBMOVED = (SQLITE_READONLY | (4 << 8));
public const int SQLITE_ABORT_ROLLBACK = (SQLITE_ABORT | (2 << 8));
public const int SQLITE_CONSTRAINT_CHECK = (SQLITE_CONSTRAINT | (1 << 8));
public const int SQLITE_CONSTRAINT_COMMITHOOK = (SQLITE_CONSTRAINT | (2 << 8));
public const int SQLITE_CONSTRAINT_FOREIGNKEY = (SQLITE_CONSTRAINT | (3 << 8));
public const int SQLITE_CONSTRAINT_FUNCTION = (SQLITE_CONSTRAINT | (4 << 8));
public const int SQLITE_CONSTRAINT_NOTNULL = (SQLITE_CONSTRAINT | (5 << 8));
public const int SQLITE_CONSTRAINT_PRIMARYKEY = (SQLITE_CONSTRAINT | (6 << 8));
public const int SQLITE_CONSTRAINT_TRIGGER = (SQLITE_CONSTRAINT | (7 << 8));
public const int SQLITE_CONSTRAINT_UNIQUE = (SQLITE_CONSTRAINT | (8 << 8));
public const int SQLITE_CONSTRAINT_VTAB = (SQLITE_CONSTRAINT | (9 << 8));
public const int SQLITE_CONSTRAINT_ROWID = (SQLITE_CONSTRAINT | (10 << 8));
public const int SQLITE_NOTICE_RECOVER_WAL = (SQLITE_NOTICE | (1 << 8));
public const int SQLITE_NOTICE_RECOVER_ROLLBACK = (SQLITE_NOTICE | (2 << 8));
public const int SQLITE_WARNING_AUTOINDEX = (SQLITE_WARNING | (1 << 8));
public const int SQLITE_CREATE_INDEX = 1; /* Index Name Table Name */
public const int SQLITE_CREATE_TABLE = 2; /* Table Name NULL */
public const int SQLITE_CREATE_TEMP_INDEX = 3; /* Index Name Table Name */
public const int SQLITE_CREATE_TEMP_TABLE = 4; /* Table Name NULL */
public const int SQLITE_CREATE_TEMP_TRIGGER = 5; /* Trigger Name Table Name */
public const int SQLITE_CREATE_TEMP_VIEW = 6; /* View Name NULL */
public const int SQLITE_CREATE_TRIGGER = 7; /* Trigger Name Table Name */
public const int SQLITE_CREATE_VIEW = 8; /* View Name NULL */
public const int SQLITE_DELETE = 9; /* Table Name NULL */
public const int SQLITE_DROP_INDEX = 10; /* Index Name Table Name */
public const int SQLITE_DROP_TABLE = 11; /* Table Name NULL */
public const int SQLITE_DROP_TEMP_INDEX = 12; /* Index Name Table Name */
public const int SQLITE_DROP_TEMP_TABLE = 13; /* Table Name NULL */
public const int SQLITE_DROP_TEMP_TRIGGER = 14; /* Trigger Name Table Name */
public const int SQLITE_DROP_TEMP_VIEW = 15; /* View Name NULL */
public const int SQLITE_DROP_TRIGGER = 16; /* Trigger Name Table Name */
public const int SQLITE_DROP_VIEW = 17; /* View Name NULL */
public const int SQLITE_INSERT = 18; /* Table Name NULL */
public const int SQLITE_PRAGMA = 19; /* Pragma Name 1st arg or NULL */
public const int SQLITE_READ = 20; /* Table Name Column Name */
public const int SQLITE_SELECT = 21; /* NULL NULL */
public const int SQLITE_TRANSACTION = 22; /* Operation NULL */
public const int SQLITE_UPDATE = 23; /* Table Name Column Name */
public const int SQLITE_ATTACH = 24; /* Filename NULL */
public const int SQLITE_DETACH = 25; /* Database Name NULL */
public const int SQLITE_ALTER_TABLE = 26; /* Database Name Table Name */
public const int SQLITE_REINDEX = 27; /* Index Name NULL */
public const int SQLITE_ANALYZE = 28; /* Table Name NULL */
public const int SQLITE_CREATE_VTABLE = 29; /* Table Name Module Name */
public const int SQLITE_DROP_VTABLE = 30; /* Table Name Module Name */
public const int SQLITE_FUNCTION = 31; /* NULL Function Name */
public const int SQLITE_SAVEPOINT = 32; /* Operation Savepoint Name */
public const int SQLITE_COPY = 0; /* No longer used */
public const int SQLITE_RECURSIVE = 33; /* NULL NULL */
public const int SQLITE_CHECKPOINT_PASSIVE = 0;
public const int SQLITE_CHECKPOINT_FULL = 1;
public const int SQLITE_CHECKPOINT_RESTART = 2;
public const int SQLITE_CHECKPOINT_TRUNCATE = 3;
public const int SQLITE_DBSTATUS_LOOKASIDE_USED = 0;
public const int SQLITE_DBSTATUS_CACHE_USED = 1;
public const int SQLITE_DBSTATUS_SCHEMA_USED = 2;
public const int SQLITE_DBSTATUS_STMT_USED = 3;
public const int SQLITE_DBSTATUS_LOOKASIDE_HIT = 4;
public const int SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE = 5;
public const int SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL = 6;
public const int SQLITE_DBSTATUS_CACHE_HIT = 7;
public const int SQLITE_DBSTATUS_CACHE_MISS = 8;
public const int SQLITE_DBSTATUS_CACHE_WRITE = 9;
public const int SQLITE_DBSTATUS_DEFERRED_FKS = 10;
public const int SQLITE_STATUS_MEMORY_USED = 0;
public const int SQLITE_STATUS_PAGECACHE_USED = 1;
public const int SQLITE_STATUS_PAGECACHE_OVERFLOW = 2;
public const int SQLITE_STATUS_SCRATCH_USED = 3;
public const int SQLITE_STATUS_SCRATCH_OVERFLOW = 4;
public const int SQLITE_STATUS_MALLOC_SIZE = 5;
public const int SQLITE_STATUS_PARSER_STACK = 6;
public const int SQLITE_STATUS_PAGECACHE_SIZE = 7;
public const int SQLITE_STATUS_SCRATCH_SIZE = 8;
public const int SQLITE_STATUS_MALLOC_COUNT = 9;
public const int SQLITE_STMTSTATUS_FULLSCAN_STEP = 1;
public const int SQLITE_STMTSTATUS_SORT = 2;
public const int SQLITE_STMTSTATUS_AUTOINDEX = 3;
public const int SQLITE_STMTSTATUS_VM_STEP = 4;
// Authorizer Return Codes
public const int SQLITE_DENY = 1; /* Abort the SQL statement with an error */
public const int SQLITE_IGNORE = 2; /* Don't allow access, but don't generate an error */
public const int SQLITE_TRACE_STMT = 0x01;
public const int SQLITE_TRACE_PROFILE = 0x02;
public const int SQLITE_TRACE_ROW = 0x04;
public const int SQLITE_TRACE_CLOSE = 0x08;
static public int sqlite3_open(utf8z filename, out sqlite3 db)
{
int rc = Provider.sqlite3_open(filename, out var p_db);
// TODO check rc?
db = sqlite3.New(p_db);
return rc;
}
static public int sqlite3_open(string filename, out sqlite3 db)
{
return sqlite3_open(filename.to_utf8z(), out db);
}
static public int sqlite3_open_v2(utf8z filename, out sqlite3 db, int flags, utf8z vfs)
{
int rc = Provider.sqlite3_open_v2(filename, out var p_db, flags, vfs);
// TODO check rc?
db = sqlite3.New(p_db);
return rc;
}
static public int sqlite3_open_v2(string filename, out sqlite3 db, int flags, string vfs)
{
return sqlite3_open_v2(filename.to_utf8z(), out db, flags, vfs.to_utf8z());
}
static public int sqlite3__vfs__delete(utf8z vfs, utf8z pathname, int syncdir)
{
return Provider.sqlite3__vfs__delete(vfs, pathname, syncdir);
}
static public int sqlite3__vfs__delete(string vfs, string pathname, int syncdir)
{
return sqlite3__vfs__delete(vfs.to_utf8z(), pathname.to_utf8z(), syncdir);
}
// called by the SafeHandle
static internal int internal_sqlite3_close_v2(IntPtr p)
{
return Provider.sqlite3_close_v2(p);
}
// called by the SafeHandle
static internal int internal_sqlite3_close(IntPtr p)
{
return Provider.sqlite3_close(p);
}
// called by apps that want the return code
static public int sqlite3_close_v2(sqlite3 db)
{
return db.manual_close_v2();
}
// called by apps that want the return code
static public int sqlite3_close(sqlite3 db)
{
return db.manual_close();
}
static public int sqlite3_enable_shared_cache(int enable)
{
return Provider.sqlite3_enable_shared_cache(enable);
}
static public void sqlite3_interrupt(sqlite3 db)
{
Provider.sqlite3_interrupt(db);
}
static public int sqlite3_config_log(delegate_log f, object v)
{
return Provider.sqlite3_config_log(f, v);
}
static public int sqlite3_config_log(strdelegate_log f, object v)
{
delegate_log cb;
if (f == null)
{
cb = null;
}
else
{
cb =
(ob, e, msg) =>
{
f(ob, e, msg.utf8_to_string());
};
}
return sqlite3_config_log(cb, v);
}
static public void sqlite3_log(int errcode, utf8z s)
{
Provider.sqlite3_log(errcode, s);
}
static public void sqlite3_log(int errcode, string s)
{
sqlite3_log(errcode, s.to_utf8z());
}
static public void sqlite3_commit_hook(sqlite3 db, delegate_commit f, object v)
{
Provider.sqlite3_commit_hook(db, f, v);
}
static public void sqlite3_rollback_hook(sqlite3 db, delegate_rollback f, object v)
{
Provider.sqlite3_rollback_hook(db, f, v);
}
static public void sqlite3_trace(sqlite3 db, delegate_trace f, object v)
{
Provider.sqlite3_trace(db, f, v);
}
static public void sqlite3_trace(sqlite3 db, strdelegate_trace f, object v)
{
delegate_trace cb;
if (f == null)
{
cb = null;
}
else
{
cb =
(ob, sp) =>
{
f(v, sp.utf8_to_string());
};
}
sqlite3_trace(db, cb, v);
}
static public void sqlite3_profile(sqlite3 db, delegate_profile f, object v)
{
Provider.sqlite3_profile(db, f, v);
}
static public void sqlite3_profile(sqlite3 db, strdelegate_profile f, object v)
{
delegate_profile cb;
if (f == null)
{
cb = null;
}
else
{
cb =
(ob, sp, ns) =>
{
f(v, sp.utf8_to_string(), ns);
};
}
sqlite3_profile(db, cb, v);
}
static public void sqlite3_progress_handler(sqlite3 db, int instructions, delegate_progress func, object v)
{
Provider.sqlite3_progress_handler(db, instructions, func, v);
}
static public void sqlite3_update_hook(sqlite3 db, delegate_update f, object v)
{
Provider.sqlite3_update_hook(db, f, v);
}
static public void sqlite3_update_hook(sqlite3 db, strdelegate_update f, object v)
{
delegate_update cb;
if (f == null)
{
cb = null;
}
else
{
cb =
(ob, typ, dbname, tbl, rowid) =>
{
f(ob, typ, dbname.utf8_to_string(), tbl.utf8_to_string(), rowid);
};
}
sqlite3_update_hook(db, cb, v);
}
static public int sqlite3_create_collation(sqlite3 db, string name, object v, strdelegate_collation f)
{
var p = name.to_utf8_with_z();
delegate_collation cb;
if (f == null)
{
cb = null;
}
else
{
cb =
(ob, s1, s2) =>
{
return f(ob, s1.utf8_span_to_string(), s2.utf8_span_to_string());
};
}
return Provider.sqlite3_create_collation(db, p, v, cb);
}
static public int sqlite3_create_function(sqlite3 db, string name, int nArg, int flags, object v, delegate_function_scalar func)
{
var p = name.to_utf8_with_z();
var rc = Provider.sqlite3_create_function(db, p, nArg, flags, v, func);
return rc;
}
static public int sqlite3_create_function(sqlite3 db, string name, int nArg, int flags, object v, delegate_function_aggregate_step func_step, delegate_function_aggregate_final func_final)
{
var p = name.to_utf8_with_z();
var rc = Provider.sqlite3_create_function(db, p, nArg, flags, v, func_step, func_final);
return rc;
}
static public int sqlite3_create_function(sqlite3 db, string name, int nArg, object v, delegate_function_scalar func)
{
return sqlite3_create_function(db, name, nArg, 0, v, func);
}
static public int sqlite3_create_function(sqlite3 db, string name, int nArg, object v, delegate_function_aggregate_step func_step, delegate_function_aggregate_final func_final)
{
return sqlite3_create_function(db, name, nArg, 0, v, func_step, func_final);
}
static public int sqlite3_db_status(sqlite3 db, int op, out int current, out int highest, int resetFlg)
{
return Provider.sqlite3_db_status(db, op, out current, out highest, resetFlg);
}
// TODO do we need this to be public?
public static string utf8_span_to_string(this ReadOnlySpan<byte> p)
{
if (p.Length == 0)
{
return "";
}
unsafe
{
fixed (byte* q = p)
{
return System.Text.Encoding.UTF8.GetString(q, p.Length);
}
}
}
static public int sqlite3_key(sqlite3 db, ReadOnlySpan<byte> k)
{
return Provider.sqlite3_key(db, k);
}
static public int sqlite3_key_v2(sqlite3 db, utf8z name, ReadOnlySpan<byte> k)
{
return Provider.sqlite3_key_v2(db, name, k);
}
static public int sqlite3_rekey(sqlite3 db, ReadOnlySpan<byte> k)
{
return Provider.sqlite3_rekey(db, k);
}
static public int sqlite3_rekey_v2(sqlite3 db, utf8z name, ReadOnlySpan<byte> k)
{
return Provider.sqlite3_rekey_v2(db, name, k);
}
static public utf8z sqlite3_libversion()
{
return Provider.sqlite3_libversion();
}
static public int sqlite3_libversion_number()
{
return Provider.sqlite3_libversion_number();
}
static public int sqlite3_threadsafe()
{
return Provider.sqlite3_threadsafe();
}
static public int sqlite3_initialize()
{
return Provider.sqlite3_initialize();
}
static public int sqlite3_shutdown()
{
return Provider.sqlite3_shutdown();
}
static public int sqlite3_config(int op)
{
return Provider.sqlite3_config(op);
}
static public int sqlite3_config(int op, int val)
{
return Provider.sqlite3_config(op, val);
}
static public int sqlite3_enable_load_extension(sqlite3 db, int onoff)
{
return Provider.sqlite3_enable_load_extension(db, onoff);
}
static public utf8z sqlite3_sourceid()
{
return Provider.sqlite3_sourceid();
}
static public long sqlite3_memory_used()
{
return Provider.sqlite3_memory_used();
}
static public long sqlite3_memory_highwater(int resetFlag)
{
return Provider.sqlite3_memory_highwater(resetFlag);
}
static public int sqlite3_status(int op, out int current, out int highwater, int resetFlag)
{
return Provider.sqlite3_status(op, out current, out highwater, resetFlag);
}
static public utf8z sqlite3_errmsg(sqlite3 db)
{
return Provider.sqlite3_errmsg(db);
}
static public int sqlite3_db_readonly(sqlite3 db, utf8z dbName)
{
return Provider.sqlite3_db_readonly(db, dbName);
}
static public int sqlite3_db_readonly(sqlite3 db, string dbName)
{
return sqlite3_db_readonly(db, dbName.to_utf8z());
}
static public utf8z sqlite3_db_filename(sqlite3 db, utf8z att)
{
return Provider.sqlite3_db_filename(db, att);
}
static public utf8z sqlite3_db_filename(sqlite3 db, string att)
{
return sqlite3_db_filename(db, att.to_utf8z());
}
static public long sqlite3_last_insert_rowid(sqlite3 db)
{
return Provider.sqlite3_last_insert_rowid(db);
}
static public int sqlite3_changes(sqlite3 db)
{
return Provider.sqlite3_changes(db);
}
static public int sqlite3_total_changes(sqlite3 db)
{
return Provider.sqlite3_total_changes(db);
}
static public int sqlite3_get_autocommit(sqlite3 db)
{
return Provider.sqlite3_get_autocommit(db);
}
static public int sqlite3_busy_timeout(sqlite3 db, int ms)
{
return Provider.sqlite3_busy_timeout(db, ms);
}
static public int sqlite3_extended_result_codes(sqlite3 db, int onoff)
{
return Provider.sqlite3_extended_result_codes(db, onoff);
}
static public int sqlite3_errcode(sqlite3 db)
{
return Provider.sqlite3_errcode(db);
}
static public int sqlite3_extended_errcode(sqlite3 db)
{
return Provider.sqlite3_extended_errcode(db);
}
static public utf8z sqlite3_errstr(int rc)
{
return Provider.sqlite3_errstr(rc);
}
static public int sqlite3_prepare_v2(sqlite3 db, ReadOnlySpan<byte> sql, out sqlite3_stmt stmt)
{
int rc = Provider.sqlite3_prepare_v2(db, sql, out var p, out var sp_tail);
stmt = sqlite3_stmt.From(p, db);
return rc;
}
static public int sqlite3_prepare_v2(sqlite3 db, utf8z sql, out sqlite3_stmt stmt)
{
int rc = Provider.sqlite3_prepare_v2(db, sql, out var p, out var sp_tail);
stmt = sqlite3_stmt.From(p, db);
return rc;
}
static public int sqlite3_prepare_v2(sqlite3 db, string sql, out sqlite3_stmt stmt)
{
return sqlite3_prepare_v2(db, sql.to_utf8z(), out stmt);
}
static public int sqlite3_prepare_v2(sqlite3 db, ReadOnlySpan<byte> sql, out sqlite3_stmt stmt, out ReadOnlySpan<byte> tail)
{
int rc = Provider.sqlite3_prepare_v2(db, sql, out var p, out tail);
stmt = sqlite3_stmt.From(p, db);
return rc;
}
static public int sqlite3_prepare_v2(sqlite3 db, utf8z sql, out sqlite3_stmt stmt, out utf8z tail)
{
int rc = Provider.sqlite3_prepare_v2(db, sql, out var p, out tail);
stmt = sqlite3_stmt.From(p, db);
return rc;
}
static public int sqlite3_prepare_v2(sqlite3 db, string sql, out sqlite3_stmt stmt, out string tail)
{
int rc = sqlite3_prepare_v2(db, sql.to_utf8z(), out stmt, out var sp_tail);
tail = sp_tail.utf8_to_string();
return rc;
}
static public int sqlite3_prepare_v3(sqlite3 db, ReadOnlySpan<byte> sql, uint flags, out sqlite3_stmt stmt)
{
int rc = Provider.sqlite3_prepare_v3(db, sql, flags, out var p, out var sp_tail);
stmt = sqlite3_stmt.From(p, db);
return rc;
}
static public int sqlite3_prepare_v3(sqlite3 db, utf8z sql, uint flags, out sqlite3_stmt stmt)
{
int rc = Provider.sqlite3_prepare_v3(db, sql, flags, out var p, out var sp_tail);
stmt = sqlite3_stmt.From(p, db);
return rc;
}
static public int sqlite3_prepare_v3(sqlite3 db, string sql, uint flags, out sqlite3_stmt stmt)
{
return sqlite3_prepare_v3(db, sql.to_utf8z(), flags, out stmt);
}
static public int sqlite3_prepare_v3(sqlite3 db, ReadOnlySpan<byte> sql, uint flags, out sqlite3_stmt stmt, out ReadOnlySpan<byte> tail)
{
int rc = Provider.sqlite3_prepare_v3(db, sql, flags, out var p, out tail);
stmt = sqlite3_stmt.From(p, db);
return rc;
}
static public int sqlite3_prepare_v3(sqlite3 db, utf8z sql, uint flags, out sqlite3_stmt stmt, out utf8z tail)
{
int rc = Provider.sqlite3_prepare_v3(db, sql, flags, out var p, out tail);
stmt = sqlite3_stmt.From(p, db);
return rc;
}
static public int sqlite3_prepare_v3(sqlite3 db, string sql, uint flags, out sqlite3_stmt stmt, out string tail)
{
int rc = sqlite3_prepare_v3(db, sql.to_utf8z(), flags, out stmt, out var sp_tail);
tail = sp_tail.utf8_to_string();
return rc;
}
static public int sqlite3_exec(sqlite3 db, string sql, strdelegate_exec callback, object user_data, out string errMsg)
{
delegate_exec cb;
if (callback != null)
{
cb =
(ob, values, names) =>
{
var a_v = new string[values.Length];
var a_n = new string[names.Length];
for (int i = 0; i < values.Length; i++)
{
a_v[i] = util.from_utf8_z(values[i]);
a_n[i] = util.from_utf8_z(names[i]);
}
return callback(ob, a_v, a_n);
};
}
else
{
cb = null;
}
var rc = Provider.sqlite3_exec(db, sql.to_utf8z(), cb, user_data, out var p_errMsg);
if (p_errMsg == IntPtr.Zero)
{
errMsg = null;
}
else
{
errMsg = util.from_utf8_z(p_errMsg);
Provider.sqlite3_free(p_errMsg);
}
return rc;
}
static public int sqlite3_exec(sqlite3 db, string sql, out string errMsg)
{
var rc = Provider.sqlite3_exec(db, sql.to_utf8z(), null, null, out var p_errMsg);
if (p_errMsg == IntPtr.Zero)
{
errMsg = null;
}
else
{
errMsg = util.from_utf8_z(p_errMsg);
Provider.sqlite3_free(p_errMsg);
}
return rc;
}
static public int sqlite3_exec(sqlite3 db, string sql)
{
var rc = Provider.sqlite3_exec(db, sql.to_utf8z(), null, null, out var p_errMsg);
if (p_errMsg == IntPtr.Zero)
{
}
else
{
Provider.sqlite3_free(p_errMsg);
}
return rc;
}
static public int sqlite3_step(sqlite3_stmt stmt)
{
return Provider.sqlite3_step(stmt);
}
// called by apps that want the return code
static public int sqlite3_finalize(sqlite3_stmt stmt)
{
return stmt.manual_close();
}
// called by the SafeHandle
static public int internal_sqlite3_finalize(IntPtr stmt)
{
return Provider.sqlite3_finalize(stmt);
}
static public int sqlite3_reset(sqlite3_stmt stmt)
{
return Provider.sqlite3_reset(stmt);
}
static public int sqlite3_clear_bindings(sqlite3_stmt stmt)
{
return Provider.sqlite3_clear_bindings(stmt);
}
public static int sqlite3_stmt_status(sqlite3_stmt stmt, int op, int resetFlg)
{
return Provider.sqlite3_stmt_status(stmt, op, resetFlg);
}
static public int sqlite3_complete(utf8z sql)
{
return Provider.sqlite3_complete(sql);
}
static public int sqlite3_complete(string sql)
{
return sqlite3_complete(sql.to_utf8z());
}
static public int sqlite3_compileoption_used(utf8z s)
{
return Provider.sqlite3_compileoption_used(s);
}
static public int sqlite3_compileoption_used(string s)
{
return sqlite3_compileoption_used(s.to_utf8z());
}
static public utf8z sqlite3_compileoption_get(int n)
{
return Provider.sqlite3_compileoption_get(n);
}
static public int sqlite3_table_column_metadata(sqlite3 db, utf8z dbName, utf8z tblName, utf8z colName, out utf8z dataType, out utf8z collSeq, out int notNull, out int primaryKey, out int autoInc)
{
return Provider.sqlite3_table_column_metadata(db, dbName, tblName, colName, out dataType, out collSeq, out notNull, out primaryKey, out autoInc);
}
static public int sqlite3_table_column_metadata(sqlite3 db, string dbName, string tblName, string colName, out string dataType, out string collSeq, out int notNull, out int primaryKey, out int autoInc)
{
var rc = sqlite3_table_column_metadata(db, dbName.to_utf8z(), tblName.to_utf8z(), colName.to_utf8z(), out var p_dataType, out var p_collSeq, out notNull, out primaryKey, out autoInc);
dataType = p_dataType.utf8_to_string();
collSeq = p_collSeq.utf8_to_string();
return rc;
}
static public utf8z sqlite3_sql(sqlite3_stmt stmt)
{
return Provider.sqlite3_sql(stmt);
}
static public sqlite3 sqlite3_db_handle(sqlite3_stmt stmt)
{
#if not
IntPtr p = Provider.sqlite3_db_handle(stmt.ptr);
Assert(p == stmt.db);
#endif
return stmt.db;
}
static public sqlite3_stmt sqlite3_next_stmt(sqlite3 db, sqlite3_stmt stmt)
{
IntPtr p = Provider.sqlite3_next_stmt(db, (stmt != null) ? stmt.ptr : IntPtr.Zero);
if (p == IntPtr.Zero)
{
return null;
}
else
{
return db.find_stmt(p);
}
}
static public int sqlite3_bind_zeroblob(sqlite3_stmt stmt, int index, int size)
{
return Provider.sqlite3_bind_zeroblob(stmt, index, size);
}
static public utf8z sqlite3_bind_parameter_name(sqlite3_stmt stmt, int index)
{
return Provider.sqlite3_bind_parameter_name(stmt, index);
}
// probably unnecessary since we pass user_data back as one of the
// params to xFunc, xStep, and xFinal.
static public object sqlite3_user_data(sqlite3_context context)
{
return context.user_data;
}
static public void sqlite3_result_null(sqlite3_context context)
{
Provider.sqlite3_result_null(context.ptr);
}
static public void sqlite3_result_blob(sqlite3_context context, ReadOnlySpan<byte> val)
{
Provider.sqlite3_result_blob(context.ptr, val);
}
static public void sqlite3_result_error(sqlite3_context context, ReadOnlySpan<byte> val)
{
Provider.sqlite3_result_error(context.ptr, val);
}
static public void sqlite3_result_error(sqlite3_context context, utf8z val)
{
Provider.sqlite3_result_error(context.ptr, val);
}
static public void sqlite3_result_error(sqlite3_context context, string val)
{
sqlite3_result_error(context, val.to_utf8z());
}
static public void sqlite3_result_text(sqlite3_context context, ReadOnlySpan<byte> val)
{
Provider.sqlite3_result_text(context.ptr, val);
}
static public void sqlite3_result_text(sqlite3_context context, utf8z val)
{
Provider.sqlite3_result_text(context.ptr, val);
}
static public void sqlite3_result_text(sqlite3_context context, string val)
{
sqlite3_result_text(context, val.to_utf8z());
}