谁有ZEOSDBO在D7下控制和读取SQLite的demo,发给我看下好吗?邮箱:[email protected]
控件包里的example里的需要装别的控件,而且编译不过,真搞不懂。我搞了很久总是报错,请教什么问题?procedure TMainFrm.ExceSQL(str: string);//*********执行SQL语句***********//begin
ZConnection1.Connected:= True;
ZQuery1.SQL.text:=str;
ZQuery1.Open;
ZQuery1.ExecSQL;
ZQuery1.Active;
ZQuery1.Close;
ZConnection1.Connected:= False;
end;procedure TMainFrm.FormCreate(Sender: TObject);//***********主窗口创建*****************//var
i,x,Row,Col,RowNo,ColNo,h,w: Integer;
p: TPanel;
begin
ZConnection1.Database:= DBFile;
self.ExceSQL('create table MSGroup(ID INTEGER PRIMARY KEY,CreateDate,CreateUserID,RecordState,Name,UpID,Description,LevelCode)');
self.ExceSQL('create table MSSG(ID INTEGER PRIMARY KEY,CreateDate,CreateUserID,RecordState,Name,Type,Format,GroupID)');
self.ExceSQL('CREATE TABLE MSVW(ID INTEGER PRIMARY KEY,CreateDate,CreateUserID,RecordState,Name,Type,Port,BaudRate,RowNo,ColNo,PWidth)');
self.ExceSQL('insert into MSVW(RowNo,ColNo,PWidth) values (5,13,897)');
self.ExceSQL('select * from MSVW');
end;运行就报错,提示数据库找不到,有时候又说第一个表已经存在,我每次运行的时候都会把数据库删除,
现在好像是创建第一个表后就报错,在数据库里打开有第一个插入的表。网上好像几乎没有很系统的zeosdbo控件的资料,
控件包里的example里的需要装别的控件,而且编译不过,真搞不懂。我搞了很久总是报错,请教什么问题?procedure TMainFrm.ExceSQL(str: string);//*********执行SQL语句***********//begin
ZConnection1.Connected:= True;
ZQuery1.SQL.text:=str;
ZQuery1.Open;
ZQuery1.ExecSQL;
ZQuery1.Active;
ZQuery1.Close;
ZConnection1.Connected:= False;
end;procedure TMainFrm.FormCreate(Sender: TObject);//***********主窗口创建*****************//var
i,x,Row,Col,RowNo,ColNo,h,w: Integer;
p: TPanel;
begin
ZConnection1.Database:= DBFile;
self.ExceSQL('create table MSGroup(ID INTEGER PRIMARY KEY,CreateDate,CreateUserID,RecordState,Name,UpID,Description,LevelCode)');
self.ExceSQL('create table MSSG(ID INTEGER PRIMARY KEY,CreateDate,CreateUserID,RecordState,Name,Type,Format,GroupID)');
self.ExceSQL('CREATE TABLE MSVW(ID INTEGER PRIMARY KEY,CreateDate,CreateUserID,RecordState,Name,Type,Port,BaudRate,RowNo,ColNo,PWidth)');
self.ExceSQL('insert into MSVW(RowNo,ColNo,PWidth) values (5,13,897)');
self.ExceSQL('select * from MSVW');
end;运行就报错,提示数据库找不到,有时候又说第一个表已经存在,我每次运行的时候都会把数据库删除,
现在好像是创建第一个表后就报错,在数据库里打开有第一个插入的表。网上好像几乎没有很系统的zeosdbo控件的资料,
后面添加检查数据表是否存在,如果已经存在就删除数据表的代码:self.ExceSQL('
if object_id(''MSGroup'') IS NOT NULL DROP TABLE MSGroup
if object_id(''MSSG'') IS NOT NULL DROP TABLE MSSG
if object_id(''MSVW'') IS NOT NULL DROP TABLE MSVW
')
这个是mssql的语法吧
人家是sqlite
//俺是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;
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;