Public Wiki editing is temporarily disabled to stop vandalism.
|
|
Table of Contents
DISQLite3 WikiPublic Wiki editing is temporarily disabled to stop vandalism. BLOBs and TStreamHere is a demo which shows how to write any TStream to a database BLOB and read it back. It also describes the advantages of the different methods. An updated version of this demo is distributed with the DISQLite3 package! sqlite3_get_table() ExampleA simple example project which shows how to use sqlite3_get_table() is available here. An updated version of this demo is distributed with the DISQLite3 package! Compress Text and BLOBsNeed to compress database text and BLOBs? You can easily add ZLib compression – just like MySQL – to DISQLite3 by registering the custom SQL functions provided in the DISQLite3ZLib.pas source code unit:
The Cast Compressed Results
It is not required, but you can optionally CAST the SELECT CAST(COMPRESS('Text to compress') AS BLOB);
An SELECT CAST(UNCOMPRESS(Compressed_Blob) AS TEXT); Automatic Compression Using ViewsA simple view allows you to access compressed data as if it was uncompressed: /* Table to store compressed data. */ CREATE TABLE IF NOT EXISTS Compressed (t TEXT); /* View to uncompress data on the fly. */ CREATE VIEW IF NOT EXISTS Uncompressed AS SELECT UNCOMPRESS(t) AS t FROM Compressed; If you also want to handle uncompressed inserts and updates via the view, then also create the following triggers: /* Trigger on view to insert compressed data */ CREATE TRIGGER Uncompressed_Insert INSTEAD OF INSERT ON Uncompressed BEGIN INSERT INTO Compressed (t) VALUES (COMPRESS(new.t)); END; /* Trigger on view to update compressed data */ CREATE TRIGGER Uncompressed_Update INSTEAD OF UPDATE ON Uncompressed BEGIN UPDATE Compressed SET t = COMPRESS(new.t) WHERE Compressed.RowID = old.RowID; END; SQL TransactionsTransaction Handling in DelphiDelphi exceptions are an easy way to handle transactions. This is the basic structure: { Using the TDISQLite3Database component. } uses DISQLite3Database; procedure TDISQLite3Database_Transaction_Usage; var DB: TDISQLite3Database; begin { ... assume database is already opened ... } DB.StartTransaction; try { ...a series of sql commands to update or insert ... } DB.Commit; except DB.Rollback; raise; end; end; { Directly using the DISQLite3 API. } uses DISQLite3Api; procedure DISQLite3_API_Transaction_Usage; var DB: sqlite3; begin { ... assume database is already connected ... } sqlite3_exec_fast(DB, 'BEGIN TRANSACTION;'); try { ...a series of sql commands to update or insert ... } sqlite3_exec_fast(DB, 'COMMIT TRANSACTION;'); except sqlite3_exec_fast(DB, 'ROLLBACK TRANSACTION;'); raise; end; end;
Please take care that your code raises an exception wherever something can go wrong. END [TRANSACTION] vs. COMMIT [TRANSACTION]There is no difference between the two – END [TRANSACTION] is the same as COMMIT [TRANSACTION]. TDISQLite3Database and sqlite3_create_collation()
How can you use sqlite3_create_collation( DB.Handle, // Handle to database. 'SYSTEM', // Name of the new collation. SQLITE_UTF16LE, // String encoding for function callback. nil, // User data. SQLite3_Compare_User_UTF16LE); // Function callback.
New component icons for DISQLite3There are some new Delphi design-time icons available here which are based on the official "feather" logo of SQLite. To use the new icon replace the file "DISQLite3Reg.dcr" in the source folder of the DISQLite3 distribution with the new file in the archive and recompile the Delphi package. The GIMP source file that was used to generate the icons is included in the ZIP archive. Thanks for DISQLite3
wiki/sqlite3/index.txt · Last modified: 2009/10/28 19:28 (external edit)
|
| Copyright (c) 2000-2010 Ralf Junker – http://www.yunqa.de/delphi/ – Disclaimer – Haftungsausschluss – Impressum |