Page 1 of 1

How to save the recordset by OpenNext ?

Posted: Mon 28 Oct 2013 14:42
by stlcours
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.

Re: How to save the recordset by OpenNext ?

Posted: Mon 28 Oct 2013 15:34
by AndreyZ
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.

Re: How to save the recordset by OpenNext ?

Posted: Mon 28 Oct 2013 16:32
by stlcours
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.

Re: How to save the recordset by OpenNext ?

Posted: Tue 29 Oct 2013 08:20
by AndreyZ
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;