public function Connection::preprocessQuery in Drupal driver for SQL Server and SQL Azure 8.2
Same name and namespace in other branches
- 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php \Drupal\Driver\Database\sqlsrv\Connection::preprocessQuery()
- 3.0.x drivers/lib/Drupal/Driver/Database/sqlsrv/Connection.php \Drupal\Driver\Database\sqlsrv\Connection::preprocessQuery()
Internal function: massage a query to make it compliant with SQL Server.
1 call to Connection::preprocessQuery()
- Connection::prepareQuery in drivers/
lib/ Drupal/ Driver/ Database/ sqlsrv/ Connection.php - Internal prepare a query.
File
- drivers/
lib/ Drupal/ Driver/ Database/ sqlsrv/ Connection.php, line 642 - Definition of Drupal\Driver\Database\sqlsrv\Connection
Class
- Connection
- Temporary tables: temporary table support is done by means of global temporary tables (#) to avoid the use of DIRECT QUERIES. You can enable and disable the use of direct queries with $this->driver_settings->defaultDirectQuery =…
Namespace
Drupal\Driver\Database\sqlsrvCode
public function preprocessQuery($query) {
// Generate a cache signature for this query.
$query_signature = md5($query);
// Drill through everything...
if ($cache = $this->connection
->Cache('query_cache')
->Get($query_signature)) {
return $cache->data;
}
// Force quotes around some SQL Server reserved keywords.
if (preg_match('/^SELECT/i', $query)) {
$query = preg_replace_callback(self::RESERVED_REGEXP, [
$this,
'replaceReservedCallback',
], $query);
}
// Last chance to modify some SQL Server-specific syntax.
$replacements = [];
// Add prefixes to Drupal-specific functions.
$defaultSchema = $this
->schema()
->GetDefaultSchema();
foreach ($this
->schema()
->DrupalSpecificFunctions() as $function) {
$replacements['/\\b(?<![:.])(' . preg_quote($function) . ')\\(/i'] = "{$defaultSchema}.\$1(";
}
// Rename some functions.
$funcs = [
'LENGTH' => 'LEN',
'POW' => 'POWER',
];
foreach ($funcs as $function => $replacement) {
$replacements['/\\b(?<![:.])(' . preg_quote($function) . ')\\(/i'] = $replacement . '(';
}
// Replace the ANSI concatenation operator with SQL Server poor one.
$replacements['/\\|\\|/'] = '+';
// Now do all the replacements at once.
$query = preg_replace(array_keys($replacements), array_values($replacements), $query);
// Assuming that queries have placeholders, the total number of different
// queries stored in the cache is not that big.
$this->connection
->Cache('query_cache')
->Set($query_signature, $query);
return $query;
}