Page 1 of 1

[solved] IZResultSet.BeforeFirst dont work

Posted: 17.09.2012, 22:03
by josimarz
Hello,

I'm using the ZDBC API to execute queries. Like this:

Code: Select all

var
   Rs: IZResultSet;
begin
   Rs :=
      ZConn.DbcConnection.CreateStatement.ExecuteQuery('SELECT A FROM T');
   while Rs.Next do
   begin
      //
   end;
At one point I wish to return to the top of the resultset, before the first record:

Code: Select all

Rs.BeforeFirst;
But does not work. The pointer remains in the same position. The following works:

Code: Select all

Rs.First;
That would be a bug?

Database: mysql 5.5.25
ZEOS: 6.6.6

Best regards,
Josimar

Posted: 20.09.2012, 15:11
by EgonHugeist
josimarz,

The walk through the resultsets has dependencies to the scrolltype they have. Some are NativeResultset/ForwardOnly and others are CachedResultset/scrollintensive. This will be decided from the the PlainDriver or an Info.Value[useresult]=True.

But i have no idea about 6.6 and if that really is a bug or a wanted behavior. Did you test it with Zeos7 too?

Posted: 25.09.2012, 14:56
by josimarz
EgonHugeist,

The solution is change the ResultSetConcurrency property to rcUpdatable:

Code: Select all

var
   Conn: IZConnection;
   Stmt: IZStatement;
   Rs: IZResultSet;
begin
   {...}
   Stmt := Conn.CreateStatement;
   Stmt.SetResultSetConcurrency(rcUpdatable); // solution

   Rs := Stmt.ExecuteQuery('SELECT A FROM T');

   Rs.Last;
   Writeln('Record count: ', Rs.GetRow);

   Rs.BeforeFirst; // work!
   while Rs.Next do
      Writeln(Rs.GetString(1));
end;
I have not tested on version 7.

Best regards,
Josimar

Posted: 25.09.2012, 15:39
by EgonHugeist
josimarz,

well a updateable resultset needs a scrollable cursor.... Great hint.