class DatabaseStatement_sqlsrv in Drupal driver for SQL Server and SQL Azure 7
Same name and namespace in other branches
- 7.3 sqlsrv/database.inc \DatabaseStatement_sqlsrv
- 7.2 sqlsrv/database.inc \DatabaseStatement_sqlsrv
Hierarchy
- class \DatabaseStatementPrefetch implements \Iterator, DatabaseStatementInterface
- class \DatabaseStatement_sqlsrv implements \Iterator, DatabaseStatementInterface
Expanded class hierarchy of DatabaseStatement_sqlsrv
File
- sqlsrv/
database.inc, line 462 - Database interface code for Microsoft SQL Server.
View source
class DatabaseStatement_sqlsrv extends DatabaseStatementPrefetch implements Iterator, DatabaseStatementInterface {
// Flag to tell if statement should be run insecure.
private $insecure = FALSE;
// Tells the statement to set insecure parameters
// such as SQLSRV_ATTR_DIRECT_QUERY and ATTR_EMULATE_PREPARES.
public function RequireInsecure() {
$this->insecure = TRUE;
}
protected function getStatement($query, &$args = array()) {
$pdo_options = array();
// Set insecure options if requested so.
if ($this->insecure) {
// We have to log this, prepared statements are a security RISK.
watchdog('SQL Server Driver', 'An insecure query has been executed against the database. This is not critical, but worth looking into.');
$options = $this->dbh
->getConnectionOptions();
// These are defined in class Connection.
$pdo_options = $options['pdo'];
}
return $this->dbh
->PDOPrepare($query, $pdo_options);
}
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();
if (!empty($logger)) {
$query_start = microtime(TRUE);
}
// Prepare the query.
$statement = $this
->getStatement($this->queryString, $args);
if (!$statement) {
$this
->throwPDOException();
}
$return = $statement
->execute($args);
if (!$return) {
$this
->throwPDOException();
}
// Fetch all the data from the reply, in order to release any lock
// as soon as possible.
$this->rowCount = $statement
->rowCount();
// Bind the binary columns properly.
$null = array();
for ($i = 0; $i < $statement
->columnCount(); $i++) {
$meta = $statement
->getColumnMeta($i);
if ($meta['sqlsrv:decl_type'] == 'varbinary') {
$null[$i] = NULL;
$statement
->bindColumn($i + 1, $null[$i], PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY);
}
}
try {
$this->data = $statement
->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $e) {
$this->data = array();
}
$this->resultRowCount = count($this->data);
if ($this->resultRowCount) {
$this->columnNames = array_keys($this->data[0]);
}
else {
$this->columnNames = array();
}
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]);
}
}
if ($dropped_columns) {
// Renumber columns.
$this->columnNames = array_values($this->columnNames);
foreach ($this->data as $k => $row) {
foreach ($dropped_columns as $column) {
unset($this->data[$k][$column]);
}
}
}
// Destroy the statement as soon as possible.
unset($statement);
// Initialize the first row in $this->currentRow.
$this
->next();
return $return;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DatabaseStatementPrefetch:: |
protected | property | The list of column names in this result set. | |
DatabaseStatementPrefetch:: |
protected | property | The key of the current row. | |
DatabaseStatementPrefetch:: |
protected | property | The current row, retrieved in PDO::FETCH_ASSOC format. | |
DatabaseStatementPrefetch:: |
protected | property | Main data store. | |
DatabaseStatementPrefetch:: |
public | property | Reference to the database connection object for this statement. | |
DatabaseStatementPrefetch:: |
protected | property | Holds supplementary default fetch options. | |
DatabaseStatementPrefetch:: |
protected | property | Holds the default fetch style. | |
DatabaseStatementPrefetch:: |
protected | property | Driver-specific options. Can be used by child classes. | |
DatabaseStatementPrefetch:: |
protected | property | Holds supplementary current fetch options (which will be used by the next fetch). | |
DatabaseStatementPrefetch:: |
protected | property | Holds the current fetch style (which will be used by the next fetch). | |
DatabaseStatementPrefetch:: |
protected | property | The query string. | |
DatabaseStatementPrefetch:: |
protected | property | The number of rows in this result set. | |
DatabaseStatementPrefetch:: |
protected | property | The number of rows affected by the last query. | |
DatabaseStatementPrefetch:: |
public | function | Return the current row formatted according to the current fetch style. | |
DatabaseStatementPrefetch:: |
public | function | ||
DatabaseStatementPrefetch:: |
public | function | ||
DatabaseStatementPrefetch:: |
public | function |
Returns the result set as an associative array keyed by the given field. Overrides DatabaseStatementInterface:: |
|
DatabaseStatementPrefetch:: |
public | function |
Returns the entire result set as a single associative array. Overrides DatabaseStatementInterface:: |
|
DatabaseStatementPrefetch:: |
public | function |
Fetches the next row and returns it as an associative array. Overrides DatabaseStatementInterface:: |
|
DatabaseStatementPrefetch:: |
public | function |
Returns an entire single column of a result set as an indexed array. Overrides DatabaseStatementInterface:: |
|
DatabaseStatementPrefetch:: |
public | function | ||
DatabaseStatementPrefetch:: |
public | function |
Returns a single field from the next record of a result set. Overrides DatabaseStatementInterface:: |
|
DatabaseStatementPrefetch:: |
public | function | ||
DatabaseStatementPrefetch:: |
public | function |
Return the object's SQL query string. Overrides DatabaseStatementInterface:: |
|
DatabaseStatementPrefetch:: |
public | function | ||
DatabaseStatementPrefetch:: |
public | function | ||
DatabaseStatementPrefetch:: |
public | function | ||
DatabaseStatementPrefetch:: |
public | function |
Returns the number of rows affected by the last SQL statement. Overrides DatabaseStatementInterface:: |
|
DatabaseStatementPrefetch:: |
public | function | ||
DatabaseStatementPrefetch:: |
protected | function | Throw a PDO Exception based on the last PDO error. | |
DatabaseStatementPrefetch:: |
public | function | ||
DatabaseStatementPrefetch:: |
public | function | ||
DatabaseStatement_sqlsrv:: |
private | property | ||
DatabaseStatement_sqlsrv:: |
public | function |
Executes a prepared statement. Overrides DatabaseStatementPrefetch:: |
|
DatabaseStatement_sqlsrv:: |
protected | function |
Grab a PDOStatement object from a given query and its arguments. Overrides DatabaseStatementPrefetch:: |
|
DatabaseStatement_sqlsrv:: |
public | function |