Change record status: 
Project: 
Introduced in branch: 
10.1.x
Introduced in version: 
10.1.0
Description: 

Now an event can be dispatched at the start and at the end of a query statement execution. This can allow profilers to collect and log database query starts and ends. This can then be combined with other logged data to better analyse and debug Drupal.

The events are not dispatched by default, to avoid performance impacts. Calling code needs to opt-in for event dispatching by calling ::enableEvents(TRUE) on the database Connection object. The legacy database logger does so when logging database queries is enabled by running Drupal\Core\Database\Database::startLog('YOUR_LOGGING_KEY').

Both new events implement the class Drupal\Core\Database\Event\StatementExecutionEvent.

API additions:

  1. The method Drupal\Core\Database\Log::logFromEvent() adds database query loggings events data to the query log.
  2. The method Drupal\Core\Database\Connection::isEventEnabled() returns the status of the database API events being dispatched.
  3. The methods Drupal\Core\Database\Connection::enableEvents() and Drupal\Core\Database\Connection::disableEvents() enable or disable the dispatching of database API events.
  4. The method Drupal\Core\Database\Connection::dispatchEvent() is used to throw database API events.
  5. The method Drupal\Core\Database\Connection::findCallerFromDebugBacktrace() is used get the last non-database call from the debug backtrace data.
  6. The method Drupal\Core\Database\Connection::removeDatabaseEntriesFromDebugBacktrace() is used remove database calls from the debug backtrace data.

API deprecations:

  1. The method Drupal\Core\Database\Log::log() and is replaced by the new method Drupal\Core\Database\Log::logFromEvent().
  2. The method Drupal\Core\Database\Log::findCaller() and is replaced by the new method Drupal\Core\Database\Connection::findCallerFromDebugBacktrace()
  3. The method Drupal\Core\Database\Log::removeDatabaseEntries() and is replaced by the new method Drupal\Core\Database\Connection::removeDatabaseEntriesFromDebugBacktrace()
  4. The method Drupal\Core\Database\Log::getDebugBacktrace() and there is no replacement.
Impacts: 
Site builders, administrators, editors
Module developers

Comments

andypost’s picture

in 10.3 there was added handling of exceptions in queries