How to get multiple resultsets using Zdbc interface (Mysql)

ZeosLib tutorials and code snipets

Moderators: gto, cipto_kh

User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

How to get multiple resultsets using Zdbc interface (Mysql)

Postby mdaems » 14.03.2007, 12:25

:!: This only works when you use SVN Testing branch version 228 or higher.:!:

[syntax="delphi"]
procedure TForm1.Button1Click(Sender: TObject);
var conn: IZConnection;
stmt: IZStatement;
rs: IZResultSet;
updateCount: integer;
s, SQL: string;
begin
ZConnection.Properties.Add('CLIENT_MULTI_STATEMENTS=1');
ZConnection1.Connect;

conn := ZConnection1.DbcConnection;
stmt := conn.CreateStatement;

SQL := 'SELECT field1 t1_fld from table_2; ' +
'SELECT field1 t1_fld from table_1; ' +
'insert into table_2 (field1) values (''pretest''); ' +
'insert into table_1 (field1) values (''the contents''); ' +
'insert into table_2 (field1) values (''test'');';

s := '';
if stmt.Execute( SQL ) then begin
repeat
rs := stmt.GetResultSet;
if (rs <> nil) and rs.First then begin
if s <> '' then s := s + '; ';
s := s + rs.GetString(1);
end else begin
updateCount := stmt.GetUpdateCount;
if s <> '' then s := s + '; ';
s := s + IntToStr(updateCount);
end;

until not stmt.GetMoreResults and (stmt.GetUpdateCount = -1);
end;

stmt := nil;

MessageBox(Application.Handle, PChar(s), 'multiresults test', MB_OK);
end;
[/syntax]

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 1 guest