how to use TZQuery with multi statement sql string

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
srboslavr
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 11.08.2010, 10:41

how to use TZQuery with multi statement sql string

Post by srboslavr »

Hi,
I use ZeosLib 6.6 and Delphi 5.0 and MySQL 5.5
Most of thinks works fine, but I have
problem with TZQuery. ( I am moving some app from BDe to ZeosLib).
Lot of queries have multiple statements like:

drop table if exists tempTable;
create temporary table tempTable(
id char(10) not null primary key,
value1 float null,
value2 float null);
insert into tempTable
(id, value1, value2)
select SifArtikla, sum(Kolicina), sum(Kolicina*Cena)
from PredracunSta
group by SifArtikla;

select * from tempTable;


When I call query.open method,
I receive an error:
Can not open a ResultSet

Is there any solution to run multi - statements query?

Best regards,
jeremicm
Senior Boarder
Senior Boarder
Posts: 61
Joined: 18.10.2006, 17:07
Contact:

Post by jeremicm »

You can't "drop table if exists..." with open...
also can't create table with open...
try this...

drop table if exists tempTable;
execsql;

create temporary table tempTable(
id char(10) not null primary key,
value1 float null,
value2 float null);
execsql;

insert into tempTable
(id, value1, value2)
select SifArtikla, sum(Kolicina), sum(Kolicina*Cena)
from PredracunSta
group by SifArtikla;
execsql

select * from tempTable;
open;
User avatar
Pitfiend
Senior Boarder
Senior Boarder
Posts: 68
Joined: 12.12.2009, 07:27

Post by Pitfiend »

execsql is a metod from zquery object. just in case. I think you can send every non select in the same query, call execsql and then set your select statment and open it.
jeremicm
Senior Boarder
Senior Boarder
Posts: 61
Joined: 18.10.2006, 17:07
Contact:

Post by jeremicm »

Pitfiend wrote:I think you can send every non select in the same query, call execsql and then set your select statment and open it.
You can, but from my experience, it's safer to exec them one by one... sometimes (when queries are to long or there is to many of them) some of queries won't execute and there's no error to warn about that...

Yes, it's faster to put them all together and it's less code to type... but i don't think it's good way to do it...
guidoaerts
Senior Boarder
Senior Boarder
Posts: 93
Joined: 01.07.2009, 16:07

Post by guidoaerts »

Or you could use a TZSqlProcessor to execute the statements in a script...
Guido
Post Reply