Einzelnen Beitrag anzeigen

Benutzerbild von Leuselator
Leuselator

Registriert seit: 18. Mär 2003
Ort: Berlin
589 Beiträge
 
Delphi 8 Architect
 
#6

Re: Erfahrungen mit Abfragen, die mehrere Ergebnismengen lie

  Alt 13. Jan 2004, 23:22
@Thema: ich komme auf die Idee, weil im PSDK zu finden ist:
Zitat:
Receiving Multiple Recordsets
The Microsoft OLE DB Provider for SQL Server supports returning multiple Recordset objects for a single command containing multiple SQL statements, one Recordset per SQL statement. The order in which the Recordsets are returned follows the order in which the SQL statements are placed in the command text.

The first code example in this section demonstrates this feature by querying two tables, Orders and Customers, in the Northwind database to examine who is the customer whose ID is "ALFKI" and where are the orders shipped.

The Microsoft OLE DB Provider for SQL Server also returns multiple resultsets to ADO when the command contains a COMPUTE clause. For example, a command containing the following SQL statement—

SELECT ProductID, ProductName, UnitPrice
FROM PRODUCTS
COMPUTE AVG(UnitPrice)
—will return the results in two Recordset objects: one for the rowset of (ProductID, ProductName, UnitPrice), and the other for the average price of all products in the table. You can use the Recordset.NextRecordset method to enumerate the two objects as shown in the second code example in this section.
und siehe da TADODataSet kennt auch die Methode NextRecordSet! Das es trotzdem nicht auf Anhieb funktioniert hat, scheint daran zu liegen, dass das TAdoDataSet (auch BetterAdoDataSet) das 2. Select ignoriert?
Wenn ich jedoch auf dem Server eine Stored Procedure aufrufe, die mehrere RecordSets zurückliefert (und genau um diesen Fall gin es mir eigentlich) dann kann man mit:
Delphi-Quellcode:
var i : Integer;
try
  MeinAdoDataSet.RecordSet := MeinAdoDataSet.NextRecordSet(i);
except
  // Ende erreicht - keine weiteren RecordSets
end;
wunderbar die einzelnen Recordsets durchparsen. Allerdings nur 1x, von Anfang bis Ende ("PreviousRecordSet" gibts nicht)

@MrSpock: Werde trotzdem mal in der Richtung graben...

@All: Gruß
Tim Leuschner
Programmierer = moderner Sysiphos: stets wenn er meint, den Stein seiner Dummheit auf den Berg des Wissens gewuchtet zu haben, erblickt er einen völlig neuen Aspekt und der Dummfels poltert mit Getöse zurück ins Tal der Unwissenheit...
  Mit Zitat antworten Zitat