function TPDO.query_as_is (sql: AnsiString): IPDOStatement;
TPDO.query_as_is executes an SQL statement in a single function call, returning the result set (if any) returned by the statement as a PDOStatement object.
For a query that you need to issue multiple times, you will realize better performance if you prepare an IPDOStatement object using TPDO.prepare_as_is or TPDO.prepare_select and issue the statement with multiple calls to IPDOStatement.execute after binding.
If you do not fetch all of the data in a result set before issuing your next call to TPDO::query_as_is or TPDO::query_select, there should not be any problem. Any remaining result is freed before another query is sent to the database server.
Parameters
sql: The SQL statement to prepare and execute.
Return Values
TPDO.query returns a IPDOStatement object.
Example
A nice feature of TPDO.query_as_id is that it enables you to iterate over the rowset returned by a successfully executed SELECT statement.
procedure example; Begin {stmt and db are global IPDOStatement and TPDO objects} {row is a global TPDORowNative object} stmt := db.query_as_is ('SELECT name, colour, calories FROM fruit ORDER BY name'); while (stmt.fetch(row)) do writeln ( row.hash('name').asString + chr(9) + row.hash('colour').asString + chr(9) + row.hash('calories').asString ); end;
The above example will output:
apple red 150 banana yellow 250 kiwi brown 75 lemon yellow 25 orange orange 300 pear green 150 watermelon pink 90
The difference between TPDO.query_as_is and TPDO.query_select is that the former accepts the query as a string, which can be anything, and the later accepts 6 components so that it can assembly a SELECT statement as a function of which the connected database server.