forked from Moosevellous/Trace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sqlite3.bas
1134 lines (1044 loc) · 64.1 KB
/
Sqlite3.bas
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
Attribute VB_Name = "Sqlite3"
'LICENSE: The MIT License (MIT)
'
'Copyright (c) 2010-2011 Govert van Drimmelen
'
'Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated _
documentation files (the "Software"), to deal in the Software without restriction, including without limitation _
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and _
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'The above copyright notice and this permission notice shall be included in all copies or substantial portions of _
the Software.
'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO _
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE _
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, _
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE _
SOFTWARE.
' Option Explicit
'
'' Notes:
'' Microsoft uses UTF-16, little endian byte order.
'
'Private Const JULIANDAY_OFFSET As Double = 2415018.5
'
'' Returned from SQLite3Initialize
'Public Const SQLITE_INIT_OK As Long = 0
'Public Const SQLITE_INIT_ERROR As Long = 1
'
'' SQLite data types
'Public Const SQLITE_INTEGER As Long = 1
'Public Const SQLITE_FLOAT As Long = 2
'Public Const SQLITE_TEXT As Long = 3
'Public Const SQLITE_BLOB As Long = 4
'Public Const SQLITE_NULL As Long = 5
'
'' SQLite atandard return value
'Public Const SQLITE_OK As Long = 0 ' Successful result
'Public Const SQLITE_ERROR As Long = 1 ' SQL error or missing database
'Public Const SQLITE_INTERNAL As Long = 2 ' Internal logic error in SQLite
'Public Const SQLITE_PERM As Long = 3 ' Access permission denied
'Public Const SQLITE_ABORT As Long = 4 ' Callback routine requested an abort
'Public Const SQLITE_BUSY As Long = 5 ' The database file is locked
'Public Const SQLITE_LOCKED As Long = 6 ' A table in the database is locked
'Public Const SQLITE_NOMEM As Long = 7 ' A malloc() failed
'Public Const SQLITE_READONLY As Long = 8 ' Attempt to write a readonly database
'Public Const SQLITE_INTERRUPT As Long = 9 ' Operation terminated by sqlite3_interrupt()
'Public Const SQLITE_IOERR As Long = 10 ' Some kind of disk I/O error occurred
'Public Const SQLITE_CORRUPT As Long = 11 ' The database disk image is malformed
'Public Const SQLITE_NOTFOUND As Long = 12 ' NOT USED. Table or record not found
'Public Const SQLITE_FULL As Long = 13 ' Insertion failed because database is full
'Public Const SQLITE_CANTOPEN As Long = 14 ' Unable to open the database file
'Public Const SQLITE_PROTOCOL As Long = 15 ' NOT USED. Database lock protocol error
'Public Const SQLITE_EMPTY As Long = 16 ' Database is empty
'Public Const SQLITE_SCHEMA As Long = 17 ' The database schema changed
'Public Const SQLITE_TOOBIG As Long = 18 ' String or BLOB exceeds size limit
'Public Const SQLITE_CONSTRAINT As Long = 19 ' Abort due to constraint violation
'Public Const SQLITE_MISMATCH As Long = 20 ' Data type mismatch
'Public Const SQLITE_MISUSE As Long = 21 ' Library used incorrectly
'Public Const SQLITE_NOLFS As Long = 22 ' Uses OS features not supported on host
'Public Const SQLITE_AUTH As Long = 23 ' Authorization denied
'Public Const SQLITE_FORMAT As Long = 24 ' Auxiliary database format error
'Public Const SQLITE_RANGE As Long = 25 ' 2nd parameter to sqlite3_bind out of range
'Public Const SQLITE_NOTADB As Long = 26 ' File opened that is not a database file
'Public Const SQLITE_ROW As Long = 100 ' sqlite3_step() has another row ready
'Public Const SQLITE_DONE As Long = 101 ' sqlite3_step() has finished executing
'
'' Extended error codes
'Public Const SQLITE_IOERR_READ As Long = 266 ' (SQLITE_IOERR | (1<<8))
'Public Const SQLITE_IOERR_SHORT_READ As Long = 522 '(SQLITE_IOERR | (2<<8))
'Public Const SQLITE_IOERR_WRITE As Long = 778 '(SQLITE_IOERR | (3<<8))
'Public Const SQLITE_IOERR_FSYNC As Long = 1034 '(SQLITE_IOERR | (4<<8))
'Public Const SQLITE_IOERR_DIR_FSYNC As Long = 1290 '(SQLITE_IOERR | (5<<8))
'Public Const SQLITE_IOERR_TRUNCATE As Long = 1546 '(SQLITE_IOERR | (6<<8))
'Public Const SQLITE_IOERR_FSTAT As Long = 1802 '(SQLITE_IOERR | (7<<8))
'Public Const SQLITE_IOERR_UNLOCK As Long = 2058 '(SQLITE_IOERR | (8<<8))
'Public Const SQLITE_IOERR_RDLOCK As Long = 2314 '(SQLITE_IOERR | (9<<8))
'Public Const SQLITE_IOERR_DELETE As Long = 2570 '(SQLITE_IOERR | (10<<8))
'Public Const SQLITE_IOERR_BLOCKED As Long = 2826 '(SQLITE_IOERR | (11<<8))
'Public Const SQLITE_IOERR_NOMEM As Long = 3082 '(SQLITE_IOERR | (12<<8))
'Public Const SQLITE_IOERR_ACCESS As Long = 3338 '(SQLITE_IOERR | (13<<8))
'Public Const SQLITE_IOERR_CHECKRESERVEDLOCK As Long = 3594 '(SQLITE_IOERR | (14<<8))
'Public Const SQLITE_IOERR_LOCK As Long = 3850 '(SQLITE_IOERR | (15<<8))
'Public Const SQLITE_IOERR_CLOSE As Long = 4106 '(SQLITE_IOERR | (16<<8))
'Public Const SQLITE_IOERR_DIR_CLOSE As Long = 4362 '(SQLITE_IOERR | (17<<8))
'Public Const SQLITE_LOCKED_SHAREDCACHE As Long = 265 '(SQLITE_LOCKED | (1<<8) )
'
'' Options for Text and Blob binding
'Private Const SQLITE_STATIC As Long = 0
'Private Const SQLITE_TRANSIENT As Long = -1
'
'' System calls
'Private Const CP_UTF8 As Long = 65001
'Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cbMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
'Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cbMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
'Private Declare Function lstrcpynW Lib "kernel32" (ByVal pwsDest As Long, ByVal pwsSource As Long, ByVal cchCount As Long) As Long
'Private Declare Function lstrcpyW Lib "kernel32" (ByVal pwsDest As Long, ByVal pwsSource As Long) As Long
'Private Declare Function lstrlenW Lib "kernel32" (ByVal pwsString As Long) As Long
'Private Declare Function SysAllocString Lib "OleAut32" (ByRef pwsString As Long) As Long
'Private Declare Function SysStringLen Lib "OleAut32" (ByVal bstrString As Long) As Long
'Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
'Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
'
''=====================================================================================
'' SQLite StdCall Imports
''-----------------------
'' SQLite library version
'Private Declare Function sqlite3_stdcall_libversion Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_libversion@0" () As Long ' PtrUtf8String
'' Database connections
'Private Declare Function sqlite3_stdcall_open16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_open16@8" (ByVal pwsFileName As Long, ByRef hDb As Long) As Long ' PtrDb
'Private Declare Function sqlite3_stdcall_close Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_close@4" (ByVal hDb As Long) As Long
'' Database connection error info
'Private Declare Function sqlite3_stdcall_errmsg Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_errmsg@4" (ByVal hDb As Long) As Long ' PtrUtf8String
'Private Declare Function sqlite3_stdcall_errmsg16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_errmsg16@4" (ByVal hDb As Long) As Long ' PtrUtf16String
'Private Declare Function sqlite3_stdcall_errcode Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_errcode@4" (ByVal hDb As Long) As Long
'Private Declare Function sqlite3_stdcall_extended_errcode Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_extended_errcode@4" (ByVal hDb As Long) As Long
'' Database connection change counts
'Private Declare Function sqlite3_stdcall_changes Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_changes@4" (ByVal hDb As Long) As Long
'Private Declare Function sqlite3_stdcall_total_changes Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_total_changes@4" (ByVal hDb As Long) As Long
'
'' Statements
'Private Declare Function sqlite3_stdcall_prepare16_v2 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_prepare16_v2@20" _
' (ByVal hDb As Long, ByVal pwsSql As Long, ByVal nSqlLength As Long, ByRef hStmt As Long, ByVal ppwsTailOut As Long) As Long
'Private Declare Function sqlite3_stdcall_step Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_step@4" (ByVal hStmt As Long) As Long
'Private Declare Function sqlite3_stdcall_reset Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_reset@4" (ByVal hStmt As Long) As Long
'Private Declare Function sqlite3_stdcall_finalize Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_finalize@4" (ByVal hStmt As Long) As Long
'
'' Statement column access (0-based indices)
'Private Declare Function sqlite3_stdcall_column_count Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_count@4" (ByVal hStmt As Long) As Long
'Private Declare Function sqlite3_stdcall_column_type Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_type@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long
'Private Declare Function sqlite3_stdcall_column_name Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_name@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long ' PtrString
'Private Declare Function sqlite3_stdcall_column_name16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_name16@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long ' PtrWString
'
'Private Declare Function sqlite3_stdcall_column_blob Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_blob@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long ' PtrData
'Private Declare Function sqlite3_stdcall_column_bytes Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_bytes@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long
'Private Declare Function sqlite3_stdcall_column_bytes16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_bytes16@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long
'Private Declare Function sqlite3_stdcall_column_double Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_double@8" (ByVal hStmt As Long, ByVal iCol As Long) As Double
'Private Declare Function sqlite3_stdcall_column_int Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_int@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long
'Private Declare Function sqlite3_stdcall_column_int64 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_int64@8" (ByVal hStmt As Long, ByVal iCol As Long) As Currency ' UNTESTED ....?
'Private Declare Function sqlite3_stdcall_column_text Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_text@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long ' PtrString
'Private Declare Function sqlite3_stdcall_column_text16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_text16@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long ' PtrWString
'Private Declare Function sqlite3_stdcall_column_value Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_value@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long ' PtrSqlite3Value
'
'' Statement parameter binding (1-based indices!)
'Private Declare Function sqlite3_stdcall_bind_parameter_count Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_parameter_count@4" (ByVal hStmt As Long) As Long
'Private Declare Function sqlite3_stdcall_bind_parameter_name Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_parameter_name@8" (ByVal hStmt As Long, ByVal paramIndex As Long) As Long
'Private Declare Function sqlite3_stdcall_bind_parameter_index Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_parameter_index@8" (ByVal hStmt As Long, ByVal paramName As Long) As Long
'Private Declare Function sqlite3_stdcall_bind_null Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_null@8" (ByVal hStmt As Long, ByVal paramIndex As Long) As Long
'Private Declare Function sqlite3_stdcall_bind_blob Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_blob@20" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal pValue As Long, ByVal nBytes As Long, ByVal pfDelete As Long) As Long
'Private Declare Function sqlite3_stdcall_bind_zeroblob Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_zeroblob@12" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal nBytes As Long) As Long
'Private Declare Function sqlite3_stdcall_bind_double Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_double@16" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal value As Double) As Long
'Private Declare Function sqlite3_stdcall_bind_int Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_int@12" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal value As Long) As Long
'Private Declare Function sqlite3_stdcall_bind_int64 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_int64@16" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal value As Currency) As Long ' UNTESTED ....?
'Private Declare Function sqlite3_stdcall_bind_text Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_text@20" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal psValue As Long, ByVal nBytes As Long, ByVal pfDelete As Long) As Long
'Private Declare Function sqlite3_stdcall_bind_text16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_text16@20" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal pswValue As Long, ByVal nBytes As Long, ByVal pfDelete As Long) As Long
'Private Declare Function sqlite3_stdcall_bind_value Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_value@12" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal pSqlite3Value As Long) As Long
'Private Declare Function sqlite3_stdcall_clear_bindings Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_clear_bindings@4" (ByVal hStmt As Long) As Long
'
''Backup
'Private Declare Function sqlite3_stdcall_sleep Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_sleep@4" (ByVal msToSleep As Long) As Long
'Private Declare Function sqlite3_stdcall_backup_init Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_init@16" (ByVal hDbDest As Long, ByVal zDestName As Long, ByVal hDbSource As Long, ByVal zSourceName As Long) As Long
'Private Declare Function sqlite3_stdcall_backup_step Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_step@8" (ByVal hBackup As Long, ByVal nPage As Long) As Long
'Private Declare Function sqlite3_stdcall_backup_finish Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_finish@4" (ByVal hBackup As Long) As Long
'Private Declare Function sqlite3_stdcall_backup_remaining Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_remaining@4" (ByVal hBackup As Long) As Long
'Private Declare Function sqlite3_stdcall_backup_pagecount Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_pagecount@4" (ByVal hBackup As Long) As Long
'
''=====================================================================================
'' Initialize - load libraries explicitly
'Private hSQLiteLibrary As Long
'Private hSQLiteStdCallLibrary As Long
'
'Public Function SQLite3Initialize(Optional ByVal libDir As String) As Long
' ' A nice option here is to call SetDllDirectory, but that API is only available since Windows XP SP1.
' If libDir = "" Then libDir = ThisWorkbook.path
' If Right(libDir, 1) <> "\" Then libDir = libDir & "\"
'
' If hSQLiteLibrary = 0 Then
' hSQLiteLibrary = LoadLibrary(libDir + "SQLite3.dll")
' If hSQLiteLibrary = 0 Then
' Debug.Print "SQLite3Initialize Error Loading " + libDir + "SQLite3.dll:", Err.LastDllError
' SQLite3Initialize = SQLITE_INIT_ERROR
' Exit Function
' End If
' End If
'
' If hSQLiteStdCallLibrary = 0 Then
' hSQLiteStdCallLibrary = LoadLibrary(libDir + "SQLite3_StdCall.dll")
' If hSQLiteStdCallLibrary = 0 Then
' Debug.Print "SQLite3Initialize Error Loading " + libDir + "SQLite3_StdCall.dll:", Err.LastDllError
' SQLite3Initialize = SQLITE_INIT_ERROR
' Exit Function
' End If
' End If
' SQLite3Initialize = SQLITE_INIT_OK
'End Function
'
'Public Sub SQLite3Free()
' If hSQLiteLibrary <> 0 Then
' FreeLibrary hSQLiteLibrary
' End If
' If hSQLiteStdCallLibrary <> 0 Then
' FreeLibrary hSQLiteStdCallLibrary
' End If
'End Sub
'
'
''=====================================================================================
'' SQLite library version
'
'Public Function SQLite3LibVersion() As String
' SQLite3LibVersion = Utf8PtrToString(sqlite3_stdcall_libversion())
'End Function
'
''=====================================================================================
'' Database connections
'
'Public Function SQLite3Open(ByVal fileName As String, ByRef dbHandle As Long) As Long
' SQLite3Open = sqlite3_stdcall_open16(StrPtr(fileName), dbHandle)
'End Function
'
'Public Function SQLite3Close(ByVal dbHandle As Long) As Long
' SQLite3Close = sqlite3_stdcall_close(dbHandle)
'End Function
'
''=====================================================================================
'' Error information
'
'Public Function SQLite3ErrMsg(ByVal dbHandle As Long) As String
' SQLite3ErrMsg = Utf8PtrToString(sqlite3_stdcall_errmsg(dbHandle))
'End Function
'
'Public Function SQLite3ErrCode(ByVal dbHandle As Long) As Long
' SQLite3ErrCode = sqlite3_stdcall_errcode(dbHandle)
'End Function
'
'Public Function SQLite3ExtendedErrCode(ByVal dbHandle As Long) As Long
' SQLite3ExtendedErrCode = sqlite3_stdcall_extended_errcode(dbHandle)
'End Function
'
''=====================================================================================
'' Change Counts
'
'Public Function SQLite3Changes(ByVal dbHandle As Long) As Long
' SQLite3Changes = sqlite3_stdcall_changes(dbHandle)
'End Function
'
'Public Function SQLite3TotalChanges(ByVal dbHandle As Long) As Long
' SQLite3TotalChanges = sqlite3_stdcall_total_changes(dbHandle)
'End Function
'
''=====================================================================================
'' Statements
'
'Public Function SQLite3PrepareV2(ByVal dbHandle As Long, ByVal sql As String, ByRef stmthandle As Long) As Long
' ' Only the first statement (up to ';') is prepared. Currently we don't retrieve the 'tail' pointer.
' SQLite3PrepareV2 = sqlite3_stdcall_prepare16_v2(dbHandle, StrPtr(sql), Len(sql) * 2, stmthandle, 0)
'End Function
'
'Public Function SQLite3Step(ByVal stmthandle As Long) As Long
' SQLite3Step = sqlite3_stdcall_step(stmthandle)
'End Function
'
'Public Function SQLite3Reset(ByVal stmthandle As Long) As Long
' SQLite3Reset = sqlite3_stdcall_reset(stmthandle)
'End Function
'
'Public Function SQLite3Finalize(ByVal stmthandle As Long) As Long
' SQLite3Finalize = sqlite3_stdcall_finalize(stmthandle)
'End Function
'
''=====================================================================================
'' Statement column access (0-based indices)
'
'Public Function SQLite3ColumnCount(ByVal stmthandle As Long) As Long
' SQLite3ColumnCount = sqlite3_stdcall_column_count(stmthandle)
'End Function
'
'Public Function SQLite3ColumnType(ByVal stmthandle As Long, ByVal ZeroBasedColIndex As Long) As Long
' SQLite3ColumnType = sqlite3_stdcall_column_type(stmthandle, ZeroBasedColIndex)
'End Function
'
'Public Function SQLite3ColumnName(ByVal stmthandle As Long, ByVal ZeroBasedColIndex As Long) As String
' SQLite3ColumnName = Utf8PtrToString(sqlite3_stdcall_column_name(stmthandle, ZeroBasedColIndex))
'End Function
'
'Public Function SQLite3ColumnDouble(ByVal stmthandle As Long, ByVal ZeroBasedColIndex As Long) As Double
' SQLite3ColumnDouble = sqlite3_stdcall_column_double(stmthandle, ZeroBasedColIndex)
'End Function
'
'Public Function SQLite3ColumnInt32(ByVal stmthandle As Long, ByVal ZeroBasedColIndex As Long) As Long
' SQLite3ColumnInt32 = sqlite3_stdcall_column_int(stmthandle, ZeroBasedColIndex)
'End Function
'
'Public Function SQLite3ColumnText(ByVal stmthandle As Long, ByVal ZeroBasedColIndex As Long) As String
' SQLite3ColumnText = Utf8PtrToString(sqlite3_stdcall_column_text(stmthandle, ZeroBasedColIndex))
'End Function
'
'Public Function SQLite3ColumnDate(ByVal stmthandle As Long, ByVal ZeroBasedColIndex As Long) As Date
' SQLite3ColumnDate = FromJulianDay(sqlite3_stdcall_column_double(stmthandle, ZeroBasedColIndex))
'End Function
'
''=====================================================================================
'' Statement bindings
'
'Public Function SQLite3BindText(ByVal stmthandle As Long, ByVal OneBasedParamIndex As Long, ByVal value As String) As Long
' SQLite3BindText = sqlite3_stdcall_bind_text16(stmthandle, OneBasedParamIndex, StrPtr(value), -1, SQLITE_TRANSIENT)
'End Function
'
'Public Function SQLite3BindDouble(ByVal stmthandle As Long, ByVal OneBasedParamIndex As Long, ByVal value As Double) As Long
' SQLite3BindDouble = sqlite3_stdcall_bind_double(stmthandle, OneBasedParamIndex, value)
'End Function
'
'Public Function SQLite3BindInt32(ByVal stmthandle As Long, ByVal OneBasedParamIndex As Long, ByVal value As Long) As Long
' SQLite3BindInt32 = sqlite3_stdcall_bind_int(stmthandle, OneBasedParamIndex, value)
'End Function
'
'Public Function SQLite3BindDate(ByVal stmthandle As Long, ByVal OneBasedParamIndex As Long, ByVal value As Date) As Long
' SQLite3BindDate = sqlite3_stdcall_bind_double(stmthandle, OneBasedParamIndex, ToJulianDay(value))
'End Function
'
'Public Function SQLite3BindNull(ByVal stmthandle As Long, ByVal OneBasedParamIndex As Long) As Long
' SQLite3BindNull = sqlite3_stdcall_bind_null(stmthandle, OneBasedParamIndex)
'End Function
'
'Public Function SQLite3BindParameterCount(ByVal stmthandle As Long) As Long
' SQLite3BindParameterCount = sqlite3_stdcall_bind_parameter_count(stmthandle)
'End Function
'
'Public Function SQLite3BindParameterName(ByVal stmthandle As Long, ByVal OneBasedParamIndex As Long) As String
' SQLite3BindParameterName = Utf8PtrToString(sqlite3_stdcall_bind_parameter_name(stmthandle, OneBasedParamIndex))
'End Function
'
'Public Function SQLite3BindParameterIndex(ByVal stmthandle As Long, ByVal paramName As String) As Long
' Dim buf() As Byte
' buf = StringToUtf8Bytes(paramName)
' SQLite3BindParameterIndex = sqlite3_stdcall_bind_parameter_index(stmthandle, VarPtr(buf(0)))
'End Function
'
'Public Function SQLite3ClearBindings(ByVal stmthandle As Long) As Long
' SQLite3ClearBindings = sqlite3_stdcall_clear_bindings(stmthandle)
'End Function
'
'
''=====================================================================================
'' Backup
'Public Function SQLite3Sleep(ByVal timeToSleepInMs As Long) As Long
' SQLite3Sleep = sqlite3_stdcall_sleep(timeToSleepInMs)
'End Function
'
'Public Function SQLite3BackupInit(ByVal dbHandleDestination As Long, ByVal destinationName As String, ByVal dbHandleSource As Long, ByVal sourceName As String) As Long
' Dim bufDestinationName() As Byte
' Dim bufSourceName() As Byte
' bufDestinationName = StringToUtf8Bytes(destinationName)
' bufSourceName = StringToUtf8Bytes(sourceName)
' SQLite3BackupInit = sqlite3_stdcall_backup_init(dbHandleDestination, VarPtr(bufDestinationName(0)), dbHandleSource, VarPtr(bufSourceName(0)))
'End Function
'
'Public Function SQLite3BackupFinish(ByVal backupHandle As Long) As Long
' SQLite3BackupFinish = sqlite3_stdcall_backup_finish(backupHandle)
'End Function
'
'Public Function SQLite3BackupStep(ByVal backupHandle As Long, ByVal numberOfPages) As Long
' SQLite3BackupStep = sqlite3_stdcall_backup_step(backupHandle, numberOfPages)
'End Function
'
'Public Function SQLite3BackupPageCount(ByVal backupHandle As Long) As Long
' SQLite3BackupPageCount = sqlite3_stdcall_backup_pagecount(backupHandle)
'End Function
'
'Public Function SQLite3BackupRemaining(ByVal backupHandle As Long) As Long
' SQLite3BackupRemaining = sqlite3_stdcall_backup_remaining(backupHandle)
'End Function
'
'' String Helpers
'Function Utf8PtrToString(ByVal pUtf8String As Long) As String
' Dim buf As String
' Dim cSize As Long
' Dim retVal As Long
'
' cSize = MultiByteToWideChar(CP_UTF8, 0, pUtf8String, -1, 0, 0)
' ' cSize includes the terminating null character
' If cSize <= 1 Then
' Utf8PtrToString = ""
' Exit Function
' End If
'
' Utf8PtrToString = String(cSize - 1, "*")
' retVal = MultiByteToWideChar(CP_UTF8, 0, pUtf8String, cSize - 1, StrPtr(Utf8PtrToString), cSize - 1)
' If retVal = 0 Then
' Debug.Print "Utf8PtrToString Error:", Err.LastDllError
' Exit Function
' End If
'End Function
'
'Function StringToUtf8Bytes(ByVal str As String) As Variant
' Dim bSize As Long
' Dim retVal As Long
' Dim buf() As Byte
'
' bSize = WideCharToMultiByte(CP_UTF8, 0, StrPtr(str), -1, 0, 0, 0, 0)
' If bSize = 0 Then
' Exit Function
' End If
'
' ReDim buf(bSize)
' retVal = WideCharToMultiByte(CP_UTF8, 0, StrPtr(str), -1, VarPtr(buf(0)), bSize, 0, 0)
' If retVal = 0 Then
' Debug.Print "StringToUtf8Bytes Error:", Err.LastDllError
' Exit Function
' End If
' StringToUtf8Bytes = buf
'End Function
'
'Function Utf16PtrToString(ByVal pUtf16String As Long) As String
' Dim StrLen As Long
' Dim retVal As Long
'
' StrLen = lstrlenW(pUtf16String)
' Utf16PtrToString = String(StrLen, "*")
' lstrcpynW StrPtr(Utf16PtrToString), pUtf16String, StrLen
'End Function
'
'' Date Helpers
'Public Function ToJulianDay(oleDate As Date) As Double
' ToJulianDay = CDbl(oleDate) + JULIANDAY_OFFSET
'End Function
'
'Public Function FromJulianDay(julianDay As Double) As Date
' FromJulianDay = CDate(julianDay - JULIANDAY_OFFSET)
'End Function
Option Explicit
' Notes:
' Microsoft uses UTF-16, little endian byte order.
Private Const JULIANDAY_OFFSET As Double = 2415018.5
' Returned from SQLite3Initialize
Public Const SQLITE_INIT_OK As Long = 0
Public Const SQLITE_INIT_ERROR As Long = 1
' SQLite data types
Public Const SQLITE_INTEGER As Long = 1
Public Const SQLITE_FLOAT As Long = 2
Public Const SQLITE_TEXT As Long = 3
Public Const SQLITE_BLOB As Long = 4
Public Const SQLITE_NULL As Long = 5
' SQLite atandard return value
Public Const SQLITE_OK As Long = 0 ' Successful result
Public Const SQLITE_ERROR As Long = 1 ' SQL error or missing database
Public Const SQLITE_INTERNAL As Long = 2 ' Internal logic error in SQLite
Public Const SQLITE_PERM As Long = 3 ' Access permission denied
Public Const SQLITE_ABORT As Long = 4 ' Callback routine requested an abort
Public Const SQLITE_BUSY As Long = 5 ' The database file is locked
Public Const SQLITE_LOCKED As Long = 6 ' A table in the database is locked
Public Const SQLITE_NOMEM As Long = 7 ' A malloc() failed
Public Const SQLITE_READONLY As Long = 8 ' Attempt to write a readonly database
Public Const SQLITE_INTERRUPT As Long = 9 ' Operation terminated by sqlite3_interrupt()
Public Const SQLITE_IOERR As Long = 10 ' Some kind of disk I/O error occurred
Public Const SQLITE_CORRUPT As Long = 11 ' The database disk image is malformed
Public Const SQLITE_NOTFOUND As Long = 12 ' NOT USED. Table or record not found
Public Const SQLITE_FULL As Long = 13 ' Insertion failed because database is full
Public Const SQLITE_CANTOPEN As Long = 14 ' Unable to open the database file
Public Const SQLITE_PROTOCOL As Long = 15 ' NOT USED. Database lock protocol error
Public Const SQLITE_EMPTY As Long = 16 ' Database is empty
Public Const SQLITE_SCHEMA As Long = 17 ' The database schema changed
Public Const SQLITE_TOOBIG As Long = 18 ' String or BLOB exceeds size limit
Public Const SQLITE_CONSTRAINT As Long = 19 ' Abort due to constraint violation
Public Const SQLITE_MISMATCH As Long = 20 ' Data type mismatch
Public Const SQLITE_MISUSE As Long = 21 ' Library used incorrectly
Public Const SQLITE_NOLFS As Long = 22 ' Uses OS features not supported on host
Public Const SQLITE_AUTH As Long = 23 ' Authorization denied
Public Const SQLITE_FORMAT As Long = 24 ' Auxiliary database format error
Public Const SQLITE_RANGE As Long = 25 ' 2nd parameter to sqlite3_bind out of range
Public Const SQLITE_NOTADB As Long = 26 ' File opened that is not a database file
Public Const SQLITE_ROW As Long = 100 ' sqlite3_step() has another row ready
Public Const SQLITE_DONE As Long = 101 ' sqlite3_step() has finished executing
' Extended error codes
Public Const SQLITE_IOERR_READ As Long = 266 '(SQLITE_IOERR | (1<<8))
Public Const SQLITE_IOERR_SHORT_READ As Long = 522 '(SQLITE_IOERR | (2<<8))
Public Const SQLITE_IOERR_WRITE As Long = 778 '(SQLITE_IOERR | (3<<8))
Public Const SQLITE_IOERR_FSYNC As Long = 1034 '(SQLITE_IOERR | (4<<8))
Public Const SQLITE_IOERR_DIR_FSYNC As Long = 1290 '(SQLITE_IOERR | (5<<8))
Public Const SQLITE_IOERR_TRUNCATE As Long = 1546 '(SQLITE_IOERR | (6<<8))
Public Const SQLITE_IOERR_FSTAT As Long = 1802 '(SQLITE_IOERR | (7<<8))
Public Const SQLITE_IOERR_UNLOCK As Long = 2058 '(SQLITE_IOERR | (8<<8))
Public Const SQLITE_IOERR_RDLOCK As Long = 2314 '(SQLITE_IOERR | (9<<8))
Public Const SQLITE_IOERR_DELETE As Long = 2570 '(SQLITE_IOERR | (10<<8))
Public Const SQLITE_IOERR_BLOCKED As Long = 2826 '(SQLITE_IOERR | (11<<8))
Public Const SQLITE_IOERR_NOMEM As Long = 3082 '(SQLITE_IOERR | (12<<8))
Public Const SQLITE_IOERR_ACCESS As Long = 3338 '(SQLITE_IOERR | (13<<8))
Public Const SQLITE_IOERR_CHECKRESERVEDLOCK As Long = 3594 '(SQLITE_IOERR | (14<<8))
Public Const SQLITE_IOERR_LOCK As Long = 3850 '(SQLITE_IOERR | (15<<8))
Public Const SQLITE_IOERR_CLOSE As Long = 4106 '(SQLITE_IOERR | (16<<8))
Public Const SQLITE_IOERR_DIR_CLOSE As Long = 4362 '(SQLITE_IOERR | (17<<8))
Public Const SQLITE_LOCKED_SHAREDCACHE As Long = 265 '(SQLITE_LOCKED | (1<<8) )
' Flags For File Open Operations
Public Const SQLITE_OPEN_READONLY As Long = 1 ' Ok for sqlite3_open_v2()
Public Const SQLITE_OPEN_READWRITE As Long = 2 ' Ok for sqlite3_open_v2()
Public Const SQLITE_OPEN_CREATE As Long = 4 ' Ok for sqlite3_open_v2()
Public Const SQLITE_OPEN_DELETEONCLOSE As Long = 8 ' VFS only
Public Const SQLITE_OPEN_EXCLUSIVE As Long = 16 ' VFS only
Public Const SQLITE_OPEN_AUTOPROXY As Long = 32 ' VFS only
Public Const SQLITE_OPEN_URI As Long = 64 ' Ok for sqlite3_open_v2()
Public Const SQLITE_OPEN_MEMORY As Long = 128 ' Ok for sqlite3_open_v2()
Public Const SQLITE_OPEN_MAIN_DB As Long = 256 ' VFS only
Public Const SQLITE_OPEN_TEMP_DB As Long = 512 ' VFS only
Public Const SQLITE_OPEN_TRANSIENT_DB As Long = 1024 ' VFS only
Public Const SQLITE_OPEN_MAIN_JOURNAL As Long = 2048 ' VFS only
Public Const SQLITE_OPEN_TEMP_JOURNAL As Long = 4096 ' VFS only
Public Const SQLITE_OPEN_SUBJOURNAL As Long = 8192 ' VFS only
Public Const SQLITE_OPEN_MASTER_JOURNAL As Long = 16384 ' VFS only
Public Const SQLITE_OPEN_NOMUTEX As Long = 32768 ' Ok for sqlite3_open_v2()
Public Const SQLITE_OPEN_FULLMUTEX As Long = 65536 ' Ok for sqlite3_open_v2()
Public Const SQLITE_OPEN_SHAREDCACHE As Long = 131072 ' Ok for sqlite3_open_v2()
Public Const SQLITE_OPEN_PRIVATECACHE As Long = 262144 ' Ok for sqlite3_open_v2()
Public Const SQLITE_OPEN_WAL As Long = 524288 ' VFS only
' Options for Text and Blob binding
Private Const SQLITE_STATIC As Long = 0
Private Const SQLITE_TRANSIENT As Long = -1
' System calls
Private Const CP_UTF8 As Long = 65001
#If Win64 Then
Private Declare PtrSafe Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As LongPtr, ByVal cbMultiByte As Long, ByVal lpWideCharStr As LongPtr, ByVal cchWideChar As Long) As Long
Private Declare PtrSafe Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As LongPtr, ByVal cchWideChar As Long, ByVal lpMultiByteStr As LongPtr, ByVal cbMultiByte As Long, ByVal lpDefaultChar As LongPtr, ByVal lpUsedDefaultChar As LongPtr) As Long
Private Declare PtrSafe Sub RtlMoveMemory Lib "kernel32" (ByVal pDest As LongPtr, ByVal pSource As LongPtr, ByVal length As Long)
Private Declare PtrSafe Function lstrcpynW Lib "kernel32" (ByVal pwsDest As LongPtr, ByVal pwsSource As LongPtr, ByVal cchCount As Long) As LongPtr
Private Declare PtrSafe Function lstrcpyW Lib "kernel32" (ByVal pwsDest As LongPtr, ByVal pwsSource As LongPtr) As LongPtr
Private Declare PtrSafe Function lstrlenW Lib "kernel32" (ByVal pwsString As LongPtr) As Long
Private Declare PtrSafe Function SysAllocString Lib "OleAut32" (ByRef pwsString As LongPtr) As LongPtr
Private Declare PtrSafe Function SysStringLen Lib "OleAut32" (ByVal bstrString As LongPtr) As Long
Private Declare PtrSafe Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As LongPtr
Private Declare PtrSafe Function FreeLibrary Lib "kernel32" (ByVal hLibModule As LongPtr) As Long
#Else
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cbMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cbMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
Private Declare Sub RtlMoveMemory Lib "kernel32" (ByVal pDest As Long, ByVal pSource As Long, ByVal length As Long)
Private Declare Function lstrcpynW Lib "kernel32" (ByVal pwsDest As Long, ByVal pwsSource As Long, ByVal cchCount As Long) As Long
Private Declare Function lstrcpyW Lib "kernel32" (ByVal pwsDest As Long, ByVal pwsSource As Long) As Long
Private Declare Function lstrlenW Lib "kernel32" (ByVal pwsString As Long) As Long
Private Declare Function SysAllocString Lib "OleAut32" (ByRef pwsString As Long) As Long
Private Declare Function SysStringLen Lib "OleAut32" (ByVal bstrString As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
#End If
'=====================================================================================
' SQLite StdCall Imports
'-----------------------
#If Win64 Then
' SQLite library version
Private Declare PtrSafe Function sqlite3_libversion Lib "SQLite3" () As LongPtr ' PtrUtf8String
' Database connections
Private Declare PtrSafe Function sqlite3_open16 Lib "SQLite3" (ByVal pwsFileName As LongPtr, ByRef hDb As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_open_v2 Lib "SQLite3" (ByVal pwsFileName As LongPtr, ByRef hDb As LongPtr, ByVal iFlags As Long, ByVal zVfs As LongPtr) As Long ' PtrDb
Private Declare PtrSafe Function sqlite3_close Lib "SQLite3" (ByVal hDb As LongPtr) As Long
' Database connection error info
Private Declare PtrSafe Function sqlite3_errmsg Lib "SQLite3" (ByVal hDb As LongPtr) As LongPtr ' PtrUtf8String
Private Declare PtrSafe Function sqlite3_errmsg16 Lib "SQLite3" (ByVal hDb As LongPtr) As LongPtr ' PtrUtf16String
Private Declare PtrSafe Function sqlite3_errcode Lib "SQLite3" (ByVal hDb As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_extended_errcode Lib "SQLite3" (ByVal hDb As LongPtr) As Long
' Database connection change counts
Private Declare PtrSafe Function sqlite3_changes Lib "SQLite3" (ByVal hDb As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_total_changes Lib "SQLite3" (ByVal hDb As LongPtr) As Long
' Statements
Private Declare PtrSafe Function sqlite3_prepare16_v2 Lib "SQLite3" _
(ByVal hDb As LongPtr, ByVal pwsSql As LongPtr, ByVal nSqlLength As Long, ByRef hStmt As LongPtr, ByVal ppwsTailOut As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_step Lib "SQLite3" (ByVal hStmt As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_reset Lib "SQLite3" (ByVal hStmt As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_finalize Lib "SQLite3" (ByVal hStmt As LongPtr) As Long
' Statement column access (0-based indices)
Private Declare PtrSafe Function sqlite3_column_count Lib "SQLite3" (ByVal hStmt As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_column_type Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As Long
Private Declare PtrSafe Function sqlite3_column_name Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongPtr ' PtrString
Private Declare PtrSafe Function sqlite3_column_name16 Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongPtr ' PtrWString
Private Declare PtrSafe Function sqlite3_column_blob Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongPtr ' PtrData
Private Declare PtrSafe Function sqlite3_column_bytes Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As Long
Private Declare PtrSafe Function sqlite3_column_bytes16 Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As Long
Private Declare PtrSafe Function sqlite3_column_double Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As Double
Private Declare PtrSafe Function sqlite3_column_int Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As Long
Private Declare PtrSafe Function sqlite3_column_int64 Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongLong
Private Declare PtrSafe Function sqlite3_column_text Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongPtr ' PtrString
Private Declare PtrSafe Function sqlite3_column_text16 Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongPtr ' PtrWString
Private Declare PtrSafe Function sqlite3_column_value Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongPtr ' PtrSqlite3Value
' Statement parameter binding (1-based indices!)
Private Declare PtrSafe Function sqlite3_bind_parameter_count Lib "SQLite3" (ByVal hStmt As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_bind_parameter_name Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long) As LongPtr
Private Declare PtrSafe Function sqlite3_bind_parameter_index Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramName As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_bind_null Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long) As Long
Private Declare PtrSafe Function sqlite3_bind_blob Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal pValue As LongPtr, ByVal nBytes As Long, ByVal pfDelete As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_bind_zeroblob Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal nBytes As Long) As Long
Private Declare PtrSafe Function sqlite3_bind_double Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal Value As Double) As Long
Private Declare PtrSafe Function sqlite3_bind_int Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal Value As Long) As Long
Private Declare PtrSafe Function sqlite3_bind_int64 Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal Value As LongLong) As Long
Private Declare PtrSafe Function sqlite3_bind_text Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal psValue As LongPtr, ByVal nBytes As Long, ByVal pfDelete As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_bind_text16 Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal pswValue As LongPtr, ByVal nBytes As Long, ByVal pfDelete As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_bind_value Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal pSqlite3Value As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_clear_bindings Lib "SQLite3" (ByVal hStmt As LongPtr) As Long
'Backup
Private Declare PtrSafe Function sqlite3_sleep Lib "SQLite3" (ByVal msToSleep As Long) As Long
Private Declare PtrSafe Function sqlite3_backup_init Lib "SQLite3" (ByVal hDbDest As LongPtr, ByVal zDestName As LongPtr, ByVal hDbSource As LongPtr, ByVal zSourceName As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_backup_step Lib "SQLite3" (ByVal hBackup As LongPtr, ByVal nPage As Long) As Long
Private Declare PtrSafe Function sqlite3_backup_finish Lib "SQLite3" (ByVal hBackup As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_backup_remaining Lib "SQLite3" (ByVal hBackup As LongPtr) As Long
Private Declare PtrSafe Function sqlite3_backup_pagecount Lib "SQLite3" (ByVal hBackup As LongPtr) As Long
#Else
' SQLite library version
Private Declare Function sqlite3_libversion Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_libversion@0" () As Long ' PtrUtf8String
' Database connections
Private Declare Function sqlite3_open16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_open16@8" (ByVal pwsFileName As Long, ByRef hDb As Long) As Long ' PtrDb
Private Declare Function sqlite3_open_v2 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_open_v2@16" (ByVal pwsFileName As Long, ByRef hDb As Long, ByVal iFlags As Long, ByVal zVfs As Long) As Long ' PtrDb
Private Declare Function sqlite3_close Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_close@4" (ByVal hDb As Long) As Long
' Database connection error info
Private Declare Function sqlite3_errmsg Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_errmsg@4" (ByVal hDb As Long) As Long ' PtrUtf8String
Private Declare Function sqlite3_errmsg16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_errmsg16@4" (ByVal hDb As Long) As Long ' PtrUtf16String
Private Declare Function sqlite3_errcode Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_errcode@4" (ByVal hDb As Long) As Long
Private Declare Function sqlite3_extended_errcode Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_extended_errcode@4" (ByVal hDb As Long) As Long
' Database connection change counts
Private Declare Function sqlite3_changes Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_changes@4" (ByVal hDb As Long) As Long
Private Declare Function sqlite3_total_changes Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_total_changes@4" (ByVal hDb As Long) As Long
' Statements
Private Declare Function sqlite3_prepare16_v2 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_prepare16_v2@20" _
(ByVal hDb As Long, ByVal pwsSql As Long, ByVal nSqlLength As Long, ByRef hStmt As Long, ByVal ppwsTailOut As Long) As Long
Private Declare Function sqlite3_step Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_step@4" (ByVal hStmt As Long) As Long
Private Declare Function sqlite3_reset Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_reset@4" (ByVal hStmt As Long) As Long
Private Declare Function sqlite3_finalize Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_finalize@4" (ByVal hStmt As Long) As Long
' Statement column access (0-based indices)
Private Declare Function sqlite3_column_count Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_count@4" (ByVal hStmt As Long) As Long
Private Declare Function sqlite3_column_type Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_type@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long
Private Declare Function sqlite3_column_name Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_name@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long ' PtrString
Private Declare Function sqlite3_column_name16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_name16@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long ' PtrWString
Private Declare Function sqlite3_column_blob Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_blob@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long ' PtrData
Private Declare Function sqlite3_column_bytes Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_bytes@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long
Private Declare Function sqlite3_column_bytes16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_bytes16@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long
Private Declare Function sqlite3_column_double Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_double@8" (ByVal hStmt As Long, ByVal iCol As Long) As Double
Private Declare Function sqlite3_column_int Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_int@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long
Private Declare Function sqlite3_column_int64 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_int64@8" (ByVal hStmt As Long, ByVal iCol As Long) As Currency ' UNTESTED ....?
Private Declare Function sqlite3_column_text Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_text@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long ' PtrString
Private Declare Function sqlite3_column_text16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_text16@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long ' PtrWString
Private Declare Function sqlite3_column_value Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_value@8" (ByVal hStmt As Long, ByVal iCol As Long) As Long ' PtrSqlite3Value
' Statement parameter binding (1-based indices!)
Private Declare Function sqlite3_bind_parameter_count Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_parameter_count@4" (ByVal hStmt As Long) As Long
Private Declare Function sqlite3_bind_parameter_name Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_parameter_name@8" (ByVal hStmt As Long, ByVal paramIndex As Long) As Long
Private Declare Function sqlite3_bind_parameter_index Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_parameter_index@8" (ByVal hStmt As Long, ByVal paramName As Long) As Long
Private Declare Function sqlite3_bind_null Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_null@8" (ByVal hStmt As Long, ByVal paramIndex As Long) As Long
Private Declare Function sqlite3_bind_blob Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_blob@20" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal pValue As Long, ByVal nBytes As Long, ByVal pfDelete As Long) As Long
Private Declare Function sqlite3_bind_zeroblob Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_zeroblob@12" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal nBytes As Long) As Long
Private Declare Function sqlite3_bind_double Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_double@16" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal Value As Double) As Long
Private Declare Function sqlite3_bind_int Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_int@12" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal Value As Long) As Long
Private Declare Function sqlite3_bind_int64 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_int64@16" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal Value As Currency) As Long ' UNTESTED ....?
Private Declare Function sqlite3_bind_text Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_text@20" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal psValue As Long, ByVal nBytes As Long, ByVal pfDelete As Long) As Long
Private Declare Function sqlite3_bind_text16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_text16@20" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal pswValue As Long, ByVal nBytes As Long, ByVal pfDelete As Long) As Long
Private Declare Function sqlite3_bind_value Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_value@12" (ByVal hStmt As Long, ByVal paramIndex As Long, ByVal pSqlite3Value As Long) As Long
Private Declare Function sqlite3_clear_bindings Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_clear_bindings@4" (ByVal hStmt As Long) As Long
'Backup
Private Declare Function sqlite3_sleep Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_sleep@4" (ByVal msToSleep As Long) As Long
Private Declare Function sqlite3_backup_init Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_init@16" (ByVal hDbDest As Long, ByVal zDestName As Long, ByVal hDbSource As Long, ByVal zSourceName As Long) As Long
Private Declare Function sqlite3_backup_step Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_step@8" (ByVal hBackup As Long, ByVal nPage As Long) As Long
Private Declare Function sqlite3_backup_finish Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_finish@4" (ByVal hBackup As Long) As Long
Private Declare Function sqlite3_backup_remaining Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_remaining@4" (ByVal hBackup As Long) As Long
Private Declare Function sqlite3_backup_pagecount Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_pagecount@4" (ByVal hBackup As Long) As Long
#End If
'=====================================================================================
' Initialize - load libraries explicitly
#If Win64 Then
Private hSQLiteLibrary As LongPtr
Private hSQLiteStdCallLibrary As LongPtr
#Else
Private hSQLiteLibrary As Long
Private hSQLiteStdCallLibrary As Long
#End If
Public Function SQLite3Initialize(Optional ByVal libDir As String) As Long
' A nice option here is to call SetDllDirectory, but that API is only available since Windows XP SP1.
If libDir = "" Then libDir = ThisWorkbook.Path
If Right(libDir, 1) <> "\" Then libDir = libDir & "\"
If hSQLiteLibrary = 0 Then
hSQLiteLibrary = LoadLibrary(libDir + "SQLite3.dll")
If hSQLiteLibrary = 0 Then
Debug.Print "SQLite3Initialize Error Loading " + libDir + "SQLite3.dll:", Err.LastDllError
SQLite3Initialize = SQLITE_INIT_ERROR
Exit Function
End If
End If
#If Win64 Then
#Else
If hSQLiteStdCallLibrary = 0 Then
hSQLiteStdCallLibrary = LoadLibrary(libDir + "SQLite3_StdCall.dll")
If hSQLiteStdCallLibrary = 0 Then
Debug.Print "SQLite3Initialize Error Loading " + libDir + "SQLite3_StdCall.dll:", Err.LastDllError
SQLite3Initialize = SQLITE_INIT_ERROR
Exit Function
End If
End If
#End If
SQLite3Initialize = SQLITE_INIT_OK
End Function
Public Sub SQLite3Free()
If hSQLiteLibrary <> 0 Then
FreeLibrary hSQLiteLibrary
End If
If hSQLiteStdCallLibrary <> 0 Then
FreeLibrary hSQLiteStdCallLibrary
End If
End Sub
'=====================================================================================
' SQLite library version
Public Function SQLite3LibVersion() As String
SQLite3LibVersion = Utf8PtrToString(sqlite3_libversion())
End Function
'=====================================================================================
' Database connections
#If Win64 Then
Public Function SQLite3Open(ByVal fileName As String, ByRef dbHandle As LongPtr) As Long
#Else
Public Function SQLite3Open(ByVal fileName As String, ByRef dbHandle As Long) As Long
#End If
SQLite3Open = sqlite3_open16(StrPtr(fileName), dbHandle)
End Function
#If Win64 Then
Public Function SQLite3OpenV2(ByVal fileName As String, ByRef dbHandle As LongPtr, ByVal flags As Long, ByVal vfsName As String) As Long
#Else
Public Function SQLite3OpenV2(ByVal fileName As String, ByRef dbHandle As Long, ByVal flags As Long, ByVal vfsName As String) As Long
#End If
Dim bufFileName() As Byte
Dim bufVfsName() As Byte
bufFileName = StringToUtf8Bytes(fileName)
If vfsName = Empty Then
SQLite3OpenV2 = sqlite3_open_v2(VarPtr(bufFileName(0)), dbHandle, flags, 0)
Else
bufVfsName = StringToUtf8Bytes(vfsName)
SQLite3OpenV2 = sqlite3_open_v2(VarPtr(bufFileName(0)), dbHandle, flags, VarPtr(bufVfsName(0)))
End If
End Function
#If Win64 Then
Public Function SQLite3Close(ByVal dbHandle As LongPtr) As Long
#Else
Public Function SQLite3Close(ByVal dbHandle As Long) As Long
#End If
SQLite3Close = sqlite3_close(dbHandle)
End Function
'=====================================================================================
' Error information
#If Win64 Then
Public Function SQLite3ErrMsg(ByVal dbHandle As LongPtr) As String
#Else
Public Function SQLite3ErrMsg(ByVal dbHandle As Long) As String
#End If
SQLite3ErrMsg = Utf8PtrToString(sqlite3_errmsg(dbHandle))
End Function
#If Win64 Then
Public Function SQLite3ErrCode(ByVal dbHandle As LongPtr) As Long
#Else
Public Function SQLite3ErrCode(ByVal dbHandle As Long) As Long
#End If
SQLite3ErrCode = sqlite3_errcode(dbHandle)
End Function
#If Win64 Then
Public Function SQLite3ExtendedErrCode(ByVal dbHandle As LongPtr) As Long
#Else
Public Function SQLite3ExtendedErrCode(ByVal dbHandle As Long) As Long
#End If
SQLite3ExtendedErrCode = sqlite3_extended_errcode(dbHandle)
End Function
'=====================================================================================
' Change Counts
#If Win64 Then
Public Function SQLite3Changes(ByVal dbHandle As LongPtr) As Long
#Else
Public Function SQLite3Changes(ByVal dbHandle As Long) As Long
#End If
SQLite3Changes = sqlite3_changes(dbHandle)
End Function
#If Win64 Then
Public Function SQLite3TotalChanges(ByVal dbHandle As LongPtr) As Long
#Else
Public Function SQLite3TotalChanges(ByVal dbHandle As Long) As Long
#End If
SQLite3TotalChanges = sqlite3_total_changes(dbHandle)
End Function
'=====================================================================================
' Statements
#If Win64 Then
Public Function SQLite3PrepareV2(ByVal dbHandle As LongPtr, ByVal sql As String, ByRef stmtHandle As LongPtr) As Long
#Else
Public Function SQLite3PrepareV2(ByVal dbHandle As Long, ByVal sql As String, ByRef stmtHandle As Long) As Long
#End If
' Only the first statement (up to ';') is prepared. Currently we don't retrieve the 'tail' pointer.
SQLite3PrepareV2 = sqlite3_prepare16_v2(dbHandle, StrPtr(sql), Len(sql) * 2, stmtHandle, 0)
End Function
#If Win64 Then
Public Function SQLite3Step(ByVal stmtHandle As LongPtr) As Long
#Else
Public Function SQLite3Step(ByVal stmtHandle As Long) As Long
#End If
SQLite3Step = sqlite3_step(stmtHandle)
End Function
#If Win64 Then
Public Function SQLite3Reset(ByVal stmtHandle As LongPtr) As Long
#Else
Public Function SQLite3Reset(ByVal stmtHandle As Long) As Long
#End If
SQLite3Reset = sqlite3_reset(stmtHandle)
End Function
#If Win64 Then
Public Function SQLite3Finalize(ByVal stmtHandle As LongPtr) As Long
#Else
Public Function SQLite3Finalize(ByVal stmtHandle As Long) As Long
#End If
SQLite3Finalize = sqlite3_finalize(stmtHandle)
End Function
'=====================================================================================
' Statement column access (0-based indices)
#If Win64 Then
Public Function SQLite3ColumnCount(ByVal stmtHandle As LongPtr) As Long
#Else
Public Function SQLite3ColumnCount(ByVal stmtHandle As Long) As Long
#End If
SQLite3ColumnCount = sqlite3_column_count(stmtHandle)
End Function
#If Win64 Then
Public Function SQLite3ColumnType(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As Long
#Else
Public Function SQLite3ColumnType(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Long
#End If
SQLite3ColumnType = sqlite3_column_type(stmtHandle, ZeroBasedColIndex)
End Function
#If Win64 Then
Public Function SQLite3ColumnName(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As String
#Else
Public Function SQLite3ColumnName(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As String
#End If
SQLite3ColumnName = Utf8PtrToString(sqlite3_column_name(stmtHandle, ZeroBasedColIndex))
End Function
#If Win64 Then
Public Function SQLite3ColumnDouble(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As Double
#Else
Public Function SQLite3ColumnDouble(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Double
#End If
SQLite3ColumnDouble = sqlite3_column_double(stmtHandle, ZeroBasedColIndex)
End Function
#If Win64 Then
Public Function SQLite3ColumnInt32(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As Long
#Else
Public Function SQLite3ColumnInt32(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Long
#End If
SQLite3ColumnInt32 = sqlite3_column_int(stmtHandle, ZeroBasedColIndex)
End Function
#If Win64 Then
Public Function SQLite3ColumnText(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As String
#Else
Public Function SQLite3ColumnText(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As String
#End If
SQLite3ColumnText = Utf8PtrToString(sqlite3_column_text(stmtHandle, ZeroBasedColIndex))
End Function
#If Win64 Then
Public Function SQLite3ColumnDate(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As Date
#Else
Public Function SQLite3ColumnDate(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Date
#End If
SQLite3ColumnDate = FromJulianDay(sqlite3_column_double(stmtHandle, ZeroBasedColIndex))
End Function
#If Win64 Then
Public Function SQLite3ColumnBlob(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As Byte()
Dim ptr As LongPtr
#Else
Public Function SQLite3ColumnBlob(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Byte()
Dim ptr As Long
#End If
Dim length As Long
Dim buf() As Byte
ptr = sqlite3_column_blob(stmtHandle, ZeroBasedColIndex)
length = sqlite3_column_bytes(stmtHandle, ZeroBasedColIndex)
ReDim buf(length - 1)
RtlMoveMemory VarPtr(buf(0)), ptr, length
SQLite3ColumnBlob = buf
End Function
'=====================================================================================
' Statement bindings
#If Win64 Then
Public Function SQLite3BindText(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long, ByVal Value As String) As Long
#Else
Public Function SQLite3BindText(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As String) As Long
#End If
SQLite3BindText = sqlite3_bind_text16(stmtHandle, OneBasedParamIndex, StrPtr(Value), -1, SQLITE_TRANSIENT)
End Function
#If Win64 Then
Public Function SQLite3BindDouble(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long, ByVal Value As Double) As Long
#Else
Public Function SQLite3BindDouble(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As Double) As Long
#End If
SQLite3BindDouble = sqlite3_bind_double(stmtHandle, OneBasedParamIndex, Value)
End Function
#If Win64 Then
Public Function SQLite3BindInt32(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long, ByVal Value As Long) As Long
#Else
Public Function SQLite3BindInt32(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As Long) As Long
#End If
SQLite3BindInt32 = sqlite3_bind_int(stmtHandle, OneBasedParamIndex, Value)
End Function
#If Win64 Then
Public Function SQLite3BindDate(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long, ByVal Value As Date) As Long
#Else
Public Function SQLite3BindDate(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As Date) As Long
#End If
SQLite3BindDate = sqlite3_bind_double(stmtHandle, OneBasedParamIndex, ToJulianDay(Value))
End Function
#If Win64 Then
Public Function SQLite3BindBlob(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long, ByRef Value() As Byte) As Long
#Else
Public Function SQLite3BindBlob(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByRef Value() As Byte) As Long
#End If
Dim length As Long
length = UBound(Value) - LBound(Value) + 1
SQLite3BindBlob = sqlite3_bind_blob(stmtHandle, OneBasedParamIndex, VarPtr(Value(0)), length, SQLITE_TRANSIENT)
End Function
#If Win64 Then
Public Function SQLite3BindNull(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long) As Long
#Else
Public Function SQLite3BindNull(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long) As Long
#End If
SQLite3BindNull = sqlite3_bind_null(stmtHandle, OneBasedParamIndex)
End Function
#If Win64 Then
Public Function SQLite3BindParameterCount(ByVal stmtHandle As LongPtr) As Long
#Else
Public Function SQLite3BindParameterCount(ByVal stmtHandle As Long) As Long
#End If
SQLite3BindParameterCount = sqlite3_bind_parameter_count(stmtHandle)
End Function
#If Win64 Then
Public Function SQLite3BindParameterName(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long) As String
#Else
Public Function SQLite3BindParameterName(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long) As String
#End If
SQLite3BindParameterName = Utf8PtrToString(sqlite3_bind_parameter_name(stmtHandle, OneBasedParamIndex))
End Function
#If Win64 Then