ADO.NET 2.0 SQLite Data Provider
Version 184.108.40.206 - Dec 19, 2005
Interop using SQLite 3.2.8
Written by Robert Simpson (firstname.lastname@example.org)
Released to the public domain, use at your own risk!
The latest version can be downloaded
Supports the Full and Compact .NET Framework.
On the Compact Framework, it is faster than the newly-introduced Sql Server
Mobile, often more than 10x faster at inserts/updates. SQLite databases
are also a fraction of the size of Sql Mobile databases.
Full Visual Studio 2005 Design-Time Support. You can add a SQLite
database to the Servers list, design queries with the Query Designer,
drag-and-drop tables onto a Typed DataSet, etc.
Single file redistributable for the full .net framework (Compact Framework
requires 2 binaries). The core sqlite3 codebase and the ADO.NET wrapper
are combined into one multi-module assembly.
Native 64-bit multi-module assemblies for Itanium and X64 processors.
Full support for ATTACH'ed databases. Exposed as Catalogs
in the schema. When cloning a connection, all attached databases are
automatically re-attached to the new connection.
DbConnection.GetSchema(...) support includes the MetaDataCollections, DataSourceInformation,
Columns, Tables, Views, ViewColumns, Catalogs, Indexes,
IndexColumns and ForeignKeys
Enhanced DbDataReader.GetSchemaTable() functionality returns catalog, namespace
and detailed schema information even for complex queries.
Named and unnamed parameters.
Full UTF-8 and UTF-16 support, each with optimized pipelines into the native
Multiple simultaneous DataReaders (one DataReader per Command however).
Full support for user-defined scalar and aggregate functions, encapsulated into
an easy-to-use base class in which only a couple of overrides are necessary to
implement new SQL functions.
Full support for user-defined collating sequences, every bit as simple to
implement as user-defined functions and uses the same base class.
Create and encrypt databases using Win2K+ Encrypting File System (EFS).
Supports creating NTFS compressed database files.
Full source for the entire engine and wrapper. No copyrights.
Public Domain. 100% free. If you want to know if you can use it in
your commercial project, please read the previous sentence again -- only slower
and sound out the words this time.
Design-Time Support (new as of 1.0.14)
Until an installer is created, through a command-prompt or Windows Explorer, navigate to the SQLite.NET\bin\Designer
folder and execute the INSTALL.CMD
file. The script and
batch file will register the System.Data.SQLite DLL in the Global Assembly Cache,
and modify the machine.config file to add SQLite to the list of default data providers.
DbFactory Support (Non-Compact Framework)
In order to use the SQLiteFactory and have the SQLite data provider enumerated
in the DbProviderFactories methods, you must add the following segment into your application's app.config file:
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
See the help documentation for further details on implementing both version-specific (GAC enabled) and version independent DBProviderFactories support.
Compiling for the Compact Framework
Just change the target platform from Win32 to Compact Framework and
recompile. The Compact Framework has no support for enumerating
attributes in an assembly, therefore all user-defined collating sequences and
functions must be explicitly registered. See the testce
sample application for an example of how to explicitly register user-defined
collating sequences and functions.
Many thanks to the fine folks at
http://sourceforge.net/projects/sqlite-wince for the Windows CE code!
Distributing The SQLite Engine and ADO.NET Assembly
For Win32 platforms, only the System.Data.SQLite.DLL file in
the bin folder should be distributed with your
application(s). This DLL contains both the managed wrapper and the native
For Compact Framework platforms, your application should reference the System.Data.SQLite.DLL
file in the bin\CompactFramework folder. The System.Data.SQLite.DLL
and SQLite.Interop.DLL files from the bin\CompactFramework
folder must be distributed with your application(s). They contain the
managed wrapper and the native SQLite3 codebase respectively. The Compact
Framework does not currently support managed C++, thus the reason for two
Development Notes Regarding the SQLite 3 Source Code
Steps for merging the sqlite3 core codebase (without Compact Framework support --
that's another story):
Download the latest sqlite3 source from
Extract the source code to the SQLite.Interop\src directory
of this project
Open the src\select.c file.
Add #include "../interop.h" to the top of the file
where the other include's are.
Scroll down the select.c file to around line 822.
Change the name of the function static void generateColumnNames to static
void _generateColumnNames (note the underscore in front of the name).
220.127.116.11 - December 19, 2005
- Update core SQLite engine to 3.2.8
1.0.24 - December 9, 2005
- Fixed the Catalogs schema bug that caused attached databases not to be re-attached to a cloned connection
- Enhanced transactions to allow for a deferred or immediate writelock. SQLiteConnection.BeginTransaction()
now has an additional overload to support it
- Commands are now prepared as they are executed instead of beforehand. This
fixes a bug whereby a multi-statement command that alters the database and subsequently
references the altered data would fail during Prepare().
- Tightened up the SQLiteDataReader to prevent reading columns before calling
the first Read() and to prevent reading columns after the last Read().
- A more descriptive error is thrown if there aren't enough parameters in the command
to satisfy the parameters required by the statement(s).
1.0.23 - November 21, 2005
- Named parameters may now begin with @ to ease portability of
the provider. SQLite's named parameters are ordinarily prefixed with a :
or $. The designer will still use the $
prefix however, since its more compatible with the default SQLite engine.
- Added several alternate ISO8601 date/time formats to SQLiteConvert.cs to increase
- Relaxed coersion restrictions to work better with SQLite's inherent typelessness.
1.0.22 - November 11, 2005
- Fixed some globalization issues which resulted in incorrect case-insensitive comparisons
- Fixed a bug in the routine that finds all user-defined functions in a loaded assembly.
It would throw an exception if any of the types in the assembly could not be loaded.
The exception is now caught and handled appropriately.
1.0.21 - November 4, 2005
- Fixed a designer bug when creating typed datasets with parameterized queries.
- The above fix then exposed another bug in the datareader's ability to query schema
information on parameterized commands, which was also fixed.
- Compiled against the RTM version of VS2005.
- Rewrote the design-time install script to use the XML DOM objects when writing
to the machine.config and to automatically register the DLL in the GAC.
- Made changes to the app.config descriptions and help file to improve version-independent
1.0.20 - October 19, 2005
Fixed a shortcut in SQLiteBase.GetValue which was insufficient for
international environments. The shortcut was removed and the "proper"
procedure put in.
1.0.19 - October 5, 2005
Code merge with SQLite 3.2.7
Fixed bugs in the CE port code (os_wince.c) which were brought to
light by recent changes in the SQLite engine.
Recompiled and modified to be compatible with the September VS2005 Release
Beta 2 users should continue to use 18.104.22.168
22.214.171.124 - September 19, 2005
Code merge with SQLite 3.2.6
1.0.18 - September 1, 2005
Added type-specific method calls when using the various SQLite classes that
would've normally returned a a generic Db base class, which aligns the code
better with the Microsoft-supplied data providers.
1.0.17 - August 26, 2005
Code merge with SQLite 3.2.5
Added Itanium and x64 build settings to the project (needs testing)
Bugfixes and enhancements to several schema types
Additional design-time support to include index and foreign key
enumerations. Requires re-registering the designer using
INSTALL.CMD. The new designer code now allows the VS query designer and
typed datasets to automatically link up foreign keys, use indexes, and
automatically generate relationships from the schema.
Additional static methods on SQLiteConnection to create a database file,
encrypt a file using the Encrypted File System (EFS) on NTFS (requires NT 2K or
above) and NTFS file compression
1.0.16 - August 24, 2005
Code merge with SQLite 3.2.4 with the large delete bugfix in CVS (which will
become 3.2.5 soon)
Added new GetSchema() types: IndexColumns, ViewColumns, ForeignKeys
1.0.15 - August 22, 2005
Code merge with SQLite 3.2.3
Minor updates for better design-time experience. More design-time code to
follow in subsequent releases.
1.0.14 - August 16, 2005
Fixed a bug in the SQLiteDataAdapter due to insufficient implementation of the
class. The RowUpdating and RowUpdated events are now properly
implemented, but unfortunately inserting and updating data in a DataTable or
DataSet is now much slower. This is the proper design however, so the
changes are here to stay.
Lots of schema changes to support Visual Studio's Data Designer architecture.
Designer support for the provider. It's not 100%, but you can design
queries, add typed datasets and perform quite a number of tasks all within
Visual Studio now.
1.0.13 - August 8, 2005
Fixed a named parameter bug in the base SQLite_UTF16 class, which of course
only showed up when a database connection was opened using the
Fixed a performance issue in SQLite_UTF16 involving string marshaling.
1.0.12 - August 5, 2005
Full support for the Compact Framework. Each build (Debug/Release) now
has a platform, either Win32 or Compact Framework. The correct
projects are built accordingly. See the Distributing
section for information on what files need to be distributed for each
Modified SQLite3.Reset() and Step() functions to transparently handle timeouts
while waiting on the database to become available (typically when a writer is
waiting on a reader to finish, or a reader is waiting on a writer to finish).
Lots of code cleanup as suggested by the Code Analyzer (FxCop).
Lots of updates to the helpfile (as you can see).
Statements were already prepared lazily in a SQLiteCommand, but now
its even more lazy. Statements are now only prepared if the statements
haven't been previously prepared and a Prepare() function is called (and the
command is associated with a connection) or just prior to the command being
1.0.11 - August 1, 2005
For everything except the Compact Framework, System.Data.SQLite.DLL is
now the only DLL required to use this provider! The
assembly is now a multi-module assembly, containing both the native SQLite3
codebase and the C# classes built on top of it. The Compact Framework
version (when completed) will not be able to support this feature, so backwards
compatibility with the Compact Framework has been preserved for the future.
Fixed a bug in SQLiteCommand.ExecuteScalar() that caused it to stop executing
commands once it obtained the first column of the first row-returning
resultset. Any remaining statements after the row-returning statement was
1.0.10 - June 10, 2005
Fixed a bug in the SQLite3.cs Prepare() function that created a statement even
when the SQLite engine returned a NULL pointer. Typically this occurs when
multiple statements are processed and there are trailing comments at the end of
Fixed a bug in SQLiteStatement.cs that retrieved parameter names for a
parameterized query. SQLite's parameters are 1-based, and the function
was starting at 0. This was fine when all parameters were unnamed, but
for named parameters it caused the parameters to be out of whack.
1.0.09a - May 25, 2005
Fixed a broken helpfile and corrected some obsolete help remarks in
Added a version resource to the SQLite.Interop.DLL.
1.0.09 - May 24, 2005
Code merge with the latest 3.21 version of SQLite.
Removed obsolete methods and properties for Whidbey Beta 2
1.0.08 Refresh - Mar 24, 2005
Code merge with the latest 3.20 version of SQLite.
Recompiled the help file to fix a build error in it.
1.0.08 - Mar 11, 2005
Added additional #if statements to support the old beta 1 edition of VS2005.
Code merged the SQLite 3.14 source.
1.0.07 - Mar 5, 2005
Made more optimizations to frequently-called functions, resulting in
significant performance gains in all tests.
Recompiled the binaries using the latest VS2005 February CTP, resulting in yet
more significant speed gains. The 100k insert test used to take 3.5
seconds and the insertwithidentity took almost 8 seconds. With the above
two changes, those tests are now executing in 1.9 and 4.9 seconds respectively.
1.0.06 - Mar 1, 2005
Speed-ups to SQLiteDataReader. It was interop'ing unnecessarily every
time it tried to fetch a field due to a logic error.
Changed/Added some code to SQLiteConvert's internal DbType, Type and
Fixed the SQLiteDataReader to obey the flags set in the optional
CommandBehavior flag from SQLiteCommand.ExecuteReader().
Changed the default page size to 1024 to reflect the defaults of SQLite.
Ignores the "Page Size" connection string option for memory databases, as tests
revealed that changing it resulted in memory corruption errors.
Performance enhancements to the SQLiteCommand and SQLiteStatement classes which
reduced the 100,000 row insert execution time as well as the various Function
execution times significantly.
1.0.05 - Feb 25, 2005
Fixed the SQLite3 C# class step/reset functions to accomodate schema changes
that invalidate a prepared statement. Statements are recompiled
Moved all native DLL declarations to an UnsafeNativeMethods class.
Split several classes into their own modules for readability.
Renamed many internal variables, reviewed access to variables marked as
internal and altered their protection levels accordingly.
Due to the presence of the altered sqlite3 codebase and so many added interop
functions, I decided to rename the sqlite3 C project and the DLL to
SQLite.Interop.DLL. This is the same core sqlite3 codebase but designed
specifically for this ADO.NET provider. This eliminates any possibility
of someone dropping another build of sqlite3.dll into the system and rendering
the provider inoperable. In the future if the folks at sqlite.org finally
introduce a method of retrieving column usage for an arbitrary prepared
statement, I'll retool this library to be a lightweight function call wrapper
around the core binary distribution.
Added [SuppressUnmanagedCodeSecurity] attribute to the UnsafeNativeMethods
class which brings VS2005 November CTP execution speeds inline with the
Added a bin
directory to the project root where pre-compiled binaries can be found.
Added a doc
directory where preliminary documentation on the class library can be found.
Documented a lot more of the classes internally.
1.0.04 - Feb 24, 2005
Removed the SQLiteContext class and revamped the way UserFunctions work to
simplify the imlementation.
Fixed a counting bug in the TestCases class, specifically in the function tests
where I wasn't resetting the counter and it was consequently reporting
intrinsic and raw select calls as being much much faster than they actually
were. The numbers are now much closer to what I expected for performance,
with .NET user-functions still being the slowest, but only by a small margin.
Small performance tweaks to SQLiteDataReader.
Added PageSize to the SQLiteConnectionStringBuilder and subsequently to the
Added a PRAGMA encoding=XXX execution statement to the SQLiteConnection after
opening a connection.
1.0.03 - Feb 23, 2005
Fixed up SQLiteCommandBuilder to correct implementation errors, which resulted
in an enormous performance boost in the InsertMany test. 10,000 row
insert that executed in 1500ms now executes in 500ms.
Fixed several errors in the SQLite3_UTF16 class. ToString() was working
incorrectly and the Open() method failed to register user defined functions and
Fixed a bug in SQLiteCommand.ClearCommands() whereby only the first statement
was being properly cleaned up.
Fixed a bug in SQLiteDataReader whereby calling NextResult() would not properly
reset the previously-executed command in the sequence.
Added an InsertManyWithIdentityFetch test, which appends a select clause to
populate the ID of the last inserted row into the InsertCommand, demonstrating
ADO.NET's ability to auto-fetch identity columns on insert.
1.0.02 - Feb 21, 2005
Tweaks to the xxx_interop functions that return char *'s, so they also return
the length. Saves an interop call to get the UTF-8 string length during
conversion to a .NET string.
Reworked the whole interop.c thing into interop.h and reduced the code required
to merge the main sqlite3 codebase.
Added support for user-defined collations.