0

I have a procedure on MySQL that returns two results and I need to show this on Delphi but I didn't find how to pass for each result.

enter image description here

Here is how appear on DBForge when I execute, I want this on delphi too, show Query1 and Query2 in a TTabControl.

How to go through this queries and get the name of the query like: Query1,Query2?

BDuarte
  • 129
  • 11
  • You mean two result sets? Which dataset components are you using? – MartynA Apr 23 '21 at 11:07
  • If SP produces 2 resultsets then a collection of resultsets is returned to the program. Iterate over it (maybe, some method like output.NextRowset exists?). – Akina Apr 23 '21 at 11:07
  • In FIreDAC, the method to use to iterate over result sets is the `NextRecordSet` method. See https://stackoverflow.com/q/58641661/2663863 and http://docwiki.embarcadero.com/RADStudio/Sydney/en/Command_Batches_(FireDAC) – MartynA Apr 23 '21 at 11:11
  • 1
    Could you edit your question and add an example of very simple procedure producing two result sets? Don't need to be the actual procedure you use, just one simple that we can try to understand your problem. Show the procedure and the required table structure. – fpiette Apr 23 '21 at 13:36
  • @fpiette You will find an example [here](https://stackoverflow.com/questions/1683794/retrieving-multiple-result-sets-with-stored-procedure-in-php-mysqli). – Olivier Apr 23 '21 at 14:16
  • 1
    The queries don't have names. DBForge is just assigning sequential names to the resultsets. You can't get the query names, because they don't exist. – Ken White Apr 23 '21 at 21:53
  • @Olivier That not what I ask. I ask that the OP edit his question and add more details, most notably the procedure he is talking about. – fpiette Apr 24 '21 at 05:25

2 Answers2

0

You don't say what DB interface lib you're using, like FireDAC, Zeos, or something else.

You're going to issue something like a dbxyz.ExecSQL() call and check for some results.

It sounds like you're expecting to get back multiple records in the result set. Using a TTabControl, you'd simply create a list of tabs like "Result-1", "Result-2", and so on, depending on how many records you get back. (They're results, not queries.) You could select the first one by default.

When another tab is clicked, use the control's TabIndex property to select the corresponding result from the result set, then format up the data in that result and display it in whatever format you're using below the tabs.

There's so little detail you've given that it's impossible to show any code for anything other than the tab control's OnChange handler that will use the TabIndex property to find the desired result set. But this is the overall approach I'd take for this using the TTabControl.

David
  • 101
  • 1
  • 10
-1

I solve the problem with the command

 var 
  tab: TTabItem;
  stringGrid: TStringGrid;

repeat

    tab:= TTabItem.Create(nil);
    tab.Parent:= tabcontrol1;
    tab.Text:= query.Fields.Fields[0].FieldName; //the table name

    stringGrid:= TStringGrid.Create(Self);
    stringGrid.Parent:= tab;
    stringGrid.Align:= TAlignLayout.Client;


    for I := 1  to query.FieldCount-1 do
    begin
      
      stringGrid.AddObject(TStringColumn.Create(stringGrid));
      stringGrid.Columns[i-1].Header:= query.Fields.Fields[i].FieldName;

      query.First;

      for j := 0 to query.RecordCount-1 do
      begin
       stringGrid.cells[i-1, j]:= query.Fields.Fields[i].value;
       query.Next;
      end;
    end;

    stringGrid.RowCount:= j;

until not query.openNext;
BDuarte
  • 129
  • 11
  • Q&A at SO are supposed to be for the beneft of future readers, and I think your answer will likely be very little help to them because it does not include the code whch goes between the `repeat` and `until`. – MartynA Apr 26 '21 at 15:27
  • Actually, my question was about go through multi results of a query and this code is the key for this, where is my comment you can add whatever you want to do with the results – BDuarte Apr 26 '21 at 16:06