Pascal Data Objects

function IPDOStatement.columnCount: Integer;

Use IPDOStatement.columnCount to return the number of columns in the result set represented by the IPDOStatement object.

If the IPDOStatement object was returned from TPDO.query_as_is / TPDO.query_select, the column count is immediately available.

If the IPDOStatement object was returned from TPDO.prepare_as_is / TPDO.prepare_select, an accurate column count will not be available until you invoke IPDOStatement.execute.

Return Values

Returns the number of columns in the result set represented by the IPDOStatement object. If there is no result set, IPDOStatement.columnCount returns 0.

Examples

This example demonstrates how IPDOStatement.columnCount operates with and without a result set.

procedure example1;
var
  colcount: Byte;
begin
   stmt := db.prepare_as_is('SELECT name, colour FROM fruit');

  {Count the number of columns in the (non-existent) result set}
  colcount = stmt.columnCount; 
  writeln (format('Before execute(), result set has %d columns (should be 0)',[colcount]);

  stmt.execute;

  {Count the number of columns in the result set}
  colcount = stmt.columnCount; 
  writeln (format('After execute(), result set has %d columns (should be 2)',[colcount]);
end;

The above example will output:

Before execute(), result set has 0 columns (should be 0)
After execute(), result set has 2 columns (should be 2)