2,497
社区成员
发帖
与我相关
我的任务
分享
begin
ZConnection1.Connected:= True;
ZQuery1.SQL.text:=str;
//ZQuery1.Open; 如果是insert update之类的直接ExecSQL就行了
ZQuery1.ExecSQL;
//ZQuery1.Active;
//ZQuery1.Close;
ZConnection1.Connected:= False;
end;
begin
ZConnection1.Connected:= True;
ZQuery1.SQL.text:=str;
ZQuery1.Open;
//ZQuery1.ExecSQL;如果是SELECT 直接OPEN就行了,你又是OPEN 又是execsql又是active的,不出错才怪
//ZQuery1.Active;
ZQuery1.Close;
ZConnection1.Connected:= False;
end;
//俺是Turbo delphi,全用代码创建的。
ZConnection1 :=TZconnection.Create(Self);
ZConnection1.Protocol :='sqlite-3'; //非常重要
qrTmp :=TZReadOnlyQuery.Create(Self);
qrTmp.Connection :=ZConnection1;
if not FileExists(AppPath+'SysDB.db') then
begin
Application.MessageBox('database file do not exists',PChar(Application.Title),MB_OK OR MB_ICONERROR);
Application.Terminate;
end;
ZConnection1.Database :=AppPath+'SysDB.db';
ZConnection1.Connect;
if SQLiteEncrypted(AppPath+'SysDB.db') then
begin
s :=ZConnection1.Version;
db := (ZConnection1.DbcConnection as IZSQLiteConnection).GetConnectionHandle;
i := (ZConnection1.DbcConnection as IZSQLiteConnection).GetPlainDriver.Key(db, PChar(pwd), Length(pwd+s));
if i<>0 then
begin
//Application.Messagebox('Can''t open encrypted database',PChar(Application.Title),MB_OK OR MB_ICONERROR);
Application.Terminate;
end;
pwd :='';
end;
function SQLiteEncrypted(Filename :string):Boolean;
var Header :Array [0..14] of byte;
sHeader :string;
SQLiteFile:file;
i :Integer;
begin
Result :=False;
if FileExists(Filename) then
begin
AssignFile(SQLiteFile,Filename);
Reset(SQLiteFile,1);
Try
BlockRead(SQLiteFile,Header,15);
for i:=0 to 14 do
sHeader :=sHeader+Chr(Header[i]);
Result :=not (sHeader='SQLite format 3');
finally
CloseFile(SQLiteFile);
end;
end;
end;