public function Statement::execute in Drupal driver for SQL Server and SQL Azure 8
Same name and namespace in other branches
- 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Statement.php \Drupal\Driver\Database\sqlsrv\Statement::execute()
Executes a prepared statement
Parameters
$args: An array of values with as many elements as there are bound parameters in the SQL statement being executed. This can be NULL.
$options: An array of options for this query.
Return value
TRUE on success, or FALSE on failure.
Overrides Statement::execute
File
- drivers/
lib/ Drupal/ Driver/ Database/ sqlsrv/ Statement.php, line 35 - Definition of Drupal\Driver\Database\sqlsrv\Statement
Class
Namespace
Drupal\Driver\Database\sqlsrvCode
public function execute($args = array(), $options = array()) {
if (isset($options['fetch'])) {
if (is_string($options['fetch'])) {
// Default to an object. Note: db fields will be added to the object
// before the constructor is run. If you need to assign fields after
// the constructor is run, see http://drupal.org/node/315092.
$this
->setFetchMode(PDO::FETCH_CLASS, $options['fetch']);
}
else {
$this
->setFetchMode($options['fetch']);
}
}
$logger = $this->dbh
->getLogger();
$query_start = microtime(TRUE);
// If parameteres have already been binded
// to the statement and we pass an empty array here
// we will get a PDO Exception.
if (empty($args)) {
$args = NULL;
}
// Execute the query. Bypass parent override
// and directly call PDOStatement implementation.
$return = PDOStatement::execute($args);
if (!$return) {
$this
->throwPDOException($statement);
}
// Bind column types properly.
$null = array();
$this->columnNames = array();
for ($i = 0; $i < $this
->columnCount(); $i++) {
$meta = $this
->getColumnMeta($i);
$this->columnNames[] = $meta['name'];
$sqlsrv_type = $meta['sqlsrv:decl_type'];
$parts = explode(' ', $sqlsrv_type);
$type = reset($parts);
switch ($type) {
case 'varbinary':
$null[$i] = NULL;
$this
->bindColumn($i + 1, $null[$i], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
break;
case 'int':
case 'bit':
case 'smallint':
case 'tinyint':
$null[$i] = NULL;
$this
->bindColumn($i + 1, $null[$i], PDO::PARAM_INT);
break;
case 'nvarchar':
case 'varchar':
$null[$i] = NULL;
$this
->bindColumn($i + 1, $null[$i], PDO::PARAM_STR, 0, PDO::SQLSRV_ENCODING_UTF8);
break;
}
}
if (!empty($logger)) {
$query_end = microtime(TRUE);
$logger
->log($this, $args, $query_end - $query_start);
}
// Remove technical columns from the final result set.
$droppable_columns = array_flip(isset($options['sqlsrv_drop_columns']) ? $options['sqlsrv_drop_columns'] : array());
$dropped_columns = array();
foreach ($this->columnNames as $k => $column) {
if (substr($column, 0, 2) == '__' || isset($droppable_columns[$column])) {
$dropped_columns[] = $column;
unset($this->columnNames[$k]);
}
}
return $return;
}