Sign in Join
Wiki copytemporary

TSQLite3Connection/fr: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: TSQLite3Connection/fr

OldNewLine
1+> **Note:** Au lieu d'utiliser un TMySQLite3Connection, un simili-proxy [[TSQLConnector/fr|TSQLConnector]] peut être utilisé pour créer des applications de bases de données plus génériques.
2+
3+**TSQLite3Connection** ![](/wiki-images/5/5e/Tsqlite3connection.png) est le composant de connexion pour l'utilisation de [[SQLite/fr|SQLite]]. Le composant se trouve dans l'[[SQLdb tab/fr|onglet SQLdb]] de la [[Component Palette/fr|palette de composants]].
4+
5+TSQLite3connection est un composant, non visuel de la FCL et non pas de la LCL, ce qui veut dire qu'il peut être aussi utilisé dans des applications TSQLite3connection console p.ex.tout comme dans les applications Lazarus avec IHM. Malheureusement il n'y a pas de docs FCL sur TSQLite3Connection mais son interface est similaire à son parent ([[TSQLConnection/fr|TSQLConnection]]). Comme SQLite est est une base de données embarquée (i.e. sans serveur), son utilisation peut ne pas demander de définir .host, .username ni .password. L'exemple ci-dessous illustre la façon de l'utiliser dans un programme ObjectPascal, utilisé dans Lazarus un réglage similaire peut etre réalisé dans l'inspecteur d'objet.
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+ try
19+ Trans := TSQLTransaction.Create(Connect);
20+ try
21+ Connect.Transaction := Trans;
22+ Connect.DatabaseName := 'test_dbase';
23+ Trans.StartTransaction; // opens Connect, EInOutError if SQLite not installed
24+ try
25+ Connect.ExecuteDirect('create table TBLNAMES (ID integer Primary Key, NAME varchar(40));');
26+ Trans.Commit;
27+ except
28+ Trans.Rollback;
29+ raise;
30+ end;
31+ finally
32+ Trans.Free;
33+ end;
34+ finally
35+ Connect.Free;
36+ end;
37+end.
38+```
39+
40+La procédure ExecuteDirect() est un moyen clairement limité pour appeler SQL dans une application réelle, vous aurez besoin de quelque chose comme TSQLQuery.
41+
42+## Voir aussi
43+
44+- [Doc. TSQLConnection](http://www.freepascal.org/docs-html/fcl/sqldb/tsqlconnection.html)
45+- [[TSQLConnector/fr|TSQLConnector]]
46+- \[\[SQLite/fr\|SQLite\]
47+
48+---
49+*From the Free Pascal wiki, page "TSQLite3Connection/fr", 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).*

Back to history