Pascal Data Objects

function IPDOStatement.fetch (var row: TPDORowKeyStrings): Boolean; overload;

function IPDOStatement.fetch (var row: TPDORowNative): Boolean; overload;

This overloaded function Fetches a row from a result set associated with a IPDOStatement object.


version 1: row, TPDORowKeyStrings Object
version 2: row, TPDORowNative object

For version 1, the result type is actually a 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 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 TPDORowNative for details.


Using the simple TStringList result

procedure example1;
    row: TPDORowKeyStrings;
    columnCount, loop: Byte;
   db.setAttribute (COLUMN_CASE, CASE_UPPER);
   stmt := db.query_as_is ('SELECT name, colour FROM fruit');
   while (stmt.fetch(row)) do begin
       columnCount := row.count;
       for loop := 0 to columnCount - 1 do
           writeln (row.strings[loop] + chr(9) + row.names[loop] + chr(9) + row.ValueFromIndex[loop]);
       writeln ('  name = ' + row.values['NAME'] + '  colour = ' + row.values['COLOUR']);     

The above example will output:

NAME=apple	NAME	apple
  name = apple  color = red
NAME=banana	NAME	banana
COLOUR=yellow	COLOUR	yellow
  name = banana  color = yellow

Using the native result

procedure example1;
    row: TPDORowNative;
    columnCount, loop: Byte;
    pool, totalpool: Integer;
   totalpool := 0;
   stmt := db.query_as_is ('SELECT team_name, number_players FROM roster');
   while (stmt.fetch(row)) do begin
       columnCount := row.columnCount; 
       for loop := 0 to columnCount - 1 do begin
           writeln ('Team name = ' + row.hash('team_name').asString + 
                    '    Number of players = ' + row.hash('number_players').asString);
           pool := row.column[1].asWord * 15;  {another way to reference 'number_players'} 
           totalpool := totalpool + pool;
   writeln (format('Margin = %d', [totalpool]));

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