Pascal Data Objects

function IPDOStatement.execute: Boolean; overload;

function IPDOStatement.execute (DelimitedBind: AnsiString): Boolean; overload;

This overloaded function executes a previously prepared statement. The second version of the function combines the steps of variable binding and execution into a single step.

Parameters

For version 1, there are no parameters. Any variable markers must have been previously bound. For version 2, DelimitedBind: This is a string of variables concatenated with a pipe symbol "|" in the order which the markers appear in the original SQL statement.

Return Values

Both versions return TRUE on success or FALSE on failure.

Examples

Example 1. Execute a prepared statement with bound variables

procedure example1;
var
   calories: Integer;
   color:    AnsiString;
Begin
   calories := 150;
   colour   := 'red';
   stmt := db.prepare_as_is (
         'SELECT name, colour, calories ' + 
         'FROM fruit ' + 
         'WHERE calories < :calories AND colour = :colour');
   stmt.bindValue ('calories', calories);
   stmt.bindValue ('colour', colour);
   stmt.execute;
End;

Example 2. Execute a prepared statement with a concatenated piped string of insert values

procedure example2;
var
   calories: Integer;
   color:    AnsiString;
Begin
   calories := 150;
   colour   := 'red';
   stmt := db.prepare_as_is (
         'SELECT name, colour, calories ' + 
         'FROM fruit ' + 
         'WHERE calories < :calories AND colour = :colour');
   stmt.execute (format('%s|%s'),[IntToStr(calories),colour]);
end;

Example 3. Execute a prepared statement with question mark placeholders

procedure example3;
var
   calories: Integer;
   color:    AnsiString;
Begin
   calories := 150;
   colour   := 'red';
   stmt := db.prepare_as_is (
         'SELECT name, colour, calories ' + 
         'FROM fruit ' + 
         'WHERE calories < ? AND colour = ?');
   stmt.bindValue (1, calories);
   stmt.bindValue (2, colour);
   stmt.execute;
End;