The first example of Sqlite (ii) under Delphi FIREDAC

Source: Internet
Author: User
Tags sqlite


To facilitate the test, I copied a copy of the official C:\Users\Public\Documents\Embarcadero\Studio\14.0\Samples\data\FDDemo.sdb to C:\Temp\. Fddemo.sdb.

{Create a new VCL Forms Application, then add the following controls (recommended by pressing Ctrl + . After adding with keyboard input):}

TFDPhysSQLiteDriverLink // is used to drive automatic connections; one for each database: TFDPhys****DriverLink
TFDGUIxWaitCursor // "waiting cursor" for automatic management of GUI programs; similar things in Console and FMX
TFDConnection // data connection
TFDQuery // data query
TDataSource // data source
TDBGrid // data display

// After using FireDAC.Phys.SQLite, you don't need to add TFDPhysSQLiteDriverLink
// After using FireDAC.VCLUI.Wait, you don't need to add TFDGUIxWaitCursor


{Simply a few lines of code that renders the data in the Orders table in FDDemo.sdb}
Procedure TForm1.FormCreate(Sender: TObject);
Begin
  FDConnection1.DriverName := 'SQLite';
  FDConnection1.Params.Add('Database=C:\Temp\FDDemo.sdb');

  FDQuery1.Connection := FDConnection1;
  DataSource1.DataSet := FDQuery1;
  DBGrid1.DataSource := DataSource1;

  FDQuery1.SQL.Text := 'SELECT * FROM Orders'; // SQLite supports the SQL92 standard very well, and is currently ignored: http://www.sqlite.org/omitted.html

  FDConnection1.Open();
  FDQuery1.Open();

  DBGrid1.Align := alClient;
End;


 {Slightly change the code}

Procedure TForm1.FormCreate(Sender: TObject);
Begin
// FDConnection1.ConnectionString := 'DriverID=SQLite; Database=C:\Temp\FDDemo.sdb'; // Can replace the following two lines
   FDConnection1.Params.Add('DriverID=SQLite'); // Same as FDConnection1.DriverName := 'SQLite';
   FDConnection1.Params.Add('Database=C:\Temp\FDDemo.sdb');

   FDQuery1.Connection := FDConnection1;
   DataSource1.DataSet := FDQuery1;
   DBGrid1.DataSource := DataSource1;

   FDQuery1.SQL.Text := 'SELECT * FROM Orders';

   FDConnection1.Connected := True;
   FDQuery1.Active := True;

   DBGrid1.Align := alClient;
End;


{Change it again}


procedure TForm1.FormCreate(Sender: TObject);
begin
  FDQuery1.Connection := FDConnection1;
  DataSource1.DataSet := FDQuery1;
  DBGrid1.DataSource := DataSource1;

  FDConnection1.Open('DriverID=SQLite;Database=C:\Temp\FDDemo.sdb');
  FDQuery1.Open('SELECT * FROM Orders');

  DBGrid1.Align := alClient;
end;


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.