We're going to use the fddemo.sdb database to access it and start our first SQLite access example.
Our Fddemo.sdb storage directory is in:C:\Program Files (x86) \embarcadero\studio\14.0\samples\data
New VCL Forms Application
Press Ctrl +. key in the XE6 IDE to quickly enter the VCL forms application, and a new VCL forms application application is created after carriage return.
Adding FIREDAC related components
Continue to press CTRL +. Key to quickly enter the following characters, create the following components:
Fdphyssqlitedriverlink //SQLite Driver Auto Connect component, equivalent to uses FireDAC.Phys.SQLite;fdguixwaitcursor // The waiting cursor for automatic management of GUI programs, equivalent to uses FireDAC.VCLUI.Wait; Fdconnection // data connection fdquery // data query DataSource // Data Source DBGrid // data table display
When added, the IDE looks like the effect:
Next we enter a simple code, as follows:
proceduretform1.formcreate (sender:tobject);varDbstr:string;begin //set the path to the Fddemo.sdbDBSTR: ='C:\Program Files (x86) \embarcadero\studio\14.0\samples\data\fddemo.sdb'; Fdconnection1.drivername:='SQLite'; FDCONNECTION1.PARAMS.ADD ('database='+dbstr); Fdquery1.connection:=FDConnection1; Datasource1.dataset:=FDQuery1; Dbgrid1.datasource:=DataSource1; FDQuery1.SQL.Text:='SELECT * from Products'; Fdquery1.open (); Fdconnection1.open (); Dbgrid1.align:=alclient;End;
OK, so far, we have completed a small example of SQLite, press F9 to start running it, the effect is as follows:
By looking at the teacher's code, we find that fdconnection can use ConnectionString to set up the connection content.
//fdconnection1.drivername: = ' SQLite '; // FDConnection1.Params.Add (' database= ' + dbstr), equivalent to the following line of code fdconnection1.connectionstring:'driverid=sqlite; database=' + dbstr;
Of course the Fdconnection.open method and the Fdquery.open method support the following uses:
Fdconnection1.open ('driverid=sqlite; database=' + dbstr); Fdquery1.open ('SELECT *from Products');
The Open method directly assigns ConnectionString and SQL statements.
SQLite in the FIREDAC (II.)