TSQLite3Connection: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: TSQLite3Connection
| Old | New | Line | |
|---|---|---|---|
| 1 | + | > **Note:** Instead of using a TSQLite3Connection a proxy-like [[TSQLConnector]] may be used to create more generic database applications | |
| 2 | + | ||
| 3 | + | **TSQLite3Connection**  is the database connection component for use [[SQLite]]. The component is found on [[SQLdb tab]] of the [[Component Palette]]. | |
| 4 | + | ||
| 5 | + | TSQLite3connection is a FCL (not LCL) non visual component meaning that it can be used in (eg) ObjectPascal, console applications as well as Lazarus GUI ones. Unfortunately there are no FCL docs for TSQLite3Connection but its interface is similar to its parent ( [[TSQLConnection]] ). As SQLite is an embedded or non-server database, its use may not require setting .host, .username nor .password. An example of how its used in an ObjectPascal programme is below, when used in Lazarus, similar setting can be made using the Object Inspector. | |
| 6 | + | ||
| 7 | + | ``` pascal | |
| 8 | + | program BasicDBase; | |
| 9 | + | {$mode objfpc} {$ifdef mswindows}{$apptype console}{$endif} | |
| 10 | + | uses | |
| 11 | + | sqldb, sqlite3conn; | |
| 12 | + | var | |
| 13 | + | Connect : TSQLite3Connection; | |
| 14 | + | Trans : TSQLTransaction; | |
| 15 | + | ||
| 16 | + | begin | |
| 17 | + | Connect := TSQLite3Connection.Create(nil); | |
| 18 | + | Trans := TSQLTransaction.Create(Connect); | |
| 19 | + | Connect.Transaction := Trans; | |
| 20 | + | Connect.DatabaseName := 'test_dbase'; | |
| 21 | + | Trans.StartTransaction; // opens Connect, EInOutError if SQLite not installed | |
| 22 | + | Connect.ExecuteDirect('create table TBLNAMES (ID integer Primary Key, NAME varchar(40));'); | |
| 23 | + | Trans.Commit; | |
| 24 | + | Trans.Free; | |
| 25 | + | Connect.Free; | |
| 26 | + | end. | |
| 27 | + | ``` | |
| 28 | + | ||
| 29 | + | The ExecuteDirect() procedure is a fairly limited means to call SQL, in a real ap, you will need something like TSQLQuery. Note also the above demo does not do any error checking. | |
| 30 | + | ||
| 31 | + | ## See also | |
| 32 | + | ||
| 33 | + | - [[TSQLConnector]] | |
| 34 | + | - [[SQLite]] | |
| 35 | + | ||
| 36 | + | --- | |
| 37 | + | *From the Free Pascal wiki, page "TSQLite3Connection", as it stood on 2020-03-01 after a change by Bart, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
