Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Comment: |
|
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
eb3d0c06747e65c079fd85246335a172 |
User & Date: | ab 2010-06-25 13:48:26 |
Original Comment: |
|
2010-06-27
| ||
06:56 |
| |
2010-06-25
| ||
13:48 |
| |
08:52 | possibility to add a background picture to the ribbon pages (in unit SQLite3ToolBar) check-in: c298cbd968 user: ab tags: trunk | |
Changes to SQLite3/SQLite3.pas.
1 2 3 4 5 6 7 8 9 10 .. 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 ... 107 108 109 110 111 112 113 114 115 116 117 118 119 120 ... 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 ... 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 .... 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 .... 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 .... 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 .... 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 .... 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 .... 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 .... 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 |
/// SQLite3 3.6.23.1 embedded Database engine // - this unit is a part of the freeware Synopse SQLite3 database framework, // licensed under a MPL/GPL/LGPL tri-license; version 1.7 unit SQLite3; { This file is part of Synopse SQLite3 database framework. Synopse SQLite3 database framework. Copyright (C) 2010 Arnaud Bouchez Synopse Informatique - http://synopse.info ................................................................................ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. ***** END LICENSE BLOCK ***** SQLite3 3.6.23.1 database engine ********************************** Brand new SQLite3 library to be used with Delphi - FLEXIBLE: in process, local or remote access (JSON RESTFUL HTTP server) - 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: staticaly linked into a single Delphi unit (no external dll required) ................................................................................ - SQLite3 database layer updated to version 3.6.23.1 Version 1.7 - alter table with newly added fields to a TSQLRecord Version 1.8 - includes Unitary Testing class and functions Todo: - port to other systems than Delphi+Win32 (use external DLL?) } interface ................................................................................ {{ get all table names contained in this database file } procedure GetTableNames(var Names: TRawUTF8DynArray); {{ get all field names for a specified Table } procedure GetFieldNames(var Names: TRawUTF8DynArray; const TableName: RawUTF8); {{ retrieve the user_version stored in the SQLite3 database file - user-version is a 32-bit signed integers stored in the database header } function user_version: cardinal; {{ open a BLOB incrementally for read[/write] access - find a BLOB located in row RowID, column ColumnName, table TableName in database DBName; in other words, the same BLOB that would be selected by: ! SELECT ColumnName FROM DBName.TableName WHERE rowid = RowID; - use after a TSQLRequest.BindZero() to reserve Blob memory - if RowID=-1, then the last inserted RowID is used - will raise an ESQLException on any error } ................................................................................ - Applications should finalize all prepared statements and close all BLOB handles associated with the sqlite3 object prior to attempting to close the object (sqlite3_next_stmt() interface can be used for this task) - if invoked while a transaction is open, the transaction is automatically rolled back } function sqlite3_close(DB: TSQLHandle): integer; {$ifdef USEC}cdecl;{$endif} external; {{ Return the version of the SQLite database engine, in ascii format - currently returns '3.6.23.1' } function sqlite3_libversion: PUTF8Char; {$ifdef USEC}cdecl;{$endif} external; {{ Returns English-language text that describes an error, using UTF-8 encoding (which, with English text, is the same as Ansi). - Memory to hold the error message string is managed internally. The application does not need to worry about freeing the result. However, the error string might be overwritten or deallocated by ................................................................................ /// this test case will test most functions, classes and types defined and // implemented in the SQLite3 unit, i.e. the SQLite3 engine itself, // with a memory-based approach // - this class will also test the TSQLRestServerStatic class, and its // 100% Delphi simple database engine TTestMemoryBased = class(TTestSQLite3Engine); implementation { ************ direct access to sqlite3.c / sqlite3.obj consts and functions } { ................................................................................ - the following defines must be added in the beginning of the sqlite3.c file: //#define SQLITE_ENABLE_FTS3 // this unit is FTS3-ready, but not compiled with it by default // but for FTS3 to compile, you will have to change: // isspace -> sqlite3Isspace in fts3isspace() function, // tolower -> sqlite3Tolower in simpleNext() function, // isalnum -> sqlite3Isalnum in simpleCreate() function // this conditional is defined at compile time, in order to create sqlite3fts3.obj #define SQLITE_DEFAULT_MEMSTATUS 0 // don't need any debug here #define SQLITE_THREADSAFE 0 // assuming multi-thread safety is made by caller #define SQLITE_OMIT_SHARED_CACHE // no need of shared cache in a threadsafe calling model #define SQLITE_OMIT_AUTOINIT // sqlite3_initialize() is done in initialization section below -> no AUTOINIT #define SQLITE_OMIT_DEPRECATED // spare some code size #define SQLITE_OMIT_TRACE 1 // trace is time consuming (at least under windows) #define SQLITE_OMIT_LOAD_EXTENSION // we don't need extension in an embedded engine //#define SQLITE_OMIT_LOOKASIDE // since we use FastMM4, LookAside is not needed but seems mandatory in c source and, in the sqlite3.c source file, the following functions are made external in order to allow our proprietary but simple and efficient encryption system: extern int winRead( ................................................................................ FileClose(F); end; // we override default WinRead() and WinWrite() functions below, in order // to add our proprietary (but efficient) encryption engine type {$A4} // C alignment is 4 bytes TSQLFile = record // called winFile (expand sqlite3_file) in sqlite3.c pMethods: pointer; // sqlite3_io_methods_ptr h: THandle; // Handle for accessing the file bulk: cardinal; // lockType+sharedLockByte are word-aligned lastErrno: cardinal; // The Windows errno from the last I/O error // asm code generated from c is [esi+12] for lastErrNo -> OK end; {$A+} function WinWrite(var F: TSQLFile; buf: PByte; buflen: integer; off: Int64): integer; {$ifdef USEC}cdecl;{$endif} // Write data from a buffer into a file. Return SQLITE_OK on success // or some other error code on failure var n: integer; ................................................................................ Execute('PRAGMA user_version',tmp); result := tmp; except on Exception do result := 0; end; end; { TSQLRequest } procedure TSQLRequest.Bind(Param: Integer; Value: Int64); begin sqlite3_check(RequestDB,sqlite3_bind_Int64(Request,Param,Value)); end; ................................................................................ { ************ Unit-Testing classes and functions } { TTestSQLite3 } procedure TTestSQLite3.Sqlite3DatabaseEngine; begin AddCase([TTestFileBased,TTestMemoryBased]); end; { TTestSQLite3Engine } destructor TTestSQLite3Engine.Destroy; begin Demo.Free; ................................................................................ Owner.CustomVersions := Owner.CustomVersions+#13#10'SQlite3 engine used: '+ sqlite3_libversion; IsMemory := InheritsFrom(TTestMemoryBased); if IsMemory then TempFileName := ':memory:' else begin TempFileName := 'test.db3'; DeleteFile(pointer(TempFileName)); // use a temporary file end; if not IsMemory then CreateSQLEncryptTable('password1'); Demo := TSQLDataBase.Create(TempFileName); Demo.UseCache := true; // use the cache for the JSON requests Demo.Execute( ' CREATE TABLE IF NOT EXISTS People (' + ' ID INTEGER PRIMARY KEY,'+ ' FirstName TEXT COLLATE SYSTEMNOCASE,' + ' LastName TEXT,' + ' Data BLOB,'+ ' YearOfBirth INTEGER,' + ................................................................................ if not IsMemory then begin // check file encryption password change FreeAndNil(Demo); // if any exception occurs in Create(), Demo.Free is OK ChangeSQLEncryptTablePassWord(TempFileName,'password1',''); ChangeSQLEncryptTablePassWord(TempFileName,'','NewPass'); CreateSQLEncryptTable('NewPass'); Demo := TSQLDataBase.Create(TempFileName); // reuse the temporary file Demo.UseCache := true; // use the cache for the JSON requests Check(Hash32(Demo.ExecuteJSON(Req))=$56CB147E,'ExecuteJSON crypted'); end; Demo.GetTableNames(Names); Check(length(Names)=1); Check(Names[0]='People'); end; |
| | | | > > > > > > > > > > > > > > > | | > > > > > > > | > | | | | | > > > > > > | > | > > > > > > > > > > > | < < > > > > > |
1 2 3 4 5 6 7 8 9 10 .. 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 ... 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 ... 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 ... 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 .... 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 .... 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 .... 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 .... 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 .... 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 .... 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 .... 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 |
/// SQLite3 3.7 draft embedded Database engine // - this unit is a part of the freeware Synopse SQLite3 database framework, // licensed under a MPL/GPL/LGPL tri-license; version 1.8 unit SQLite3; { This file is part of Synopse SQLite3 database framework. Synopse SQLite3 database framework. Copyright (C) 2010 Arnaud Bouchez Synopse Informatique - http://synopse.info ................................................................................ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. ***** END LICENSE BLOCK ***** SQLite3 3.7 database engine ***************************** Brand new SQLite3 library to be used with Delphi - FLEXIBLE: in process, local or remote access (JSON RESTFUL HTTP server) - 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: staticaly linked into a single Delphi unit (no external dll required) ................................................................................ - SQLite3 database layer updated to version 3.6.23.1 Version 1.7 - alter table with newly added fields to a TSQLRecord Version 1.8 - includes Unitary Testing class and functions - update engine to version 3.7 draft (snapshot as of 2010-06-25 11:35 UTC) - SetWALMode() method for enabling Write-Ahead Logging for the database - the RTREE extension is now compiled by default into the engine Todo: - port to other systems than Delphi+Win32 (use external DLL?) } interface ................................................................................ {{ get all table names contained in this database file } procedure GetTableNames(var Names: TRawUTF8DynArray); {{ get all field names for a specified Table } procedure GetFieldNames(var Names: TRawUTF8DynArray; const TableName: RawUTF8); {{ retrieve the user_version stored in the SQLite3 database file - user-version is a 32-bit signed integers stored in the database header } function user_version: cardinal; {{ enable the Write-Ahead Logging for the database - beginning with version 3.7.0 of the SQLite3 engine, a new "Write-Ahead Log" option (hereafter referred to as "WAL") is available - WAL might be very slightly slower (perhaps 1% or 2% slower) than the traditional rollback-journal approach in applications that do mostly reads and seldom write; but WAL provides more concurrency as readers do not block writers and a writer does not block readers. Reading and writing can proceed concurrently. With our SQLite3 framework, it's not needed. - by default, this option is not set: only implement if you really need it, but our SQlite3 framework use locked actions, so there should be no benefit } procedure SetWALMode(Value: Boolean); {{ open a BLOB incrementally for read[/write] access - find a BLOB located in row RowID, column ColumnName, table TableName in database DBName; in other words, the same BLOB that would be selected by: ! SELECT ColumnName FROM DBName.TableName WHERE rowid = RowID; - use after a TSQLRequest.BindZero() to reserve Blob memory - if RowID=-1, then the last inserted RowID is used - will raise an ESQLException on any error } ................................................................................ - Applications should finalize all prepared statements and close all BLOB handles associated with the sqlite3 object prior to attempting to close the object (sqlite3_next_stmt() interface can be used for this task) - if invoked while a transaction is open, the transaction is automatically rolled back } function sqlite3_close(DB: TSQLHandle): integer; {$ifdef USEC}cdecl;{$endif} external; {{ Return the version of the SQLite database engine, in ascii format - currently returns '3.7' } function sqlite3_libversion: PUTF8Char; {$ifdef USEC}cdecl;{$endif} external; {{ Returns English-language text that describes an error, using UTF-8 encoding (which, with English text, is the same as Ansi). - Memory to hold the error message string is managed internally. The application does not need to worry about freeing the result. However, the error string might be overwritten or deallocated by ................................................................................ /// this test case will test most functions, classes and types defined and // implemented in the SQLite3 unit, i.e. the SQLite3 engine itself, // with a memory-based approach // - this class will also test the TSQLRestServerStatic class, and its // 100% Delphi simple database engine TTestMemoryBased = class(TTestSQLite3Engine); /// this test case will test most functions, classes and types defined and // implemented in the SQLite3 unit, i.e. the SQLite3 engine itself, // with a file-based approach // - purpose of this class is to test Write-Ahead Logging for the database TTestFileBasedWAL = class(TTestFileBased); implementation { ************ direct access to sqlite3.c / sqlite3.obj consts and functions } { ................................................................................ - the following defines must be added in the beginning of the sqlite3.c file: //#define SQLITE_ENABLE_FTS3 // this unit is FTS3-ready, but not compiled with it by default // but for FTS3 to compile, you will have to change: // isspace -> sqlite3Isspace in fts3isspace() function, // tolower -> sqlite3Tolower in simpleNext() function, // isalnum -> sqlite3Isalnum in simpleCreate() function, // if you don't use FTS3, dont define this conditional: you'll spare 50KB of code // this conditional is defined at compile time, in order to create sqlite3fts3.obj #define SQLITE_DEFAULT_MEMSTATUS 0 // don't need any debug here #define SQLITE_THREADSAFE 0 // assuming multi-thread safety is made by caller #define SQLITE_OMIT_SHARED_CACHE 1 // no need of shared cache in a threadsafe calling model #define SQLITE_OMIT_AUTOINIT 1 // sqlite3_initialize() is done in initialization section below -> no AUTOINIT #define SQLITE_OMIT_DEPRECATED 1 // spare some code size #define SQLITE_OMIT_TRACE 1 // we don't need sqlite3_profile() and sqlite3_trace() interfaces #define SQLITE_OMIT_LOAD_EXTENSION 1 // we don't need extension in an embedded engine #define SQLITE_OMIT_COMPILEOPTION_DIAGS 1 // we don't need Compilation Options Diagnostics in our embedded engine #define SQLITE_OMIT_PROGRESS_CALLBACK 1 // we don't need sqlite3_progress_handler() API function #define SQLITE_ENABLE_RTREE 1 // the RTREE extension is now (from v.1.8/3.7) compiled into the engine //#define SQLITE_OMIT_LOOKASIDE // since we use FastMM4, LookAside is not needed but seems mandatory in c source and, in the sqlite3.c source file, the following functions are made external in order to allow our proprietary but simple and efficient encryption system: extern int winRead( ................................................................................ FileClose(F); end; // we override default WinRead() and WinWrite() functions below, in order // to add our proprietary (but efficient) encryption engine type {$A4} // bcc32 default alignment is 4 bytes TSQLFile = record // called winFile (expand sqlite3_file) in sqlite3.c pMethods: pointer; // sqlite3_io_methods_ptr pVfs: pointer; // The VFS used to open this file (new in version 3.7) h: THandle; // Handle for accessing the file bulk: cardinal; // lockType+sharedLockByte are word-aligned lastErrno: cardinal; // The Windows errno from the last I/O error // asm code generated from c is [esi+16] for lastErrNo -> OK end; {$A+} function WinWrite(var F: TSQLFile; buf: PByte; buflen: integer; off: Int64): integer; {$ifdef USEC}cdecl;{$endif} // Write data from a buffer into a file. Return SQLITE_OK on success // or some other error code on failure var n: integer; ................................................................................ Execute('PRAGMA user_version',tmp); result := tmp; except on Exception do result := 0; end; end; procedure TSQLDataBase.SetWALMode(Value: Boolean); const CMD: array[boolean] of RawUTF8 = ('DELETE;','WAL;'); begin try Execute('PRAGMA journal_mode='+CMD[value]); except on Exception do ; end; end; { TSQLRequest } procedure TSQLRequest.Bind(Param: Integer; Value: Int64); begin sqlite3_check(RequestDB,sqlite3_bind_Int64(Request,Param,Value)); end; ................................................................................ { ************ Unit-Testing classes and functions } { TTestSQLite3 } procedure TTestSQLite3.Sqlite3DatabaseEngine; begin AddCase([TTestFileBased,TTestFileBasedWAL,TTestMemoryBased]); end; { TTestSQLite3Engine } destructor TTestSQLite3Engine.Destroy; begin Demo.Free; ................................................................................ Owner.CustomVersions := Owner.CustomVersions+#13#10'SQlite3 engine used: '+ sqlite3_libversion; IsMemory := InheritsFrom(TTestMemoryBased); if IsMemory then TempFileName := ':memory:' else begin TempFileName := 'test.db3'; DeleteFile(pointer(TempFileName)); // use a temporary file CreateSQLEncryptTable('password1'); end; Demo := TSQLDataBase.Create(TempFileName); Demo.UseCache := true; // use the cache for the JSON requests if InheritsFrom(TTestFileBasedWAL) then Demo.SetWALMode(true); // test Write-Ahead Logging for the database Demo.Execute( ' CREATE TABLE IF NOT EXISTS People (' + ' ID INTEGER PRIMARY KEY,'+ ' FirstName TEXT COLLATE SYSTEMNOCASE,' + ' LastName TEXT,' + ' Data BLOB,'+ ' YearOfBirth INTEGER,' + ................................................................................ if not IsMemory then begin // check file encryption password change FreeAndNil(Demo); // if any exception occurs in Create(), Demo.Free is OK ChangeSQLEncryptTablePassWord(TempFileName,'password1',''); ChangeSQLEncryptTablePassWord(TempFileName,'','NewPass'); CreateSQLEncryptTable('NewPass'); Demo := TSQLDataBase.Create(TempFileName); // reuse the temporary file Demo.UseCache := true; // use the cache for the JSON requests if InheritsFrom(TTestFileBasedWAL) then Demo.SetWALMode(true); // test Write-Ahead Logging for the database Check(Hash32(Demo.ExecuteJSON(Req))=$56CB147E,'ExecuteJSON crypted'); end; Demo.GetTableNames(Names); Check(length(Names)=1); Check(Names[0]='People'); end; |
Changes to SQLite3/SQLite3Commons.pas.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
methods) - some compatibility fixes for Delphi 2009/2010 - fixed bug: negative numbers were not updated when calling *.Update() Version 1.8 - includes Unitary Testing class and functions - fixed bug in TSQLTable.GetJSONValues: FirstRow parameter not used String usage in the Synopse SQLite3 database framework: - RawUTF8 is used for every internal data usage, since both SQLite3 and JSON do expect UTF-8 encoding - WinAnsiString where WinAnsi-encoded AnsiString (code page 1252) are needed |
> |
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
methods)
- some compatibility fixes for Delphi 2009/2010
- fixed bug: negative numbers were not updated when calling *.Update()
Version 1.8
- includes Unitary Testing class and functions
- fixed bug in TSQLTable.GetJSONValues: FirstRow parameter not used
- update engine to version 3.7 draft (snapshot as of 2010-06-25 11:35 UTC)
String usage in the Synopse SQLite3 database framework:
- RawUTF8 is used for every internal data usage, since both SQLite3 and
JSON do expect UTF-8 encoding
- WinAnsiString where WinAnsi-encoded AnsiString (code page 1252) are needed
|
Changes to SQLite3/SQLite3HttpServer.pas.
1
2
3
4
5
6
7
8
9
10
...
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/// HTTP/1.1 RESTFUL JSON SQLite3 Server classes // - this unit is a part of the freeware Synopse SQLite3 database framework, // licensed under a MPL/GPL/LGPL tri-license; version 1.6 unit SQLite3HttpServer; { This file is part of Synopse SQLite3 database framework. Synopse SQLite3 database framework. Copyright (C) 2010 Arnaud Bouchez Synopse Informatique - http://synopse.info ................................................................................ end; { TTestClientServerAccess } procedure TTestClientServerAccess._TSQLite3HttpClient; var Resp: TSQLTable; begin Client := TSQLite3HttpClient.Create('localhost','888',Model); Resp := Client.List([TSQLRecordPeople],'*'); if Check(Resp<>nil) then exit; try Check(Resp.InheritsFrom(TSQLTableJSON)); Check(Hash32(TSQLTableJSON(Resp).JSONData)=$1AAF56E9); finally |
|
|
|
1
2
3
4
5
6
7
8
9
10
...
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
/// HTTP/1.1 RESTFUL JSON SQLite3 Server classes // - this unit is a part of the freeware Synopse SQLite3 database framework, // licensed under a MPL/GPL/LGPL tri-license; version 1.8 unit SQLite3HttpServer; { This file is part of Synopse SQLite3 database framework. Synopse SQLite3 database framework. Copyright (C) 2010 Arnaud Bouchez Synopse Informatique - http://synopse.info ................................................................................ end; { TTestClientServerAccess } procedure TTestClientServerAccess._TSQLite3HttpClient; var Resp: TSQLTable; begin Client := TSQLite3HttpClient.Create('127.0.0.1','888',Model); Resp := Client.List([TSQLRecordPeople],'*'); if Check(Resp<>nil) then exit; try Check(Resp.InheritsFrom(TSQLTableJSON)); Check(Hash32(TSQLTableJSON(Resp).JSONData)=$1AAF56E9); finally |
Changes to SQLite3/sqlite3.c.
more than 10,000 changes
Deleted SQLite3/sqlite3.obj.
Deleted SQLite3/sqlite3fts3.obj.