You are here

protected function Connection::addDebugInfoToQuery in Drupal driver for SQL Server and SQL Azure 8.2

Adds debugging information to a query in the form of comments.

Parameters

string $query:

Return value

string

1 call to Connection::addDebugInfoToQuery()
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 286
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\sqlsrv

Code

protected function addDebugInfoToQuery($query) {

  // The current user service might not be available
  // if this is too early bootstrap
  $uid = null;
  static $loading_user;

  // Use loading user to prevent recursion!
  // Because the user entity can be stored in
  // the database itself.
  if (empty($loading_user)) {
    try {
      $loading_user = true;
      $oUser = \Drupal::currentUser();
      $uid = null;
      if ($oUser != null) {
        $uid = $oUser
          ->getAccount()
          ->id();
      }
    } catch (\Exception $e) {
    } finally {
      $loading_user = false;
    }
  }

  // Drupal specific aditional information for the dump.
  $extra = array(
    '-- uid:' . ($uid ? $uid : 'NULL'),
  );
  $comment = $this->connection
    ->GetCallstackAsComment(DRUPAL_ROOT, $extra);
  $query = $comment . $query;
  return $query;
}