ZEOSDBO在D7里控制和读取SQLite的数据

sdeevenlee 2011-08-30 06:24:16
谁有ZEOSDBO在D7下控制和读取SQLite的demo,发给我看下好吗?邮箱:137101195@qq.com
控件包里的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控件的资料,
...全文
383 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sdeevenlee 2011-09-03
  • 打赏
  • 举报
回复
cdsn上真是热心呀,非常感谢你们。这几天没登录,不好意思,问题的原因是ZEOSDBO控件在找不到数据库文件的时候会自动创建数据库,而我又手动创建,所以重复了,导致报错。
OO_is_just_P 2011-09-01
  • 打赏
  • 举报
回复
你的问题在

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;
OO_is_just_P 2011-09-01
  • 打赏
  • 举报
回复

//俺是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;
haitao 2011-08-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 liw125008 的回复:]
ZConnection1.Database:= DBFile;
后面添加检查数据表是否存在,如果已经存在就删除数据表的代码:

self.ExceSQL('
if object_id(''MSGroup'') IS NOT NULL DROP TABLE MSGroup
if object_id(''MSSG'') IS NOT NULL DROP TABLE MSSG
if obje……
[/Quote]

这个是mssql的语法吧
人家是sqlite。。。。。。。。。
kevin_li125 2011-08-31
  • 打赏
  • 举报
回复
ZConnection1.Database:= DBFile;
后面添加检查数据表是否存在,如果已经存在就删除数据表的代码:

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
')


ZeosDBO is a database middleware components for Borland development tools, including Delphi, C++ Builder and Kylix. The following compilers are supported: Delphi 5 - 7C++ Builder 5 - 6Kylix 2 - 3ZeosDBO supports direct connectivity to the following databases using the vendor provided, native interface: MySQL 3.20 - 4.1PostgreSQL 6.5 - 7.4Firebird 1.0 - 1.5Interbase 5.0 - 7.5Microsoft SQL Server 7, 2000Sybase ASE 12.0, 12.5Oracle 9iSQLite 2.8For other databases we propose to use implemented Active Data Objects (ADO) Bridge. Advantages of using ZeosDBO: Platform independance. The ZeosDBO is highly generic. Applications written in ZeosDBO can be migrated across databases without major changes. ZeosDBO is open source, written for usability and extensibility. ZeosDBO leverages the amazing power of the Delphi development environment without relying on a performance killing middleware. ZeosDBO is an extremely thin abstraction layer, unlike ‘thick‘ layered protocols like ADO and BDE. Package contents: ZCore - Core classes and interfaces. Contains Java style objects and collections as well as compatibility types and functions. ZParseSql - SQL specific for syntax and lexical analysis. ZPlain - Native plain API to supported SQL servers. ZDbc - Port of Java Database Connectivity API (JDBC 2.0). DBC API acts as intermediate layer between Plain API and highlevel TDataset or DBExpress components. ZComponent - visual components descended from TDataset. Installed components: TZConnection: This component encapsulates the database connection and transaction management. TZReadOnlyQuery: TDataset component to execute SQL queries and process data in read-only mode. TZQuery: TDataset component which allows data modifications in regular and cached mode. TZUpdateSQL: Analog of standard TUpdateSQL component to explicite definition of Insert/Update/Delete SQL statements for TDataset modifications. TZStoredProc: The component to execute SQL stored procedures. TZSQLProcessor: The component to execute SQL scripts for different SQL and various delimiter types. TZSQLMonitor: The component to monitor all outgoing SQL queries and other logging information. TZSQLMetadata: Specialized TDataset component which provides an access to database metadata such as tables, columns, indices, etc.

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧