SQLite3-based
The Database storage of this framework uses the SQLite3 library, which is a Free, Secure, Zero-Configuration, ServerLess, Single Stable Cross-Platform Database File database engine. As stated below, you can use any other database access layer than the SQLite3 library, if you wish. A fast in-memory engine is included.
Framework presentation
- Flexible
in process, local or remote access;
- REST and MVC
built on the great Model-View-Controller
and Representational
state transfer architectural patterns;
- Standard
full UTF-8 and Unicode, SQLite3 engine (enhanced but not hacked);
- Precise
individual records can be locked for update;
- Secure
tested, multi-thread oriented, atomic commit, encryption ready;
- Simple
statically linked into a single Delphi unit (no external dll nor framework
required);
- Light
use native classes, not TDataSet nor TDataSource;
- Smart
queries share a JSON-based memory cache for immediate response;
- Fast
tuned object pascal and i386 assembler code with direct use of FastMM4;
- Open
can use any
database engine as storage (not only SQLite3)
- Easy
tables are defined from classes properties, most queries made with no SQL
written;
- AJAX
use of JSON format for all data transfers makes it 100% AJAX ready - server can
be accessed without any Delphi client;
- Free
full source code provided, with permissive license.
Framework description
From the technical point of view, this framework uses a compiled version of the official SQLite3 library source code, and includes it natively into Delphi code. In such an integration, some points can be highlighted:
- The framework is unitary tested with provided regression tests;
- It uses purely UTF-8 encoded strings: fast Ansi/Unicode conversion routines are included, and is also Delphi 2009 ready (but Unicode works very well with older Delphi versions, whatever the marketing says);
- This framework allows optional on the fly fast encryption of the data on disk;
- Coder has to inherit the TSQLRecord class to define Table structure once in some published properties and easily interact with the server (alla Ruby on Rails): you don't need to know about the SQL language itself - just play with objects;
- TSQLDatabase can cache the last results for SELECT statements, in order to speed up most read queries, for lighter web server or client UI e.g.;
- Uses ISO 8601:2004 format to properly handle date/time values in TEXT field, or in a faster and smaller to store integer equivalent;
- Client / Server oriented, with optimized request caching and intelligent update (SQLite3 doesn't cache any query just disk accesses);
- Since JSON format is used internally, and HTTP is available as transport layer, this framework is AJAX and Web 2.0 ready;
- User authentication ready (SQLite3 is user-free designed);
- Direct User Interface generation: grids are created on the fly, together with a modern Ribbon ('Office 2007'-like) screen layout - the code just has to define actions, and assign them to the tables, in order to construct the whole interface from a few lines of code, without any IDE usage;
- Included full-featured Reporting feature;
- Direct Grid search lookup by pressing keys: handle unicode and case insensitive search, and also soundex (in English, French or Spanish) search;
- Full UTF-8 and i18n (i.e. internationalization) handled from the ground up;
- Most common SQL command consists in a record retrieval from its ID: this particular query is natively speed up via SQL statement preparation and pre-compilation.
SQLite3-enhanced
This framework therefore adds some very useful capabilities to the Standard SQLite3 database engine, but keeping all its advantages, as listed in the previous paragraph of this document:
- Faster database access, through unified memory model, and usage of the FastMM4 memory manager (which is almost 10 times faster than the default Windows memory manager for memory allocation);
- Optional direct encryption of the data on the disk (up to AES-256 level, that is Top-Secret security);
- Database layout is declared once in the Delphi source code (as published properties of classes), avoiding common field or table names mismatch;
- Locking of the database at the record level (SQLite3 only handles file-level locking);
- SQLite3 library unit was compiled including RTREE extension for doing very fast range queries;
- It can optionaly include FTS3 full text search engine (MATCH operator) after sqlite3.c recompile (by default, FTS3 is not compiled, saving more than 50KB of code);
- The framework makes use only of newest API (sqlite3_prepare_v2) and follows SQLite3 official documentation;
- SQLite3 source code was compiled without thread mutex: the caller has to be thread-safe aware; this is faster on most configurations, since mutex has to be acquired once): low level sqlite3_*() functions are not thread-safe, asTSQLRequest and TSQLBlobStream which just wrap them; but TSQLDataBase is thread-safe, asTSQLTableDB/TSQLRestServerDB/TSQLRestClientDB which call TSQLDataBase;
- Compiled with SQLITE_OMIT_SHARED_CACHE define, since with the new Client/Server approach of this framework, no concurrent access could happen, and an internal efficient caching algorithm is added, avoiding most call of the SQLite3 engine in multi-user environnment (any AJAX usage should benefit of it);
- The embedded SQLite3 database engine can be easily updated from the official SQLite3 source code available at http://sqlite.org.
8 reactions
1 From Edwin - 05/01/2010, 08:39
Nice work!
Would you include an obj file that includes FTS3? Thank you.
May I ask you to promote it (along with the enhanced RTF for D7) on the Third party tools group of the Delphi newsgroup?
2 From A.Bouchez - 05/01/2010, 16:56
Thanks Edwin for your interest.
I've already promoted it in the Borland newsgroup... but the Enhanced RunTime Library did raise some "Licence Violation Error" exceptions in the forum. So I stopped arguing there, since I'm no lawyer, but my modified files need the Delphi IDE to be running in order to install them. The files appear to be very stable, and are used in many of our projects, even some multi-threaded biological software which need some high level of SQA.
I'm looking today at the Free Pascal Compiler (version 2.4.0 was just released), and I'm very impressed about it... I'm making some adaptation for the Synopse SQLite3 framework to compile with it. It's a bit tricky (the RTTI is not the same as the Delphi's ), but it will work. I'm fed up with paying the big money for every Delphi update, and I don't like the String=UnicodeString only approach since Delphi 2009 (it's not even customizable with a compiler option like $H). I spent some time in the Free Pascal Compiler source code, and was very impressed. The compiler itself is a great piece of coding. It's efficient, fast, and has a very well designed architecture. The Run Time Library itself is less consistent, and some part are very disappointing (not at all 64 bits optimized, and the i386 asm abuse the rep lodsb / stosb instructions, which are dead slow on modern CPU - I think the pure pascal version should be faster than the "optimized" asm used).
You can download an obj file compiled with the SQLITE_ENABLE_FTS3 from here. I just compiled it using the free borland C++ compiler, but didn't try it. If you have some feedback, thank you!
3 From Edwin Yip - 07/01/2010, 05:08
thank you for the obj file
I think to gain more popularity thorough documentation and samples are necessary.
I'm currently using another DELPHI port of Sqlite3
4 From Edwin - 07/01/2010, 07:25
Hi A.Bouchez,
Thank you for the obi file.
I tried compiling the TestSQL3.dpr project but had the following error:
[Error] SynCrtSock.pas(1855): Undeclared identifier: 'HexChars'
BTW, the font color of the links and the comment editor of your blog is really difficult to read.
5 From A.Bouchez - 08/01/2010, 10:42
About the "HexChars", they are included in the LVCL or our Enhanced VCL, in SysUtils.pas.
I'm working on a version which will work with all version of Delphi, with or without the LVCL or EnhancedVCL. For now, just copy and paste HexChars[] and TwoDigitLookup[] const arrays in the units which need these.
6 From A.Bouchez - 08/01/2010, 10:45
Yes I now documentation is a need.
I'm preparing it. There is a lot of comment in the code already. Stay tuned!
7 From Devi - 10/01/2010, 08:06
Hi,
I managed to compile sqlite3.obj using AES encryption but without FTS3.
As you mentioned in sqlite3.pas, if I want to use FTS3
I had to change some of the following:
isspace -> sqlite3Isspace
tolower -> sqlite3Tolower"
isalnum -> sqlite3Isalnum
My question is, where I had to change the code in sqlite3.c?
Examples:
"static int fts3isspace (char c) (
return (c & 0x80) == 0? sqlite3Isspace (c): 0; / / isspace (c): 0; << is this part?
) "
Regards,
Devi
8 From A. Bouchez - 12/01/2010, 15:34
With the last version of the SQlite3.c code, you don't have to change it any more. To answer your question, just search&replace strings.
I will send these days the 3.6.22 version of the .obj file, with or without the FTS3.