Delphi XE using SQLite3

Developing with Delphi small programs, previously used the Access database, but because Access depends on the office, feeling a little less convenient, look at Delphi using SQLite3.

SQLite is a lightweight database is ACID compliance relational database management system, which is contained in a relatively small C library.

Download SQLite

Official website download page https://www.sqlite.org/download.html

Find the next chart content, according to their own development environment option to download the 32-bit or 64-bit dll dll, tools can be connected to a SQLite3 tool.

Delphi XE using SQLite3

Delphi simple SQLite

With the tools to create a database EtTest.db, inside a table User (two field Id and name), made in the root directory of E.

  1. Under the program into the corresponding directory dll, dll version must correspond to the environment and development .
    Delphi XE using SQLite3
  2. Select both controls TSQLConnection and TSQLQuery.
  3. Configuring TSQLConnection
    (1) placed TSQLConnection controls, Name is SQLConnection1.
    (2) as set SQLConnection1.ConnectionName SQLITECONNECTION.
    (3) to set SQLConnection1.Driver Sqlite
    Delphi XE using SQLite3
    set (4) SQLConnection1.Params the Database for the E: \ EtTest.db (according to your actual situation) point [OK]
    Delphi XE using SQLite3
  4. Configuring TSQLQuery, put TSQLQuery controls, Name is SQLQuery1.
    SQLQuery1.SQLConnection select SQLConnection1.
  5. Two simple operation, add and query
    Delphi XE using SQLite3
    (1) inquiry
    procedure TForm1.SearchClick(Sender: TObject);
    begin
        SQLConnection1.Connected := True;
        SQLQuery1.Close;
        SQLQuery1.SQL.Clear;
        SQLQuery1.SQL.Add('select id,name from user;');
        SQLQuery1.Open;
        while Not SQLQuery1.Eof do
        begin
            Memo1.Lines.Add(SQLQuery1.FieldByName('id').AsString + '  ' + SQLQuery1.FieldByName('name').AsString) ;
    SQLQuery1.Next;
        end;
    end;

    (2) Add

procedure TForm1.AddClick(Sender: TObject);
begin
  SQLConnection1.Connected := True;
  SQLQuery1.Close;

  SQLQuery1.SQL.Clear;
  SQLQuery1.SQL.Add('insert into user(name) values(' + QuotedStr('李四')+ ');');
  SQLQuery1.ExecSQL;
end;

Guess you like

Origin blog.51cto.com/470462/2482061