├── .gitattributes ├── .gitignore ├── .mailmap ├── Distribution ├── ChangeLog.txt ├── SQLite3_StdCall.dll ├── SQLiteForExcel.xls ├── SQLiteForExcel_64.xlsm ├── SQLiteForWord.doc ├── sqlite3.dll └── x64 │ └── sqlite3.dll ├── License.txt ├── README.md └── Source ├── SQLite3VBAModules ├── Sqlite3.bas ├── Sqlite3Demo.bas ├── Sqlite3Demo_64.bas └── Sqlite3_64.bas └── SQLite3_StdCall ├── Notes.txt ├── SQLite3_StdCall.c ├── SQLite3_StdCall.h ├── SQLite3_StdCall.sln ├── SQLite3_StdCall.vcxproj ├── SQLite3_StdCall.vcxproj.filters ├── dllmain.c ├── sqlite3.def ├── sqlite3.exp ├── sqlite3.h ├── sqlite3.lib ├── stdafx.c └── stdafx.h /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | # DNX 42 | project.lock.json 43 | artifacts/ 44 | 45 | *_i.c 46 | *_p.c 47 | *_i.h 48 | *.ilk 49 | *.meta 50 | *.obj 51 | *.pch 52 | *.pdb 53 | *.pgc 54 | *.pgd 55 | *.rsp 56 | *.sbr 57 | *.tlb 58 | *.tli 59 | *.tlh 60 | *.tmp 61 | *.tmp_proj 62 | *.log 63 | *.vspscc 64 | *.vssscc 65 | .builds 66 | *.pidb 67 | *.svclog 68 | *.scc 69 | 70 | # Chutzpah Test files 71 | _Chutzpah* 72 | 73 | # Visual C++ cache files 74 | ipch/ 75 | *.aps 76 | *.ncb 77 | *.opensdf 78 | *.sdf 79 | *.cachefile 80 | *.opendb 81 | 82 | # Visual Studio profiler 83 | *.psess 84 | *.vsp 85 | *.vspx 86 | 87 | # TFS 2012 Local Workspace 88 | $tf/ 89 | 90 | # Guidance Automation Toolkit 91 | *.gpState 92 | 93 | # ReSharper is a .NET coding add-in 94 | _ReSharper*/ 95 | *.[Rr]e[Ss]harper 96 | *.DotSettings.user 97 | 98 | # JustCode is a .NET coding add-in 99 | .JustCode 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | _NCrunch_* 109 | .*crunch*.local.xml 110 | 111 | # MightyMoose 112 | *.mm.* 113 | AutoTest.Net/ 114 | 115 | # Web workbench (sass) 116 | .sass-cache/ 117 | 118 | # Installshield output folder 119 | [Ee]xpress/ 120 | 121 | # DocProject is a documentation generator add-in 122 | DocProject/buildhelp/ 123 | DocProject/Help/*.HxT 124 | DocProject/Help/*.HxC 125 | DocProject/Help/*.hhc 126 | DocProject/Help/*.hhk 127 | DocProject/Help/*.hhp 128 | DocProject/Help/Html2 129 | DocProject/Help/html 130 | 131 | # Click-Once directory 132 | publish/ 133 | 134 | # Publish Web Output 135 | *.[Pp]ublish.xml 136 | *.azurePubxml 137 | ## TODO: Comment the next line if you want to checkin your 138 | ## web deploy settings but do note that will include unencrypted 139 | ## passwords 140 | #*.pubxml 141 | 142 | *.publishproj 143 | 144 | # NuGet Packages 145 | *.nupkg 146 | # The packages folder can be ignored because of Package Restore 147 | **/packages/* 148 | # except build/, which is used as an MSBuild target. 149 | !**/packages/build/ 150 | # Uncomment if necessary however generally it will be regenerated when needed 151 | #!**/packages/repositories.config 152 | 153 | # Windows Azure Build Output 154 | csx/ 155 | *.build.csdef 156 | 157 | # Windows Store app package directory 158 | AppPackages/ 159 | 160 | # Visual Studio cache files 161 | # files ending in .cache can be ignored 162 | *.[Cc]ache 163 | # but keep track of directories ending in .cache 164 | !*.[Cc]ache/ 165 | 166 | # Others 167 | ClientBin/ 168 | [Ss]tyle[Cc]op.* 169 | ~$* 170 | *~ 171 | *.dbmdl 172 | *.dbproj.schemaview 173 | *.pfx 174 | *.publishsettings 175 | node_modules/ 176 | orleans.codegen.cs 177 | 178 | # RIA/Silverlight projects 179 | Generated_Code/ 180 | 181 | # Backup & report files from converting an old project file 182 | # to a newer Visual Studio version. Backup files are not needed, 183 | # because we have git ;-) 184 | _UpgradeReport_Files/ 185 | Backup*/ 186 | UpgradeLog*.XML 187 | UpgradeLog*.htm 188 | 189 | # SQL Server files 190 | *.mdf 191 | *.ldf 192 | 193 | # Business Intelligence projects 194 | *.rdl.data 195 | *.bim.layout 196 | *.bim_*.settings 197 | 198 | # Microsoft Fakes 199 | FakesAssemblies/ 200 | 201 | # Node.js Tools for Visual Studio 202 | .ntvs_analysis.dat 203 | 204 | # Visual Studio 6 build log 205 | *.plg 206 | 207 | # Visual Studio 6 workspace options file 208 | *.opt 209 | 210 | # LightSwitch generated files 211 | GeneratedArtifacts/ 212 | _Pvt_Extensions/ 213 | ModelManifest.xml 214 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | 2 | Govert van Drimmelen govert_cp 3 | Govert van Drimmelen govert_cp <2b25b41bbf01b7d265f78f98bda07e53ff173630NvGJUJxL> 4 | -------------------------------------------------------------------------------- /Distribution/ChangeLog.txt: -------------------------------------------------------------------------------- 1 | Version 1.0 (12 March 2016) 2 | =========================== 3 | * Fix bug in SQLite3Free when SQLite3Initialize / SQLite3Free is called repeatedly. 4 | * Fix up demo code to place file under TEMP directory. 5 | * Update Distribution version of SQLite3.dll to 3.11.1. 6 | * Update and rebuild SQLite3_StdCall.dll under Visual Studio 2015, with updated sqlite3.h. 7 | 8 | Version 0.9 (8 November 2012) 9 | ============================= 10 | * Add support for sqlite_open_v2 11 | 12 | Version 0.8 (24 July 2012) 13 | ========================== 14 | * Added (non-incremental) Blob access, and small test. 15 | * Add support for 64-bit Excel 2010. 16 | The SQLiteForExcel_64.xlsm has VBA code that supports 32-bit and 64-bit versions of Excel. 17 | * Updated Distribution version of SQLite3.dll to 3.7.13 and added x64\SQLite3.dll. 18 | 19 | Version 0.7 (25 June 2011) 20 | ========================== 21 | * Fixed Unicode string conversion bug. 22 | * Updated Distribution version of SQLite3.dll to 3.7.7. 23 | 24 | Version 0.6 (8 April 2011) 25 | ========================== 26 | * Fixed empty string bug. 27 | * Added SQLiteForWord example. 28 | * Updated Distribution version of SQLite3.dll to 3.7.5. 29 | 30 | Version 0.5 (6 August 2010) 31 | =========================== 32 | * Fixed Excel 2003 compatibility - Byte() return becomes Variant. 33 | * Fixed SQLite3ErrCode and SQLite3ExtendedErrCode. 34 | * Added Backup API. 35 | * Updated Distribution version of SQLite3.dll to 3.6.23. 36 | 37 | Version 0.4 (15 January 2010) 38 | ============================= 39 | * Initial release. -------------------------------------------------------------------------------- /Distribution/SQLite3_StdCall.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/govert/SQLiteForExcel/8aae8bd5c69a9083a67a295fcbcfde838c755f4f/Distribution/SQLite3_StdCall.dll -------------------------------------------------------------------------------- /Distribution/SQLiteForExcel.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/govert/SQLiteForExcel/8aae8bd5c69a9083a67a295fcbcfde838c755f4f/Distribution/SQLiteForExcel.xls -------------------------------------------------------------------------------- /Distribution/SQLiteForExcel_64.xlsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/govert/SQLiteForExcel/8aae8bd5c69a9083a67a295fcbcfde838c755f4f/Distribution/SQLiteForExcel_64.xlsm -------------------------------------------------------------------------------- /Distribution/SQLiteForWord.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/govert/SQLiteForExcel/8aae8bd5c69a9083a67a295fcbcfde838c755f4f/Distribution/SQLiteForWord.doc -------------------------------------------------------------------------------- /Distribution/sqlite3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/govert/SQLiteForExcel/8aae8bd5c69a9083a67a295fcbcfde838c755f4f/Distribution/sqlite3.dll -------------------------------------------------------------------------------- /Distribution/x64/sqlite3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/govert/SQLiteForExcel/8aae8bd5c69a9083a67a295fcbcfde838c755f4f/Distribution/x64/sqlite3.dll -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Govert van Drimmelen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | [SQLite](http://www.sqlite.org) is a small, easy-to-use, open-source SQL database engine. This project, *SQLite for Excel*, is a lightweight wrapper to give access to the SQLite3 library from VBA. It provides a high-performance path to the SQLite3 API functions, preserving the semantics of the SQLite3 library calls and allowing access to the distributed SQLite3.dll without recompilation. 3 | 4 | ## Release Details 5 | 6 | The current release has the following parts: 7 | ### Distribution directory 8 | * *ChangeLog.txt* contains details of the changes in every version. 9 | * *SQLite3_StdCall.dll* is a small and very simple C .dll that makes it possible to use the standard SQLite3 .dll from VBA. It just passes calls from VBA on to SQLite without any change in the parameters, but this allows the StdCall calling convention that VB6 and VBA is limited to. 10 | * *SQLiteForExcel.xls* contains the two VBA modules: 11 | * *SQLite3.bas VBA module* has all the VBA Declares, and does the parameter and string conversions. It exposes a number of SQLite3xxxx functions. These map as directly as possible to the SQLite C API, with no change in the semantics. Although I have not exposed the whole API, most of the core interface is included, in particular the prepared statement, binding, retrieval and backup functions. Date values are stored as Julian day real numbers in the database. 12 | * *SQLite3Demo.bas VBA module* has tests that serve as nice examples of how to use the SQLite3xxxx functions. 13 | * *SQLiteForExcel_64.xlsm* contains 64-bit versions of the two VBA modules in a version that supports both 32-bit and 64-bit versions of Excel.The corresponding {"Sqlite3Demo_64.bas"} module shows how to target both 32-bit and 64-bit Excel with the same VBA code (some #Ifs are required). (Note that the default install of Office is always the 32-bit version, even on a 64-bit version of Windows. Only if the 64-bit version of Office has been specifically selected will the 64-bit modules be required.) 14 | * *sqlite3.dll* is a copy of SQLite version 3.11.1, as downloaded from the SQLite website. 15 | * *x64\SQLite3.dll* is a 64-bit build of SQLite 3.11.1. 16 | 17 | ### Source directory 18 | * *SQLite3VBAModules* contains the four VBA modules described about (32-bit and 64-bit). 19 | * *SQLite3_StdCall* contains the C language source code for the library described above. 20 | 21 | # Getting Started 22 | * Download the release archive .zip file from https://github.com/govert/SQLiteForExcel/releases. 23 | * Unzip the download to a convenient location. 24 | * Open the Distribution\SQLiteForExcel.xls file. 25 | * Open the VBA Editor (Alt+F11). 26 | * Note the SQLite3 module which contains the declarations and helper functions to access SQLite. 27 | * Examine and run the example test code in the SQLite3Demo module. 28 | * Find the documentation for the SQLite functions here: http://sqlite.org/cintro.html. The complete query language for SQLite is documented here: http://sqlite.org/lang.html. 29 | 30 | # Sample projects 31 | * Brian Gonzalez has made a refactored version of the project with a class / interface style. Have a look at his fork here: https://github.com/b-gonzalez/SQLiteForExcel 32 | 33 | * *SQLite for Access* - Thomas Gewinnus has ported the SQLite-Interface to Access-VBA and added a small DAO-like-Layer (class SQLiteDatabase). See Module Test__SQLiteDatabase for samples. Download the .accdb file from https://s3.amazonaws.com/share.excel-dna.net/Beispiel.zip. 34 | 35 | # Related Projects 36 | * The *SQLite* home is at http://www.sqlite.org and the most recent version of the SQLite3.dll library can be found here http://www.sqlite.org/download.html. 37 | * To create User-Defined Functions (UDFs) for Excel using C#, VB.NET or F#, have a look at my [Excel-DNA](https://github.com/Excel-DNA/ExcelDna) project. It provides free and easy integration of .NET with Excel. 38 | * For access to SQLite from .NET I recommend: 39 | * the official [System.Data.SQLite](http://system.data.sqlite.org) is a full-featured ADO.NET driver with full Linq and Entity Framework support, or 40 | * the sweet-looking [sqlite-net](https://github.com/praeclarum/sqlite-net), a light-weight wrapper with attribute-based object-to-database mapping and some Linq support. 41 | 42 | # Support 43 | Create a new [GitHub Issue](https://github.com/govert/SQLiteForExcel/issues). You are also welcome to contact me directly at mailto:govert@icon.co.za with questions, comments or suggestions. 44 | -------------------------------------------------------------------------------- /Source/SQLite3VBAModules/Sqlite3.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "Sqlite3" 2 | Option Explicit 3 | 4 | ' Notes: 5 | ' Microsoft uses UTF-16, little endian byte order. 6 | 7 | Private Const JULIANDAY_OFFSET As Double = 2415018.5 8 | 9 | ' Returned from SQLite3Initialize 10 | Public Const SQLITE_INIT_OK As Long = 0 11 | Public Const SQLITE_INIT_ERROR As Long = 1 12 | 13 | ' SQLite data types 14 | Public Const SQLITE_INTEGER As Long = 1 15 | Public Const SQLITE_FLOAT As Long = 2 16 | Public Const SQLITE_TEXT As Long = 3 17 | Public Const SQLITE_BLOB As Long = 4 18 | Public Const SQLITE_NULL As Long = 5 19 | 20 | ' SQLite atandard return value 21 | Public Const SQLITE_OK As Long = 0 ' Successful result 22 | Public Const SQLITE_ERROR As Long = 1 ' SQL error or missing database 23 | Public Const SQLITE_INTERNAL As Long = 2 ' Internal logic error in SQLite 24 | Public Const SQLITE_PERM As Long = 3 ' Access permission denied 25 | Public Const SQLITE_ABORT As Long = 4 ' Callback routine requested an abort 26 | Public Const SQLITE_BUSY As Long = 5 ' The database file is locked 27 | Public Const SQLITE_LOCKED As Long = 6 ' A table in the database is locked 28 | Public Const SQLITE_NOMEM As Long = 7 ' A malloc() failed 29 | Public Const SQLITE_READONLY As Long = 8 ' Attempt to write a readonly database 30 | Public Const SQLITE_INTERRUPT As Long = 9 ' Operation terminated by sqlite3_interrupt() 31 | Public Const SQLITE_IOERR As Long = 10 ' Some kind of disk I/O error occurred 32 | Public Const SQLITE_CORRUPT As Long = 11 ' The database disk image is malformed 33 | Public Const SQLITE_NOTFOUND As Long = 12 ' NOT USED. Table or record not found 34 | Public Const SQLITE_FULL As Long = 13 ' Insertion failed because database is full 35 | Public Const SQLITE_CANTOPEN As Long = 14 ' Unable to open the database file 36 | Public Const SQLITE_PROTOCOL As Long = 15 ' NOT USED. Database lock protocol error 37 | Public Const SQLITE_EMPTY As Long = 16 ' Database is empty 38 | Public Const SQLITE_SCHEMA As Long = 17 ' The database schema changed 39 | Public Const SQLITE_TOOBIG As Long = 18 ' String or BLOB exceeds size limit 40 | Public Const SQLITE_CONSTRAINT As Long = 19 ' Abort due to constraint violation 41 | Public Const SQLITE_MISMATCH As Long = 20 ' Data type mismatch 42 | Public Const SQLITE_MISUSE As Long = 21 ' Library used incorrectly 43 | Public Const SQLITE_NOLFS As Long = 22 ' Uses OS features not supported on host 44 | Public Const SQLITE_AUTH As Long = 23 ' Authorization denied 45 | Public Const SQLITE_FORMAT As Long = 24 ' Auxiliary database format error 46 | Public Const SQLITE_RANGE As Long = 25 ' 2nd parameter to sqlite3_bind out of range 47 | Public Const SQLITE_NOTADB As Long = 26 ' File opened that is not a database file 48 | Public Const SQLITE_ROW As Long = 100 ' sqlite3_step() has another row ready 49 | Public Const SQLITE_DONE As Long = 101 ' sqlite3_step() has finished executing 50 | 51 | ' Extended error codes 52 | Public Const SQLITE_IOERR_READ As Long = 266 '(SQLITE_IOERR | (1<<8)) 53 | Public Const SQLITE_IOERR_SHORT_READ As Long = 522 '(SQLITE_IOERR | (2<<8)) 54 | Public Const SQLITE_IOERR_WRITE As Long = 778 '(SQLITE_IOERR | (3<<8)) 55 | Public Const SQLITE_IOERR_FSYNC As Long = 1034 '(SQLITE_IOERR | (4<<8)) 56 | Public Const SQLITE_IOERR_DIR_FSYNC As Long = 1290 '(SQLITE_IOERR | (5<<8)) 57 | Public Const SQLITE_IOERR_TRUNCATE As Long = 1546 '(SQLITE_IOERR | (6<<8)) 58 | Public Const SQLITE_IOERR_FSTAT As Long = 1802 '(SQLITE_IOERR | (7<<8)) 59 | Public Const SQLITE_IOERR_UNLOCK As Long = 2058 '(SQLITE_IOERR | (8<<8)) 60 | Public Const SQLITE_IOERR_RDLOCK As Long = 2314 '(SQLITE_IOERR | (9<<8)) 61 | Public Const SQLITE_IOERR_DELETE As Long = 2570 '(SQLITE_IOERR | (10<<8)) 62 | Public Const SQLITE_IOERR_BLOCKED As Long = 2826 '(SQLITE_IOERR | (11<<8)) 63 | Public Const SQLITE_IOERR_NOMEM As Long = 3082 '(SQLITE_IOERR | (12<<8)) 64 | Public Const SQLITE_IOERR_ACCESS As Long = 3338 '(SQLITE_IOERR | (13<<8)) 65 | Public Const SQLITE_IOERR_CHECKRESERVEDLOCK As Long = 3594 '(SQLITE_IOERR | (14<<8)) 66 | Public Const SQLITE_IOERR_LOCK As Long = 3850 '(SQLITE_IOERR | (15<<8)) 67 | Public Const SQLITE_IOERR_CLOSE As Long = 4106 '(SQLITE_IOERR | (16<<8)) 68 | Public Const SQLITE_IOERR_DIR_CLOSE As Long = 4362 '(SQLITE_IOERR | (17<<8)) 69 | Public Const SQLITE_LOCKED_SHAREDCACHE As Long = 265 '(SQLITE_LOCKED | (1<<8) ) 70 | 71 | ' Flags For File Open Operations 72 | Public Const SQLITE_OPEN_READONLY As Long = 1 ' Ok for sqlite3_open_v2() 73 | Public Const SQLITE_OPEN_READWRITE As Long = 2 ' Ok for sqlite3_open_v2() 74 | Public Const SQLITE_OPEN_CREATE As Long = 4 ' Ok for sqlite3_open_v2() 75 | Public Const SQLITE_OPEN_DELETEONCLOSE As Long = 8 ' VFS only 76 | Public Const SQLITE_OPEN_EXCLUSIVE As Long = 16 ' VFS only 77 | Public Const SQLITE_OPEN_AUTOPROXY As Long = 32 ' VFS only 78 | Public Const SQLITE_OPEN_URI As Long = 64 ' Ok for sqlite3_open_v2() 79 | Public Const SQLITE_OPEN_MEMORY As Long = 128 ' Ok for sqlite3_open_v2() 80 | Public Const SQLITE_OPEN_MAIN_DB As Long = 256 ' VFS only 81 | Public Const SQLITE_OPEN_TEMP_DB As Long = 512 ' VFS only 82 | Public Const SQLITE_OPEN_TRANSIENT_DB As Long = 1024 ' VFS only 83 | Public Const SQLITE_OPEN_MAIN_JOURNAL As Long = 2048 ' VFS only 84 | Public Const SQLITE_OPEN_TEMP_JOURNAL As Long = 4096 ' VFS only 85 | Public Const SQLITE_OPEN_SUBJOURNAL As Long = 8192 ' VFS only 86 | Public Const SQLITE_OPEN_MASTER_JOURNAL As Long = 16384 ' VFS only 87 | Public Const SQLITE_OPEN_NOMUTEX As Long = 32768 ' Ok for sqlite3_open_v2() 88 | Public Const SQLITE_OPEN_FULLMUTEX As Long = 65536 ' Ok for sqlite3_open_v2() 89 | Public Const SQLITE_OPEN_SHAREDCACHE As Long = 131072 ' Ok for sqlite3_open_v2() 90 | Public Const SQLITE_OPEN_PRIVATECACHE As Long = 262144 ' Ok for sqlite3_open_v2() 91 | Public Const SQLITE_OPEN_WAL As Long = 524288 ' VFS only 92 | 93 | ' Options for Text and Blob binding 94 | Private Const SQLITE_STATIC As Long = 0 95 | Private Const SQLITE_TRANSIENT As Long = -1 96 | 97 | ' System calls 98 | Private Const CP_UTF8 As Long = 65001 99 | 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 100 | 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 101 | Private Declare Sub RtlMoveMemory Lib "kernel32" (ByVal pDest As Long, ByVal pSource As Long, ByVal length As Long) 102 | Private Declare Function lstrcpynW Lib "kernel32" (ByVal pwsDest As Long, ByVal pwsSource As Long, ByVal cchCount As Long) As Long 103 | Private Declare Function lstrcpyW Lib "kernel32" (ByVal pwsDest As Long, ByVal pwsSource As Long) As Long 104 | Private Declare Function lstrlenW Lib "kernel32" (ByVal pwsString As Long) As Long 105 | Private Declare Function SysAllocString Lib "OleAut32" (ByRef pwsString As Long) As Long 106 | Private Declare Function SysStringLen Lib "OleAut32" (ByVal bstrString As Long) As Long 107 | Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long 108 | Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long 109 | 110 | '===================================================================================== 111 | ' SQLite StdCall Imports 112 | '----------------------- 113 | ' SQLite library version 114 | Private Declare Function sqlite3_stdcall_libversion Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_libversion@0" () As Long ' PtrUtf8String 115 | ' Database connections 116 | 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 117 | Private Declare Function sqlite3_stdcall_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 118 | Private Declare Function sqlite3_stdcall_close Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_close@4" (ByVal hDb As Long) As Long 119 | ' Database connection error info 120 | Private Declare Function sqlite3_stdcall_errmsg Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_errmsg@4" (ByVal hDb As Long) As Long ' PtrUtf8String 121 | Private Declare Function sqlite3_stdcall_errmsg16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_errmsg16@4" (ByVal hDb As Long) As Long ' PtrUtf16String 122 | Private Declare Function sqlite3_stdcall_errcode Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_errcode@4" (ByVal hDb As Long) As Long 123 | Private Declare Function sqlite3_stdcall_extended_errcode Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_extended_errcode@4" (ByVal hDb As Long) As Long 124 | ' Database connection change counts 125 | Private Declare Function sqlite3_stdcall_changes Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_changes@4" (ByVal hDb As Long) As Long 126 | Private Declare Function sqlite3_stdcall_total_changes Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_total_changes@4" (ByVal hDb As Long) As Long 127 | 128 | ' Statements 129 | Private Declare Function sqlite3_stdcall_prepare16_v2 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_prepare16_v2@20" _ 130 | (ByVal hDb As Long, ByVal pwsSql As Long, ByVal nSqlLength As Long, ByRef hStmt As Long, ByVal ppwsTailOut As Long) As Long 131 | Private Declare Function sqlite3_stdcall_step Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_step@4" (ByVal hStmt As Long) As Long 132 | Private Declare Function sqlite3_stdcall_reset Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_reset@4" (ByVal hStmt As Long) As Long 133 | Private Declare Function sqlite3_stdcall_finalize Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_finalize@4" (ByVal hStmt As Long) As Long 134 | 135 | ' Statement column access (0-based indices) 136 | Private Declare Function sqlite3_stdcall_column_count Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_count@4" (ByVal hStmt As Long) As Long 137 | 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 138 | 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 139 | 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 140 | 141 | 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 142 | 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 143 | 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 144 | 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 145 | 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 146 | 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 ....? 147 | 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 148 | 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 149 | 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 150 | 151 | ' Statement parameter binding (1-based indices!) 152 | Private Declare Function sqlite3_stdcall_bind_parameter_count Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_parameter_count@4" (ByVal hStmt As Long) As Long 153 | 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 154 | 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 155 | 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 156 | 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 157 | 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 158 | 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 159 | 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 160 | 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 ....? 161 | 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 162 | 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 163 | 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 164 | Private Declare Function sqlite3_stdcall_clear_bindings Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_clear_bindings@4" (ByVal hStmt As Long) As Long 165 | 166 | 'Backup 167 | Private Declare Function sqlite3_stdcall_sleep Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_sleep@4" (ByVal msToSleep As Long) As Long 168 | 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 169 | 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 170 | Private Declare Function sqlite3_stdcall_backup_finish Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_finish@4" (ByVal hBackup As Long) As Long 171 | Private Declare Function sqlite3_stdcall_backup_remaining Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_remaining@4" (ByVal hBackup As Long) As Long 172 | Private Declare Function sqlite3_stdcall_backup_pagecount Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_pagecount@4" (ByVal hBackup As Long) As Long 173 | 174 | '===================================================================================== 175 | ' Initialize - load libraries explicitly 176 | Private hSQLiteLibrary As Long 177 | Private hSQLiteStdCallLibrary As Long 178 | 179 | Public Function SQLite3Initialize(Optional ByVal libDir As String) As Long 180 | ' A nice option here is to call SetDllDirectory, but that API is only available since Windows XP SP1. 181 | If libDir = "" Then libDir = ThisWorkbook.Path 182 | If Right(libDir, 1) <> "\" Then libDir = libDir & "\" 183 | 184 | If hSQLiteLibrary = 0 Then 185 | hSQLiteLibrary = LoadLibrary(libDir + "SQLite3.dll") 186 | If hSQLiteLibrary = 0 Then 187 | Debug.Print "SQLite3Initialize Error Loading " + libDir + "SQLite3.dll:", Err.LastDllError 188 | SQLite3Initialize = SQLITE_INIT_ERROR 189 | Exit Function 190 | End If 191 | End If 192 | 193 | If hSQLiteStdCallLibrary = 0 Then 194 | hSQLiteStdCallLibrary = LoadLibrary(libDir + "SQLite3_StdCall.dll") 195 | If hSQLiteStdCallLibrary = 0 Then 196 | Debug.Print "SQLite3Initialize Error Loading " + libDir + "SQLite3_StdCall.dll:", Err.LastDllError 197 | SQLite3Initialize = SQLITE_INIT_ERROR 198 | Exit Function 199 | End If 200 | End If 201 | SQLite3Initialize = SQLITE_INIT_OK 202 | End Function 203 | 204 | Public Sub SQLite3Free() 205 | Dim refCount As Long 206 | If hSQLiteStdCallLibrary <> 0 Then 207 | refCount = FreeLibrary(hSQLiteStdCallLibrary) 208 | hSQLiteStdCallLibrary = 0 209 | If refCount = 0 Then 210 | Debug.Print "SQLite3Free Error Freeing SQLite3_StdCall.dll:", refCount, Err.LastDllError 211 | End If 212 | End If 213 | If hSQLiteLibrary <> 0 Then 214 | refCount = FreeLibrary(hSQLiteLibrary) 215 | hSQLiteLibrary = 0 216 | If refCount = 0 Then 217 | Debug.Print "SQLite3Free Error Freeing SQLite3.dll:", refCount, Err.LastDllError 218 | End If 219 | End If 220 | End Sub 221 | 222 | 223 | '===================================================================================== 224 | ' SQLite library version 225 | 226 | Public Function SQLite3LibVersion() As String 227 | SQLite3LibVersion = Utf8PtrToString(sqlite3_stdcall_libversion()) 228 | End Function 229 | 230 | '===================================================================================== 231 | ' Database connections 232 | 233 | Public Function SQLite3Open(ByVal fileName As String, ByRef dbHandle As Long) As Long 234 | SQLite3Open = sqlite3_stdcall_open16(StrPtr(fileName), dbHandle) 235 | End Function 236 | 237 | Public Function SQLite3OpenV2(ByVal fileName As String, ByRef dbHandle As Long, ByVal flags As Long, ByVal vfsName As String) As Long 238 | Dim bufFileName() As Byte 239 | Dim bufVfsName() As Byte 240 | bufFileName = StringToUtf8Bytes(fileName) 241 | If vfsName = Empty Then 242 | SQLite3OpenV2 = sqlite3_stdcall_open_v2(VarPtr(bufFileName(0)), dbHandle, flags, 0) 243 | Else 244 | bufVfsName = StringToUtf8Bytes(vfsName) 245 | SQLite3OpenV2 = sqlite3_stdcall_open_v2(VarPtr(bufFileName(0)), dbHandle, flags, VarPtr(bufVfsName(0))) 246 | End If 247 | End Function 248 | 249 | Public Function SQLite3Close(ByVal dbHandle As Long) As Long 250 | SQLite3Close = sqlite3_stdcall_close(dbHandle) 251 | End Function 252 | 253 | '===================================================================================== 254 | ' Error information 255 | 256 | Public Function SQLite3ErrMsg(ByVal dbHandle As Long) As String 257 | SQLite3ErrMsg = Utf8PtrToString(sqlite3_stdcall_errmsg(dbHandle)) 258 | End Function 259 | 260 | Public Function SQLite3ErrCode(ByVal dbHandle As Long) As Long 261 | SQLite3ErrCode = sqlite3_stdcall_errcode(dbHandle) 262 | End Function 263 | 264 | Public Function SQLite3ExtendedErrCode(ByVal dbHandle As Long) As Long 265 | SQLite3ExtendedErrCode = sqlite3_stdcall_extended_errcode(dbHandle) 266 | End Function 267 | 268 | '===================================================================================== 269 | ' Change Counts 270 | 271 | Public Function SQLite3Changes(ByVal dbHandle As Long) As Long 272 | SQLite3Changes = sqlite3_stdcall_changes(dbHandle) 273 | End Function 274 | 275 | Public Function SQLite3TotalChanges(ByVal dbHandle As Long) As Long 276 | SQLite3TotalChanges = sqlite3_stdcall_total_changes(dbHandle) 277 | End Function 278 | 279 | '===================================================================================== 280 | ' Statements 281 | 282 | Public Function SQLite3PrepareV2(ByVal dbHandle As Long, ByVal sql As String, ByRef stmtHandle As Long) As Long 283 | ' Only the first statement (up to ';') is prepared. Currently we don't retrieve the 'tail' pointer. 284 | SQLite3PrepareV2 = sqlite3_stdcall_prepare16_v2(dbHandle, StrPtr(sql), Len(sql) * 2, stmtHandle, 0) 285 | End Function 286 | 287 | Public Function SQLite3Step(ByVal stmtHandle As Long) As Long 288 | SQLite3Step = sqlite3_stdcall_step(stmtHandle) 289 | End Function 290 | 291 | Public Function SQLite3Reset(ByVal stmtHandle As Long) As Long 292 | SQLite3Reset = sqlite3_stdcall_reset(stmtHandle) 293 | End Function 294 | 295 | Public Function SQLite3Finalize(ByVal stmtHandle As Long) As Long 296 | SQLite3Finalize = sqlite3_stdcall_finalize(stmtHandle) 297 | End Function 298 | 299 | '===================================================================================== 300 | ' Statement column access (0-based indices) 301 | 302 | Public Function SQLite3ColumnCount(ByVal stmtHandle As Long) As Long 303 | SQLite3ColumnCount = sqlite3_stdcall_column_count(stmtHandle) 304 | End Function 305 | 306 | Public Function SQLite3ColumnType(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Long 307 | SQLite3ColumnType = sqlite3_stdcall_column_type(stmtHandle, ZeroBasedColIndex) 308 | End Function 309 | 310 | Public Function SQLite3ColumnName(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As String 311 | SQLite3ColumnName = Utf8PtrToString(sqlite3_stdcall_column_name(stmtHandle, ZeroBasedColIndex)) 312 | End Function 313 | 314 | Public Function SQLite3ColumnDouble(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Double 315 | SQLite3ColumnDouble = sqlite3_stdcall_column_double(stmtHandle, ZeroBasedColIndex) 316 | End Function 317 | 318 | Public Function SQLite3ColumnInt32(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Long 319 | SQLite3ColumnInt32 = sqlite3_stdcall_column_int(stmtHandle, ZeroBasedColIndex) 320 | End Function 321 | 322 | Public Function SQLite3ColumnText(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As String 323 | SQLite3ColumnText = Utf8PtrToString(sqlite3_stdcall_column_text(stmtHandle, ZeroBasedColIndex)) 324 | End Function 325 | 326 | Public Function SQLite3ColumnDate(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Date 327 | SQLite3ColumnDate = FromJulianDay(sqlite3_stdcall_column_double(stmtHandle, ZeroBasedColIndex)) 328 | End Function 329 | 330 | Public Function SQLite3ColumnBlob(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Byte() 331 | Dim ptr As Long 332 | Dim length As Long 333 | Dim buf() As Byte 334 | 335 | ptr = sqlite3_stdcall_column_blob(stmtHandle, ZeroBasedColIndex) 336 | length = sqlite3_stdcall_column_bytes(stmtHandle, ZeroBasedColIndex) 337 | ReDim buf(length - 1) 338 | RtlMoveMemory VarPtr(buf(0)), ptr, length 339 | SQLite3ColumnBlob = buf 340 | End Function 341 | 342 | '===================================================================================== 343 | ' Statement bindings 344 | 345 | Public Function SQLite3BindText(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As String) As Long 346 | SQLite3BindText = sqlite3_stdcall_bind_text16(stmtHandle, OneBasedParamIndex, StrPtr(Value), -1, SQLITE_TRANSIENT) 347 | End Function 348 | 349 | Public Function SQLite3BindDouble(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As Double) As Long 350 | SQLite3BindDouble = sqlite3_stdcall_bind_double(stmtHandle, OneBasedParamIndex, Value) 351 | End Function 352 | 353 | Public Function SQLite3BindInt32(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As Long) As Long 354 | SQLite3BindInt32 = sqlite3_stdcall_bind_int(stmtHandle, OneBasedParamIndex, Value) 355 | End Function 356 | 357 | Public Function SQLite3BindDate(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As Date) As Long 358 | SQLite3BindDate = sqlite3_stdcall_bind_double(stmtHandle, OneBasedParamIndex, ToJulianDay(Value)) 359 | End Function 360 | 361 | Public Function SQLite3BindBlob(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByRef Value() As Byte) As Long 362 | Dim length As Long 363 | length = UBound(Value) - LBound(Value) + 1 364 | SQLite3BindBlob = sqlite3_stdcall_bind_blob(stmtHandle, OneBasedParamIndex, VarPtr(Value(0)), length, SQLITE_TRANSIENT) 365 | End Function 366 | 367 | Public Function SQLite3BindNull(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long) As Long 368 | SQLite3BindNull = sqlite3_stdcall_bind_null(stmtHandle, OneBasedParamIndex) 369 | End Function 370 | 371 | Public Function SQLite3BindParameterCount(ByVal stmtHandle As Long) As Long 372 | SQLite3BindParameterCount = sqlite3_stdcall_bind_parameter_count(stmtHandle) 373 | End Function 374 | 375 | Public Function SQLite3BindParameterName(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long) As String 376 | SQLite3BindParameterName = Utf8PtrToString(sqlite3_stdcall_bind_parameter_name(stmtHandle, OneBasedParamIndex)) 377 | End Function 378 | 379 | Public Function SQLite3BindParameterIndex(ByVal stmtHandle As Long, ByVal paramName As String) As Long 380 | Dim buf() As Byte 381 | buf = StringToUtf8Bytes(paramName) 382 | SQLite3BindParameterIndex = sqlite3_stdcall_bind_parameter_index(stmtHandle, VarPtr(buf(0))) 383 | End Function 384 | 385 | Public Function SQLite3ClearBindings(ByVal stmtHandle As Long) As Long 386 | SQLite3ClearBindings = sqlite3_stdcall_clear_bindings(stmtHandle) 387 | End Function 388 | 389 | 390 | '===================================================================================== 391 | ' Backup 392 | Public Function SQLite3Sleep(ByVal timeToSleepInMs As Long) As Long 393 | SQLite3Sleep = sqlite3_stdcall_sleep(timeToSleepInMs) 394 | End Function 395 | 396 | Public Function SQLite3BackupInit(ByVal dbHandleDestination As Long, ByVal destinationName As String, ByVal dbHandleSource As Long, ByVal sourceName As String) As Long 397 | Dim bufDestinationName() As Byte 398 | Dim bufSourceName() As Byte 399 | bufDestinationName = StringToUtf8Bytes(destinationName) 400 | bufSourceName = StringToUtf8Bytes(sourceName) 401 | SQLite3BackupInit = sqlite3_stdcall_backup_init(dbHandleDestination, VarPtr(bufDestinationName(0)), dbHandleSource, VarPtr(bufSourceName(0))) 402 | End Function 403 | 404 | Public Function SQLite3BackupFinish(ByVal backupHandle As Long) As Long 405 | SQLite3BackupFinish = sqlite3_stdcall_backup_finish(backupHandle) 406 | End Function 407 | 408 | Public Function SQLite3BackupStep(ByVal backupHandle As Long, ByVal numberOfPages) As Long 409 | SQLite3BackupStep = sqlite3_stdcall_backup_step(backupHandle, numberOfPages) 410 | End Function 411 | 412 | Public Function SQLite3BackupPageCount(ByVal backupHandle As Long) As Long 413 | SQLite3BackupPageCount = sqlite3_stdcall_backup_pagecount(backupHandle) 414 | End Function 415 | 416 | Public Function SQLite3BackupRemaining(ByVal backupHandle As Long) As Long 417 | SQLite3BackupRemaining = sqlite3_stdcall_backup_remaining(backupHandle) 418 | End Function 419 | 420 | ' String Helpers 421 | Function Utf8PtrToString(ByVal pUtf8String As Long) As String 422 | Dim buf As String 423 | Dim cSize As Long 424 | Dim RetVal As Long 425 | 426 | cSize = MultiByteToWideChar(CP_UTF8, 0, pUtf8String, -1, 0, 0) 427 | ' cSize includes the terminating null character 428 | If cSize <= 1 Then 429 | Utf8PtrToString = "" 430 | Exit Function 431 | End If 432 | 433 | Utf8PtrToString = String(cSize - 1, "*") ' and a termintating null char. 434 | RetVal = MultiByteToWideChar(CP_UTF8, 0, pUtf8String, -1, StrPtr(Utf8PtrToString), cSize) 435 | If RetVal = 0 Then 436 | Debug.Print "Utf8PtrToString Error:", Err.LastDllError 437 | Exit Function 438 | End If 439 | End Function 440 | 441 | Function StringToUtf8Bytes(ByVal str As String) As Variant 442 | Dim bSize As Long 443 | Dim RetVal As Long 444 | Dim buf() As Byte 445 | 446 | bSize = WideCharToMultiByte(CP_UTF8, 0, StrPtr(str), -1, 0, 0, 0, 0) 447 | If bSize = 0 Then 448 | Exit Function 449 | End If 450 | 451 | ReDim buf(bSize) 452 | RetVal = WideCharToMultiByte(CP_UTF8, 0, StrPtr(str), -1, VarPtr(buf(0)), bSize, 0, 0) 453 | If RetVal = 0 Then 454 | Debug.Print "StringToUtf8Bytes Error:", Err.LastDllError 455 | Exit Function 456 | End If 457 | StringToUtf8Bytes = buf 458 | End Function 459 | 460 | Function Utf16PtrToString(ByVal pUtf16String As Long) As String 461 | Dim StrLen As Long 462 | Dim RetVal As Long 463 | 464 | StrLen = lstrlenW(pUtf16String) 465 | Utf16PtrToString = String(StrLen, "*") 466 | lstrcpynW StrPtr(Utf16PtrToString), pUtf16String, StrLen 467 | End Function 468 | 469 | ' Date Helpers 470 | Public Function ToJulianDay(oleDate As Date) As Double 471 | ToJulianDay = CDbl(oleDate) + JULIANDAY_OFFSET 472 | End Function 473 | 474 | Public Function FromJulianDay(julianDay As Double) As Date 475 | FromJulianDay = CDate(julianDay - JULIANDAY_OFFSET) 476 | End Function 477 | -------------------------------------------------------------------------------- /Source/SQLite3VBAModules/Sqlite3Demo.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "Sqlite3Demo" 2 | Option Explicit 3 | 4 | Dim TestFile As String 5 | 6 | Public Sub AllTests() 7 | ' Check that this location can be written to 8 | ' Note that this file will be deleted after the tests complete! 9 | TestFile = Environ("TEMP") & "\TestSqlite3ForExcel.db3" 10 | 11 | Dim InitReturn As Long 12 | InitReturn = SQLite3Initialize ' Default path is ThisWorkbook.Path but can specify other path where the .dlls reside. 13 | If InitReturn <> SQLITE_INIT_OK Then 14 | Debug.Print "Error Initializing SQLite. Error: " & Err.LastDllError 15 | Exit Sub 16 | End If 17 | 18 | TestVersion 19 | TestOpenClose 20 | TestOpenCloseV2 21 | TestError 22 | TestInsert 23 | TestSelect 24 | TestBinding 25 | TestDates 26 | TestStrings 27 | TestBackup 28 | TestBlob 29 | TestWriteReadOnly 30 | 31 | SQLite3Free ' Quite optional 32 | 33 | Debug.Print "----- All Tests Complete -----" 34 | End Sub 35 | 36 | Public Sub TestVersion() 37 | 38 | Debug.Print SQLite3LibVersion() 39 | 40 | End Sub 41 | 42 | Public Sub TestApiCallSpeed() 43 | 44 | Dim i As Long 45 | Dim version As String 46 | Dim start As Date 47 | 48 | start = Now() 49 | For i = 0 To 10000000 ' 10 million 50 | version = SQLite3LibVersion() 51 | Next 52 | 53 | Debug.Print "ApiCall Elapsed: " & Format(Now() - start, "HH:mm:ss") 54 | 55 | End Sub 56 | 57 | Public Sub TestOpenClose() 58 | Dim myDbHandle As Long 59 | Dim RetVal As Long 60 | 61 | RetVal = SQLite3Open(TestFile, myDbHandle) 62 | Debug.Print "SQLite3Open returned " & RetVal 63 | 64 | RetVal = SQLite3Close(myDbHandle) 65 | Debug.Print "SQLite3Close returned " & RetVal 66 | 67 | Kill TestFile 68 | 69 | End Sub 70 | 71 | Public Sub TestOpenCloseV2() 72 | Dim myDbHandle As Long 73 | Dim myDbHandleV2 As Long 74 | Dim RetVal As Long 75 | 76 | ' Open the database in Read Write Access 77 | RetVal = SQLite3Open(TestFile, myDbHandle) 78 | Debug.Print "SQLite3Open returned " & RetVal 79 | 80 | ' Open the database in Read Only Access 81 | RetVal = SQLite3OpenV2(TestFile, myDbHandleV2, SQLITE_OPEN_READONLY, "") 82 | Debug.Print "SQLite3OpenV2 returned " & RetVal 83 | 84 | RetVal = SQLite3Close(myDbHandleV2) 85 | Debug.Print "SQLite3Close V2 returned " & RetVal 86 | 87 | RetVal = SQLite3Close(myDbHandle) 88 | Debug.Print "SQLite3Close returned " & RetVal 89 | 90 | Kill TestFile 91 | 92 | End Sub 93 | 94 | Public Sub TestError() 95 | Dim myDbHandle As Long 96 | Dim RetVal As Long 97 | 98 | Dim ErrMsg As String 99 | 100 | Debug.Print "----- TestError Start -----" 101 | 102 | ' DbHandle is set up even if there is an error ! 103 | RetVal = SQLite3Open("::::", myDbHandle) 104 | Debug.Print "SQLite3Open returned " & RetVal 105 | 106 | ErrMsg = SQLite3ErrMsg(myDbHandle) 107 | Debug.Print "SQLite3Open error message: " & ErrMsg 108 | 109 | RetVal = SQLite3Close(myDbHandle) 110 | Debug.Print "SQLite3Close returned " & RetVal 111 | 112 | Debug.Print "----- TestError End -----" 113 | 114 | End Sub 115 | 116 | Public Sub TestStatement() 117 | Dim myDbHandle As Long 118 | Dim myStmtHandle As Long 119 | Dim RetVal As Long 120 | 121 | Dim stepMsg As String 122 | 123 | Debug.Print "----- TestStatement Start -----" 124 | 125 | ' Open the database - getting a DbHandle back 126 | RetVal = SQLite3Open(TestFile, myDbHandle) 127 | Debug.Print "SQLite3Open returned " & RetVal 128 | 129 | ' Create the sql statement - getting a StmtHandle back 130 | RetVal = SQLite3PrepareV2(myDbHandle, "CREATE TABLE MyFirstTable (TheId INTEGER, TheText TEXT, TheValue REAL)", myStmtHandle) 131 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 132 | 133 | ' Start running the statement 134 | RetVal = SQLite3Step(myStmtHandle) 135 | Debug.Print "SQLite3Step returned " & RetVal 136 | 137 | ' Finalize (delete) the statement 138 | RetVal = SQLite3Finalize(myStmtHandle) 139 | Debug.Print "SQLite3Finalize returned " & RetVal 140 | 141 | ' Close the database 142 | RetVal = SQLite3Close(myDbHandle) 143 | Kill TestFile 144 | 145 | Debug.Print "----- TestStatement End -----" 146 | End Sub 147 | 148 | Public Sub TestInsert() 149 | Dim myDbHandle As Long 150 | Dim myStmtHandle As Long 151 | Dim RetVal As Long 152 | Dim recordsAffected As Long 153 | 154 | Dim stepMsg As String 155 | 156 | Debug.Print "----- TestInsert Start -----" 157 | 158 | ' Open the database - getting a DbHandle back 159 | RetVal = SQLite3Open(TestFile, myDbHandle) 160 | Debug.Print "SQLite3Open returned " & RetVal 161 | 162 | '------------------------ 163 | ' Create the table 164 | ' ================ 165 | ' Create the sql statement - getting a StmtHandle back 166 | RetVal = SQLite3PrepareV2(myDbHandle, "CREATE TABLE MySecondTable (TheId INTEGER, TheText TEXT, TheValue REAL)", myStmtHandle) 167 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 168 | 169 | ' Start running the statement 170 | RetVal = SQLite3Step(myStmtHandle) 171 | If RetVal = SQLITE_DONE Then 172 | Debug.Print "SQLite3Step Done" 173 | Else 174 | Debug.Print "SQLite3Step returned " & RetVal 175 | End If 176 | 177 | ' Finalize (delete) the statement 178 | RetVal = SQLite3Finalize(myStmtHandle) 179 | Debug.Print "SQLite3Finalize returned " & RetVal 180 | 181 | '------------------------- 182 | ' Insert a record 183 | ' =============== 184 | ' Create the sql statement - getting a StmtHandle back 185 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MySecondTable Values (123, 'ABC', 42.1)", myStmtHandle) 186 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 187 | 188 | ' Start running the statement 189 | RetVal = SQLite3Step(myStmtHandle) 190 | If RetVal = SQLITE_DONE Then 191 | Debug.Print "SQLite3Step Done" 192 | Else 193 | Debug.Print "SQLite3Step returned " & RetVal 194 | End If 195 | 196 | ' Finalize (delete) the statement 197 | RetVal = SQLite3Finalize(myStmtHandle) 198 | Debug.Print "SQLite3Finalize returned " & RetVal 199 | 200 | '------------------------- 201 | ' Insert using helper 202 | ' ==================== 203 | recordsAffected = SQLite3ExecuteNonQuery(myDbHandle, "INSERT INTO MySecondTable Values (456, 'DEF', 49.3)") 204 | Debug.Print "SQLite3Execute - Insert affected " & recordsAffected & " record(s)." 205 | 206 | ' Close the database 207 | RetVal = SQLite3Close(myDbHandle) 208 | Kill TestFile 209 | 210 | Debug.Print "----- TestInsert End -----" 211 | End Sub 212 | 213 | Public Sub TestSelect() 214 | Dim myDbHandle As Long 215 | Dim myStmtHandle As Long 216 | Dim RetVal As Long 217 | 218 | Dim stepMsg As String 219 | 220 | Debug.Print "----- TestSelect Start -----" 221 | 222 | ' Open the database - getting a DbHandle back 223 | RetVal = SQLite3Open(TestFile, myDbHandle) 224 | Debug.Print "SQLite3Open returned " & RetVal 225 | 226 | '------------------------ 227 | ' Create the table 228 | ' ================ 229 | ' Create the sql statement - getting a StmtHandle back 230 | RetVal = SQLite3PrepareV2(myDbHandle, "CREATE TABLE MyFirstTable (TheId INTEGER, TheText TEXT, TheValue REAL)", myStmtHandle) 231 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 232 | 233 | ' Start running the statement 234 | RetVal = SQLite3Step(myStmtHandle) 235 | If RetVal = SQLITE_DONE Then 236 | Debug.Print "SQLite3Step Done" 237 | Else 238 | Debug.Print "SQLite3Step returned " & RetVal 239 | End If 240 | 241 | ' Finalize (delete) the statement 242 | RetVal = SQLite3Finalize(myStmtHandle) 243 | Debug.Print "SQLite3Finalize returned " & RetVal 244 | 245 | '------------------------- 246 | ' Insert a record 247 | ' =============== 248 | ' Create the sql statement - getting a StmtHandle back 249 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyFirstTable Values (123, 'ABC', 42.1)", myStmtHandle) 250 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 251 | 252 | ' Start running the statement 253 | RetVal = SQLite3Step(myStmtHandle) 254 | If RetVal = SQLITE_DONE Then 255 | Debug.Print "SQLite3Step Done" 256 | Else 257 | Debug.Print "SQLite3Step returned " & RetVal 258 | End If 259 | 260 | ' Finalize (delete) the statement 261 | RetVal = SQLite3Finalize(myStmtHandle) 262 | Debug.Print "SQLite3Finalize returned " & RetVal 263 | 264 | '------------------------- 265 | ' Insert another record 266 | ' =============== 267 | ' Create the sql statement - getting a StmtHandle back 268 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyFirstTable Values (987654, ""ZXCVBNM"", NULL)", myStmtHandle) 269 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 270 | 271 | ' Start running the statement 272 | RetVal = SQLite3Step(myStmtHandle) 273 | If RetVal = SQLITE_DONE Then 274 | Debug.Print "SQLite3Step Done" 275 | Else 276 | Debug.Print "SQLite3Step returned " & RetVal 277 | End If 278 | 279 | ' Finalize (delete) the statement 280 | RetVal = SQLite3Finalize(myStmtHandle) 281 | Debug.Print "SQLite3Finalize returned " & RetVal 282 | 283 | '------------------------- 284 | ' Select statement 285 | ' =============== 286 | ' Create the sql statement - getting a StmtHandle back 287 | RetVal = SQLite3PrepareV2(myDbHandle, "SELECT * FROM MyFirstTable", myStmtHandle) 288 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 289 | 290 | ' Start running the statement 291 | RetVal = SQLite3Step(myStmtHandle) 292 | If RetVal = SQLITE_ROW Then 293 | Debug.Print "SQLite3Step Row Ready" 294 | PrintColumns myStmtHandle 295 | Else 296 | Debug.Print "SQLite3Step returned " & RetVal 297 | End If 298 | 299 | ' Move to next row 300 | RetVal = SQLite3Step(myStmtHandle) 301 | If RetVal = SQLITE_ROW Then 302 | Debug.Print "SQLite3Step Row Ready" 303 | PrintColumns myStmtHandle 304 | Else 305 | Debug.Print "SQLite3Step returned " & RetVal 306 | End If 307 | 308 | ' Move on again (now we are done) 309 | RetVal = SQLite3Step(myStmtHandle) 310 | If RetVal = SQLITE_DONE Then 311 | Debug.Print "SQLite3Step Done" 312 | Else 313 | Debug.Print "SQLite3Step returned " & RetVal 314 | End If 315 | 316 | ' Finalize (delete) the statement 317 | RetVal = SQLite3Finalize(myStmtHandle) 318 | Debug.Print "SQLite3Finalize returned " & RetVal 319 | 320 | 321 | ' Close the database 322 | RetVal = SQLite3Close(myDbHandle) 323 | Kill TestFile 324 | 325 | Debug.Print "----- TestSelect End -----" 326 | End Sub 327 | 328 | Sub PrintColumns(ByVal stmtHandle As Long) 329 | Dim colCount As Long 330 | Dim colName As String 331 | Dim colType As Long 332 | Dim colTypeName As String 333 | Dim colValue As Variant 334 | 335 | Dim i As Long 336 | 337 | colCount = SQLite3ColumnCount(stmtHandle) 338 | Debug.Print "Column count: " & colCount 339 | For i = 0 To colCount - 1 340 | colName = SQLite3ColumnName(stmtHandle, i) 341 | colType = SQLite3ColumnType(stmtHandle, i) 342 | colTypeName = TypeName(colType) 343 | colValue = ColumnValue(stmtHandle, i, colType) 344 | Debug.Print "Column " & i & ":", colName, colTypeName, colValue 345 | Next 346 | End Sub 347 | 348 | Sub PrintParameters(ByVal stmtHandle As Long) 349 | Dim paramCount As Long 350 | Dim paramName As String 351 | 352 | Dim i As Long 353 | 354 | paramCount = SQLite3BindParameterCount(stmtHandle) 355 | Debug.Print "Parameter count: " & paramCount 356 | For i = 1 To paramCount 357 | paramName = SQLite3BindParameterName(stmtHandle, i) 358 | Debug.Print "Parameter " & i & ":", paramName 359 | Next 360 | End Sub 361 | 362 | 363 | Function TypeName(ByVal SQLiteType As Long) As String 364 | Select Case SQLiteType 365 | Case SQLITE_INTEGER: 366 | TypeName = "INTEGER" 367 | Case SQLITE_FLOAT: 368 | TypeName = "FLOAT" 369 | Case SQLITE_TEXT: 370 | TypeName = "TEXT" 371 | Case SQLITE_BLOB: 372 | TypeName = "BLOB" 373 | Case SQLITE_NULL: 374 | TypeName = "NULL" 375 | End Select 376 | End Function 377 | 378 | Function ColumnValue(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long, ByVal SQLiteType As Long) As Variant 379 | Select Case SQLiteType 380 | Case SQLITE_INTEGER: 381 | ColumnValue = SQLite3ColumnInt32(stmtHandle, ZeroBasedColIndex) 382 | Case SQLITE_FLOAT: 383 | ColumnValue = SQLite3ColumnDouble(stmtHandle, ZeroBasedColIndex) 384 | Case SQLITE_TEXT: 385 | ColumnValue = SQLite3ColumnText(stmtHandle, ZeroBasedColIndex) 386 | Case SQLITE_BLOB: 387 | ColumnValue = SQLite3ColumnText(stmtHandle, ZeroBasedColIndex) 388 | Case SQLITE_NULL: 389 | ColumnValue = Null 390 | End Select 391 | End Function 392 | 393 | Public Sub TestBinding() 394 | Dim myDbHandle As Long 395 | Dim myStmtHandle As Long 396 | Dim RetVal As Long 397 | Dim stepMsg As String 398 | Dim i As Long 399 | 400 | Dim paramIndexId As Long 401 | Dim paramIndexDate As Long 402 | 403 | Dim startDate As Date 404 | Dim curDate As Date 405 | Dim curValue As Double 406 | Dim offset As Long 407 | 408 | Dim testStart As Date 409 | 410 | Debug.Print "----- TestBinding Start -----" 411 | 412 | ' Open the database - getting a DbHandle back 413 | RetVal = SQLite3Open(TestFile, myDbHandle) 414 | Debug.Print "SQLite3Open returned " & RetVal 415 | 416 | '------------------------ 417 | ' Create the table 418 | ' ================ 419 | ' (O've got no error checking here...) 420 | SQLite3PrepareV2 myDbHandle, "CREATE TABLE MyBigTable (TheId INTEGER, TheDate REAL, TheText TEXT, TheValue REAL)", myStmtHandle 421 | SQLite3Step myStmtHandle 422 | SQLite3Finalize myStmtHandle 423 | 424 | '--------------------------- 425 | ' Add an index 426 | ' ================ 427 | SQLite3PrepareV2 myDbHandle, "CREATE INDEX idx_MyBigTable_Id_Date ON MyBigTable (TheId, TheDate)", myStmtHandle 428 | SQLite3Step myStmtHandle 429 | SQLite3Finalize myStmtHandle 430 | 431 | ' START Insert Time 432 | testStart = Now() 433 | 434 | '------------------- 435 | ' Begin transaction 436 | '================== 437 | SQLite3PrepareV2 myDbHandle, "BEGIN TRANSACTION", myStmtHandle 438 | SQLite3Step myStmtHandle 439 | SQLite3Finalize myStmtHandle 440 | 441 | '------------------------- 442 | ' Prepare an insert statement with parameters 443 | ' =============== 444 | ' Create the sql statement - getting a StmtHandle back 445 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyBigTable Values (?, ?, ?, ?)", myStmtHandle) 446 | If RetVal <> SQLITE_OK Then 447 | Debug.Print "SQLite3PrepareV2 returned " & SQLite3ErrMsg(myDbHandle) 448 | Beep 449 | End If 450 | 451 | Randomize 452 | startDate = DateValue("1 Jan 2000") 453 | 454 | For i = 1 To 100000 455 | curDate = startDate + i 456 | curValue = Rnd() * 1000 457 | 458 | RetVal = SQLite3BindInt32(myStmtHandle, 1, 42000 + i) 459 | If RetVal <> SQLITE_OK Then 460 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 461 | Beep 462 | End If 463 | 464 | RetVal = SQLite3BindDate(myStmtHandle, 2, curDate) 465 | If RetVal <> SQLITE_OK Then 466 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 467 | Beep 468 | End If 469 | 470 | RetVal = SQLite3BindText(myStmtHandle, 3, "The quick brown fox jumped over the lazy dog.") 471 | If RetVal <> SQLITE_OK Then 472 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 473 | Beep 474 | End If 475 | 476 | RetVal = SQLite3BindDouble(myStmtHandle, 4, curValue) 477 | If RetVal <> SQLITE_OK Then 478 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 479 | Beep 480 | End If 481 | 482 | RetVal = SQLite3Step(myStmtHandle) 483 | If RetVal <> SQLITE_DONE Then 484 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 485 | Beep 486 | End If 487 | 488 | RetVal = SQLite3Reset(myStmtHandle) 489 | If RetVal <> SQLITE_OK Then 490 | Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle) 491 | Beep 492 | End If 493 | Next 494 | 495 | ' Finalize (delete) the statement 496 | RetVal = SQLite3Finalize(myStmtHandle) 497 | Debug.Print "SQLite3Finalize returned " & RetVal 498 | 499 | '------------------- 500 | ' Commit transaction 501 | '================== 502 | ' (I'm re-using the same variable myStmtHandle for the new statement) 503 | SQLite3PrepareV2 myDbHandle, "COMMIT TRANSACTION", myStmtHandle 504 | SQLite3Step myStmtHandle 505 | SQLite3Finalize myStmtHandle 506 | 507 | ' STOP Insert Time 508 | Debug.Print "Insert Elapsed: " & Format(Now() - testStart, "HH:mm:ss") 509 | 510 | ' START Select Time 511 | testStart = Now() 512 | 513 | '------------------------- 514 | ' Select statement 515 | ' =============== 516 | ' Create the sql statement - getting a StmtHandle back 517 | ' Now using named parameters! 518 | RetVal = SQLite3PrepareV2(myDbHandle, "SELECT TheId, datetime(TheDate), TheText, TheValue FROM MyBigTable WHERE TheId = @FindThisId AND TheDate <= @FindThisDate LIMIT 1", myStmtHandle) 519 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 520 | 521 | paramIndexId = SQLite3BindParameterIndex(myStmtHandle, "@FindThisId") 522 | If paramIndexId = 0 Then 523 | Debug.Print "SQLite3BindParameterIndex could not find the Id parameter!" 524 | Beep 525 | End If 526 | 527 | paramIndexDate = SQLite3BindParameterIndex(myStmtHandle, "@FindThisDate") 528 | If paramIndexDate = 0 Then 529 | Debug.Print "SQLite3BindParameterIndex could not find the Date parameter!" 530 | Beep 531 | End If 532 | 533 | startDate = DateValue("1 Jan 2000") 534 | 535 | 536 | For i = 1 To 100000 537 | offset = i Mod 10000 538 | ' Bind the parameters 539 | RetVal = SQLite3BindInt32(myStmtHandle, paramIndexId, 42000 + 500 + offset) 540 | If RetVal <> SQLITE_OK Then 541 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 542 | Beep 543 | End If 544 | 545 | RetVal = SQLite3BindDate(myStmtHandle, paramIndexDate, startDate + 500 + offset) 546 | If RetVal <> SQLITE_OK Then 547 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 548 | Beep 549 | End If 550 | 551 | RetVal = SQLite3Step(myStmtHandle) 552 | If RetVal = SQLITE_ROW Then 553 | ' We have access to the result columns here. 554 | If offset = 1 Then 555 | Debug.Print "At row " & i 556 | Debug.Print "------------" 557 | PrintColumns myStmtHandle 558 | Debug.Print "============" 559 | End If 560 | ElseIf RetVal = SQLITE_DONE Then 561 | Debug.Print "No row found" 562 | End If 563 | 564 | RetVal = SQLite3Reset(myStmtHandle) 565 | If RetVal <> SQLITE_OK Then 566 | Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle) 567 | Beep 568 | End If 569 | Next 570 | 571 | ' Finalize (delete) the statement 572 | RetVal = SQLite3Finalize(myStmtHandle) 573 | Debug.Print "SQLite3Finalize returned " & RetVal 574 | 575 | ' STOP Select time 576 | Debug.Print "Select Elapsed: " & Format(Now() - testStart, "HH:mm:ss") 577 | 578 | ' Close the database 579 | RetVal = SQLite3Close(myDbHandle) 580 | Kill TestFile 581 | 582 | Debug.Print "----- TestBinding End -----" 583 | End Sub 584 | 585 | 586 | Public Sub TestBindingMore() 587 | Dim myDbHandle As Long 588 | Dim myStmtHandle As Long 589 | Dim RetVal As Long 590 | Dim stepMsg As String 591 | Dim i As Long 592 | 593 | Dim paramIndexId As Long 594 | Dim paramIndexDate As Long 595 | 596 | Dim startDate As Date 597 | Dim curDate As Date 598 | Dim curValue As Double 599 | Dim offset As Long 600 | 601 | Dim testStart As Date 602 | 603 | Debug.Print "----- TestBinding Start -----" 604 | 605 | ' Open the database - getting a DbHandle back 606 | RetVal = SQLite3Open(TestFile, myDbHandle) 607 | Debug.Print "SQLite3Open returned " & RetVal 608 | 609 | '------------------------ 610 | ' Create the table 611 | ' ================ 612 | ' (O've got no error checking here...) 613 | SQLite3ExecuteNonQuery myDbHandle, "CREATE TABLE MyBigTable (TheId INTEGER, TheDate REAL, TheText TEXT, TheValue REAL)" 614 | 615 | '--------------------------- 616 | ' Add an index 617 | ' ================ 618 | SQLite3ExecuteNonQuery myDbHandle, "CREATE INDEX idx_MyBigTable_Id_Date ON MyBigTable (TheId, TheDate)" 619 | 620 | ' START Insert Time 621 | testStart = Now() 622 | 623 | '------------------- 624 | ' Begin transaction 625 | '================== 626 | SQLite3ExecuteNonQuery myDbHandle, "BEGIN TRANSACTION" 627 | 628 | '------------------------- 629 | ' Prepare an insert statement with parameters 630 | ' =============== 631 | ' Create the sql statement - getting a StmtHandle back 632 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyBigTable Values (?, ?, ?, ?)", myStmtHandle) 633 | If RetVal <> SQLITE_OK Then 634 | Debug.Print "SQLite3PrepareV2 returned " & SQLite3ErrMsg(myDbHandle) 635 | Beep 636 | End If 637 | 638 | PrintParameters myStmtHandle 639 | 640 | Randomize 641 | startDate = DateValue("1 Jan 2000") 642 | 643 | For i = 1 To 100000 644 | curDate = startDate + i 645 | curValue = Rnd() * 1000 646 | 647 | RetVal = SQLite3BindInt32(myStmtHandle, 1, 42000 + i) 648 | If RetVal <> SQLITE_OK Then 649 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 650 | Beep 651 | End If 652 | 653 | RetVal = SQLite3BindDate(myStmtHandle, 2, curDate) 654 | If RetVal <> SQLITE_OK Then 655 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 656 | Beep 657 | End If 658 | 659 | RetVal = SQLite3BindText(myStmtHandle, 3, "The quick brown fox jumped over the lazy dog.") 660 | If RetVal <> SQLITE_OK Then 661 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 662 | Beep 663 | End If 664 | 665 | RetVal = SQLite3BindDouble(myStmtHandle, 4, curValue) 666 | If RetVal <> SQLITE_OK Then 667 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 668 | Beep 669 | End If 670 | 671 | RetVal = SQLite3Step(myStmtHandle) 672 | If RetVal <> SQLITE_DONE Then 673 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 674 | Beep 675 | End If 676 | 677 | RetVal = SQLite3Reset(myStmtHandle) 678 | If RetVal <> SQLITE_OK Then 679 | Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle) 680 | Beep 681 | End If 682 | Next 683 | 684 | ' Finalize (delete) the statement 685 | RetVal = SQLite3Finalize(myStmtHandle) 686 | Debug.Print "SQLite3Finalize returned " & RetVal 687 | 688 | '------------------- 689 | ' Commit transaction 690 | '================== 691 | SQLite3ExecuteNonQuery myDbHandle, "COMMIT TRANSACTION" 692 | 693 | ' STOP Insert Time 694 | Debug.Print "Insert Elapsed: " & Format(Now() - testStart, "HH:mm:ss") 695 | 696 | ' START Select Time 697 | testStart = Now() 698 | 699 | '------------------------- 700 | ' Select statement 701 | ' =============== 702 | ' Create the sql statement - getting a StmtHandle back 703 | ' Now using named parameters! 704 | RetVal = SQLite3PrepareV2(myDbHandle, "SELECT TheId, datetime(TheDate), TheText, TheValue FROM MyBigTable WHERE TheId = @FindThisId AND TheDate <= julianday(@FindThisDate) LIMIT 1", myStmtHandle) 705 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 706 | 707 | PrintParameters myStmtHandle 708 | 709 | paramIndexId = SQLite3BindParameterIndex(myStmtHandle, "@FindThisId") 710 | If paramIndexId = 0 Then 711 | Debug.Print "SQLite3BindParameterIndex could not find the Id parameter!" 712 | Beep 713 | End If 714 | 715 | paramIndexDate = SQLite3BindParameterIndex(myStmtHandle, "@FindThisDate") 716 | If paramIndexDate = 0 Then 717 | Debug.Print "SQLite3BindParameterIndex could not find the Date parameter!" 718 | Beep 719 | End If 720 | 721 | startDate = DateValue("1 Jan 2000") 722 | 723 | For i = 1 To 10000 724 | offset = i Mod 1000 725 | ' Bind the parameters 726 | RetVal = SQLite3BindInt32(myStmtHandle, paramIndexId, 4200 + 500 + offset) 727 | If RetVal <> SQLITE_OK Then 728 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 729 | Beep 730 | End If 731 | 732 | RetVal = SQLite3BindText(myStmtHandle, paramIndexDate, Format(startDate + 500 + offset, "yyyy-MM-dd HH:mm:ss")) 733 | If RetVal <> SQLITE_OK Then 734 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 735 | Beep 736 | End If 737 | 738 | RetVal = SQLite3Step(myStmtHandle) 739 | If RetVal = SQLITE_ROW Then 740 | ' We have access to the result columns here. 741 | If offset = 1 Then 742 | Debug.Print "At row " & i 743 | Debug.Print "------------" 744 | PrintColumns myStmtHandle 745 | Debug.Print "============" 746 | End If 747 | ElseIf RetVal = SQLITE_DONE Then 748 | Debug.Print "No row found" 749 | End If 750 | 751 | RetVal = SQLite3Reset(myStmtHandle) 752 | If RetVal <> SQLITE_OK Then 753 | Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle) 754 | Beep 755 | End If 756 | Next 757 | 758 | ' Finalize (delete) the statement 759 | RetVal = SQLite3Finalize(myStmtHandle) 760 | Debug.Print "SQLite3Finalize returned " & RetVal 761 | 762 | ' STOP Select time 763 | Debug.Print "Select Elapsed: " & Format(Now() - testStart, "HH:mm:ss") 764 | 765 | ' Close the database 766 | RetVal = SQLite3Close(myDbHandle) 767 | Kill TestFile 768 | 769 | Debug.Print "----- TestBinding End -----" 770 | End Sub 771 | 772 | Public Sub TestDates() 773 | Dim myDbHandle As Long 774 | Dim myStmtHandle As Long 775 | Dim RetVal As Long 776 | Dim stepMsg As String 777 | Dim i As Long 778 | 779 | Dim myDate As Date 780 | Dim myEvent As String 781 | 782 | Debug.Print "----- TestDates Start -----" 783 | 784 | ' Open the database - getting a DbHandle back 785 | RetVal = SQLite3Open(TestFile, myDbHandle) 786 | Debug.Print "SQLite3Open returned " & RetVal 787 | 788 | '------------------------ 789 | ' Create the table 790 | ' ================ 791 | ' (I've got no error checking here...) 792 | SQLite3ExecuteNonQuery myDbHandle, "CREATE TABLE MyDateTable (MyDate REAL, MyEvent TEXT)" 793 | 794 | '------------------------- 795 | ' Prepare an insert statement with parameters 796 | ' =============== 797 | ' Create the sql statement - getting a StmtHandle back 798 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyDateTable Values (@SomeDate, @SomeEvent)", myStmtHandle) 799 | If RetVal <> SQLITE_OK Then 800 | Debug.Print "SQLite3PrepareV2 returned " & SQLite3ErrMsg(myDbHandle) 801 | Beep 802 | End If 803 | 804 | RetVal = SQLite3BindDate(myStmtHandle, 1, DateSerial(2010, 6, 19)) 805 | If RetVal <> SQLITE_OK Then 806 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 807 | Beep 808 | End If 809 | 810 | RetVal = SQLite3BindText(myStmtHandle, 2, "Nice trip somewhere") 811 | If RetVal <> SQLITE_OK Then 812 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 813 | Beep 814 | End If 815 | 816 | RetVal = SQLite3Step(myStmtHandle) 817 | If RetVal <> SQLITE_DONE Then 818 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 819 | Beep 820 | End If 821 | 822 | ' Finalize the statement 823 | RetVal = SQLite3Finalize(myStmtHandle) 824 | Debug.Print "SQLite3Finalize returned " & RetVal 825 | 826 | '------------------------- 827 | ' Select statement 828 | ' =============== 829 | ' Create the sql statement - getting a StmtHandle back 830 | ' Now using named parameters! 831 | RetVal = SQLite3PrepareV2(myDbHandle, "SELECT * FROM MyDateTable", myStmtHandle) 832 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 833 | 834 | RetVal = SQLite3Step(myStmtHandle) 835 | If RetVal = SQLITE_ROW Then 836 | ' We have access to the result columns here. 837 | myDate = SQLite3ColumnDate(myStmtHandle, 0) 838 | myEvent = SQLite3ColumnText(myStmtHandle, 1) 839 | Debug.Print "Event: " & myEvent, "Date: " & myDate 840 | ElseIf RetVal = SQLITE_DONE Then 841 | Debug.Print "No row found" 842 | End If 843 | 844 | ' Finalize (delete) the statement 845 | RetVal = SQLite3Finalize(myStmtHandle) 846 | Debug.Print "SQLite3Finalize returned " & RetVal 847 | 848 | ' Close the database 849 | RetVal = SQLite3Close(myDbHandle) 850 | Kill TestFile 851 | 852 | Debug.Print "----- TestDates End -----" 853 | End Sub 854 | 855 | 856 | Public Sub TestStrings() 857 | Dim myDbHandle As Long 858 | Dim myStmtHandle As Long 859 | Dim RetVal As Long 860 | Dim stepMsg As String 861 | Dim i As Long 862 | 863 | Dim myString1 As String 864 | Dim myString2 As String 865 | Dim myLongString As String 866 | Dim myStringResult As String 867 | 868 | Debug.Print "----- TestStrings Start -----" 869 | 870 | ' Open the database - getting a DbHandle back 871 | RetVal = SQLite3Open(TestFile, myDbHandle) 872 | Debug.Print "SQLite3Open returned " & RetVal 873 | 874 | myString2 = "" 875 | myLongString = String(10000, "A") 876 | 877 | '------------------------ 878 | ' Create the table 879 | ' ================ 880 | ' (I've got no error checking here...) 881 | SQLite3ExecuteNonQuery myDbHandle, "CREATE TABLE MyStringTable (MyValue TEXT)" 882 | 883 | '------------------------- 884 | ' Prepare an insert statement with parameters 885 | ' =============== 886 | ' Create the sql statement - getting a StmtHandle back 887 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyStringTable Values (@SomeString)", myStmtHandle) 888 | If RetVal <> SQLITE_OK Then 889 | Debug.Print "SQLite3PrepareV2 returned " & SQLite3ErrMsg(myDbHandle) 890 | Beep 891 | End If 892 | 893 | RetVal = SQLite3BindText(myStmtHandle, 1, myString1) 894 | If RetVal <> SQLITE_OK Then 895 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 896 | Beep 897 | End If 898 | 899 | RetVal = SQLite3Step(myStmtHandle) 900 | If RetVal <> SQLITE_DONE Then 901 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 902 | Beep 903 | End If 904 | 905 | RetVal = SQLite3Reset(myStmtHandle) 906 | If RetVal <> SQLITE_OK Then 907 | Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle) 908 | Beep 909 | End If 910 | 911 | RetVal = SQLite3BindText(myStmtHandle, 1, myString2) 912 | If RetVal <> SQLITE_OK Then 913 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 914 | Beep 915 | End If 916 | 917 | RetVal = SQLite3Step(myStmtHandle) 918 | If RetVal <> SQLITE_DONE Then 919 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 920 | Beep 921 | End If 922 | 923 | RetVal = SQLite3Reset(myStmtHandle) 924 | If RetVal <> SQLITE_OK Then 925 | Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle) 926 | Beep 927 | End If 928 | 929 | RetVal = SQLite3BindText(myStmtHandle, 1, myLongString) 930 | If RetVal <> SQLITE_OK Then 931 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 932 | Beep 933 | End If 934 | 935 | RetVal = SQLite3Step(myStmtHandle) 936 | If RetVal <> SQLITE_DONE Then 937 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 938 | Beep 939 | End If 940 | ' Finalize the statement 941 | RetVal = SQLite3Finalize(myStmtHandle) 942 | Debug.Print "SQLite3Finalize returned " & RetVal 943 | 944 | '------------------------- 945 | ' Select statement 946 | ' =============== 947 | ' Create the sql statement - getting a StmtHandle back 948 | ' Now using named parameters! 949 | RetVal = SQLite3PrepareV2(myDbHandle, "SELECT * FROM MyStringTable", myStmtHandle) 950 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 951 | 952 | RetVal = SQLite3Step(myStmtHandle) 953 | If RetVal = SQLITE_ROW Then 954 | ' We have access to the result columns here. 955 | myStringResult = SQLite3ColumnText(myStmtHandle, 0) 956 | Debug.Print "Result1: " + myStringResult 957 | ElseIf RetVal = SQLITE_DONE Then 958 | Debug.Print "No row found" 959 | End If 960 | 961 | RetVal = SQLite3Step(myStmtHandle) 962 | If RetVal = SQLITE_ROW Then 963 | ' We have access to the result columns here. 964 | myStringResult = SQLite3ColumnText(myStmtHandle, 0) 965 | Debug.Print "Result2: " + myStringResult 966 | ElseIf RetVal = SQLITE_DONE Then 967 | Debug.Print "No row found" 968 | End If 969 | 970 | RetVal = SQLite3Step(myStmtHandle) 971 | If RetVal = SQLITE_ROW Then 972 | ' We have access to the result columns here. 973 | myStringResult = SQLite3ColumnText(myStmtHandle, 0) 974 | 975 | Debug.Print "Long String is the same: " & (myStringResult = myLongString) 976 | ElseIf RetVal = SQLITE_DONE Then 977 | Debug.Print "No row found" 978 | End If 979 | 980 | ' Finalize (delete) the statement 981 | RetVal = SQLite3Finalize(myStmtHandle) 982 | Debug.Print "SQLite3Finalize returned " & RetVal 983 | 984 | ' Close the database 985 | RetVal = SQLite3Close(myDbHandle) 986 | Kill TestFile 987 | 988 | Debug.Print "----- TestStrings End -----" 989 | End Sub 990 | 991 | Public Sub TestBackup() 992 | Dim testFileBackup As String 993 | 994 | Dim myDbHandle As Long 995 | Dim myDbBackupHandle As Long 996 | Dim myBackupHandle As Long 997 | 998 | Dim RetVal As Long 999 | Dim i As Long 1000 | 1001 | Debug.Print "----- TestBackup Start -----" 1002 | 1003 | ' Open the database - getting a DbHandle back 1004 | RetVal = SQLite3Open(TestFile, myDbHandle) 1005 | Debug.Print "SQLite3Open returned " & RetVal 1006 | 1007 | SQLite3ExecuteNonQuery myDbHandle, "CREATE TABLE MyTestTable (Key INT PRIMARY KEY, Value TEXT)" 1008 | SQLite3ExecuteNonQuery myDbHandle, "INSERT INTO MyTestTable VALUES (1, 'First')" 1009 | SQLite3ExecuteNonQuery myDbHandle, "INSERT INTO MyTestTable VALUES (2, 'Second')" 1010 | SQLite3ExecuteQuery myDbHandle, "SELECT * FROM MyTestTable" 1011 | 1012 | ' Now do a backup 1013 | testFileBackup = TestFile & ".bak" 1014 | RetVal = SQLite3Open(testFileBackup, myDbBackupHandle) 1015 | Debug.Print "SQLite3Open returned " & RetVal 1016 | 1017 | myBackupHandle = SQLite3BackupInit(myDbBackupHandle, "main", myDbHandle, "main") 1018 | If myBackupHandle <> 0 Then 1019 | RetVal = SQLite3BackupStep(myBackupHandle, -1) 1020 | Debug.Print "SQLite3BackupStep returned " & RetVal 1021 | RetVal = SQLite3BackupFinish(myBackupHandle) 1022 | Debug.Print "SQLite3BackupFinish returned " & RetVal 1023 | End If 1024 | RetVal = SQLite3ErrCode(myDbBackupHandle) 1025 | Debug.Print "Backup result " & RetVal 1026 | Debug.Print "Selecting from backup:" 1027 | SQLite3ExecuteQuery myDbBackupHandle, "SELECT * FROM MyTestTable" 1028 | 1029 | RetVal = SQLite3Close(myDbHandle) 1030 | RetVal = SQLite3Close(myDbBackupHandle) 1031 | 1032 | Kill TestFile 1033 | Kill testFileBackup 1034 | 1035 | Debug.Print "----- TestBackup End -----" 1036 | End Sub 1037 | 1038 | Public Sub TestBlob() 1039 | Dim myDbHandle As Long 1040 | Dim myStmtHandle As Long 1041 | Dim RetVal As Long 1042 | Dim stepMsg As String 1043 | Dim i As Long 1044 | 1045 | Dim myBlob(2) As Byte 1046 | Dim myBlobResult() As Byte 1047 | 1048 | Debug.Print "----- TestBlob Start -----" 1049 | 1050 | ' Open the database - getting a DbHandle back 1051 | RetVal = SQLite3Open(TestFile, myDbHandle) 1052 | Debug.Print "SQLite3Open returned " & RetVal 1053 | 1054 | myBlob(0) = 90 1055 | myBlob(1) = 91 1056 | myBlob(2) = 92 1057 | 1058 | '------------------------ 1059 | ' Create the table 1060 | ' ================ 1061 | ' (I've got no error checking here...) 1062 | SQLite3ExecuteNonQuery myDbHandle, "CREATE TABLE MyBlobTable (MyValue BLOB)" 1063 | 1064 | '------------------------- 1065 | ' Prepare an insert statement with parameters 1066 | ' =============== 1067 | ' Create the sql statement - getting a StmtHandle back 1068 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyBlobTable Values (@SomeString)", myStmtHandle) 1069 | If RetVal <> SQLITE_OK Then 1070 | Debug.Print "SQLite3PrepareV2 returned " & SQLite3ErrMsg(myDbHandle) 1071 | Beep 1072 | End If 1073 | 1074 | RetVal = SQLite3BindBlob(myStmtHandle, 1, myBlob) 1075 | If RetVal <> SQLITE_OK Then 1076 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 1077 | Beep 1078 | End If 1079 | 1080 | RetVal = SQLite3Step(myStmtHandle) 1081 | If RetVal <> SQLITE_DONE Then 1082 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 1083 | Beep 1084 | End If 1085 | 1086 | ' Finalize the statement 1087 | RetVal = SQLite3Finalize(myStmtHandle) 1088 | Debug.Print "SQLite3Finalize returned " & RetVal 1089 | 1090 | '------------------------- 1091 | ' Select statement 1092 | ' =============== 1093 | ' Create the sql statement - getting a StmtHandle back 1094 | ' Now using named parameters! 1095 | RetVal = SQLite3PrepareV2(myDbHandle, "SELECT * FROM MyBlobTable", myStmtHandle) 1096 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 1097 | 1098 | RetVal = SQLite3Step(myStmtHandle) 1099 | If RetVal = SQLITE_ROW Then 1100 | ' We have access to the result columns here. 1101 | myBlobResult = SQLite3ColumnBlob(myStmtHandle, 0) 1102 | For i = LBound(myBlobResult) To UBound(myBlobResult) 1103 | Debug.Print "Blob byte " & i & ": " & myBlobResult(i) 1104 | Next 1105 | ElseIf RetVal = SQLITE_DONE Then 1106 | Debug.Print "No row found" 1107 | End If 1108 | 1109 | ' Finalize (delete) the statement 1110 | RetVal = SQLite3Finalize(myStmtHandle) 1111 | Debug.Print "SQLite3Finalize returned " & RetVal 1112 | 1113 | ' Close the database 1114 | RetVal = SQLite3Close(myDbHandle) 1115 | Kill TestFile 1116 | 1117 | Debug.Print "----- TestBlob End -----" 1118 | End Sub 1119 | 1120 | 1121 | Public Sub TestWriteReadOnly() 1122 | Dim myDbHandle As Long 1123 | Dim myDbHandleV2 As Long 1124 | Dim myStmtHandle As Long 1125 | Dim RetVal As Long 1126 | 1127 | ' Open the database in Read Write Access 1128 | RetVal = SQLite3Open(TestFile, myDbHandle) 1129 | Debug.Print "SQLite3Open returned " & RetVal 1130 | 1131 | ' Open the database in Read Only Access 1132 | RetVal = SQLite3OpenV2(TestFile, myDbHandleV2, SQLITE_OPEN_READONLY, Empty) 1133 | Debug.Print "SQLite3OpenV2 returned " & RetVal 1134 | 1135 | ' Create the sql statement - getting a StmtHandle back 1136 | RetVal = SQLite3PrepareV2(myDbHandle, "CREATE TABLE MyFirstTable (TheId INTEGER, TheText TEXT, TheValue REAL)", myStmtHandle) 1137 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 1138 | 1139 | ' Start running the statement 1140 | RetVal = SQLite3Step(myStmtHandle) 1141 | Debug.Print "SQLite3Step returned " & RetVal 1142 | 1143 | ' Finalize (delete) the statement 1144 | RetVal = SQLite3Finalize(myStmtHandle) 1145 | Debug.Print "SQLite3Finalize returned " & RetVal 1146 | 1147 | ' Create the sql statement - getting a StmtHandle back with Read Only 1148 | RetVal = SQLite3PrepareV2(myDbHandleV2, "CREATE TABLE MySecondTable (TheId INTEGER, TheText TEXT, TheValue REAL)", myStmtHandle) 1149 | 'RetVal = SQLite3PrepareV2(myDbHandleV2, "SELECT * FROM MyFirstTable", myStmtHandle) 1150 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 1151 | 1152 | ' Start running the statement with Read Only 1153 | RetVal = SQLite3Step(myStmtHandle) 1154 | Debug.Print "SQLite3Step returned " & RetVal 1155 | 1156 | If RetVal = SQLITE_READONLY Then 1157 | Debug.Print "Cannot Write in Read Only database" 1158 | End If 1159 | 1160 | ' Finalize (delete) the statement with Read Only 1161 | RetVal = SQLite3Finalize(myStmtHandle) 1162 | Debug.Print "SQLite3Finalize returned " & RetVal 1163 | 1164 | ' Create the sql statement - getting a StmtHandle back with Read Only 1165 | RetVal = SQLite3PrepareV2(myDbHandleV2, "SELECT * FROM MyFirstTable", myStmtHandle) 1166 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 1167 | 1168 | ' Start running the statement with Read Only 1169 | RetVal = SQLite3Step(myStmtHandle) 1170 | Debug.Print "SQLite3Step returned " & RetVal 1171 | 1172 | If RetVal = SQLITE_DONE Then 1173 | Debug.Print "But Reading is granted on Read Only database" 1174 | End If 1175 | 1176 | ' Finalize (delete) the statement with Read Only 1177 | RetVal = SQLite3Finalize(myStmtHandle) 1178 | Debug.Print "SQLite3Finalize returned " & RetVal 1179 | 1180 | RetVal = SQLite3Close(myDbHandleV2) 1181 | Debug.Print "SQLite3Close V2 returned " & RetVal 1182 | 1183 | RetVal = SQLite3Close(myDbHandle) 1184 | Debug.Print "SQLite3Close returned " & RetVal 1185 | 1186 | Kill TestFile 1187 | 1188 | End Sub 1189 | 1190 | 1191 | ' SQLite3 Helper Functions 1192 | Public Function SQLite3ExecuteNonQuery(ByVal dbHandle As Long, ByVal SqlCommand As String) As Long 1193 | Dim stmtHandle As Long 1194 | 1195 | SQLite3PrepareV2 dbHandle, SqlCommand, stmtHandle 1196 | SQLite3Step stmtHandle 1197 | SQLite3Finalize stmtHandle 1198 | 1199 | SQLite3ExecuteNonQuery = SQLite3Changes(dbHandle) 1200 | End Function 1201 | 1202 | Public Sub SQLite3ExecuteQuery(ByVal dbHandle As Long, ByVal sqlQuery As String) 1203 | ' Dumps a query to the debug window. No error checking 1204 | 1205 | Dim stmtHandle As Long 1206 | Dim RetVal As Long 1207 | 1208 | RetVal = SQLite3PrepareV2(dbHandle, sqlQuery, stmtHandle) 1209 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 1210 | 1211 | ' Start running the statement 1212 | RetVal = SQLite3Step(stmtHandle) 1213 | If RetVal = SQLITE_ROW Then 1214 | Debug.Print "SQLite3Step Row Ready" 1215 | PrintColumns stmtHandle 1216 | Else 1217 | Debug.Print "SQLite3Step returned " & RetVal 1218 | End If 1219 | 1220 | ' Move to next row 1221 | RetVal = SQLite3Step(stmtHandle) 1222 | Do While RetVal = SQLITE_ROW 1223 | Debug.Print "SQLite3Step Row Ready" 1224 | PrintColumns stmtHandle 1225 | RetVal = SQLite3Step(stmtHandle) 1226 | Loop 1227 | 1228 | If RetVal = SQLITE_DONE Then 1229 | Debug.Print "SQLite3Step Done" 1230 | Else 1231 | Debug.Print "SQLite3Step returned " & RetVal 1232 | End If 1233 | 1234 | ' Finalize (delete) the statement 1235 | RetVal = SQLite3Finalize(stmtHandle) 1236 | Debug.Print "SQLite3Finalize returned " & RetVal 1237 | End Sub 1238 | 1239 | -------------------------------------------------------------------------------- /Source/SQLite3VBAModules/Sqlite3Demo_64.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "Sqlite3Demo" 2 | Option Explicit 3 | 4 | Dim TestFile As String 5 | 6 | Public Sub AllTests() 7 | ' Check that this location can be written to 8 | ' Note that this file will be deleted after the tests complete! 9 | TestFile = Environ("TEMP") & "\TestSqlite3ForExcel.db3" 10 | 11 | Dim InitReturn As Long 12 | #If Win64 Then 13 | ' I put the 64-bit version of SQLite.dll under a subdirectory called x64 14 | InitReturn = SQLite3Initialize(ThisWorkbook.Path + "\x64") 15 | #Else 16 | InitReturn = SQLite3Initialize ' Default path is ThisWorkbook.Path but can specify other path where the .dlls reside. 17 | #End If 18 | If InitReturn <> SQLITE_INIT_OK Then 19 | Debug.Print "Error Initializing SQLite. Error: " & Err.LastDllError 20 | Exit Sub 21 | End If 22 | 23 | TestVersion 24 | TestOpenClose 25 | TestOpenCloseV2 26 | TestError 27 | TestInsert 28 | TestSelect 29 | TestBinding 30 | TestDates 31 | TestStrings 32 | TestBackup 33 | TestBlob 34 | TestWriteReadOnly 35 | SQLite3Free ' Quite optional 36 | 37 | Debug.Print "----- All Tests Complete -----" 38 | End Sub 39 | 40 | Public Sub TestVersion() 41 | 42 | Debug.Print SQLite3LibVersion() 43 | 44 | End Sub 45 | 46 | Public Sub TestApiCallSpeed() 47 | 48 | Dim i As Long 49 | Dim version As String 50 | Dim start As Date 51 | 52 | start = Now() 53 | For i = 0 To 10000000 ' 10 million 54 | version = SQLite3LibVersion() 55 | Next 56 | 57 | Debug.Print "ApiCall Elapsed: " & Format(Now() - start, "HH:mm:ss") 58 | 59 | End Sub 60 | 61 | Public Sub TestOpenClose() 62 | #If Win64 Then 63 | Dim myDbHandle As LongPtr 64 | #Else 65 | Dim myDbHandle As Long 66 | #End If 67 | Dim RetVal As Long 68 | 69 | RetVal = SQLite3Open(TestFile, myDbHandle) 70 | Debug.Print "SQLite3Open returned " & RetVal 71 | 72 | RetVal = SQLite3Close(myDbHandle) 73 | Debug.Print "SQLite3Close returned " & RetVal 74 | 75 | Kill TestFile 76 | 77 | End Sub 78 | 79 | Public Sub TestOpenCloseV2() 80 | #If Win64 Then 81 | Dim myDbHandle As LongPtr 82 | Dim myDbHandleV2 As LongPtr 83 | #Else 84 | Dim myDbHandle As Long 85 | Dim myDbHandleV2 As Long 86 | #End If 87 | Dim RetVal As Long 88 | 89 | ' Open the database in Read Write Access 90 | RetVal = SQLite3Open(TestFile, myDbHandle) 91 | Debug.Print "SQLite3Open returned " & RetVal 92 | 93 | ' Open the database in Read Only Access 94 | RetVal = SQLite3OpenV2(TestFile, myDbHandleV2, SQLITE_OPEN_READONLY, "") 95 | Debug.Print "SQLite3OpenV2 returned " & RetVal 96 | 97 | RetVal = SQLite3Close(myDbHandleV2) 98 | Debug.Print "SQLite3Close V2 returned " & RetVal 99 | 100 | RetVal = SQLite3Close(myDbHandle) 101 | Debug.Print "SQLite3Close returned " & RetVal 102 | 103 | Kill TestFile 104 | 105 | End Sub 106 | 107 | Public Sub TestError() 108 | #If Win64 Then 109 | Dim myDbHandle As LongPtr 110 | #Else 111 | Dim myDbHandle As Long 112 | #End If 113 | Dim RetVal As Long 114 | 115 | Dim ErrMsg As String 116 | 117 | Debug.Print "----- TestError Start -----" 118 | 119 | ' DbHandle is set up even if there is an error ! 120 | RetVal = SQLite3Open("::::", myDbHandle) 121 | Debug.Print "SQLite3Open returned " & RetVal 122 | 123 | ErrMsg = SQLite3ErrMsg(myDbHandle) 124 | Debug.Print "SQLite3Open error message: " & ErrMsg 125 | 126 | RetVal = SQLite3Close(myDbHandle) 127 | Debug.Print "SQLite3Close returned " & RetVal 128 | 129 | Debug.Print "----- TestError End -----" 130 | 131 | End Sub 132 | 133 | Public Sub TestStatement() 134 | #If Win64 Then 135 | Dim myDbHandle As LongPtr 136 | Dim myStmtHandle As LongPtr 137 | #Else 138 | Dim myDbHandle As Long 139 | Dim myStmtHandle As Long 140 | #End If 141 | 142 | Dim RetVal As Long 143 | 144 | Dim stepMsg As String 145 | 146 | Debug.Print "----- TestStatement Start -----" 147 | 148 | ' Open the database - getting a DbHandle back 149 | RetVal = SQLite3Open(TestFile, myDbHandle) 150 | Debug.Print "SQLite3Open returned " & RetVal 151 | 152 | ' Create the sql statement - getting a StmtHandle back 153 | RetVal = SQLite3PrepareV2(myDbHandle, "CREATE TABLE MyFirstTable (TheId INTEGER, TheText TEXT, TheValue REAL)", myStmtHandle) 154 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 155 | 156 | ' Start running the statement 157 | RetVal = SQLite3Step(myStmtHandle) 158 | Debug.Print "SQLite3Step returned " & RetVal 159 | 160 | ' Finalize (delete) the statement 161 | RetVal = SQLite3Finalize(myStmtHandle) 162 | Debug.Print "SQLite3Finalize returned " & RetVal 163 | 164 | ' Close the database 165 | RetVal = SQLite3Close(myDbHandle) 166 | Kill TestFile 167 | 168 | Debug.Print "----- TestStatement End -----" 169 | End Sub 170 | 171 | Public Sub TestInsert() 172 | #If Win64 Then 173 | Dim myDbHandle As LongPtr 174 | Dim myStmtHandle As LongPtr 175 | #Else 176 | Dim myDbHandle As Long 177 | Dim myStmtHandle As Long 178 | #End If 179 | Dim RetVal As Long 180 | Dim recordsAffected As Long 181 | 182 | Dim stepMsg As String 183 | 184 | Debug.Print "----- TestInsert Start -----" 185 | 186 | ' Open the database - getting a DbHandle back 187 | RetVal = SQLite3Open(TestFile, myDbHandle) 188 | Debug.Print "SQLite3Open returned " & RetVal 189 | 190 | '------------------------ 191 | ' Create the table 192 | ' ================ 193 | ' Create the sql statement - getting a StmtHandle back 194 | RetVal = SQLite3PrepareV2(myDbHandle, "CREATE TABLE MySecondTable (TheId INTEGER, TheText TEXT, TheValue REAL)", myStmtHandle) 195 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 196 | 197 | ' Start running the statement 198 | RetVal = SQLite3Step(myStmtHandle) 199 | If RetVal = SQLITE_DONE Then 200 | Debug.Print "SQLite3Step Done" 201 | Else 202 | Debug.Print "SQLite3Step returned " & RetVal 203 | End If 204 | 205 | ' Finalize (delete) the statement 206 | RetVal = SQLite3Finalize(myStmtHandle) 207 | Debug.Print "SQLite3Finalize returned " & RetVal 208 | 209 | '------------------------- 210 | ' Insert a record 211 | ' =============== 212 | ' Create the sql statement - getting a StmtHandle back 213 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MySecondTable Values (123, 'ABC', 42.1)", myStmtHandle) 214 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 215 | 216 | ' Start running the statement 217 | RetVal = SQLite3Step(myStmtHandle) 218 | If RetVal = SQLITE_DONE Then 219 | Debug.Print "SQLite3Step Done" 220 | Else 221 | Debug.Print "SQLite3Step returned " & RetVal 222 | End If 223 | 224 | ' Finalize (delete) the statement 225 | RetVal = SQLite3Finalize(myStmtHandle) 226 | Debug.Print "SQLite3Finalize returned " & RetVal 227 | 228 | '------------------------- 229 | ' Insert using helper 230 | ' ==================== 231 | recordsAffected = SQLite3ExecuteNonQuery(myDbHandle, "INSERT INTO MySecondTable Values (456, 'DEF', 49.3)") 232 | Debug.Print "SQLite3Execute - Insert affected " & recordsAffected & " record(s)." 233 | 234 | ' Close the database 235 | RetVal = SQLite3Close(myDbHandle) 236 | Kill TestFile 237 | 238 | Debug.Print "----- TestInsert End -----" 239 | End Sub 240 | 241 | Public Sub TestSelect() 242 | #If Win64 Then 243 | Dim myDbHandle As LongPtr 244 | Dim myStmtHandle As LongPtr 245 | #Else 246 | Dim myDbHandle As Long 247 | Dim myStmtHandle As Long 248 | #End If 249 | Dim RetVal As Long 250 | 251 | Dim stepMsg As String 252 | 253 | Debug.Print "----- TestSelect Start -----" 254 | 255 | ' Open the database - getting a DbHandle back 256 | RetVal = SQLite3Open(TestFile, myDbHandle) 257 | Debug.Print "SQLite3Open returned " & RetVal 258 | 259 | '------------------------ 260 | ' Create the table 261 | ' ================ 262 | ' Create the sql statement - getting a StmtHandle back 263 | RetVal = SQLite3PrepareV2(myDbHandle, "CREATE TABLE MyFirstTable (TheId INTEGER, TheText TEXT, TheValue REAL)", myStmtHandle) 264 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 265 | 266 | ' Start running the statement 267 | RetVal = SQLite3Step(myStmtHandle) 268 | If RetVal = SQLITE_DONE Then 269 | Debug.Print "SQLite3Step Done" 270 | Else 271 | Debug.Print "SQLite3Step returned " & RetVal 272 | End If 273 | 274 | ' Finalize (delete) the statement 275 | RetVal = SQLite3Finalize(myStmtHandle) 276 | Debug.Print "SQLite3Finalize returned " & RetVal 277 | 278 | '------------------------- 279 | ' Insert a record 280 | ' =============== 281 | ' Create the sql statement - getting a StmtHandle back 282 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyFirstTable Values (123, 'ABC', 42.1)", myStmtHandle) 283 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 284 | 285 | ' Start running the statement 286 | RetVal = SQLite3Step(myStmtHandle) 287 | If RetVal = SQLITE_DONE Then 288 | Debug.Print "SQLite3Step Done" 289 | Else 290 | Debug.Print "SQLite3Step returned " & RetVal 291 | End If 292 | 293 | ' Finalize (delete) the statement 294 | RetVal = SQLite3Finalize(myStmtHandle) 295 | Debug.Print "SQLite3Finalize returned " & RetVal 296 | 297 | '------------------------- 298 | ' Insert another record 299 | ' =============== 300 | ' Create the sql statement - getting a StmtHandle back 301 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyFirstTable Values (987654, ""ZXCVBNM"", NULL)", myStmtHandle) 302 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 303 | 304 | ' Start running the statement 305 | RetVal = SQLite3Step(myStmtHandle) 306 | If RetVal = SQLITE_DONE Then 307 | Debug.Print "SQLite3Step Done" 308 | Else 309 | Debug.Print "SQLite3Step returned " & RetVal 310 | End If 311 | 312 | ' Finalize (delete) the statement 313 | RetVal = SQLite3Finalize(myStmtHandle) 314 | Debug.Print "SQLite3Finalize returned " & RetVal 315 | 316 | '------------------------- 317 | ' Select statement 318 | ' =============== 319 | ' Create the sql statement - getting a StmtHandle back 320 | RetVal = SQLite3PrepareV2(myDbHandle, "SELECT * FROM MyFirstTable", myStmtHandle) 321 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 322 | 323 | ' Start running the statement 324 | RetVal = SQLite3Step(myStmtHandle) 325 | If RetVal = SQLITE_ROW Then 326 | Debug.Print "SQLite3Step Row Ready" 327 | PrintColumns myStmtHandle 328 | Else 329 | Debug.Print "SQLite3Step returned " & RetVal 330 | End If 331 | 332 | ' Move to next row 333 | RetVal = SQLite3Step(myStmtHandle) 334 | If RetVal = SQLITE_ROW Then 335 | Debug.Print "SQLite3Step Row Ready" 336 | PrintColumns myStmtHandle 337 | Else 338 | Debug.Print "SQLite3Step returned " & RetVal 339 | End If 340 | 341 | ' Move on again (now we are done) 342 | RetVal = SQLite3Step(myStmtHandle) 343 | If RetVal = SQLITE_DONE Then 344 | Debug.Print "SQLite3Step Done" 345 | Else 346 | Debug.Print "SQLite3Step returned " & RetVal 347 | End If 348 | 349 | ' Finalize (delete) the statement 350 | RetVal = SQLite3Finalize(myStmtHandle) 351 | Debug.Print "SQLite3Finalize returned " & RetVal 352 | 353 | 354 | ' Close the database 355 | RetVal = SQLite3Close(myDbHandle) 356 | Kill TestFile 357 | 358 | Debug.Print "----- TestSelect End -----" 359 | End Sub 360 | 361 | #If Win64 Then 362 | Sub PrintColumns(ByVal stmtHandle As LongPtr) 363 | #Else 364 | Sub PrintColumns(ByVal stmtHandle As Long) 365 | #End If 366 | Dim colCount As Long 367 | Dim colName As String 368 | Dim colType As Long 369 | Dim colTypeName As String 370 | Dim colValue As Variant 371 | 372 | Dim i As Long 373 | 374 | colCount = SQLite3ColumnCount(stmtHandle) 375 | Debug.Print "Column count: " & colCount 376 | For i = 0 To colCount - 1 377 | colName = SQLite3ColumnName(stmtHandle, i) 378 | colType = SQLite3ColumnType(stmtHandle, i) 379 | colTypeName = TypeName(colType) 380 | colValue = ColumnValue(stmtHandle, i, colType) 381 | Debug.Print "Column " & i & ":", colName, colTypeName, colValue 382 | Next 383 | End Sub 384 | 385 | #If Win64 Then 386 | Sub PrintParameters(ByVal stmtHandle As LongPtr) 387 | #Else 388 | Sub PrintParameters(ByVal stmtHandle As Long) 389 | #End If 390 | Dim paramCount As Long 391 | Dim paramName As String 392 | 393 | Dim i As Long 394 | 395 | paramCount = SQLite3BindParameterCount(stmtHandle) 396 | Debug.Print "Parameter count: " & paramCount 397 | For i = 1 To paramCount 398 | paramName = SQLite3BindParameterName(stmtHandle, i) 399 | Debug.Print "Parameter " & i & ":", paramName 400 | Next 401 | End Sub 402 | 403 | Function TypeName(ByVal SQLiteType As Long) As String 404 | Select Case SQLiteType 405 | Case SQLITE_INTEGER: 406 | TypeName = "INTEGER" 407 | Case SQLITE_FLOAT: 408 | TypeName = "FLOAT" 409 | Case SQLITE_TEXT: 410 | TypeName = "TEXT" 411 | Case SQLITE_BLOB: 412 | TypeName = "BLOB" 413 | Case SQLITE_NULL: 414 | TypeName = "NULL" 415 | End Select 416 | End Function 417 | 418 | #If Win64 Then 419 | Function ColumnValue(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long, ByVal SQLiteType As Long) As Variant 420 | #Else 421 | Function ColumnValue(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long, ByVal SQLiteType As Long) As Variant 422 | #End If 423 | Select Case SQLiteType 424 | Case SQLITE_INTEGER: 425 | ColumnValue = SQLite3ColumnInt32(stmtHandle, ZeroBasedColIndex) 426 | Case SQLITE_FLOAT: 427 | ColumnValue = SQLite3ColumnDouble(stmtHandle, ZeroBasedColIndex) 428 | Case SQLITE_TEXT: 429 | ColumnValue = SQLite3ColumnText(stmtHandle, ZeroBasedColIndex) 430 | Case SQLITE_BLOB: 431 | ColumnValue = SQLite3ColumnText(stmtHandle, ZeroBasedColIndex) 432 | Case SQLITE_NULL: 433 | ColumnValue = Null 434 | End Select 435 | End Function 436 | 437 | Public Sub TestBinding() 438 | #If Win64 Then 439 | Dim myDbHandle As LongPtr 440 | Dim myStmtHandle As LongPtr 441 | #Else 442 | Dim myDbHandle As Long 443 | Dim myStmtHandle As Long 444 | #End If 445 | 446 | Dim RetVal As Long 447 | Dim stepMsg As String 448 | Dim i As Long 449 | 450 | Dim paramIndexId As Long 451 | Dim paramIndexDate As Long 452 | 453 | Dim startDate As Date 454 | Dim curDate As Date 455 | Dim curValue As Double 456 | Dim offset As Long 457 | 458 | Dim testStart As Date 459 | 460 | Debug.Print "----- TestBinding Start -----" 461 | 462 | ' Open the database - getting a DbHandle back 463 | RetVal = SQLite3Open(TestFile, myDbHandle) 464 | Debug.Print "SQLite3Open returned " & RetVal 465 | 466 | '------------------------ 467 | ' Create the table 468 | ' ================ 469 | ' (O've got no error checking here...) 470 | SQLite3PrepareV2 myDbHandle, "CREATE TABLE MyBigTable (TheId INTEGER, TheDate REAL, TheText TEXT, TheValue REAL)", myStmtHandle 471 | SQLite3Step myStmtHandle 472 | SQLite3Finalize myStmtHandle 473 | 474 | '--------------------------- 475 | ' Add an index 476 | ' ================ 477 | SQLite3PrepareV2 myDbHandle, "CREATE INDEX idx_MyBigTable_Id_Date ON MyBigTable (TheId, TheDate)", myStmtHandle 478 | SQLite3Step myStmtHandle 479 | SQLite3Finalize myStmtHandle 480 | 481 | ' START Insert Time 482 | testStart = Now() 483 | 484 | '------------------- 485 | ' Begin transaction 486 | '================== 487 | SQLite3PrepareV2 myDbHandle, "BEGIN TRANSACTION", myStmtHandle 488 | SQLite3Step myStmtHandle 489 | SQLite3Finalize myStmtHandle 490 | 491 | '------------------------- 492 | ' Prepare an insert statement with parameters 493 | ' =============== 494 | ' Create the sql statement - getting a StmtHandle back 495 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyBigTable Values (?, ?, ?, ?)", myStmtHandle) 496 | If RetVal <> SQLITE_OK Then 497 | Debug.Print "SQLite3PrepareV2 returned " & SQLite3ErrMsg(myDbHandle) 498 | Beep 499 | End If 500 | 501 | Randomize 502 | startDate = DateValue("1 Jan 2000") 503 | 504 | For i = 1 To 100000 505 | curDate = startDate + i 506 | curValue = Rnd() * 1000 507 | 508 | RetVal = SQLite3BindInt32(myStmtHandle, 1, 42000 + i) 509 | If RetVal <> SQLITE_OK Then 510 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 511 | Beep 512 | End If 513 | 514 | RetVal = SQLite3BindDate(myStmtHandle, 2, curDate) 515 | If RetVal <> SQLITE_OK Then 516 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 517 | Beep 518 | End If 519 | 520 | RetVal = SQLite3BindText(myStmtHandle, 3, "The quick brown fox jumped over the lazy dog.") 521 | If RetVal <> SQLITE_OK Then 522 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 523 | Beep 524 | End If 525 | 526 | RetVal = SQLite3BindDouble(myStmtHandle, 4, curValue) 527 | If RetVal <> SQLITE_OK Then 528 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 529 | Beep 530 | End If 531 | 532 | RetVal = SQLite3Step(myStmtHandle) 533 | If RetVal <> SQLITE_DONE Then 534 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 535 | Beep 536 | End If 537 | 538 | RetVal = SQLite3Reset(myStmtHandle) 539 | If RetVal <> SQLITE_OK Then 540 | Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle) 541 | Beep 542 | End If 543 | Next 544 | 545 | ' Finalize (delete) the statement 546 | RetVal = SQLite3Finalize(myStmtHandle) 547 | Debug.Print "SQLite3Finalize returned " & RetVal 548 | 549 | '------------------- 550 | ' Commit transaction 551 | '================== 552 | ' (I'm re-using the same variable myStmtHandle for the new statement) 553 | SQLite3PrepareV2 myDbHandle, "COMMIT TRANSACTION", myStmtHandle 554 | SQLite3Step myStmtHandle 555 | SQLite3Finalize myStmtHandle 556 | 557 | ' STOP Insert Time 558 | Debug.Print "Insert Elapsed: " & Format(Now() - testStart, "HH:mm:ss") 559 | 560 | ' START Select Time 561 | testStart = Now() 562 | 563 | '------------------------- 564 | ' Select statement 565 | ' =============== 566 | ' Create the sql statement - getting a StmtHandle back 567 | ' Now using named parameters! 568 | RetVal = SQLite3PrepareV2(myDbHandle, "SELECT TheId, datetime(TheDate), TheText, TheValue FROM MyBigTable WHERE TheId = @FindThisId AND TheDate <= @FindThisDate LIMIT 1", myStmtHandle) 569 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 570 | 571 | paramIndexId = SQLite3BindParameterIndex(myStmtHandle, "@FindThisId") 572 | If paramIndexId = 0 Then 573 | Debug.Print "SQLite3BindParameterIndex could not find the Id parameter!" 574 | Beep 575 | End If 576 | 577 | paramIndexDate = SQLite3BindParameterIndex(myStmtHandle, "@FindThisDate") 578 | If paramIndexDate = 0 Then 579 | Debug.Print "SQLite3BindParameterIndex could not find the Date parameter!" 580 | Beep 581 | End If 582 | 583 | startDate = DateValue("1 Jan 2000") 584 | 585 | 586 | For i = 1 To 100000 587 | offset = i Mod 10000 588 | ' Bind the parameters 589 | RetVal = SQLite3BindInt32(myStmtHandle, paramIndexId, 42000 + 500 + offset) 590 | If RetVal <> SQLITE_OK Then 591 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 592 | Beep 593 | End If 594 | 595 | RetVal = SQLite3BindDate(myStmtHandle, paramIndexDate, startDate + 500 + offset) 596 | If RetVal <> SQLITE_OK Then 597 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 598 | Beep 599 | End If 600 | 601 | RetVal = SQLite3Step(myStmtHandle) 602 | If RetVal = SQLITE_ROW Then 603 | ' We have access to the result columns here. 604 | If offset = 1 Then 605 | Debug.Print "At row " & i 606 | Debug.Print "------------" 607 | PrintColumns myStmtHandle 608 | Debug.Print "============" 609 | End If 610 | ElseIf RetVal = SQLITE_DONE Then 611 | Debug.Print "No row found" 612 | End If 613 | 614 | RetVal = SQLite3Reset(myStmtHandle) 615 | If RetVal <> SQLITE_OK Then 616 | Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle) 617 | Beep 618 | End If 619 | Next 620 | 621 | ' Finalize (delete) the statement 622 | RetVal = SQLite3Finalize(myStmtHandle) 623 | Debug.Print "SQLite3Finalize returned " & RetVal 624 | 625 | ' STOP Select time 626 | Debug.Print "Select Elapsed: " & Format(Now() - testStart, "HH:mm:ss") 627 | 628 | ' Close the database 629 | RetVal = SQLite3Close(myDbHandle) 630 | Kill TestFile 631 | 632 | Debug.Print "----- TestBinding End -----" 633 | End Sub 634 | 635 | 636 | Public Sub TestBindingMore() 637 | #If Win64 Then 638 | Dim myDbHandle As LongPtr 639 | Dim myStmtHandle As LongPtr 640 | #Else 641 | Dim myDbHandle As Long 642 | Dim myStmtHandle As Long 643 | #End If 644 | 645 | Dim RetVal As Long 646 | Dim stepMsg As String 647 | Dim i As Long 648 | 649 | Dim paramIndexId As Long 650 | Dim paramIndexDate As Long 651 | 652 | Dim startDate As Date 653 | Dim curDate As Date 654 | Dim curValue As Double 655 | Dim offset As Long 656 | 657 | Dim testStart As Date 658 | 659 | Debug.Print "----- TestBinding Start -----" 660 | 661 | ' Open the database - getting a DbHandle back 662 | RetVal = SQLite3Open(TestFile, myDbHandle) 663 | Debug.Print "SQLite3Open returned " & RetVal 664 | 665 | '------------------------ 666 | ' Create the table 667 | ' ================ 668 | ' (O've got no error checking here...) 669 | SQLite3ExecuteNonQuery myDbHandle, "CREATE TABLE MyBigTable (TheId INTEGER, TheDate REAL, TheText TEXT, TheValue REAL)" 670 | 671 | '--------------------------- 672 | ' Add an index 673 | ' ================ 674 | SQLite3ExecuteNonQuery myDbHandle, "CREATE INDEX idx_MyBigTable_Id_Date ON MyBigTable (TheId, TheDate)" 675 | 676 | ' START Insert Time 677 | testStart = Now() 678 | 679 | '------------------- 680 | ' Begin transaction 681 | '================== 682 | SQLite3ExecuteNonQuery myDbHandle, "BEGIN TRANSACTION" 683 | 684 | '------------------------- 685 | ' Prepare an insert statement with parameters 686 | ' =============== 687 | ' Create the sql statement - getting a StmtHandle back 688 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyBigTable Values (?, ?, ?, ?)", myStmtHandle) 689 | If RetVal <> SQLITE_OK Then 690 | Debug.Print "SQLite3PrepareV2 returned " & SQLite3ErrMsg(myDbHandle) 691 | Beep 692 | End If 693 | 694 | PrintParameters myStmtHandle 695 | 696 | Randomize 697 | startDate = DateValue("1 Jan 2000") 698 | 699 | For i = 1 To 100000 700 | curDate = startDate + i 701 | curValue = Rnd() * 1000 702 | 703 | RetVal = SQLite3BindInt32(myStmtHandle, 1, 42000 + i) 704 | If RetVal <> SQLITE_OK Then 705 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 706 | Beep 707 | End If 708 | 709 | RetVal = SQLite3BindDate(myStmtHandle, 2, curDate) 710 | If RetVal <> SQLITE_OK Then 711 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 712 | Beep 713 | End If 714 | 715 | RetVal = SQLite3BindText(myStmtHandle, 3, "The quick brown fox jumped over the lazy dog.") 716 | If RetVal <> SQLITE_OK Then 717 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 718 | Beep 719 | End If 720 | 721 | RetVal = SQLite3BindDouble(myStmtHandle, 4, curValue) 722 | If RetVal <> SQLITE_OK Then 723 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 724 | Beep 725 | End If 726 | 727 | RetVal = SQLite3Step(myStmtHandle) 728 | If RetVal <> SQLITE_DONE Then 729 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 730 | Beep 731 | End If 732 | 733 | RetVal = SQLite3Reset(myStmtHandle) 734 | If RetVal <> SQLITE_OK Then 735 | Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle) 736 | Beep 737 | End If 738 | Next 739 | 740 | ' Finalize (delete) the statement 741 | RetVal = SQLite3Finalize(myStmtHandle) 742 | Debug.Print "SQLite3Finalize returned " & RetVal 743 | 744 | '------------------- 745 | ' Commit transaction 746 | '================== 747 | SQLite3ExecuteNonQuery myDbHandle, "COMMIT TRANSACTION" 748 | 749 | ' STOP Insert Time 750 | Debug.Print "Insert Elapsed: " & Format(Now() - testStart, "HH:mm:ss") 751 | 752 | ' START Select Time 753 | testStart = Now() 754 | 755 | '------------------------- 756 | ' Select statement 757 | ' =============== 758 | ' Create the sql statement - getting a StmtHandle back 759 | ' Now using named parameters! 760 | RetVal = SQLite3PrepareV2(myDbHandle, "SELECT TheId, datetime(TheDate), TheText, TheValue FROM MyBigTable WHERE TheId = @FindThisId AND TheDate <= julianday(@FindThisDate) LIMIT 1", myStmtHandle) 761 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 762 | 763 | PrintParameters myStmtHandle 764 | 765 | paramIndexId = SQLite3BindParameterIndex(myStmtHandle, "@FindThisId") 766 | If paramIndexId = 0 Then 767 | Debug.Print "SQLite3BindParameterIndex could not find the Id parameter!" 768 | Beep 769 | End If 770 | 771 | paramIndexDate = SQLite3BindParameterIndex(myStmtHandle, "@FindThisDate") 772 | If paramIndexDate = 0 Then 773 | Debug.Print "SQLite3BindParameterIndex could not find the Date parameter!" 774 | Beep 775 | End If 776 | 777 | startDate = DateValue("1 Jan 2000") 778 | 779 | For i = 1 To 10000 780 | offset = i Mod 1000 781 | ' Bind the parameters 782 | RetVal = SQLite3BindInt32(myStmtHandle, paramIndexId, 4200 + 500 + offset) 783 | If RetVal <> SQLITE_OK Then 784 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 785 | Beep 786 | End If 787 | 788 | RetVal = SQLite3BindText(myStmtHandle, paramIndexDate, Format(startDate + 500 + offset, "yyyy-MM-dd HH:mm:ss")) 789 | If RetVal <> SQLITE_OK Then 790 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 791 | Beep 792 | End If 793 | 794 | RetVal = SQLite3Step(myStmtHandle) 795 | If RetVal = SQLITE_ROW Then 796 | ' We have access to the result columns here. 797 | If offset = 1 Then 798 | Debug.Print "At row " & i 799 | Debug.Print "------------" 800 | PrintColumns myStmtHandle 801 | Debug.Print "============" 802 | End If 803 | ElseIf RetVal = SQLITE_DONE Then 804 | Debug.Print "No row found" 805 | End If 806 | 807 | RetVal = SQLite3Reset(myStmtHandle) 808 | If RetVal <> SQLITE_OK Then 809 | Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle) 810 | Beep 811 | End If 812 | Next 813 | 814 | ' Finalize (delete) the statement 815 | RetVal = SQLite3Finalize(myStmtHandle) 816 | Debug.Print "SQLite3Finalize returned " & RetVal 817 | 818 | ' STOP Select time 819 | Debug.Print "Select Elapsed: " & Format(Now() - testStart, "HH:mm:ss") 820 | 821 | ' Close the database 822 | RetVal = SQLite3Close(myDbHandle) 823 | Kill TestFile 824 | 825 | Debug.Print "----- TestBinding End -----" 826 | End Sub 827 | 828 | Public Sub TestDates() 829 | #If Win64 Then 830 | Dim myDbHandle As LongPtr 831 | Dim myStmtHandle As LongPtr 832 | #Else 833 | Dim myDbHandle As Long 834 | Dim myStmtHandle As Long 835 | #End If 836 | 837 | Dim RetVal As Long 838 | Dim stepMsg As String 839 | Dim i As Long 840 | 841 | Dim myDate As Date 842 | Dim myEvent As String 843 | 844 | Debug.Print "----- TestDates Start -----" 845 | 846 | ' Open the database - getting a DbHandle back 847 | RetVal = SQLite3Open(TestFile, myDbHandle) 848 | Debug.Print "SQLite3Open returned " & RetVal 849 | 850 | '------------------------ 851 | ' Create the table 852 | ' ================ 853 | ' (I've got no error checking here...) 854 | SQLite3ExecuteNonQuery myDbHandle, "CREATE TABLE MyDateTable (MyDate REAL, MyEvent TEXT)" 855 | 856 | '------------------------- 857 | ' Prepare an insert statement with parameters 858 | ' =============== 859 | ' Create the sql statement - getting a StmtHandle back 860 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyDateTable Values (@SomeDate, @SomeEvent)", myStmtHandle) 861 | If RetVal <> SQLITE_OK Then 862 | Debug.Print "SQLite3PrepareV2 returned " & SQLite3ErrMsg(myDbHandle) 863 | Beep 864 | End If 865 | 866 | RetVal = SQLite3BindDate(myStmtHandle, 1, DateSerial(2010, 6, 19)) 867 | If RetVal <> SQLITE_OK Then 868 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 869 | Beep 870 | End If 871 | 872 | RetVal = SQLite3BindText(myStmtHandle, 2, "Nice trip somewhere") 873 | If RetVal <> SQLITE_OK Then 874 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 875 | Beep 876 | End If 877 | 878 | RetVal = SQLite3Step(myStmtHandle) 879 | If RetVal <> SQLITE_DONE Then 880 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 881 | Beep 882 | End If 883 | 884 | ' Finalize the statement 885 | RetVal = SQLite3Finalize(myStmtHandle) 886 | Debug.Print "SQLite3Finalize returned " & RetVal 887 | 888 | '------------------------- 889 | ' Select statement 890 | ' =============== 891 | ' Create the sql statement - getting a StmtHandle back 892 | ' Now using named parameters! 893 | RetVal = SQLite3PrepareV2(myDbHandle, "SELECT * FROM MyDateTable", myStmtHandle) 894 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 895 | 896 | RetVal = SQLite3Step(myStmtHandle) 897 | If RetVal = SQLITE_ROW Then 898 | ' We have access to the result columns here. 899 | myDate = SQLite3ColumnDate(myStmtHandle, 0) 900 | myEvent = SQLite3ColumnText(myStmtHandle, 1) 901 | Debug.Print "Event: " & myEvent, "Date: " & myDate 902 | ElseIf RetVal = SQLITE_DONE Then 903 | Debug.Print "No row found" 904 | End If 905 | 906 | ' Finalize (delete) the statement 907 | RetVal = SQLite3Finalize(myStmtHandle) 908 | Debug.Print "SQLite3Finalize returned " & RetVal 909 | 910 | ' Close the database 911 | RetVal = SQLite3Close(myDbHandle) 912 | Kill TestFile 913 | 914 | Debug.Print "----- TestDates End -----" 915 | End Sub 916 | 917 | 918 | Public Sub TestStrings() 919 | #If Win64 Then 920 | Dim myDbHandle As LongPtr 921 | Dim myStmtHandle As LongPtr 922 | #Else 923 | Dim myDbHandle As Long 924 | Dim myStmtHandle As Long 925 | #End If 926 | Dim RetVal As Long 927 | Dim stepMsg As String 928 | Dim i As Long 929 | 930 | Dim myString1 As String 931 | Dim myString2 As String 932 | Dim myLongString As String 933 | Dim myStringResult As String 934 | 935 | Debug.Print "----- TestStrings Start -----" 936 | 937 | ' Open the database - getting a DbHandle back 938 | RetVal = SQLite3Open(TestFile, myDbHandle) 939 | Debug.Print "SQLite3Open returned " & RetVal 940 | 941 | myString2 = "" 942 | myLongString = String(10000, "A") 943 | 944 | '------------------------ 945 | ' Create the table 946 | ' ================ 947 | ' (I've got no error checking here...) 948 | SQLite3ExecuteNonQuery myDbHandle, "CREATE TABLE MyStringTable (MyValue TEXT)" 949 | 950 | '------------------------- 951 | ' Prepare an insert statement with parameters 952 | ' =============== 953 | ' Create the sql statement - getting a StmtHandle back 954 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyStringTable Values (@SomeString)", myStmtHandle) 955 | If RetVal <> SQLITE_OK Then 956 | Debug.Print "SQLite3PrepareV2 returned " & SQLite3ErrMsg(myDbHandle) 957 | Beep 958 | End If 959 | 960 | RetVal = SQLite3BindText(myStmtHandle, 1, myString1) 961 | If RetVal <> SQLITE_OK Then 962 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 963 | Beep 964 | End If 965 | 966 | RetVal = SQLite3Step(myStmtHandle) 967 | If RetVal <> SQLITE_DONE Then 968 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 969 | Beep 970 | End If 971 | 972 | RetVal = SQLite3Reset(myStmtHandle) 973 | If RetVal <> SQLITE_OK Then 974 | Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle) 975 | Beep 976 | End If 977 | 978 | RetVal = SQLite3BindText(myStmtHandle, 1, myString2) 979 | If RetVal <> SQLITE_OK Then 980 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 981 | Beep 982 | End If 983 | 984 | RetVal = SQLite3Step(myStmtHandle) 985 | If RetVal <> SQLITE_DONE Then 986 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 987 | Beep 988 | End If 989 | 990 | RetVal = SQLite3Reset(myStmtHandle) 991 | If RetVal <> SQLITE_OK Then 992 | Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle) 993 | Beep 994 | End If 995 | 996 | RetVal = SQLite3BindText(myStmtHandle, 1, myLongString) 997 | If RetVal <> SQLITE_OK Then 998 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 999 | Beep 1000 | End If 1001 | 1002 | RetVal = SQLite3Step(myStmtHandle) 1003 | If RetVal <> SQLITE_DONE Then 1004 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 1005 | Beep 1006 | End If 1007 | ' Finalize the statement 1008 | RetVal = SQLite3Finalize(myStmtHandle) 1009 | Debug.Print "SQLite3Finalize returned " & RetVal 1010 | 1011 | '------------------------- 1012 | ' Select statement 1013 | ' =============== 1014 | ' Create the sql statement - getting a StmtHandle back 1015 | ' Now using named parameters! 1016 | RetVal = SQLite3PrepareV2(myDbHandle, "SELECT * FROM MyStringTable", myStmtHandle) 1017 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 1018 | 1019 | RetVal = SQLite3Step(myStmtHandle) 1020 | If RetVal = SQLITE_ROW Then 1021 | ' We have access to the result columns here. 1022 | myStringResult = SQLite3ColumnText(myStmtHandle, 0) 1023 | Debug.Print "Result1: " + myStringResult 1024 | ElseIf RetVal = SQLITE_DONE Then 1025 | Debug.Print "No row found" 1026 | End If 1027 | 1028 | RetVal = SQLite3Step(myStmtHandle) 1029 | If RetVal = SQLITE_ROW Then 1030 | ' We have access to the result columns here. 1031 | myStringResult = SQLite3ColumnText(myStmtHandle, 0) 1032 | Debug.Print "Result2: " + myStringResult 1033 | ElseIf RetVal = SQLITE_DONE Then 1034 | Debug.Print "No row found" 1035 | End If 1036 | 1037 | RetVal = SQLite3Step(myStmtHandle) 1038 | If RetVal = SQLITE_ROW Then 1039 | ' We have access to the result columns here. 1040 | myStringResult = SQLite3ColumnText(myStmtHandle, 0) 1041 | 1042 | Debug.Print "Long String is the same: " & (myStringResult = myLongString) 1043 | ElseIf RetVal = SQLITE_DONE Then 1044 | Debug.Print "No row found" 1045 | End If 1046 | 1047 | ' Finalize (delete) the statement 1048 | RetVal = SQLite3Finalize(myStmtHandle) 1049 | Debug.Print "SQLite3Finalize returned " & RetVal 1050 | 1051 | ' Close the database 1052 | RetVal = SQLite3Close(myDbHandle) 1053 | Kill TestFile 1054 | 1055 | Debug.Print "----- TestStrings End -----" 1056 | End Sub 1057 | 1058 | Public Sub TestBackup() 1059 | Dim testFileBackup As String 1060 | 1061 | #If Win64 Then 1062 | Dim myDbHandle As LongPtr 1063 | Dim myDbBackupHandle As LongPtr 1064 | Dim myBackupHandle As LongPtr 1065 | #Else 1066 | Dim myDbHandle As Long 1067 | Dim myDbBackupHandle As Long 1068 | Dim myBackupHandle As Long 1069 | #End If 1070 | 1071 | Dim RetVal As Long 1072 | Dim i As Long 1073 | 1074 | Debug.Print "----- TestBackup Start -----" 1075 | 1076 | ' Open the database - getting a DbHandle back 1077 | RetVal = SQLite3Open(TestFile, myDbHandle) 1078 | Debug.Print "SQLite3Open returned " & RetVal 1079 | 1080 | SQLite3ExecuteNonQuery myDbHandle, "CREATE TABLE MyTestTable (Key INT PRIMARY KEY, Value TEXT)" 1081 | SQLite3ExecuteNonQuery myDbHandle, "INSERT INTO MyTestTable VALUES (1, 'First')" 1082 | SQLite3ExecuteNonQuery myDbHandle, "INSERT INTO MyTestTable VALUES (2, 'Second')" 1083 | SQLite3ExecuteQuery myDbHandle, "SELECT * FROM MyTestTable" 1084 | 1085 | ' Now do a backup 1086 | testFileBackup = TestFile & ".bak" 1087 | RetVal = SQLite3Open(testFileBackup, myDbBackupHandle) 1088 | Debug.Print "SQLite3Open returned " & RetVal 1089 | 1090 | myBackupHandle = SQLite3BackupInit(myDbBackupHandle, "main", myDbHandle, "main") 1091 | If myBackupHandle <> 0 Then 1092 | RetVal = SQLite3BackupStep(myBackupHandle, -1) 1093 | Debug.Print "SQLite3BackupStep returned " & RetVal 1094 | RetVal = SQLite3BackupFinish(myBackupHandle) 1095 | Debug.Print "SQLite3BackupFinish returned " & RetVal 1096 | End If 1097 | RetVal = SQLite3ErrCode(myDbBackupHandle) 1098 | Debug.Print "Backup result " & RetVal 1099 | Debug.Print "Selecting from backup:" 1100 | SQLite3ExecuteQuery myDbBackupHandle, "SELECT * FROM MyTestTable" 1101 | 1102 | RetVal = SQLite3Close(myDbHandle) 1103 | RetVal = SQLite3Close(myDbBackupHandle) 1104 | 1105 | Kill TestFile 1106 | Kill testFileBackup 1107 | 1108 | Debug.Print "----- TestBackup End -----" 1109 | End Sub 1110 | 1111 | 1112 | Public Sub TestBlob() 1113 | #If Win64 Then 1114 | Dim myDbHandle As LongPtr 1115 | Dim myStmtHandle As LongPtr 1116 | #Else 1117 | Dim myDbHandle As Long 1118 | Dim myStmtHandle As Long 1119 | #End If 1120 | Dim RetVal As Long 1121 | Dim stepMsg As String 1122 | Dim i As Long 1123 | 1124 | Dim myBlob(2) As Byte 1125 | Dim myBlobResult() As Byte 1126 | 1127 | Debug.Print "----- TestBlob Start -----" 1128 | 1129 | ' Open the database - getting a DbHandle back 1130 | RetVal = SQLite3Open(TestFile, myDbHandle) 1131 | Debug.Print "SQLite3Open returned " & RetVal 1132 | 1133 | myBlob(0) = 90 1134 | myBlob(1) = 91 1135 | myBlob(2) = 92 1136 | 1137 | '------------------------ 1138 | ' Create the table 1139 | ' ================ 1140 | ' (I've got no error checking here...) 1141 | SQLite3ExecuteNonQuery myDbHandle, "CREATE TABLE MyBlobTable (MyValue BLOB)" 1142 | 1143 | '------------------------- 1144 | ' Prepare an insert statement with parameters 1145 | ' =============== 1146 | ' Create the sql statement - getting a StmtHandle back 1147 | RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyBlobTable Values (@SomeString)", myStmtHandle) 1148 | If RetVal <> SQLITE_OK Then 1149 | Debug.Print "SQLite3PrepareV2 returned " & SQLite3ErrMsg(myDbHandle) 1150 | Beep 1151 | End If 1152 | 1153 | RetVal = SQLite3BindBlob(myStmtHandle, 1, myBlob) 1154 | If RetVal <> SQLITE_OK Then 1155 | Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle) 1156 | Beep 1157 | End If 1158 | 1159 | RetVal = SQLite3Step(myStmtHandle) 1160 | If RetVal <> SQLITE_DONE Then 1161 | Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle) 1162 | Beep 1163 | End If 1164 | 1165 | ' Finalize the statement 1166 | RetVal = SQLite3Finalize(myStmtHandle) 1167 | Debug.Print "SQLite3Finalize returned " & RetVal 1168 | 1169 | '------------------------- 1170 | ' Select statement 1171 | ' =============== 1172 | ' Create the sql statement - getting a StmtHandle back 1173 | ' Now using named parameters! 1174 | RetVal = SQLite3PrepareV2(myDbHandle, "SELECT * FROM MyBlobTable", myStmtHandle) 1175 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 1176 | 1177 | RetVal = SQLite3Step(myStmtHandle) 1178 | If RetVal = SQLITE_ROW Then 1179 | ' We have access to the result columns here. 1180 | myBlobResult = SQLite3ColumnBlob(myStmtHandle, 0) 1181 | For i = LBound(myBlobResult) To UBound(myBlobResult) 1182 | Debug.Print "Blob byte " & i & ": " & myBlobResult(i) 1183 | Next 1184 | ElseIf RetVal = SQLITE_DONE Then 1185 | Debug.Print "No row found" 1186 | End If 1187 | 1188 | ' Finalize (delete) the statement 1189 | RetVal = SQLite3Finalize(myStmtHandle) 1190 | Debug.Print "SQLite3Finalize returned " & RetVal 1191 | 1192 | ' Close the database 1193 | RetVal = SQLite3Close(myDbHandle) 1194 | Kill TestFile 1195 | 1196 | Debug.Print "----- TestBlob End -----" 1197 | End Sub 1198 | 1199 | Public Sub TestWriteReadOnly() 1200 | #If Win64 Then 1201 | Dim myDbHandle As LongPtr 1202 | Dim myDbHandleV2 As LongPtr 1203 | Dim myStmtHandle As LongPtr 1204 | #Else 1205 | Dim myDbHandle As Long 1206 | Dim myDbHandleV2 As Long 1207 | Dim myStmtHandle As Long 1208 | #End If 1209 | Dim RetVal As Long 1210 | 1211 | ' Open the database in Read Write Access 1212 | RetVal = SQLite3Open(TestFile, myDbHandle) 1213 | Debug.Print "SQLite3Open returned " & RetVal 1214 | 1215 | ' Open the database in Read Only Access 1216 | RetVal = SQLite3OpenV2(TestFile, myDbHandleV2, SQLITE_OPEN_READONLY, Empty) 1217 | Debug.Print "SQLite3OpenV2 returned " & RetVal 1218 | 1219 | ' Create the sql statement - getting a StmtHandle back 1220 | RetVal = SQLite3PrepareV2(myDbHandle, "CREATE TABLE MyFirstTable (TheId INTEGER, TheText TEXT, TheValue REAL)", myStmtHandle) 1221 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 1222 | 1223 | ' Start running the statement 1224 | RetVal = SQLite3Step(myStmtHandle) 1225 | Debug.Print "SQLite3Step returned " & RetVal 1226 | 1227 | ' Finalize (delete) the statement 1228 | RetVal = SQLite3Finalize(myStmtHandle) 1229 | Debug.Print "SQLite3Finalize returned " & RetVal 1230 | 1231 | ' Create the sql statement - getting a StmtHandle back with Read Only 1232 | RetVal = SQLite3PrepareV2(myDbHandleV2, "CREATE TABLE MySecondTable (TheId INTEGER, TheText TEXT, TheValue REAL)", myStmtHandle) 1233 | 'RetVal = SQLite3PrepareV2(myDbHandleV2, "SELECT * FROM MyFirstTable", myStmtHandle) 1234 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 1235 | 1236 | ' Start running the statement with Read Only 1237 | RetVal = SQLite3Step(myStmtHandle) 1238 | Debug.Print "SQLite3Step returned " & RetVal 1239 | 1240 | If RetVal = SQLITE_READONLY Then 1241 | Debug.Print "Cannot Write in Read Only database" 1242 | End If 1243 | 1244 | ' Finalize (delete) the statement with Read Only 1245 | RetVal = SQLite3Finalize(myStmtHandle) 1246 | Debug.Print "SQLite3Finalize returned " & RetVal 1247 | 1248 | ' Create the sql statement - getting a StmtHandle back with Read Only 1249 | RetVal = SQLite3PrepareV2(myDbHandleV2, "SELECT * FROM MyFirstTable", myStmtHandle) 1250 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 1251 | 1252 | ' Start running the statement with Read Only 1253 | RetVal = SQLite3Step(myStmtHandle) 1254 | Debug.Print "SQLite3Step returned " & RetVal 1255 | 1256 | If RetVal = SQLITE_DONE Then 1257 | Debug.Print "But Reading is granted on Read Only database" 1258 | End If 1259 | 1260 | ' Finalize (delete) the statement with Read Only 1261 | RetVal = SQLite3Finalize(myStmtHandle) 1262 | Debug.Print "SQLite3Finalize returned " & RetVal 1263 | 1264 | RetVal = SQLite3Close(myDbHandleV2) 1265 | Debug.Print "SQLite3Close V2 returned " & RetVal 1266 | 1267 | RetVal = SQLite3Close(myDbHandle) 1268 | Debug.Print "SQLite3Close returned " & RetVal 1269 | 1270 | Kill TestFile 1271 | 1272 | End Sub 1273 | 1274 | ' SQLite3 Helper Functions 1275 | #If Win64 Then 1276 | Public Function SQLite3ExecuteNonQuery(ByVal dbHandle As LongPtr, ByVal SqlCommand As String) As Long 1277 | Dim stmtHandle As LongPtr 1278 | #Else 1279 | Public Function SQLite3ExecuteNonQuery(ByVal dbHandle As Long, ByVal SqlCommand As String) As Long 1280 | Dim stmtHandle As Long 1281 | #End If 1282 | 1283 | SQLite3PrepareV2 dbHandle, SqlCommand, stmtHandle 1284 | SQLite3Step stmtHandle 1285 | SQLite3Finalize stmtHandle 1286 | 1287 | SQLite3ExecuteNonQuery = SQLite3Changes(dbHandle) 1288 | End Function 1289 | 1290 | #If Win64 Then 1291 | Public Sub SQLite3ExecuteQuery(ByVal dbHandle As LongPtr, ByVal sqlQuery As String) 1292 | Dim stmtHandle As LongPtr 1293 | #Else 1294 | Public Sub SQLite3ExecuteQuery(ByVal dbHandle As Long, ByVal sqlQuery As String) 1295 | Dim stmtHandle As Long 1296 | #End If 1297 | ' Dumps a query to the debug window. No error checking 1298 | 1299 | Dim RetVal As Long 1300 | 1301 | RetVal = SQLite3PrepareV2(dbHandle, sqlQuery, stmtHandle) 1302 | Debug.Print "SQLite3PrepareV2 returned " & RetVal 1303 | 1304 | ' Start running the statement 1305 | RetVal = SQLite3Step(stmtHandle) 1306 | If RetVal = SQLITE_ROW Then 1307 | Debug.Print "SQLite3Step Row Ready" 1308 | PrintColumns stmtHandle 1309 | Else 1310 | Debug.Print "SQLite3Step returned " & RetVal 1311 | End If 1312 | 1313 | ' Move to next row 1314 | RetVal = SQLite3Step(stmtHandle) 1315 | Do While RetVal = SQLITE_ROW 1316 | Debug.Print "SQLite3Step Row Ready" 1317 | PrintColumns stmtHandle 1318 | RetVal = SQLite3Step(stmtHandle) 1319 | Loop 1320 | 1321 | If RetVal = SQLITE_DONE Then 1322 | Debug.Print "SQLite3Step Done" 1323 | Else 1324 | Debug.Print "SQLite3Step returned " & RetVal 1325 | End If 1326 | 1327 | ' Finalize (delete) the statement 1328 | RetVal = SQLite3Finalize(stmtHandle) 1329 | Debug.Print "SQLite3Finalize returned " & RetVal 1330 | End Sub 1331 | -------------------------------------------------------------------------------- /Source/SQLite3VBAModules/Sqlite3_64.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "Sqlite3" 2 | Option Explicit 3 | 4 | ' Notes: 5 | ' Microsoft uses UTF-16, little endian byte order. 6 | 7 | Private Const JULIANDAY_OFFSET As Double = 2415018.5 8 | 9 | ' Returned from SQLite3Initialize 10 | Public Const SQLITE_INIT_OK As Long = 0 11 | Public Const SQLITE_INIT_ERROR As Long = 1 12 | 13 | ' SQLite data types 14 | Public Const SQLITE_INTEGER As Long = 1 15 | Public Const SQLITE_FLOAT As Long = 2 16 | Public Const SQLITE_TEXT As Long = 3 17 | Public Const SQLITE_BLOB As Long = 4 18 | Public Const SQLITE_NULL As Long = 5 19 | 20 | ' SQLite atandard return value 21 | Public Const SQLITE_OK As Long = 0 ' Successful result 22 | Public Const SQLITE_ERROR As Long = 1 ' SQL error or missing database 23 | Public Const SQLITE_INTERNAL As Long = 2 ' Internal logic error in SQLite 24 | Public Const SQLITE_PERM As Long = 3 ' Access permission denied 25 | Public Const SQLITE_ABORT As Long = 4 ' Callback routine requested an abort 26 | Public Const SQLITE_BUSY As Long = 5 ' The database file is locked 27 | Public Const SQLITE_LOCKED As Long = 6 ' A table in the database is locked 28 | Public Const SQLITE_NOMEM As Long = 7 ' A malloc() failed 29 | Public Const SQLITE_READONLY As Long = 8 ' Attempt to write a readonly database 30 | Public Const SQLITE_INTERRUPT As Long = 9 ' Operation terminated by sqlite3_interrupt() 31 | Public Const SQLITE_IOERR As Long = 10 ' Some kind of disk I/O error occurred 32 | Public Const SQLITE_CORRUPT As Long = 11 ' The database disk image is malformed 33 | Public Const SQLITE_NOTFOUND As Long = 12 ' NOT USED. Table or record not found 34 | Public Const SQLITE_FULL As Long = 13 ' Insertion failed because database is full 35 | Public Const SQLITE_CANTOPEN As Long = 14 ' Unable to open the database file 36 | Public Const SQLITE_PROTOCOL As Long = 15 ' NOT USED. Database lock protocol error 37 | Public Const SQLITE_EMPTY As Long = 16 ' Database is empty 38 | Public Const SQLITE_SCHEMA As Long = 17 ' The database schema changed 39 | Public Const SQLITE_TOOBIG As Long = 18 ' String or BLOB exceeds size limit 40 | Public Const SQLITE_CONSTRAINT As Long = 19 ' Abort due to constraint violation 41 | Public Const SQLITE_MISMATCH As Long = 20 ' Data type mismatch 42 | Public Const SQLITE_MISUSE As Long = 21 ' Library used incorrectly 43 | Public Const SQLITE_NOLFS As Long = 22 ' Uses OS features not supported on host 44 | Public Const SQLITE_AUTH As Long = 23 ' Authorization denied 45 | Public Const SQLITE_FORMAT As Long = 24 ' Auxiliary database format error 46 | Public Const SQLITE_RANGE As Long = 25 ' 2nd parameter to sqlite3_bind out of range 47 | Public Const SQLITE_NOTADB As Long = 26 ' File opened that is not a database file 48 | Public Const SQLITE_ROW As Long = 100 ' sqlite3_step() has another row ready 49 | Public Const SQLITE_DONE As Long = 101 ' sqlite3_step() has finished executing 50 | 51 | ' Extended error codes 52 | Public Const SQLITE_IOERR_READ As Long = 266 '(SQLITE_IOERR | (1<<8)) 53 | Public Const SQLITE_IOERR_SHORT_READ As Long = 522 '(SQLITE_IOERR | (2<<8)) 54 | Public Const SQLITE_IOERR_WRITE As Long = 778 '(SQLITE_IOERR | (3<<8)) 55 | Public Const SQLITE_IOERR_FSYNC As Long = 1034 '(SQLITE_IOERR | (4<<8)) 56 | Public Const SQLITE_IOERR_DIR_FSYNC As Long = 1290 '(SQLITE_IOERR | (5<<8)) 57 | Public Const SQLITE_IOERR_TRUNCATE As Long = 1546 '(SQLITE_IOERR | (6<<8)) 58 | Public Const SQLITE_IOERR_FSTAT As Long = 1802 '(SQLITE_IOERR | (7<<8)) 59 | Public Const SQLITE_IOERR_UNLOCK As Long = 2058 '(SQLITE_IOERR | (8<<8)) 60 | Public Const SQLITE_IOERR_RDLOCK As Long = 2314 '(SQLITE_IOERR | (9<<8)) 61 | Public Const SQLITE_IOERR_DELETE As Long = 2570 '(SQLITE_IOERR | (10<<8)) 62 | Public Const SQLITE_IOERR_BLOCKED As Long = 2826 '(SQLITE_IOERR | (11<<8)) 63 | Public Const SQLITE_IOERR_NOMEM As Long = 3082 '(SQLITE_IOERR | (12<<8)) 64 | Public Const SQLITE_IOERR_ACCESS As Long = 3338 '(SQLITE_IOERR | (13<<8)) 65 | Public Const SQLITE_IOERR_CHECKRESERVEDLOCK As Long = 3594 '(SQLITE_IOERR | (14<<8)) 66 | Public Const SQLITE_IOERR_LOCK As Long = 3850 '(SQLITE_IOERR | (15<<8)) 67 | Public Const SQLITE_IOERR_CLOSE As Long = 4106 '(SQLITE_IOERR | (16<<8)) 68 | Public Const SQLITE_IOERR_DIR_CLOSE As Long = 4362 '(SQLITE_IOERR | (17<<8)) 69 | Public Const SQLITE_LOCKED_SHAREDCACHE As Long = 265 '(SQLITE_LOCKED | (1<<8) ) 70 | 71 | ' Flags For File Open Operations 72 | Public Const SQLITE_OPEN_READONLY As Long = 1 ' Ok for sqlite3_open_v2() 73 | Public Const SQLITE_OPEN_READWRITE As Long = 2 ' Ok for sqlite3_open_v2() 74 | Public Const SQLITE_OPEN_CREATE As Long = 4 ' Ok for sqlite3_open_v2() 75 | Public Const SQLITE_OPEN_DELETEONCLOSE As Long = 8 ' VFS only 76 | Public Const SQLITE_OPEN_EXCLUSIVE As Long = 16 ' VFS only 77 | Public Const SQLITE_OPEN_AUTOPROXY As Long = 32 ' VFS only 78 | Public Const SQLITE_OPEN_URI As Long = 64 ' Ok for sqlite3_open_v2() 79 | Public Const SQLITE_OPEN_MEMORY As Long = 128 ' Ok for sqlite3_open_v2() 80 | Public Const SQLITE_OPEN_MAIN_DB As Long = 256 ' VFS only 81 | Public Const SQLITE_OPEN_TEMP_DB As Long = 512 ' VFS only 82 | Public Const SQLITE_OPEN_TRANSIENT_DB As Long = 1024 ' VFS only 83 | Public Const SQLITE_OPEN_MAIN_JOURNAL As Long = 2048 ' VFS only 84 | Public Const SQLITE_OPEN_TEMP_JOURNAL As Long = 4096 ' VFS only 85 | Public Const SQLITE_OPEN_SUBJOURNAL As Long = 8192 ' VFS only 86 | Public Const SQLITE_OPEN_MASTER_JOURNAL As Long = 16384 ' VFS only 87 | Public Const SQLITE_OPEN_NOMUTEX As Long = 32768 ' Ok for sqlite3_open_v2() 88 | Public Const SQLITE_OPEN_FULLMUTEX As Long = 65536 ' Ok for sqlite3_open_v2() 89 | Public Const SQLITE_OPEN_SHAREDCACHE As Long = 131072 ' Ok for sqlite3_open_v2() 90 | Public Const SQLITE_OPEN_PRIVATECACHE As Long = 262144 ' Ok for sqlite3_open_v2() 91 | Public Const SQLITE_OPEN_WAL As Long = 524288 ' VFS only 92 | 93 | ' Options for Text and Blob binding 94 | Private Const SQLITE_STATIC As Long = 0 95 | Private Const SQLITE_TRANSIENT As Long = -1 96 | 97 | ' System calls 98 | Private Const CP_UTF8 As Long = 65001 99 | #If Win64 Then 100 | 101 | 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 102 | 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 103 | Private Declare PtrSafe Sub RtlMoveMemory Lib "kernel32" (ByVal pDest As LongPtr, ByVal pSource As LongPtr, ByVal length As Long) 104 | Private Declare PtrSafe Function lstrcpynW Lib "kernel32" (ByVal pwsDest As LongPtr, ByVal pwsSource As LongPtr, ByVal cchCount As Long) As LongPtr 105 | Private Declare PtrSafe Function lstrcpyW Lib "kernel32" (ByVal pwsDest As LongPtr, ByVal pwsSource As LongPtr) As LongPtr 106 | Private Declare PtrSafe Function lstrlenW Lib "kernel32" (ByVal pwsString As LongPtr) As Long 107 | Private Declare PtrSafe Function SysAllocString Lib "OleAut32" (ByRef pwsString As LongPtr) As LongPtr 108 | Private Declare PtrSafe Function SysStringLen Lib "OleAut32" (ByVal bstrString As LongPtr) As Long 109 | Private Declare PtrSafe Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As LongPtr 110 | Private Declare PtrSafe Function FreeLibrary Lib "kernel32" (ByVal hLibModule As LongPtr) As Long 111 | #Else 112 | 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 113 | 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 114 | Private Declare Sub RtlMoveMemory Lib "kernel32" (ByVal pDest As Long, ByVal pSource As Long, ByVal length As Long) 115 | Private Declare Function lstrcpynW Lib "kernel32" (ByVal pwsDest As Long, ByVal pwsSource As Long, ByVal cchCount As Long) As Long 116 | Private Declare Function lstrcpyW Lib "kernel32" (ByVal pwsDest As Long, ByVal pwsSource As Long) As Long 117 | Private Declare Function lstrlenW Lib "kernel32" (ByVal pwsString As Long) As Long 118 | Private Declare Function SysAllocString Lib "OleAut32" (ByRef pwsString As Long) As Long 119 | Private Declare Function SysStringLen Lib "OleAut32" (ByVal bstrString As Long) As Long 120 | Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long 121 | Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long 122 | #End If 123 | '===================================================================================== 124 | ' SQLite StdCall Imports 125 | '----------------------- 126 | #If Win64 Then 127 | ' SQLite library version 128 | Private Declare PtrSafe Function sqlite3_libversion Lib "SQLite3" () As LongPtr ' PtrUtf8String 129 | ' Database connections 130 | Private Declare PtrSafe Function sqlite3_open16 Lib "SQLite3" (ByVal pwsFileName As LongPtr, ByRef hDb As LongPtr) As Long 131 | 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 132 | Private Declare PtrSafe Function sqlite3_close Lib "SQLite3" (ByVal hDb As LongPtr) As Long 133 | ' Database connection error info 134 | Private Declare PtrSafe Function sqlite3_errmsg Lib "SQLite3" (ByVal hDb As LongPtr) As LongPtr ' PtrUtf8String 135 | Private Declare PtrSafe Function sqlite3_errmsg16 Lib "SQLite3" (ByVal hDb As LongPtr) As LongPtr ' PtrUtf16String 136 | Private Declare PtrSafe Function sqlite3_errcode Lib "SQLite3" (ByVal hDb As LongPtr) As Long 137 | Private Declare PtrSafe Function sqlite3_extended_errcode Lib "SQLite3" (ByVal hDb As LongPtr) As Long 138 | ' Database connection change counts 139 | Private Declare PtrSafe Function sqlite3_changes Lib "SQLite3" (ByVal hDb As LongPtr) As Long 140 | Private Declare PtrSafe Function sqlite3_total_changes Lib "SQLite3" (ByVal hDb As LongPtr) As Long 141 | 142 | ' Statements 143 | Private Declare PtrSafe Function sqlite3_prepare16_v2 Lib "SQLite3" _ 144 | (ByVal hDb As LongPtr, ByVal pwsSql As LongPtr, ByVal nSqlLength As Long, ByRef hStmt As LongPtr, ByVal ppwsTailOut As LongPtr) As Long 145 | Private Declare PtrSafe Function sqlite3_step Lib "SQLite3" (ByVal hStmt As LongPtr) As Long 146 | Private Declare PtrSafe Function sqlite3_reset Lib "SQLite3" (ByVal hStmt As LongPtr) As Long 147 | Private Declare PtrSafe Function sqlite3_finalize Lib "SQLite3" (ByVal hStmt As LongPtr) As Long 148 | 149 | ' Statement column access (0-based indices) 150 | Private Declare PtrSafe Function sqlite3_column_count Lib "SQLite3" (ByVal hStmt As LongPtr) As Long 151 | Private Declare PtrSafe Function sqlite3_column_type Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As Long 152 | Private Declare PtrSafe Function sqlite3_column_name Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongPtr ' PtrString 153 | Private Declare PtrSafe Function sqlite3_column_name16 Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongPtr ' PtrWString 154 | 155 | Private Declare PtrSafe Function sqlite3_column_blob Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongPtr ' PtrData 156 | Private Declare PtrSafe Function sqlite3_column_bytes Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As Long 157 | Private Declare PtrSafe Function sqlite3_column_bytes16 Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As Long 158 | Private Declare PtrSafe Function sqlite3_column_double Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As Double 159 | Private Declare PtrSafe Function sqlite3_column_int Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As Long 160 | Private Declare PtrSafe Function sqlite3_column_int64 Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongLong 161 | Private Declare PtrSafe Function sqlite3_column_text Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongPtr ' PtrString 162 | Private Declare PtrSafe Function sqlite3_column_text16 Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongPtr ' PtrWString 163 | Private Declare PtrSafe Function sqlite3_column_value Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal iCol As Long) As LongPtr ' PtrSqlite3Value 164 | 165 | ' Statement parameter binding (1-based indices!) 166 | Private Declare PtrSafe Function sqlite3_bind_parameter_count Lib "SQLite3" (ByVal hStmt As LongPtr) As Long 167 | Private Declare PtrSafe Function sqlite3_bind_parameter_name Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long) As LongPtr 168 | Private Declare PtrSafe Function sqlite3_bind_parameter_index Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramName As LongPtr) As Long 169 | Private Declare PtrSafe Function sqlite3_bind_null Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long) As Long 170 | 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 171 | Private Declare PtrSafe Function sqlite3_bind_zeroblob Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal nBytes As Long) As Long 172 | Private Declare PtrSafe Function sqlite3_bind_double Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal Value As Double) As Long 173 | Private Declare PtrSafe Function sqlite3_bind_int Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal Value As Long) As Long 174 | Private Declare PtrSafe Function sqlite3_bind_int64 Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal Value As LongLong) As Long 175 | 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 176 | 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 177 | Private Declare PtrSafe Function sqlite3_bind_value Lib "SQLite3" (ByVal hStmt As LongPtr, ByVal paramIndex As Long, ByVal pSqlite3Value As LongPtr) As Long 178 | Private Declare PtrSafe Function sqlite3_clear_bindings Lib "SQLite3" (ByVal hStmt As LongPtr) As Long 179 | 180 | 'Backup 181 | Private Declare PtrSafe Function sqlite3_sleep Lib "SQLite3" (ByVal msToSleep As Long) As Long 182 | 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 LongPtr 183 | Private Declare PtrSafe Function sqlite3_backup_step Lib "SQLite3" (ByVal hBackup As LongPtr, ByVal nPage As Long) As Long 184 | Private Declare PtrSafe Function sqlite3_backup_finish Lib "SQLite3" (ByVal hBackup As LongPtr) As Long 185 | Private Declare PtrSafe Function sqlite3_backup_remaining Lib "SQLite3" (ByVal hBackup As LongPtr) As Long 186 | Private Declare PtrSafe Function sqlite3_backup_pagecount Lib "SQLite3" (ByVal hBackup As LongPtr) As Long 187 | #Else 188 | 189 | ' SQLite library version 190 | Private Declare Function sqlite3_libversion Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_libversion@0" () As Long ' PtrUtf8String 191 | ' Database connections 192 | Private Declare Function sqlite3_open16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_open16@8" (ByVal pwsFileName As Long, ByRef hDb As Long) As Long ' PtrDb 193 | 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 194 | Private Declare Function sqlite3_close Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_close@4" (ByVal hDb As Long) As Long 195 | ' Database connection error info 196 | Private Declare Function sqlite3_errmsg Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_errmsg@4" (ByVal hDb As Long) As Long ' PtrUtf8String 197 | Private Declare Function sqlite3_errmsg16 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_errmsg16@4" (ByVal hDb As Long) As Long ' PtrUtf16String 198 | Private Declare Function sqlite3_errcode Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_errcode@4" (ByVal hDb As Long) As Long 199 | Private Declare Function sqlite3_extended_errcode Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_extended_errcode@4" (ByVal hDb As Long) As Long 200 | ' Database connection change counts 201 | Private Declare Function sqlite3_changes Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_changes@4" (ByVal hDb As Long) As Long 202 | Private Declare Function sqlite3_total_changes Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_total_changes@4" (ByVal hDb As Long) As Long 203 | 204 | ' Statements 205 | Private Declare Function sqlite3_prepare16_v2 Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_prepare16_v2@20" _ 206 | (ByVal hDb As Long, ByVal pwsSql As Long, ByVal nSqlLength As Long, ByRef hStmt As Long, ByVal ppwsTailOut As Long) As Long 207 | Private Declare Function sqlite3_step Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_step@4" (ByVal hStmt As Long) As Long 208 | Private Declare Function sqlite3_reset Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_reset@4" (ByVal hStmt As Long) As Long 209 | Private Declare Function sqlite3_finalize Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_finalize@4" (ByVal hStmt As Long) As Long 210 | 211 | ' Statement column access (0-based indices) 212 | Private Declare Function sqlite3_column_count Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_column_count@4" (ByVal hStmt As Long) As Long 213 | 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 214 | 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 215 | 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 216 | 217 | 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 218 | 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 219 | 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 220 | 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 221 | 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 222 | 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 ....? 223 | 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 224 | 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 225 | 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 226 | 227 | ' Statement parameter binding (1-based indices!) 228 | Private Declare Function sqlite3_bind_parameter_count Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_bind_parameter_count@4" (ByVal hStmt As Long) As Long 229 | 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 230 | 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 231 | 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 232 | 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 233 | 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 234 | 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 235 | 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 236 | 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 ....? 237 | 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 238 | 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 239 | 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 240 | Private Declare Function sqlite3_clear_bindings Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_clear_bindings@4" (ByVal hStmt As Long) As Long 241 | 242 | 'Backup 243 | Private Declare Function sqlite3_sleep Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_sleep@4" (ByVal msToSleep As Long) As Long 244 | 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 245 | 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 246 | Private Declare Function sqlite3_backup_finish Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_finish@4" (ByVal hBackup As Long) As Long 247 | Private Declare Function sqlite3_backup_remaining Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_remaining@4" (ByVal hBackup As Long) As Long 248 | Private Declare Function sqlite3_backup_pagecount Lib "SQLite3_StdCall" Alias "_sqlite3_stdcall_backup_pagecount@4" (ByVal hBackup As Long) As Long 249 | #End If 250 | '===================================================================================== 251 | ' Initialize - load libraries explicitly 252 | #If Win64 Then 253 | Private hSQLiteLibrary As LongPtr 254 | Private hSQLiteStdCallLibrary As LongPtr 255 | #Else 256 | Private hSQLiteLibrary As Long 257 | Private hSQLiteStdCallLibrary As Long 258 | #End If 259 | 260 | Public Function SQLite3Initialize(Optional ByVal libDir As String) As Long 261 | ' A nice option here is to call SetDllDirectory, but that API is only available since Windows XP SP1. 262 | If libDir = "" Then libDir = ThisWorkbook.Path 263 | If Right(libDir, 1) <> "\" Then libDir = libDir & "\" 264 | 265 | If hSQLiteLibrary = 0 Then 266 | hSQLiteLibrary = LoadLibrary(libDir + "SQLite3.dll") 267 | If hSQLiteLibrary = 0 Then 268 | Debug.Print "SQLite3Initialize Error Loading " + libDir + "SQLite3.dll:", Err.LastDllError 269 | SQLite3Initialize = SQLITE_INIT_ERROR 270 | Exit Function 271 | End If 272 | End If 273 | 274 | #If Win64 Then 275 | #Else 276 | If hSQLiteStdCallLibrary = 0 Then 277 | hSQLiteStdCallLibrary = LoadLibrary(libDir + "SQLite3_StdCall.dll") 278 | If hSQLiteStdCallLibrary = 0 Then 279 | Debug.Print "SQLite3Initialize Error Loading " + libDir + "SQLite3_StdCall.dll:", Err.LastDllError 280 | SQLite3Initialize = SQLITE_INIT_ERROR 281 | Exit Function 282 | End If 283 | End If 284 | #End If 285 | SQLite3Initialize = SQLITE_INIT_OK 286 | End Function 287 | 288 | Public Sub SQLite3Free() 289 | Dim refCount As Long 290 | If hSQLiteStdCallLibrary <> 0 Then 291 | refCount = FreeLibrary(hSQLiteStdCallLibrary) 292 | hSQLiteStdCallLibrary = 0 293 | If refCount = 0 Then 294 | Debug.Print "SQLite3Free Error Freeing SQLite3_StdCall.dll:", refCount, Err.LastDllError 295 | End If 296 | End If 297 | If hSQLiteLibrary <> 0 Then 298 | refCount = FreeLibrary(hSQLiteLibrary) 299 | hSQLiteLibrary = 0 300 | If refCount = 0 Then 301 | Debug.Print "SQLite3Free Error Freeing SQLite3.dll:", refCount, Err.LastDllError 302 | End If 303 | End If 304 | End Sub 305 | 306 | 307 | '===================================================================================== 308 | ' SQLite library version 309 | 310 | Public Function SQLite3LibVersion() As String 311 | SQLite3LibVersion = Utf8PtrToString(sqlite3_libversion()) 312 | End Function 313 | 314 | '===================================================================================== 315 | ' Database connections 316 | #If Win64 Then 317 | Public Function SQLite3Open(ByVal fileName As String, ByRef dbHandle As LongPtr) As Long 318 | #Else 319 | Public Function SQLite3Open(ByVal fileName As String, ByRef dbHandle As Long) As Long 320 | #End If 321 | SQLite3Open = sqlite3_open16(StrPtr(fileName), dbHandle) 322 | End Function 323 | 324 | #If Win64 Then 325 | Public Function SQLite3OpenV2(ByVal fileName As String, ByRef dbHandle As LongPtr, ByVal flags As Long, ByVal vfsName As String) As Long 326 | #Else 327 | Public Function SQLite3OpenV2(ByVal fileName As String, ByRef dbHandle As Long, ByVal flags As Long, ByVal vfsName As String) As Long 328 | #End If 329 | 330 | Dim bufFileName() As Byte 331 | Dim bufVfsName() As Byte 332 | bufFileName = StringToUtf8Bytes(fileName) 333 | If vfsName = Empty Then 334 | SQLite3OpenV2 = sqlite3_open_v2(VarPtr(bufFileName(0)), dbHandle, flags, 0) 335 | Else 336 | bufVfsName = StringToUtf8Bytes(vfsName) 337 | SQLite3OpenV2 = sqlite3_open_v2(VarPtr(bufFileName(0)), dbHandle, flags, VarPtr(bufVfsName(0))) 338 | End If 339 | 340 | End Function 341 | 342 | #If Win64 Then 343 | Public Function SQLite3Close(ByVal dbHandle As LongPtr) As Long 344 | #Else 345 | Public Function SQLite3Close(ByVal dbHandle As Long) As Long 346 | #End If 347 | SQLite3Close = sqlite3_close(dbHandle) 348 | End Function 349 | 350 | '===================================================================================== 351 | ' Error information 352 | 353 | #If Win64 Then 354 | Public Function SQLite3ErrMsg(ByVal dbHandle As LongPtr) As String 355 | #Else 356 | Public Function SQLite3ErrMsg(ByVal dbHandle As Long) As String 357 | #End If 358 | SQLite3ErrMsg = Utf8PtrToString(sqlite3_errmsg(dbHandle)) 359 | End Function 360 | 361 | #If Win64 Then 362 | Public Function SQLite3ErrCode(ByVal dbHandle As LongPtr) As Long 363 | #Else 364 | Public Function SQLite3ErrCode(ByVal dbHandle As Long) As Long 365 | #End If 366 | SQLite3ErrCode = sqlite3_errcode(dbHandle) 367 | End Function 368 | 369 | #If Win64 Then 370 | Public Function SQLite3ExtendedErrCode(ByVal dbHandle As LongPtr) As Long 371 | #Else 372 | Public Function SQLite3ExtendedErrCode(ByVal dbHandle As Long) As Long 373 | #End If 374 | SQLite3ExtendedErrCode = sqlite3_extended_errcode(dbHandle) 375 | End Function 376 | 377 | '===================================================================================== 378 | ' Change Counts 379 | 380 | #If Win64 Then 381 | Public Function SQLite3Changes(ByVal dbHandle As LongPtr) As Long 382 | #Else 383 | Public Function SQLite3Changes(ByVal dbHandle As Long) As Long 384 | #End If 385 | SQLite3Changes = sqlite3_changes(dbHandle) 386 | End Function 387 | 388 | #If Win64 Then 389 | Public Function SQLite3TotalChanges(ByVal dbHandle As LongPtr) As Long 390 | #Else 391 | Public Function SQLite3TotalChanges(ByVal dbHandle As Long) As Long 392 | #End If 393 | SQLite3TotalChanges = sqlite3_total_changes(dbHandle) 394 | End Function 395 | 396 | '===================================================================================== 397 | ' Statements 398 | 399 | #If Win64 Then 400 | Public Function SQLite3PrepareV2(ByVal dbHandle As LongPtr, ByVal sql As String, ByRef stmtHandle As LongPtr) As Long 401 | #Else 402 | Public Function SQLite3PrepareV2(ByVal dbHandle As Long, ByVal sql As String, ByRef stmtHandle As Long) As Long 403 | #End If 404 | ' Only the first statement (up to ';') is prepared. Currently we don't retrieve the 'tail' pointer. 405 | SQLite3PrepareV2 = sqlite3_prepare16_v2(dbHandle, StrPtr(sql), Len(sql) * 2, stmtHandle, 0) 406 | End Function 407 | 408 | #If Win64 Then 409 | Public Function SQLite3Step(ByVal stmtHandle As LongPtr) As Long 410 | #Else 411 | Public Function SQLite3Step(ByVal stmtHandle As Long) As Long 412 | #End If 413 | SQLite3Step = sqlite3_step(stmtHandle) 414 | End Function 415 | 416 | #If Win64 Then 417 | Public Function SQLite3Reset(ByVal stmtHandle As LongPtr) As Long 418 | #Else 419 | Public Function SQLite3Reset(ByVal stmtHandle As Long) As Long 420 | #End If 421 | SQLite3Reset = sqlite3_reset(stmtHandle) 422 | End Function 423 | 424 | #If Win64 Then 425 | Public Function SQLite3Finalize(ByVal stmtHandle As LongPtr) As Long 426 | #Else 427 | Public Function SQLite3Finalize(ByVal stmtHandle As Long) As Long 428 | #End If 429 | SQLite3Finalize = sqlite3_finalize(stmtHandle) 430 | End Function 431 | 432 | '===================================================================================== 433 | ' Statement column access (0-based indices) 434 | 435 | #If Win64 Then 436 | Public Function SQLite3ColumnCount(ByVal stmtHandle As LongPtr) As Long 437 | #Else 438 | Public Function SQLite3ColumnCount(ByVal stmtHandle As Long) As Long 439 | #End If 440 | SQLite3ColumnCount = sqlite3_column_count(stmtHandle) 441 | End Function 442 | 443 | #If Win64 Then 444 | Public Function SQLite3ColumnType(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As Long 445 | #Else 446 | Public Function SQLite3ColumnType(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Long 447 | #End If 448 | SQLite3ColumnType = sqlite3_column_type(stmtHandle, ZeroBasedColIndex) 449 | End Function 450 | 451 | #If Win64 Then 452 | Public Function SQLite3ColumnName(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As String 453 | #Else 454 | Public Function SQLite3ColumnName(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As String 455 | #End If 456 | SQLite3ColumnName = Utf8PtrToString(sqlite3_column_name(stmtHandle, ZeroBasedColIndex)) 457 | End Function 458 | 459 | #If Win64 Then 460 | Public Function SQLite3ColumnDouble(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As Double 461 | #Else 462 | Public Function SQLite3ColumnDouble(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Double 463 | #End If 464 | SQLite3ColumnDouble = sqlite3_column_double(stmtHandle, ZeroBasedColIndex) 465 | End Function 466 | 467 | #If Win64 Then 468 | Public Function SQLite3ColumnInt32(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As Long 469 | #Else 470 | Public Function SQLite3ColumnInt32(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Long 471 | #End If 472 | SQLite3ColumnInt32 = sqlite3_column_int(stmtHandle, ZeroBasedColIndex) 473 | End Function 474 | 475 | #If Win64 Then 476 | Public Function SQLite3ColumnText(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As String 477 | #Else 478 | Public Function SQLite3ColumnText(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As String 479 | #End If 480 | SQLite3ColumnText = Utf8PtrToString(sqlite3_column_text(stmtHandle, ZeroBasedColIndex)) 481 | End Function 482 | 483 | #If Win64 Then 484 | Public Function SQLite3ColumnDate(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As Date 485 | #Else 486 | Public Function SQLite3ColumnDate(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Date 487 | #End If 488 | SQLite3ColumnDate = FromJulianDay(sqlite3_column_double(stmtHandle, ZeroBasedColIndex)) 489 | End Function 490 | 491 | #If Win64 Then 492 | Public Function SQLite3ColumnBlob(ByVal stmtHandle As LongPtr, ByVal ZeroBasedColIndex As Long) As Byte() 493 | Dim ptr As LongPtr 494 | #Else 495 | Public Function SQLite3ColumnBlob(ByVal stmtHandle As Long, ByVal ZeroBasedColIndex As Long) As Byte() 496 | Dim ptr As Long 497 | #End If 498 | 499 | Dim length As Long 500 | Dim buf() As Byte 501 | 502 | ptr = sqlite3_column_blob(stmtHandle, ZeroBasedColIndex) 503 | length = sqlite3_column_bytes(stmtHandle, ZeroBasedColIndex) 504 | ReDim buf(length - 1) 505 | RtlMoveMemory VarPtr(buf(0)), ptr, length 506 | SQLite3ColumnBlob = buf 507 | End Function 508 | '===================================================================================== 509 | ' Statement bindings 510 | 511 | #If Win64 Then 512 | Public Function SQLite3BindText(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long, ByVal Value As String) As Long 513 | #Else 514 | Public Function SQLite3BindText(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As String) As Long 515 | #End If 516 | SQLite3BindText = sqlite3_bind_text16(stmtHandle, OneBasedParamIndex, StrPtr(Value), -1, SQLITE_TRANSIENT) 517 | End Function 518 | 519 | #If Win64 Then 520 | Public Function SQLite3BindDouble(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long, ByVal Value As Double) As Long 521 | #Else 522 | Public Function SQLite3BindDouble(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As Double) As Long 523 | #End If 524 | SQLite3BindDouble = sqlite3_bind_double(stmtHandle, OneBasedParamIndex, Value) 525 | End Function 526 | 527 | #If Win64 Then 528 | Public Function SQLite3BindInt32(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long, ByVal Value As Long) As Long 529 | #Else 530 | Public Function SQLite3BindInt32(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As Long) As Long 531 | #End If 532 | SQLite3BindInt32 = sqlite3_bind_int(stmtHandle, OneBasedParamIndex, Value) 533 | End Function 534 | 535 | #If Win64 Then 536 | Public Function SQLite3BindDate(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long, ByVal Value As Date) As Long 537 | #Else 538 | Public Function SQLite3BindDate(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByVal Value As Date) As Long 539 | #End If 540 | SQLite3BindDate = sqlite3_bind_double(stmtHandle, OneBasedParamIndex, ToJulianDay(Value)) 541 | End Function 542 | 543 | #If Win64 Then 544 | Public Function SQLite3BindBlob(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long, ByRef Value() As Byte) As Long 545 | #Else 546 | Public Function SQLite3BindBlob(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long, ByRef Value() As Byte) As Long 547 | #End If 548 | Dim length As Long 549 | length = UBound(Value) - LBound(Value) + 1 550 | SQLite3BindBlob = sqlite3_bind_blob(stmtHandle, OneBasedParamIndex, VarPtr(Value(0)), length, SQLITE_TRANSIENT) 551 | End Function 552 | 553 | #If Win64 Then 554 | Public Function SQLite3BindNull(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long) As Long 555 | #Else 556 | Public Function SQLite3BindNull(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long) As Long 557 | #End If 558 | SQLite3BindNull = sqlite3_bind_null(stmtHandle, OneBasedParamIndex) 559 | End Function 560 | 561 | #If Win64 Then 562 | Public Function SQLite3BindParameterCount(ByVal stmtHandle As LongPtr) As Long 563 | #Else 564 | Public Function SQLite3BindParameterCount(ByVal stmtHandle As Long) As Long 565 | #End If 566 | SQLite3BindParameterCount = sqlite3_bind_parameter_count(stmtHandle) 567 | End Function 568 | 569 | #If Win64 Then 570 | Public Function SQLite3BindParameterName(ByVal stmtHandle As LongPtr, ByVal OneBasedParamIndex As Long) As String 571 | #Else 572 | Public Function SQLite3BindParameterName(ByVal stmtHandle As Long, ByVal OneBasedParamIndex As Long) As String 573 | #End If 574 | SQLite3BindParameterName = Utf8PtrToString(sqlite3_bind_parameter_name(stmtHandle, OneBasedParamIndex)) 575 | End Function 576 | 577 | #If Win64 Then 578 | Public Function SQLite3BindParameterIndex(ByVal stmtHandle As LongPtr, ByVal paramName As String) As Long 579 | #Else 580 | Public Function SQLite3BindParameterIndex(ByVal stmtHandle As Long, ByVal paramName As String) As Long 581 | #End If 582 | Dim buf() As Byte 583 | buf = StringToUtf8Bytes(paramName) 584 | SQLite3BindParameterIndex = sqlite3_bind_parameter_index(stmtHandle, VarPtr(buf(0))) 585 | End Function 586 | 587 | #If Win64 Then 588 | Public Function SQLite3ClearBindings(ByVal stmtHandle As LongPtr) As Long 589 | #Else 590 | Public Function SQLite3ClearBindings(ByVal stmtHandle As Long) As Long 591 | #End If 592 | SQLite3ClearBindings = sqlite3_clear_bindings(stmtHandle) 593 | End Function 594 | 595 | 596 | '===================================================================================== 597 | ' Backup 598 | Public Function SQLite3Sleep(ByVal timeToSleepInMs As Long) As Long 599 | SQLite3Sleep = sqlite3_sleep(timeToSleepInMs) 600 | End Function 601 | 602 | #If Win64 Then 603 | Public Function SQLite3BackupInit(ByVal dbHandleDestination As LongPtr, ByVal destinationName As String, ByVal dbHandleSource As LongPtr, ByVal sourceName As String) As LongPtr 604 | #Else 605 | Public Function SQLite3BackupInit(ByVal dbHandleDestination As Long, ByVal destinationName As String, ByVal dbHandleSource As Long, ByVal sourceName As String) As Long 606 | #End If 607 | Dim bufDestinationName() As Byte 608 | Dim bufSourceName() As Byte 609 | bufDestinationName = StringToUtf8Bytes(destinationName) 610 | bufSourceName = StringToUtf8Bytes(sourceName) 611 | SQLite3BackupInit = sqlite3_backup_init(dbHandleDestination, VarPtr(bufDestinationName(0)), dbHandleSource, VarPtr(bufSourceName(0))) 612 | End Function 613 | 614 | #If Win64 Then 615 | Public Function SQLite3BackupFinish(ByVal backupHandle As LongPtr) As Long 616 | #Else 617 | Public Function SQLite3BackupFinish(ByVal backupHandle As Long) As Long 618 | #End If 619 | SQLite3BackupFinish = sqlite3_backup_finish(backupHandle) 620 | End Function 621 | 622 | #If Win64 Then 623 | Public Function SQLite3BackupStep(ByVal backupHandle As LongPtr, ByVal numberOfPages) As Long 624 | #Else 625 | Public Function SQLite3BackupStep(ByVal backupHandle As Long, ByVal numberOfPages) As Long 626 | #End If 627 | SQLite3BackupStep = sqlite3_backup_step(backupHandle, numberOfPages) 628 | End Function 629 | 630 | #If Win64 Then 631 | Public Function SQLite3BackupPageCount(ByVal backupHandle As LongPtr) As Long 632 | #Else 633 | Public Function SQLite3BackupPageCount(ByVal backupHandle As Long) As Long 634 | #End If 635 | SQLite3BackupPageCount = sqlite3_backup_pagecount(backupHandle) 636 | End Function 637 | 638 | #If Win64 Then 639 | Public Function SQLite3BackupRemaining(ByVal backupHandle As LongPtr) As Long 640 | #Else 641 | Public Function SQLite3BackupRemaining(ByVal backupHandle As Long) As Long 642 | #End If 643 | SQLite3BackupRemaining = sqlite3_backup_remaining(backupHandle) 644 | End Function 645 | 646 | ' String Helpers 647 | #If Win64 Then 648 | Function Utf8PtrToString(ByVal pUtf8String As LongPtr) As String 649 | #Else 650 | Function Utf8PtrToString(ByVal pUtf8String As Long) As String 651 | #End If 652 | Dim buf As String 653 | Dim cSize As Long 654 | Dim RetVal As Long 655 | 656 | cSize = MultiByteToWideChar(CP_UTF8, 0, pUtf8String, -1, 0, 0) 657 | ' cSize includes the terminating null character 658 | If cSize <= 1 Then 659 | Utf8PtrToString = "" 660 | Exit Function 661 | End If 662 | 663 | Utf8PtrToString = String(cSize - 1, "*") ' and a termintating null char. 664 | RetVal = MultiByteToWideChar(CP_UTF8, 0, pUtf8String, -1, StrPtr(Utf8PtrToString), cSize) 665 | If RetVal = 0 Then 666 | Debug.Print "Utf8PtrToString Error:", Err.LastDllError 667 | Exit Function 668 | End If 669 | End Function 670 | 671 | Function StringToUtf8Bytes(ByVal str As String) As Variant 672 | Dim bSize As Long 673 | Dim RetVal As Long 674 | Dim buf() As Byte 675 | 676 | bSize = WideCharToMultiByte(CP_UTF8, 0, StrPtr(str), -1, 0, 0, 0, 0) 677 | If bSize = 0 Then 678 | Exit Function 679 | End If 680 | 681 | ReDim buf(bSize) 682 | RetVal = WideCharToMultiByte(CP_UTF8, 0, StrPtr(str), -1, VarPtr(buf(0)), bSize, 0, 0) 683 | If RetVal = 0 Then 684 | Debug.Print "StringToUtf8Bytes Error:", Err.LastDllError 685 | Exit Function 686 | End If 687 | StringToUtf8Bytes = buf 688 | End Function 689 | 690 | #If Win64 Then 691 | Function Utf16PtrToString(ByVal pUtf16String As LongPtr) As String 692 | #Else 693 | Function Utf16PtrToString(ByVal pUtf16String As Long) As String 694 | #End If 695 | Dim StrLen As Long 696 | 697 | StrLen = lstrlenW(pUtf16String) 698 | Utf16PtrToString = String(StrLen, "*") 699 | lstrcpynW StrPtr(Utf16PtrToString), pUtf16String, StrLen 700 | End Function 701 | 702 | ' Date Helpers 703 | Public Function ToJulianDay(oleDate As Date) As Double 704 | ToJulianDay = CDbl(oleDate) + JULIANDAY_OFFSET 705 | End Function 706 | 707 | Public Function FromJulianDay(julianDay As Double) As Date 708 | FromJulianDay = CDate(julianDay - JULIANDAY_OFFSET) 709 | End Function 710 | -------------------------------------------------------------------------------- /Source/SQLite3_StdCall/Notes.txt: -------------------------------------------------------------------------------- 1 | To update SQLite3.lib: 2 | 3 | - Copy current version of Sqlite3.def from the SQLite dll distribution. 4 | - Open a Visual Studio Command Prompt 5 | - Enter "LIB /DEF:Sqlite3.def" 6 | 7 | -------------------------------------------------------------------------------- /Source/SQLite3_StdCall/SQLite3_StdCall.c: -------------------------------------------------------------------------------- 1 | // SQLite3_StdCall.cpp : Defines the exported functions for the DLL application. 2 | // 3 | 4 | #include "stdafx.h" 5 | #include "SQLite3_StdCall.h" 6 | 7 | SQLITE3_STDCALL_API const char* __stdcall sqlite3_stdcall_libversion(void) 8 | { 9 | return sqlite3_libversion(); 10 | } 11 | 12 | SQLITE3_STDCALL_API const char * __stdcall sqlite3_stdcall_errmsg(sqlite3 *pDb) 13 | { 14 | return sqlite3_errmsg(pDb); 15 | } 16 | 17 | SQLITE3_STDCALL_API const void * __stdcall sqlite3_stdcall_errmsg16(sqlite3 *pDb) 18 | { 19 | return sqlite3_errmsg16(pDb); 20 | } 21 | 22 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_errcode(sqlite3 *pDb) 23 | { 24 | return sqlite3_errcode(pDb); 25 | } 26 | 27 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_extended_errcode(sqlite3 *pDb) 28 | { 29 | return sqlite3_extended_errcode(pDb); 30 | } 31 | 32 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_open( 33 | const char *filename, /* Database filename (UTF-8) */ 34 | sqlite3 **ppDb /* OUT: SQLite db handle */ 35 | ) 36 | { 37 | return sqlite3_open(filename, ppDb); 38 | } 39 | 40 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_open16(const void *filename, sqlite3 **ppDb) 41 | { 42 | return sqlite3_open16(filename, ppDb); 43 | } 44 | 45 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_open_v2(const char *filename, sqlite3 **ppDb, int flags, const char *zVfs) 46 | { 47 | return sqlite3_open_v2(filename, ppDb, flags, zVfs); 48 | } 49 | 50 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_close(sqlite3 *pDb) 51 | { 52 | return sqlite3_close(pDb); 53 | } 54 | 55 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_changes(sqlite3 *pDb) 56 | { 57 | return sqlite3_changes(pDb); 58 | } 59 | 60 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_total_changes(sqlite3 *pDb) 61 | { 62 | return sqlite3_total_changes(pDb); 63 | } 64 | 65 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_prepare_v2( 66 | sqlite3 *db, /* Database handle */ 67 | const char *zSql, /* SQL statement, UTF-8 encoded */ 68 | int nByte, /* Maximum length of zSql in bytes. */ 69 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 70 | const char **pzTail /* OUT: Pointer to unused portion of zSql */ 71 | ) 72 | { 73 | return sqlite3_prepare_v2(db, zSql, nByte, ppStmt, pzTail); 74 | } 75 | 76 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_prepare16_v2( 77 | sqlite3 *db, /* Database handle */ 78 | const void *zSql, /* SQL statement, UTF-16 encoded */ 79 | int nByte, /* Maximum length of zSql in bytes. */ 80 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 81 | const void **pzTail /* OUT: Pointer to unused portion of zSql */ 82 | ) 83 | { 84 | return sqlite3_prepare16_v2(db, zSql, nByte, ppStmt, pzTail); 85 | } 86 | 87 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_finalize(sqlite3_stmt *pStmt) 88 | { 89 | return sqlite3_finalize(pStmt); 90 | } 91 | 92 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_step(sqlite3_stmt *pStmt) 93 | { 94 | return sqlite3_step(pStmt); 95 | } 96 | 97 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_reset(sqlite3_stmt *pStmt) 98 | { 99 | return sqlite3_reset(pStmt); 100 | } 101 | 102 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_clear_bindings(sqlite3_stmt *pStmt) 103 | { 104 | return sqlite3_clear_bindings(pStmt); 105 | } 106 | 107 | SQLITE3_STDCALL_API const void * __stdcall sqlite3_stdcall_column_blob(sqlite3_stmt* pStmt, int iCol) 108 | { 109 | return sqlite3_column_blob(pStmt, iCol); 110 | } 111 | 112 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_column_bytes(sqlite3_stmt* pStmt, int iCol) 113 | { 114 | return sqlite3_column_bytes(pStmt, iCol); 115 | } 116 | 117 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_column_bytes16(sqlite3_stmt* pStmt, int iCol) 118 | { 119 | return sqlite3_column_bytes16(pStmt, iCol); 120 | } 121 | 122 | SQLITE3_STDCALL_API double __stdcall sqlite3_stdcall_column_double(sqlite3_stmt* pStmt, int iCol) 123 | { 124 | return sqlite3_column_double(pStmt, iCol); 125 | } 126 | 127 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_column_int(sqlite3_stmt* pStmt, int iCol) 128 | { 129 | return sqlite3_column_int(pStmt, iCol); 130 | } 131 | 132 | SQLITE3_STDCALL_API sqlite3_int64 __stdcall sqlite3_stdcall_column_int64(sqlite3_stmt* pStmt, int iCol) 133 | { 134 | return sqlite3_column_int64(pStmt, iCol); 135 | } 136 | 137 | SQLITE3_STDCALL_API const unsigned char * __stdcall sqlite3_stdcall_column_text(sqlite3_stmt* pStmt, int iCol) 138 | { 139 | return sqlite3_column_text(pStmt, iCol); 140 | } 141 | 142 | SQLITE3_STDCALL_API const void * __stdcall sqlite3_stdcall_column_text16(sqlite3_stmt* pStmt, int iCol) 143 | { 144 | return sqlite3_column_text16(pStmt, iCol); 145 | } 146 | 147 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_column_type(sqlite3_stmt* pStmt, int iCol) 148 | { 149 | return sqlite3_column_type(pStmt, iCol); 150 | } 151 | 152 | SQLITE3_STDCALL_API sqlite3_value * __stdcall sqlite3_stdcall_column_value(sqlite3_stmt* pStmt, int iCol) 153 | { 154 | return sqlite3_column_value(pStmt, iCol); 155 | } 156 | 157 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_column_count(sqlite3_stmt* pStmt) 158 | { 159 | return sqlite3_column_count(pStmt); 160 | } 161 | 162 | SQLITE3_STDCALL_API const unsigned char * __stdcall sqlite3_stdcall_column_name(sqlite3_stmt* pStmt, int iCol) 163 | { 164 | return sqlite3_column_name(pStmt, iCol); 165 | } 166 | 167 | SQLITE3_STDCALL_API const void * __stdcall sqlite3_stdcall_column_name16(sqlite3_stmt* pStmt, int iCol) 168 | { 169 | return sqlite3_column_name16(pStmt, iCol); 170 | } 171 | 172 | 173 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_bind_blob(sqlite3_stmt* pStmt, int paramIndex, const void* pValue, int nBytes, void(*pfDelete)(void*)) 174 | { 175 | return sqlite3_bind_blob(pStmt, paramIndex, pValue, nBytes, pfDelete); 176 | } 177 | 178 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_bind_double(sqlite3_stmt* pStmt, int paramIndex, double value) 179 | { 180 | return sqlite3_bind_double(pStmt, paramIndex, value); 181 | } 182 | 183 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_bind_int(sqlite3_stmt* pStmt, int paramIndex, int value) 184 | { 185 | return sqlite3_bind_int(pStmt, paramIndex, value); 186 | } 187 | 188 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_bind_int64(sqlite3_stmt* pStmt, int paramIndex, sqlite3_int64 value) 189 | { 190 | return sqlite3_bind_int64(pStmt, paramIndex, value); 191 | } 192 | 193 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_bind_null(sqlite3_stmt* pStmt, int paramIndex) 194 | { 195 | return sqlite3_bind_null(pStmt, paramIndex); 196 | } 197 | 198 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_bind_text(sqlite3_stmt* pStmt, int paramIndex, const char* zValue, int nBytes, void(*pfDelete)(void*)) 199 | { 200 | return sqlite3_bind_text(pStmt, paramIndex, zValue, nBytes, pfDelete); 201 | } 202 | 203 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_bind_text16(sqlite3_stmt* pStmt, int paramIndex, const void* zValue, int nBytes, void(*pfDelete)(void*)) 204 | { 205 | return sqlite3_bind_text16(pStmt, paramIndex, zValue, nBytes, pfDelete); 206 | } 207 | 208 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_bind_value(sqlite3_stmt* pStmt, int paramIndex, const sqlite3_value* pValue) 209 | { 210 | return sqlite3_bind_value(pStmt, paramIndex, pValue); 211 | } 212 | 213 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_bind_zeroblob(sqlite3_stmt* pStmt, int paramIndex, int nBytes) 214 | { 215 | return sqlite3_bind_zeroblob(pStmt, paramIndex, nBytes); 216 | } 217 | 218 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_bind_parameter_count(sqlite3_stmt* pStmt) 219 | { 220 | return sqlite3_bind_parameter_count(pStmt); 221 | } 222 | 223 | SQLITE3_STDCALL_API const char * __stdcall sqlite3_stdcall_bind_parameter_name(sqlite3_stmt* pStmt, int paramIndex) 224 | { 225 | return sqlite3_bind_parameter_name(pStmt, paramIndex); 226 | } 227 | 228 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_bind_parameter_index(sqlite3_stmt* pStmt, const char *zName) 229 | { 230 | return sqlite3_bind_parameter_index(pStmt, zName); 231 | } 232 | 233 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_sleep(int msToSleep) 234 | { 235 | return sqlite3_sleep(msToSleep); 236 | } 237 | // Backup API 238 | SQLITE3_STDCALL_API sqlite3_backup* __stdcall sqlite3_stdcall_backup_init( 239 | sqlite3 *pDest, /* Destination database handle */ 240 | const char *zDestName, /* Destination database name */ 241 | sqlite3 *pSource, /* Source database handle */ 242 | const char *zSourceName /* Source database name */ 243 | ) 244 | { 245 | return sqlite3_backup_init(pDest, zDestName, pSource, zSourceName); 246 | } 247 | 248 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_backup_step(sqlite3_backup *p, int nPage) 249 | { 250 | return sqlite3_backup_step(p, nPage); 251 | } 252 | 253 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_backup_finish(sqlite3_backup *p) 254 | { 255 | return sqlite3_backup_finish(p); 256 | } 257 | 258 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_backup_remaining(sqlite3_backup *p) 259 | { 260 | return sqlite3_backup_remaining(p); 261 | } 262 | 263 | SQLITE3_STDCALL_API int __stdcall sqlite3_stdcall_backup_pagecount(sqlite3_backup *p) 264 | { 265 | return sqlite3_backup_pagecount(p); 266 | } 267 | 268 | 269 | -------------------------------------------------------------------------------- /Source/SQLite3_StdCall/SQLite3_StdCall.h: -------------------------------------------------------------------------------- 1 | // The following ifdef block is the standard way of creating macros which make exporting 2 | // from a DLL simpler. All files within this DLL are compiled with the SQLITE3_STDCALL_EXPORTS 3 | // symbol defined on the command line. this symbol should not be defined on any project 4 | // that uses this DLL. This way any other project whose source files include this file see 5 | // SQLITE3_STDCALL_API functions as being imported from a DLL, whereas this DLL sees symbols 6 | // defined with this macro as being exported. 7 | #ifdef SQLITE3_STDCALL_EXPORTS 8 | #define SQLITE3_STDCALL_API __declspec(dllexport) 9 | #else 10 | #define SQLITE3_STDCALL_API __declspec(dllimport) 11 | #endif 12 | 13 | // TODO: Add declarations .... ? 14 | -------------------------------------------------------------------------------- /Source/SQLite3_StdCall/SQLite3_StdCall.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.24720.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SQLite3_StdCall", "SQLite3_StdCall.vcxproj", "{8C5F85BE-7ED1-44B6-BED7-B8DB2C5D5879}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {8C5F85BE-7ED1-44B6-BED7-B8DB2C5D5879}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {8C5F85BE-7ED1-44B6-BED7-B8DB2C5D5879}.Debug|Win32.Build.0 = Debug|Win32 16 | {8C5F85BE-7ED1-44B6-BED7-B8DB2C5D5879}.Release|Win32.ActiveCfg = Release|Win32 17 | {8C5F85BE-7ED1-44B6-BED7-B8DB2C5D5879}.Release|Win32.Build.0 = Release|Win32 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Source/SQLite3_StdCall/SQLite3_StdCall.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {8C5F85BE-7ED1-44B6-BED7-B8DB2C5D5879} 15 | SQLite3_StdCall 16 | Win32Proj 17 | 18 | 19 | 20 | DynamicLibrary 21 | v140 22 | Unicode 23 | true 24 | 25 | 26 | DynamicLibrary 27 | v140 28 | Unicode 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | <_ProjectFileVersion>14.0.24720.0 42 | 43 | 44 | $(SolutionDir)$(Configuration)\ 45 | $(Configuration)\ 46 | false 47 | false 48 | 49 | 50 | $(SolutionDir)$(Configuration)\ 51 | $(Configuration)\ 52 | false 53 | 54 | 55 | 56 | Disabled 57 | WIN32;_DEBUG;_WINDOWS;_USRDLL;SQLITE3_STDCALL_EXPORTS;%(PreprocessorDefinitions) 58 | true 59 | EnableFastChecks 60 | MultiThreadedDebug 61 | Level3 62 | EditAndContinue 63 | CompileAsC 64 | 65 | 66 | sqlite3.lib;%(AdditionalDependencies) 67 | 68 | true 69 | Windows 70 | false 71 | MachineX86 72 | Default 73 | 74 | 75 | 76 | 77 | MaxSpeed 78 | true 79 | WIN32;_DEBUG;_WINDOWS;_USRDLL;SQLITE3_STDCALL_EXPORTS;%(PreprocessorDefinitions) 80 | MultiThreaded 81 | true 82 | Level3 83 | ProgramDatabase 84 | CompileAsC 85 | 86 | 87 | sqlite3.lib;%(AdditionalDependencies) 88 | true 89 | Windows 90 | true 91 | true 92 | false 93 | MachineX86 94 | 95 | 96 | 97 | 98 | 99 | 100 | false 101 | 102 | 103 | false 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /Source/SQLite3_StdCall/SQLite3_StdCall.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | Source Files 16 | 17 | 18 | Source Files 19 | 20 | 21 | Source Files 22 | 23 | 24 | 25 | 26 | Header Files 27 | 28 | 29 | Header Files 30 | 31 | 32 | -------------------------------------------------------------------------------- /Source/SQLite3_StdCall/dllmain.c: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : Defines the entry point for the DLL application. 2 | #include "stdafx.h" 3 | 4 | BOOL APIENTRY DllMain( HMODULE hModule, 5 | DWORD ul_reason_for_call, 6 | LPVOID lpReserved 7 | ) 8 | { 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Source/SQLite3_StdCall/sqlite3.def: -------------------------------------------------------------------------------- 1 | EXPORTS 2 | sqlite3_aggregate_context 3 | sqlite3_aggregate_count 4 | sqlite3_auto_extension 5 | sqlite3_backup_finish 6 | sqlite3_backup_init 7 | sqlite3_backup_pagecount 8 | sqlite3_backup_remaining 9 | sqlite3_backup_step 10 | sqlite3_bind_blob 11 | sqlite3_bind_blob64 12 | sqlite3_bind_double 13 | sqlite3_bind_int 14 | sqlite3_bind_int64 15 | sqlite3_bind_null 16 | sqlite3_bind_parameter_count 17 | sqlite3_bind_parameter_index 18 | sqlite3_bind_parameter_name 19 | sqlite3_bind_text 20 | sqlite3_bind_text16 21 | sqlite3_bind_text64 22 | sqlite3_bind_value 23 | sqlite3_bind_zeroblob 24 | sqlite3_bind_zeroblob64 25 | sqlite3_blob_bytes 26 | sqlite3_blob_close 27 | sqlite3_blob_open 28 | sqlite3_blob_read 29 | sqlite3_blob_reopen 30 | sqlite3_blob_write 31 | sqlite3_busy_handler 32 | sqlite3_busy_timeout 33 | sqlite3_cancel_auto_extension 34 | sqlite3_changes 35 | sqlite3_clear_bindings 36 | sqlite3_close 37 | sqlite3_close_v2 38 | sqlite3_collation_needed 39 | sqlite3_collation_needed16 40 | sqlite3_column_blob 41 | sqlite3_column_bytes 42 | sqlite3_column_bytes16 43 | sqlite3_column_count 44 | sqlite3_column_database_name 45 | sqlite3_column_database_name16 46 | sqlite3_column_decltype 47 | sqlite3_column_decltype16 48 | sqlite3_column_double 49 | sqlite3_column_int 50 | sqlite3_column_int64 51 | sqlite3_column_name 52 | sqlite3_column_name16 53 | sqlite3_column_origin_name 54 | sqlite3_column_origin_name16 55 | sqlite3_column_table_name 56 | sqlite3_column_table_name16 57 | sqlite3_column_text 58 | sqlite3_column_text16 59 | sqlite3_column_type 60 | sqlite3_column_value 61 | sqlite3_commit_hook 62 | sqlite3_compileoption_get 63 | sqlite3_compileoption_used 64 | sqlite3_complete 65 | sqlite3_complete16 66 | sqlite3_config 67 | sqlite3_context_db_handle 68 | sqlite3_create_collation 69 | sqlite3_create_collation16 70 | sqlite3_create_collation_v2 71 | sqlite3_create_function 72 | sqlite3_create_function16 73 | sqlite3_create_function_v2 74 | sqlite3_create_module 75 | sqlite3_create_module_v2 76 | sqlite3_data_count 77 | sqlite3_db_cacheflush 78 | sqlite3_db_config 79 | sqlite3_db_filename 80 | sqlite3_db_handle 81 | sqlite3_db_mutex 82 | sqlite3_db_readonly 83 | sqlite3_db_release_memory 84 | sqlite3_db_status 85 | sqlite3_declare_vtab 86 | sqlite3_enable_load_extension 87 | sqlite3_enable_shared_cache 88 | sqlite3_errcode 89 | sqlite3_errmsg 90 | sqlite3_errmsg16 91 | sqlite3_errstr 92 | sqlite3_exec 93 | sqlite3_expired 94 | sqlite3_extended_errcode 95 | sqlite3_extended_result_codes 96 | sqlite3_file_control 97 | sqlite3_finalize 98 | sqlite3_free 99 | sqlite3_free_table 100 | sqlite3_get_autocommit 101 | sqlite3_get_auxdata 102 | sqlite3_get_table 103 | sqlite3_global_recover 104 | sqlite3_initialize 105 | sqlite3_interrupt 106 | sqlite3_last_insert_rowid 107 | sqlite3_libversion 108 | sqlite3_libversion_number 109 | sqlite3_limit 110 | sqlite3_load_extension 111 | sqlite3_log 112 | sqlite3_malloc 113 | sqlite3_malloc64 114 | sqlite3_memory_alarm 115 | sqlite3_memory_highwater 116 | sqlite3_memory_used 117 | sqlite3_mprintf 118 | sqlite3_msize 119 | sqlite3_mutex_alloc 120 | sqlite3_mutex_enter 121 | sqlite3_mutex_free 122 | sqlite3_mutex_leave 123 | sqlite3_mutex_try 124 | sqlite3_next_stmt 125 | sqlite3_open 126 | sqlite3_open16 127 | sqlite3_open_v2 128 | sqlite3_os_end 129 | sqlite3_os_init 130 | sqlite3_overload_function 131 | sqlite3_prepare 132 | sqlite3_prepare16 133 | sqlite3_prepare16_v2 134 | sqlite3_prepare_v2 135 | sqlite3_profile 136 | sqlite3_progress_handler 137 | sqlite3_randomness 138 | sqlite3_realloc 139 | sqlite3_realloc64 140 | sqlite3_release_memory 141 | sqlite3_reset 142 | sqlite3_reset_auto_extension 143 | sqlite3_result_blob 144 | sqlite3_result_blob64 145 | sqlite3_result_double 146 | sqlite3_result_error 147 | sqlite3_result_error16 148 | sqlite3_result_error_code 149 | sqlite3_result_error_nomem 150 | sqlite3_result_error_toobig 151 | sqlite3_result_int 152 | sqlite3_result_int64 153 | sqlite3_result_null 154 | sqlite3_result_subtype 155 | sqlite3_result_text 156 | sqlite3_result_text16 157 | sqlite3_result_text16be 158 | sqlite3_result_text16le 159 | sqlite3_result_text64 160 | sqlite3_result_value 161 | sqlite3_result_zeroblob 162 | sqlite3_result_zeroblob64 163 | sqlite3_rollback_hook 164 | sqlite3_rtree_geometry_callback 165 | sqlite3_rtree_query_callback 166 | sqlite3_set_authorizer 167 | sqlite3_set_auxdata 168 | sqlite3_shutdown 169 | sqlite3_sleep 170 | sqlite3_snprintf 171 | sqlite3_soft_heap_limit 172 | sqlite3_soft_heap_limit64 173 | sqlite3_sourceid 174 | sqlite3_sql 175 | sqlite3_status 176 | sqlite3_status64 177 | sqlite3_step 178 | sqlite3_stmt_busy 179 | sqlite3_stmt_readonly 180 | sqlite3_stmt_status 181 | sqlite3_strglob 182 | sqlite3_stricmp 183 | sqlite3_strlike 184 | sqlite3_strnicmp 185 | sqlite3_table_column_metadata 186 | sqlite3_test_control 187 | sqlite3_thread_cleanup 188 | sqlite3_threadsafe 189 | sqlite3_total_changes 190 | sqlite3_trace 191 | sqlite3_transfer_bindings 192 | sqlite3_update_hook 193 | sqlite3_uri_boolean 194 | sqlite3_uri_int64 195 | sqlite3_uri_parameter 196 | sqlite3_user_data 197 | sqlite3_value_blob 198 | sqlite3_value_bytes 199 | sqlite3_value_bytes16 200 | sqlite3_value_double 201 | sqlite3_value_dup 202 | sqlite3_value_free 203 | sqlite3_value_int 204 | sqlite3_value_int64 205 | sqlite3_value_numeric_type 206 | sqlite3_value_subtype 207 | sqlite3_value_text 208 | sqlite3_value_text16 209 | sqlite3_value_text16be 210 | sqlite3_value_text16le 211 | sqlite3_value_type 212 | sqlite3_vfs_find 213 | sqlite3_vfs_register 214 | sqlite3_vfs_unregister 215 | sqlite3_vmprintf 216 | sqlite3_vsnprintf 217 | sqlite3_vtab_config 218 | sqlite3_vtab_on_conflict 219 | sqlite3_wal_autocheckpoint 220 | sqlite3_wal_checkpoint 221 | sqlite3_wal_checkpoint_v2 222 | sqlite3_wal_hook 223 | sqlite3_win32_is_nt 224 | sqlite3_win32_mbcs_to_utf8 225 | sqlite3_win32_set_directory 226 | sqlite3_win32_sleep 227 | sqlite3_win32_utf8_to_mbcs 228 | sqlite3_win32_write_debug 229 | -------------------------------------------------------------------------------- /Source/SQLite3_StdCall/sqlite3.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/govert/SQLiteForExcel/8aae8bd5c69a9083a67a295fcbcfde838c755f4f/Source/SQLite3_StdCall/sqlite3.exp -------------------------------------------------------------------------------- /Source/SQLite3_StdCall/sqlite3.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/govert/SQLiteForExcel/8aae8bd5c69a9083a67a295fcbcfde838c755f4f/Source/SQLite3_StdCall/sqlite3.lib -------------------------------------------------------------------------------- /Source/SQLite3_StdCall/stdafx.c: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // SQLiteForVb.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /Source/SQLite3_StdCall/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | // #include "targetver.h" 9 | 10 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 11 | // Windows Header Files: 12 | #include 13 | 14 | #include "sqlite3.h" 15 | 16 | 17 | // TODO: reference additional headers your program requires here 18 | --------------------------------------------------------------------------------