Pascal Data Objects

procedure IPDOStatement.bindValue (valueIndex: Cardinal; PassedValue: Variant); overload;

procedure IPDOStatement.bindValue (valueIndex: AnsiString; PassedValue: Variant); overload;

This overloaded function binds a value to a corresponding named or question mark placeholder in the SQL statement that was use to prepare the statement.

Parameters

valueIndex: Parameter identifier. The placeholder can be referenced by either it's 0-indexed position, or its name. For names, the colon is not included, so a placeholder in the statement of :userid has a string valueIndex of userid.

PassedValue: This is the actual value to bind to the placeholder. The function type is variant, and the variant assumes the type of variable being passed to it.

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 question mark placeholders

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 < ? AND colour = ?');
   stmt.bindValue (0, calories);
   stmt.bindValue (1, colour);
   stmt.execute;
End;