public function InsertQuery_sqlsrv::__toString in Drupal driver for SQL Server and SQL Azure 7
Same name and namespace in other branches
- 7.3 sqlsrv/query.inc \InsertQuery_sqlsrv::__toString()
- 7.2 sqlsrv/query.inc \InsertQuery_sqlsrv::__toString()
Implements PHP magic __toString method to convert the query to a string.
Return value
string The prepared statement.
Overrides InsertQuery::__toString
File
- sqlsrv/
query.inc, line 124
Class
- InsertQuery_sqlsrv
- SQL Server-specific implementation of INSERT.
Code
public function __toString() {
// Create a sanitized comment string to prepend to the query.
$prefix = $this->connection
->makeComment($this->comments);
// Enable direct insertion to identity columns if necessary.
if (!empty($this->setIdentity)) {
$prefix .= 'SET IDENTITY_INSERT {' . $this->table . '} ON;';
}
// If we're selecting from a SelectQuery, finish building the query and
// pass it back, as any remaining options are irrelevant.
if (!empty($this->fromQuery)) {
return $prefix . "INSERT INTO {" . $this->table . '} (' . implode(', ', $this->connection
->quoteIdentifiers($this->insertFields)) . ') ' . $this->fromQuery;
}
// Build the list of placeholders.
$placeholders = array();
for ($i = 0; $i < count($this->insertFields); ++$i) {
$placeholders[] = ':db_insert' . $i;
}
return $prefix . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $this->connection
->quoteIdentifiers($this->insertFields)) . ') VALUES (' . implode(', ', $placeholders) . ')';
}