function DatabaseConnection_pgsql::query

Overrides DatabaseConnection::query

3 calls to DatabaseConnection_pgsql::query()
DatabaseConnection_pgsql::nextId in includes/database/pgsql/database.inc
Retrieve the next id in a sequence.
DatabaseConnection_pgsql::queryRange in includes/database/pgsql/database.inc
Runs a limited-range query on this database object.
DatabaseConnection_pgsql::queryTemporary in includes/database/pgsql/database.inc
Runs a SELECT query and stores its results in a temporary table.

File

includes/database/pgsql/database.inc, line 88

Class

DatabaseConnection_pgsql

Code

public function query($query, array $args = array(), $options = array()) {
    $options += $this->defaultOptions();
    // The PDO PostgreSQL driver has a bug which
    // doesn't type cast booleans correctly when
    // parameters are bound using associative
    // arrays.
    // See http://bugs.php.net/bug.php?id=48383
    foreach ($args as &$value) {
        if (is_bool($value)) {
            $value = (int) $value;
        }
    }
    try {
        if ($query instanceof DatabaseStatementInterface) {
            $stmt = $query;
            $stmt->execute(NULL, $options);
        }
        else {
            $this->expandArguments($query, $args);
            $stmt = $this->prepareQuery($query);
            $stmt->execute($args, $options);
        }
        switch ($options['return']) {
            case Database::RETURN_STATEMENT:
                return $stmt;
            case Database::RETURN_AFFECTED:
                return $stmt->rowCount();
            case Database::RETURN_INSERT_ID:
                $sequence_name = isset($options['sequence_name']) ? $options['sequence_name'] : NULL;
                return $this->connection
                    ->lastInsertId($sequence_name);
            case Database::RETURN_NULL:
                return;
            default:
                throw new PDOException('Invalid return directive: ' . $options['return']);
        }
    } catch (PDOException $e) {
        if ($options['throw_exception']) {
            // Add additional debug information.
            if ($query instanceof DatabaseStatementInterface) {
                $e->errorInfo['query_string'] = $stmt->getQueryString();
            }
            else {
                $e->errorInfo['query_string'] = $query;
            }
            $e->errorInfo['args'] = $args;
            throw $e;
        }
        return NULL;
    }
}

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