Sqlite使用小记
新项目决定要用SQLite!那就用SQLite吧。
语法
1、SQLite不支持Update table1 set field1=table2.field2 from table2….语句,这个比较烦恼、、
2、查询top n使用Limit代替;写在语句最后 如: Limit 2、Limit 2, 4(这个使用起来就很方便了)
3、开启事务的时候写入速度在1000行/秒左右(i3,4g内存windows 7, 5400转8M SATAII笔记本硬盘),不然就只有7条/秒了
4、写入时要作写入临时事物处理,保证同时只有一个写入其它处理于等待
Delphi控件
Delphi开发中有很多控件支接支持SQLITE
1、ASQLite3对UTF支持不好,如果库文件用Ansi保存的话那也没问题。
2、Zeosdbo
3、UniDac支持UTF, UniDac效率非常高,建议使用
SQLITE ODBC
1、安装完后就可以使用 AD0+ ODBC+SQLITE 模式,对旧版的程序升上来是很方便的。
其实真正有用的只有 sqlite3odbc.dll一个,将它导入到注册表后建一个系统DSN就可以用了,其它文件可以忽略不计;
参照如下:
var
regTmp: TRegistry;
begin
regTmp := TRegistry.Create;
regTmp.RootKey := HKEY_LOCAL_MACHINE;
if not regTmp.OpenKey('software\odbc\ODBCINST.INI\SQLite3 ODBC Driver',False) then
regTmp.CreateKey('software\odbc\ODBCINST.INI\SQLite3 ODBC Driver');
regTmp.OpenKey('software\odbc\ODBCINST.INI\SQLite3 ODBC Driver',False);
//..
regTmp.WriteString('Driver','D:\sqlite3odbc.dll');
regTmp.WriteString('Setup','D:\sqlite3odbc.dll');
regTmp.WriteInteger('UsageCount', 1);
regTmp.CloseKey;
if not regTmp.OpenKey('software\odbc\ODBCINST.INI\ODBC Drivers',False) then
regTmp.CreateKey('software\odbc\ODBCINST.INI\ODBC Drivers');
regTmp.OpenKey('software\odbc\ODBCINST.INI\ODBC Drivers',False);
//..
regTmp.WriteString('SQLite3 ODBC Driver','Installed');
regTmp.CloseKey;
regTmp.RootKey := HKEY_LOCAL_MACHINE;
if not regTmp.OpenKey('software\odbc\ODBC.INI\ODBC Data Sources',False) then
regTmp.CreateKey('software\odbc\ODBC.INI\ODBC Data Sources');
regTmp.OpenKey('software\odbc\ODBC.INI\ODBC Data Sources',False);
//..
regTmp.WriteString('SQLite3DB', 'SQLite3 ODBC Driver');
regTmp.CloseKey;
if not regTmp.OpenKey('software\odbc\ODBC.INI\SQLite3DB',False) then
regTmp.CreateKey('software\odbc\ODBC.INI\SQLite3DB');
regTmp.OpenKey('software\odbc\ODBC.INI\SQLite3DB',False);
regTmp.WriteString('Driver', 'D:\sqlite3odbc.dll');
regTmp.WriteString('Database', 'D:\HSRetailc.db');
end;