Difference between revisions of "TSQLite3Connection"
(Created page with "'''TSQLite3Connection''' image:tsqlite3connection.png is the database connection component for use SQLite. The component is found on SQLdb tab of the Component P...") |
(Use pascal highlighter) |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | '''TSQLite3Connection''' [[image:tsqlite3connection.png]] is the database connection component for use [[SQLite]]. The component is found on [[SQLdb tab]] of the [[Component Palette]]. | + | {{TSQLite3Connection}} |
+ | {{Infobox databases}} | ||
+ | |||
+ | {{Note|Instead of using a TSQLite3Connection a proxy-like [[TSQLConnector]] may be used to create more generic database applications}}'''TSQLite3Connection''' [[image:tsqlite3connection.png]] is the database connection component for use [[SQLite]]. The component is found on [[SQLdb tab]] of the [[Component Palette]]. | ||
+ | |||
+ | 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. | ||
+ | |||
+ | <syntaxhighlight lang=pascal> | ||
+ | program BasicDBase; | ||
+ | {$mode objfpc} {$ifdef mswindows}{$apptype console}{$endif} | ||
+ | uses | ||
+ | sqldb, sqlite3conn; | ||
+ | var | ||
+ | Connect : TSQLite3Connection; | ||
+ | Trans : TSQLTransaction; | ||
+ | |||
+ | begin | ||
+ | Connect := TSQLite3Connection.Create(nil); | ||
+ | Trans := TSQLTransaction.Create(Connect); | ||
+ | Connect.Transaction := Trans; | ||
+ | Connect.DatabaseName := 'test_dbase'; | ||
+ | Trans.StartTransaction; // opens Connect, EInOutError if SQLite not installed | ||
+ | Connect.ExecuteDirect('create table TBLNAMES (ID integer Primary Key, NAME varchar(40));'); | ||
+ | Trans.Commit; | ||
+ | Trans.Free; | ||
+ | Connect.Free; | ||
+ | end. | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | 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. | ||
==See also== | ==See also== | ||
− | |||
* [[TSQLConnector]] | * [[TSQLConnector]] | ||
* [[SQLite]] | * [[SQLite]] | ||
{{LCL Components}} | {{LCL Components}} |
Latest revision as of 14:01, 1 March 2020
│
English (en) │
español (es) │
français (fr) │
日本語 (ja) │
polski (pl) │
References:
Tutorials/practical articles:
Databases |
TSQLite3Connection is the database connection component for use SQLite. The component is found on SQLdb tab of the Component Palette.
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.
program BasicDBase;
{$mode objfpc} {$ifdef mswindows}{$apptype console}{$endif}
uses
sqldb, sqlite3conn;
var
Connect : TSQLite3Connection;
Trans : TSQLTransaction;
begin
Connect := TSQLite3Connection.Create(nil);
Trans := TSQLTransaction.Create(Connect);
Connect.Transaction := Trans;
Connect.DatabaseName := 'test_dbase';
Trans.StartTransaction; // opens Connect, EInOutError if SQLite not installed
Connect.ExecuteDirect('create table TBLNAMES (ID integer Primary Key, NAME varchar(40));');
Trans.Commit;
Trans.Free;
Connect.Free;
end.
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.
See also