SQLite It's an old lightweight local file database , Completely free and open source , No installation required , No configuration , Of course , In this way, the management function is not very powerful , But its main application is also in the local database , It can be said that it is the most simple and easy to use embedded local database .

SQLite As long as a DLL You can achieve all the functions .SQLite No database engine is needed , There's only one data file , It takes very little system resources , It's very suitable Demo Or small applications .

meanwhile ,SQLite It's also a relational database , Support most SQL sentence . It supports transaction mechanism and blob data type , Support most SQL92 standard , Maximum support database to 2T.

It has Python、Tcl、PHP、Java The binding of , These languages can be used directly SQLite database , Because they contain support in themselves ; also ODBC Interface , Very easy to use .

SQLite Some of the basic operations of are the same as SQL Is very similar , Basically there are SQL You can see the basic .

SQLite There are a lot of image viewing tools for , such as SQLiteSpy、SQLiteBrowser etc. .

SQLite The default is utf8 code , Use pragma encoding You can see the coding of the database .

After building the database , You can input “pragma encoding = UTF8/UTF16” To change the code , But with the data in the database , The code can't be changed .

SQLite The source code of http://www.sqlite.org get . About SQLite Further syntax and information , Please refer to http://www.sqlite.com.cn/http://www.sqlitecn.org.

delphi Use in sqlite3

Here's one delphi Use in sqlite3 Of demo:http://www.itwriting.com/blog/articles/a-simple-delphi-wrapper-for-sqlite-3/comment-page-2

This demo It contains sqlite3.pas,sqlite3table.pas,sqlite.dll Three files , It contains operations sqlite3 Source code , Using these three files , You don't need third-party components

Add step :

  1. take simple sqlite 3.0 for delphi Medium sqlite3.pas,sqlite3table.pas Copy to the folder where the project is located . And add these two files to the project .
  2. Copy sqlite.dll To build exe File folder . This is based on personal settings .

Preliminary test

  1. quote SQLiteTable3.pas unit .
  2. Create one on the form called btnVersion The button (Tbutton). stay btnVersion Of click Write the following code in the event .
    procedure TfrmAbout.btnVersionClick(Sender: TObject);
    SqliteDB :TSQLiteDatabase;
    SqliteDB :=TSQLiteDatabase.Create('');
    showmessage('Sqlite dll version:'+SqliteDb.version);

Compile operation , If you succeed , The current sqlite dll Version number of

Simple working principle description

stay simple sqlite3.0 for delphi In a few of the documents in , Two files are used . Namely sqlite3.pas,sqlite3table.pas.

  1. sqlite3.pas Realization sqlite.dll Interface external definition of .
  2. sqlite3table.pas Simple access function encapsulation .

stay delphi in , adopt sqlite3table.pas To achieve the right sqlite All kinds of access to the database .

Read and write data

There's one called test.db Of sqlite Database files , Generated in compilation exe Directory of files . There is one called testTable Table for .

Here is the basis demo Put forward and practice the reading and writing sentences :

 unit TestSqlite;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SQLiteTable3; type
TForm1 = class(TForm)
lbl1: TLabel;
ebID: TEdit;
ebName: TEdit;
lbl2: TLabel;
lbl3: TLabel;
ebNumber: TEdit;
memNotes: TMemo;
btnTest: TButton;
procedure btnTestClick(Sender: TObject);
{ Private declarations }
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.btnTestClick(Sender: TObject);
slDBpath: string;
sldb: TSQLiteDatabase;
sltb: TSQLIteTable;
sSQL: String;
Notes: String; begin
slDBPath := ExtractFilepath(application.exename)
+ 'test.db';
sldb := TSQLiteDatabase.Create(slDBPath);
if sldb.TableExists('testTable') then
sSQL := 'DROP TABLE testtable';
sSQL := sSQL + '[Name] VARCHAR (255),[Number] FLOAT, [notes] BLOB, [picture] BLOB COLLATE NOCASE);';
sldb.execsql('CREATE INDEX TestTableName ON [testtable]([Name]);'); //begin a transaction
sSQL := 'INSERT INTO testtable(Name,OtherID,Number,Notes) VALUES ("Some Name",4,587.6594,"Here are some notes");';
//do the insert
sSQL := 'INSERT INTO testtable(Name,OtherID,Number,Notes) VALUES ("Another Name",12,4758.3265,"More notes");';
//do the insert
//end the transaction
// reason : It's on disk as a file , Open the file every time you visit , If there are a lot of operations on the database , Very slow .
// terms of settlement : Submit in the form of things , Because after starting the business , A large number of operations are stored in memory ,
// Write all to the database when you commit , here , Database files are only opened once . If the operation is wrong , You can also roll back transactions . //query the data
sltb := sldb.GetTable('SELECT * FROM testtable');
if sltb.Count > then
begin //display first row
//display second row
ebName.Text := sltb.FieldAsString(sltb.FieldIndex['Name']);
ebID.Text := inttostr(sltb.FieldAsInteger(sltb.FieldIndex['ID']));
ebNumber.Text := floattostr( sltb.FieldAsDouble(sltb.FieldIndex['Number']));
Notes := sltb.FieldAsBlobText(sltb.FieldIndex['Notes']);
memNotes.Text := notes;
end; finally
end; finally
end; end.

【delphi】delphi operation sqlite3 More articles about

  1. Delphi Excel Operation Daquan

    Delphi Excel Operation Daquan ( One ) Using the dynamic creation method, first create Excel object , Use ComObj:var ExcelApp: Variant;ExcelApp := CreateOleObj ...

  2. delphi Line feed operation Word

    delphi Line feed operation I'll take my business < Travel agency management system > Of Send a group notice Part of it is dedicated to you , Hope to help you . procedure TFrmMain.N327Click(Sender: TObject ...

  3. Delphi Camera operation

    /*Title:Delphi Camera operation *Author:Insun *Blog:http://yxmhero1989.blog.163.com *From:www.4safer.com */ For writing ...

  4. Delphi Memory operations API function ( For reference , And learn one by one )

    Delphi Memory operations API function System.IsMemoryManagerSet;System.Move;System.New;System.ReallocMem;System.ReallocMemo ...

  5. delphi nethttpclient operation cookie

    delphi nethttpclient operation cookie unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysU ...

  6. iOS: Learning notes , Use FMDatabase operation sqlite3

    Use FMDatabase operation sqlite3 The database is very simple and convenient // // main.m // iOSDemo0602_sqlite3 // // Created by yao_yu on 14-6- ...

  7. IOS Database operation SQLite3 The use of, ( turn )

    iPhone Medium support pass sqlite3 To visit iPhone Local database . The specific use method is as follows 1: Add development package libsqlite3.0.dylib The first is to set up the project file , Add... To the project iPhone Version of sqlite3 Number of numbers ...

  8. Flask: operation SQLite3(0.1)

    Windows 10 Family Chinese ,Python 3.6.4,Flask 1.0.2 This paper introduces the first time in Flask Operating in the framework SQLite3 Database testing , Refer to the official website Using SQLite 3 wit ...

  9. litepal Better operation sqlite3, Configuration and basic operation

    litepal Better operation sqlite3 To configure stay app Under the build.gradle Add establish litepal.xml To configure stay app/src/main Create below assets, newly build litepal.xml & ...

Random recommendation

  1. JavaScript-Object Basic knowledge of

    1.   Definition : The object is JS Core concept of , It is also the most important data type .js All of the data can be treated as objects .                  An object is an unordered collection of data , By a number of key value pairs (key:value) constitute , from { ...

  2. [ zong ] PCA Dimension reduction

    http://blog.json.tw/using-matlab-implementing-pca-dimension-reduction With m Pen data , Every piece of information is n Vi , So you can think of them as a mx ...

  3. JS: Operation style sheet 2 : use JS Realize the function of adding and deleting a class name (addClass() and removeClass())

    var box = document.getElementById("box"); box.id = "pox"; take id = “box”, Change it to id = “po ...

  4. Atitit. Principles and introduction of computer graphics and image processing attilax summary

    Atitit. Principles and introduction of computer graphics and image processing attilax summary Computer graphics 1 The image processing . Analysis and machine vision ( The first 3 edition )1 digital image processing ( The sixth edition )2 Basis of image processing ( The first 2 edition )2 Development and evolution 1963 year , Ivan · Sue ...

  5. Android SurfaceView + MediaPlayer Achieve seamless playback of segmented video

    Android There are two ways to play video , namely : adopt VideoView To achieve or through SurfaceView + MediaPlayer Realization . From shallow to deep , First of all, let's look at what we want to do in Android Play a video on , We ...

  6. cogs My own topic Problem solving report

    The first question is very simple , It's the naked dynamic tree divide and conquer For the center of gravity of each layer, the path information of the subtree and the point information of the subtree to the center of gravity of the upper layer are maintained Spatial complexity O(nlogn) For each layer, we press dis Sort , Then record the prefix of the number of troops and When inquiring, we just ...

  7. In depth understanding of C# in this/partial/null Use

    One .this Key role 1.this Represents the currently running object Eg: public class Person { public int age; public string name; public Pe ...

  8. Android development learning Menu

    Menu is a very important component in Android development , From the Android development documentation (http://wear.techbrood.com/guide/index.html) Can be seen in , Android UI In design Menu It is mainly divided into : A.Option ...

  9. docker A summary of common commands for

    1================================================================================ docker List the... For each container IP   ...

  10. The C compiler identification is unknown terms of settlement

    Environmental Science :VS2015,CMake3.12.0. Question 1 : terms of settlement : Download and install Windows SDK version 8.1. Question two : terms of settlement : Baidu hasn't found a suitable solution to this problem for a long time , Many blogs are copied ...