function IPDOStatement.fetch_all (var rowset: TPDORowSetKeyStrings): Boolean; overload;
function IPDOStatement.fetch_all (var rowset: TPDORowSetNative): Boolean; overload;
This overloaded function Fetches the entire result set associated with a IPDOStatement object.
Parameters
version 1: row, TPDORowKeyStrings Object
version 2: row, TPDORowSetNative object
For version 1, the result type is basically an array of keyed TStringList. All the methods available to the TStringList can be performed on the row, including indexing by name, by column position, or alphabetical sorting. Both the key and the data are strings.
For version 2, the result type stores the data set in its native format, and the data can be re-cast to sorts of data types including strings, integers, real numbers, boolean, byte strings, and timestamps. Click on TPDORowSetNative for details.
Examples
Using the simple TStringList result set
procedure example1; Var rowset: TPDORowSetKeyStrings; columnCount, loop: Byte; currentRow: Integer; Begin db.setAttribute (COLUMN_CASE, CASE_UPPER); stmt := db.query_as_is ('SELECT name, colour FROM fruit'); stmt.fetch_all (rowset); if (rowset.rowCount > 0) then begin for currentRow := 0 to rowset.rowCount - 1 do with rowset.row[currentRow] do begin columnCount := count; for loop := 0 to columnCount - 1 do writeln (strings[loop] + chr(9) + names[loop] + chr(9) + ValueFromIndex[loop]); writeln (' name = ' + values['NAME'] + ' colour = ' + values['COLOUR']); end; End; End;
The above example will output:
NAME=apple NAME apple COLOUR=red COLOUR red name = apple color = red NAME=banana NAME banana COLOUR=yellow COLOUR yellow name = banana color = yellow
Using the native result set
procedure example1; Var rowset: TPDORowSetNative; loop: Byte; pool, totalpool: Integer; currentRow: Int64; Begin totalpool := 0; stmt := db.query_as_is ('SELECT team_name, number_players FROM roster'); stmt.fetch_all (rowset); if (rowset.rowCount > 0) then Begin for currentRow := 0 to rowset.rowCount - 1 do with rowset.row[currentRow] do begin for loop := 0 to columnCount - 1 do begin writeln ('Team name = ' + hash('team_name').asString + ' Number of players = ' + hash('number_players').asString); pool := column[1].asWord * 15; {another way to reference 'number_players'} totalpool := totalpool + pool; end; end; End; writeln (format('Margin = %d', [totalpool])); End;
The above example will output:
Team name = Red Hot Chili Beans Number of players = 2 Team name = Cabbage Patch Kids Number of players = 1 Team name = Transformer Turtles Number of players = 2 Margin = 75