function Connection::prepareStatement

Same name in this branch
  1. 9 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::prepareStatement()
  2. 9 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::prepareStatement()
Same name and namespace in other branches
  1. 10 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::prepareStatement()
  2. 10 core/modules/pgsql/src/Driver/Database/pgsql/Connection.php \Drupal\pgsql\Driver\Database\pgsql\Connection::prepareStatement()
  3. 10 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::prepareStatement()
  4. 11.x core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::prepareStatement()
  5. 11.x core/modules/pgsql/src/Driver/Database/pgsql/Connection.php \Drupal\pgsql\Driver\Database\pgsql\Connection::prepareStatement()
  6. 11.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::prepareStatement()

Returns a prepared statement given a SQL string.

This method caches prepared statements, reusing them when possible. It also prefixes tables names enclosed in curly braces and, optionally, quotes identifiers enclosed in square brackets.

Parameters

string $query: The query string as SQL, with curly braces surrounding the table names, and square brackets surrounding identifiers.

array $options: An associative array of options to control how the query is run. See the documentation for self::defaultOptions() for details. The content of the 'pdo' key will be passed to the prepared statement.

bool $allow_row_count: (optional) A flag indicating if row count is allowed on the statement object. Defaults to FALSE.

Return value

\Drupal\Core\Database\StatementInterface A prepared statement ready for its execute() method.

Overrides Connection::prepareStatement

File

core/modules/pgsql/src/Driver/Database/pgsql/Connection.php, line 204

Class

Connection
PostgreSQL implementation of \Drupal\Core\Database\Connection.

Namespace

Drupal\pgsql\Driver\Database\pgsql

Code

public function prepareStatement(string $query, array $options, bool $allow_row_count = FALSE) : StatementInterface {
    // mapConditionOperator converts some operations (LIKE, REGEXP, etc.) to
    // PostgreSQL equivalents (ILIKE, ~*, etc.). However PostgreSQL doesn't
    // automatically cast the fields to the right type for these operators,
    // so we need to alter the query and add the type-cast.
    $query = preg_replace('/ ([^ ]+) +(I*LIKE|NOT +I*LIKE|~\\*|!~\\*) /i', ' ${1}::text ${2} ', $query);
    return parent::prepareStatement($query, $options, $allow_row_count);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.