TADOConnection 的设置步骤:
1)单击TADOConnection控件 ConectionString按钮, 选择 "Use Connection String" ->"Build"
2)选择: "Microsoft OLE DB Provider for ODBC Drivers"
3)指定数据源: 选"使用数据源名称"->"SQLite3 Datasource"
procedure TForm1.btnTestClick(Sender: TObject)var
slDBpath: string
sldb: TSQLiteDatabase
sltb: TSQLIteTable
sSQL: string
Notes: string
i, ts: integer
begin
slDBPath := ExtractFilepath(application.exename) + 'test.db'
//slDBPath := 'r:\test.db'
sldb := TSQLiteDatabase.Create(slDBPath)
try
slDb.Synchronised := false
if sldb.TableExists('testTable') then
begin
sSQL := 'DROP TABLE testtable'
sldb.execsql(sSQL)
end
//sSQL := 'CREATE TABLE testtable ([ID] INTEGER PRIMARY KEY,[OtherID] INTEGER NULL,'
//sSQL := sSQL + '[Name] VARCHAR (255),[Number] FLOAT, [notes] BLOB, [picture] BLOB COLLATE NOCASE)'
sSQL := 'CREATE TABLE testtable ([ID] INTEGER PRIMARY KEY ,[OtherID] INTEGER NULL,'
sSQL := sSQL + '[Name] VARCHAR (255),[Notes] VARCHAR (255),[Number] FLOAT COLLATE NOCASE)'
sldb.execsql(sSQL)
//sldb.execsql('CREATE INDEX TestTableName ON [testtable]([Name])')
ts := GetTickCount()
//begin a transaction
sldb.BeginTransaction
for i := 0 to 10000 do
begin
sSQL := 'INSERT INTO testtable(Name,OtherID,Number,Notes) VALUES ("Some Name",4,587.6594,"Here are some notes")'
//do the insert
sldb.ExecSQL(sSQL)
sSQL := 'INSERT INTO testtable(Name,OtherID,Number,Notes) VALUES ("Another Name",12,4758.3265,"More notes")'
//do the insert
sldb.ExecSQL(sSQL)
end
//end the transaction
sldb.Commit
ts := GetTickCount() - ts
showmessage(format('insert 10000 : %d ms', [ts])) //'Sqlite dll version:'+SlDb.version)
//
// sSQL := 'INSERT INTO testtable(Name,OtherID,Number,Notes) VALUES ("Another Name",12,4758.3265,"More notes")'
// sldb.PrepareSQL(sSQL)
// sldb.bind
//query the data
sltb := slDb.GetTable('SELECT * FROM testtable')
try
if sltb.Count > 0 then
begin
//display first 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
sltb.Free
end
finally
sldb.Free
end
end
下载 Delphi SQLite3的开源插件 http://www.itwriting.com/repos/sqlitewrapper/trunk/sqlitesimpledelphi.zip
这个demo中包含了sqlite3.pas,sqlite3table.pas,sqlite.dll三个文件,里面包含了 *** 作sqlite3的源代码,利用这三个文件,就不需要第三方组件了
添加步骤:
将simple sqlite 3.0 for delphi 中的 sqlite3.pas,sqlite3table.pas拷贝至工程所在的文件夹。并在工程中添加这两个个文件。
拷贝 sqlite.dll到编译生成exe文件的文件夹。这个根据个人的设定。
更新到SQLite3 dll文件 http://www.sqlite.org/download.html
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)