How to save the recordset by OpenNext ?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
stlcours
Posts: 33
Joined: Wed 14 Sep 2011 20:22

How to save the recordset by OpenNext ?

Post by stlcours » Mon 28 Oct 2013 14:42

Code using ADO:

Code: Select all

procedure TForm1.Button2Click(Sender: TObject);
var
  FAdoHandle: TAdoConnection;
  VarRowsAffected: OleVariant;
  QueryResult: _RecordSet;
begin
    SQL:='SELECT 1; SELECT 2; UPDATE xxx;';
    QueryResult := FAdoHandle.ConnectionObject.Execute(SQL, VarRowsAffected, 1);
    while(QueryResult <> nil) do begin
      // do something for the result of QueryResult
      QueryResult := QueryResult.NextRecordset(VarRowsAffected); // get the next;
    end;
end;
Code using UNIDAC

Code: Select all

procedure TForm1.Button3Click(Sender: TObject);
begin
    with FUniQuery do
    begin
      SpecificOptions.Values['MySQL.FetchAll'] := 'false';
      SQL.Clear;
      SQL.Add('SELECT 1; SELECT 2; UPDATE xxx; ');
      Open;
      repeat
        //   how to get each recordset?
      until not OpenNext; // OpenNext work for "update"?
    end;
end;
There is totally three SQL instructions.
Questions:
1. How to save each result of RecordSet for these three instructions in unidac?
2. OpenNext work for the "update" instruction? Because there is none of "ExecuteNext"
3. by defaut Uniquery determine the diff sql by ";" automatically? If I use "delimiter ||" in my instructions, how unidac deal with it?

Thanks in advance.

AndreyZ

Re: How to save the recordset by OpenNext ?

Post by AndreyZ » Mon 28 Oct 2013 15:34

1. When you open a TUniQuery, it stores a resultset returned by the server, you can access it using the standard dataset properites. Here is a code example:

Code: Select all

UniQuery1.SpecificOptions.Values['FetchAll'] := 'False';
UniQuery1.SQL.Text := 'select 1; select 2; update xxx;';
UniQuery1.Open;
repeat
  ShowMessage(UniQuery1.Fields[0].AsString); // shows 1, then 2
until not UniQuery1.OpenNext;
2. OpenNext can be used for the UPDATE statements.
3. TUniQuery does not parse the provided SQL statement, it sends it to the server as it is. So, you can use any SQL statement that is correct for the used database server. As MySQL does not support || as a statement delimiter, you cannot use it.

stlcours
Posts: 33
Joined: Wed 14 Sep 2011 20:22

Re: How to save the recordset by OpenNext ?

Post by stlcours » Mon 28 Oct 2013 16:32

the 2 and 3 questions are good. But for the first question, if I use:

Code: Select all

UniQuery1.SQL.Text := 'select * from students; select * from teacher; update xxx;';
How can I save all the result recordsets of "select * from students" in a pointer of Recordset (maybe 1000 records, not just one)?
the same after OpenNext, how can I save all the result recordsets of "select * from teacher" ?
finally, does "update xxx" will return the recordsets ?

Thanks again.

AndreyZ

Re: How to save the recordset by OpenNext ?

Post by AndreyZ » Tue 29 Oct 2013 08:20

There is no way to store result sets. If you wish to work with several result sets at once, you should use several TUniQuery components. Here is a code example:

Code: Select all

UniQuery1.SQL.Text := 'select * from students';
UniQuery1.Open;
UniQuery2.SQL.Text := 'select * from teacher';
UniQuery2.Open;
UniQuery3.SQL.Text := 'update xxx';
UniQuery3.Execute;

Post Reply