Unverified Commit d78e53bb authored by alexpott's avatar alexpott

Issue #3189880 by mondrake, raman.b, Pooja Ganjage, daffie, Megha_kundar, dww,...

Issue #3189880 by mondrake, raman.b, Pooja Ganjage, daffie, Megha_kundar, dww, S_Bhandari: Use square brackets syntax in sql queries
parent 6f4c546d
......@@ -627,7 +627,7 @@ function template_preprocess_form_element_label(&$variables) {
* $context['sandbox']['progress'] = 0;
* $context['sandbox']['current_id'] = 0;
* $context['sandbox']['max'] = \Drupal::database()
* ->query('SELECT COUNT(DISTINCT id) FROM {example}')
* ->query('SELECT COUNT(DISTINCT [id]) FROM {example}')
* ->fetchField();
* }
* $limit = 5;
......
......@@ -37,7 +37,7 @@ protected function doInvalidateTags(array $tags) {
foreach ($tags as $tag) {
$this->connection->merge('cachetags')
->insertFields(['invalidations' => 1])
->expression('invalidations', 'invalidations + 1')
->expression('invalidations', '[invalidations] + 1')
->key('tag', $tag)
->execute();
}
......
......@@ -31,7 +31,7 @@ public function orderRandom() {
*
* @code
* $query = \Drupal::database()->select('example', 'e');
* $query->join('example_revision', 'er', 'e.vid = er.vid');
* $query->join('example_revision', 'er', '[e].[vid] = [er].[vid]');
* $query
* ->distinct()
* ->fields('e')
......
......@@ -379,7 +379,7 @@ public function addJoin($type, $table, $alias = NULL, $condition = NULL, $argume
*
* Example:
* @code
* $query->addExpression('SUBSTRING(thread, 1, (LENGTH(thread) - 1))', 'order_field');
* $query->addExpression('SUBSTRING([thread], 1, (LENGTH([thread]) - 1))', 'order_field');
* $query->orderBy('order_field', 'ASC');
* @endcode
* @param $direction
......
......@@ -550,7 +550,7 @@ protected function loadFromSharedTables(array &$values, array &$translations, $l
$all_fields = $revisioned_fields;
if ($data_fields) {
$all_fields = array_merge($revisioned_fields, $data_fields);
$query->leftJoin($this->dataTable, 'data', "(revision.$this->idKey = data.$this->idKey and revision.$this->langcodeKey = data.$this->langcodeKey)");
$query->leftJoin($this->dataTable, 'data', "([revision].[$this->idKey] = [data].[$this->idKey] AND [revision].[$this->langcodeKey] = [data].[$this->langcodeKey])");
$column_names = [];
// Some fields can have more then one columns in the data table so
// column names are needed.
......@@ -695,10 +695,10 @@ protected function buildQuery($ids, $revision_ids = FALSE) {
$query->addTag($this->entityTypeId . '_load_multiple');
if ($revision_ids) {
$query->join($this->revisionTable, 'revision', "revision.{$this->idKey} = base.{$this->idKey} AND revision.{$this->revisionKey} IN (:revisionIds[])", [':revisionIds[]' => $revision_ids]);
$query->join($this->revisionTable, 'revision', "[revision].[{$this->idKey}] = [base].[{$this->idKey}] AND [revision].[{$this->revisionKey}] IN (:revisionIds[])", [':revisionIds[]' => $revision_ids]);
}
elseif ($this->revisionTable) {
$query->join($this->revisionTable, 'revision', "revision.{$this->revisionKey} = base.{$this->revisionKey}");
$query->join($this->revisionTable, 'revision', "[revision].[{$this->revisionKey}] = [base].[{$this->revisionKey}]");
}
// Add fields from the {entity} table.
......@@ -724,7 +724,7 @@ protected function buildQuery($ids, $revision_ids = FALSE) {
// Compare revision ID of the base and revision table, if equal then this
// is the default revision.
$query->addExpression('CASE base.' . $this->revisionKey . ' WHEN revision.' . $this->revisionKey . ' THEN 1 ELSE 0 END', 'isDefaultRevision');
$query->addExpression('CASE [base].[' . $this->revisionKey . '] WHEN [revision].[' . $this->revisionKey . '] THEN 1 ELSE 0 END', 'isDefaultRevision');
}
$query->fields('base', $entity_fields);
......
......@@ -838,13 +838,13 @@ protected function getSelectQueryForFieldStorageDeletion($table_name, array $sha
// The bundle field is not stored in the revision table, so we need to
// join the data (or base) table and retrieve it from there.
if ($base_table && $base_table !== $table_name) {
$join_condition = "entity_table.{$this->entityType->getKey('id')} = %alias.{$this->entityType->getKey('id')}";
$join_condition = "[entity_table].[{$this->entityType->getKey('id')}] = [%alias].[{$this->entityType->getKey('id')}]";
// If the entity type is translatable, we also need to add the langcode
// to the join, otherwise we'll get duplicate rows for each language.
if ($this->entityType->isTranslatable()) {
$langcode = $this->entityType->getKey('langcode');
$join_condition .= " AND entity_table.{$langcode} = %alias.{$langcode}";
$join_condition .= " AND [entity_table].[{$langcode}] = [%alias].[{$langcode}]";
}
$select->join($base_table, 'base_table', $join_condition);
......
......@@ -555,7 +555,7 @@ protected function moveChildren($fields, $original) {
$query->expression($expression[0], $expression[1], $expression[2]);
}
$query->expression('depth', 'depth + :depth', [':depth' => $shift]);
$query->expression('depth', '[depth] + :depth', [':depth' => $shift]);
$query->condition('menu_name', $original['menu_name']);
for ($i = 1; $i <= $this->maxDepth() && $original["p$i"]; $i++) {
......
......@@ -257,13 +257,13 @@ public static function lastTestGet($test_id) {
$max_message_id_subquery = $connection
->select('simpletest', 'sub')
->condition('test_id', $test_id);
$max_message_id_subquery->addExpression('MAX(message_id)', 'max_message_id');
$max_message_id_subquery->addExpression('MAX([message_id])', 'max_message_id');
// Run a select query to return 'last_prefix' from {simpletest_test_id} and
// 'test_class' from {simpletest}.
$select = $connection->select($max_message_id_subquery, 'st_sub');
$select->join('simpletest', 'st', 'st.message_id = st_sub.max_message_id');
$select->join('simpletest_test_id', 'sttid', 'st.test_id = sttid.test_id');
$select->join('simpletest', 'st', '[st].[message_id] = [st_sub].[max_message_id]');
$select->join('simpletest_test_id', 'sttid', '[st].[test_id] = [sttid].[test_id]');
$select->addField('sttid', 'last_prefix');
$select->addField('st', 'test_class');
return $select->execute()->fetchAssoc();
......
......@@ -16,7 +16,7 @@ class FeedStorage extends SqlContentEntityStorage implements FeedStorageInterfac
* {@inheritdoc}
*/
public function getFeedIdsToRefresh() {
return $this->database->query('SELECT fid FROM {' . $this->getBaseTable() . '} WHERE queued = 0 AND checked + refresh < :time AND refresh <> :never', [
return $this->database->query('SELECT [fid] FROM {' . $this->getBaseTable() . '} WHERE [queued] = 0 AND [checked] + [refresh] < :time AND [refresh] <> :never', [
':time' => REQUEST_TIME,
':never' => static::CLEAR_NEVER,
])->fetchCol();
......
......@@ -30,7 +30,7 @@ public function __construct(Connection $connection) {
* {@inheritdoc}
*/
public function isBanned($ip) {
return (bool) $this->connection->query("SELECT * FROM {ban_ip} WHERE ip = :ip", [':ip' => $ip])->fetchField();
return (bool) $this->connection->query("SELECT * FROM {ban_ip} WHERE [ip] = :ip", [':ip' => $ip])->fetchField();
}
/**
......@@ -63,7 +63,7 @@ public function unbanIp($id) {
* {@inheritdoc}
*/
public function findById($ban_id) {
return $this->connection->query("SELECT ip FROM {ban_ip} WHERE iid = :iid", [':iid' => $ban_id])->fetchField();
return $this->connection->query("SELECT [ip] FROM {ban_ip} WHERE [iid] = :iid", [':iid' => $ban_id])->fetchField();
}
}
......@@ -120,7 +120,7 @@ public function prepareRow(Row $row) {
->fields('br', ['rid'])
->condition('module', $module)
->condition('delta', $delta);
$query->join($this->userRoleTable, 'ur', 'br.rid = ur.rid');
$query->join($this->userRoleTable, 'ur', '[br].[rid] = [ur].[rid]');
$roles = $query->execute()
->fetchCol();
$row->setSourceProperty('roles', $roles);
......
......@@ -27,7 +27,7 @@ public function query() {
$query = $this->select('i18n_blocks', 'i18n')
->fields('i18n')
->fields('b', ['bid', 'module', 'delta', 'theme', 'title']);
$query->innerJoin($this->blockTable, 'b', ('b.module = i18n.module AND b.delta = i18n.delta'));
$query->innerJoin($this->blockTable, 'b', ('[b].[module] = [i18n].[module] AND [b].[delta] = [i18n].[delta]'));
return $query;
}
......
......@@ -47,8 +47,8 @@ public function query() {
'plural',
])
->condition('i18n_mode', 1);
$query->leftjoin($this->blockTable, 'b', ('b.delta = i18n.objectid'));
$query->innerJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->leftjoin($this->blockTable, 'b', ('[b].[delta] = [i18n].[objectid]'));
$query->innerJoin('locales_target', 'lt', '[lt].[lid] = [i18n].[lid]');
// The i18n_string module adds a status column to locale_target. It was
// originally 'status' in a later revision it was named 'i18n_status'.
......
......@@ -44,11 +44,11 @@ public function query() {
// Add in the property, which is either title or body. Cast the bid to text
// so PostgreSQL can make the join.
$query->leftJoin(static::I18N_STRING_TABLE, 'i18n', 'i18n.objectid = CAST(b.bid AS CHAR(255))');
$query->leftJoin(static::I18N_STRING_TABLE, 'i18n', '[i18n].[objectid] = CAST([b].[bid] AS CHAR(255))');
$query->condition('i18n.type', 'block');
// Add in the translation for the property.
$query->innerJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->innerJoin('locales_target', 'lt', '[lt].[lid] = [i18n].[lid]');
return $query;
}
......
......@@ -27,7 +27,7 @@ public function __construct(Connection $connection) {
* {@inheritdoc}
*/
public function getBooks() {
return $this->connection->query("SELECT DISTINCT(bid) FROM {book}")->fetchCol();
return $this->connection->query("SELECT DISTINCT([bid]) FROM {book}")->fetchCol();
}
/**
......@@ -35,7 +35,7 @@ public function getBooks() {
*/
public function hasBooks() {
return (bool) $this->connection
->query('SELECT count(bid) FROM {book}')
->query('SELECT count([bid]) FROM {book}')
->fetchField();
}
......@@ -89,7 +89,7 @@ public function delete($nid) {
*/
public function loadBookChildren($pid) {
return $this->connection
->query("SELECT * FROM {book} WHERE pid = :pid", [':pid' => $pid])
->query("SELECT * FROM {book} WHERE [pid] = :pid", [':pid' => $pid])
->fetchAllAssoc('nid', \PDO::FETCH_ASSOC);
}
......@@ -160,7 +160,7 @@ public function updateMovedChildren($bid, $original, $expressions, $shift) {
$query->expression($expression[0], $expression[1], $expression[2]);
}
$query->expression('depth', 'depth + :depth', [':depth' => $shift]);
$query->expression('depth', '[depth] + :depth', [':depth' => $shift]);
$query->condition('bid', $original['bid']);
$p = 'p1';
for ($i = 1; !empty($original[$p]); $p = 'p' . ++$i) {
......
......@@ -19,7 +19,7 @@ class Book extends DrupalSqlBase {
*/
public function query() {
$query = $this->select('book', 'b')->fields('b', ['nid', 'bid']);
$query->join('menu_links', 'ml', 'b.mlid = ml.mlid');
$query->join('menu_links', 'ml', '[b].[mlid] = [ml].[mlid]');
$ml_fields = ['mlid', 'plid', 'weight', 'has_children', 'depth'];
foreach (range(1, 9) as $i) {
$field = "p$i";
......
......@@ -154,7 +154,7 @@ public function create(FieldableEntityInterface $entity, $fields) {
* {@inheritdoc}
*/
public function getMaximumCount($entity_type) {
return $this->database->query('SELECT MAX(comment_count) FROM {comment_entity_statistics} WHERE entity_type = :entity_type', [':entity_type' => $entity_type])->fetchField();
return $this->database->query('SELECT MAX([comment_count]) FROM {comment_entity_statistics} WHERE [entity_type] = :entity_type', [':entity_type' => $entity_type])->fetchField();
}
/**
......@@ -195,7 +195,7 @@ public function update(CommentInterface $comment) {
}
$query = $this->database->select('comment_field_data', 'c');
$query->addExpression('COUNT(cid)');
$query->addExpression('COUNT([cid])');
$count = $query->condition('c.entity_id', $comment->getCommentedEntityId())
->condition('c.entity_type', $comment->getCommentedEntityTypeId())
->condition('c.field_name', $comment->getFieldName())
......
......@@ -84,7 +84,7 @@ public function getMaxThread(CommentInterface $comment) {
->condition('field_name', $comment->getFieldName())
->condition('entity_type', $comment->getCommentedEntityTypeId())
->condition('default_langcode', 1);
$query->addExpression('MAX(thread)', 'thread');
$query->addExpression('MAX([thread])', 'thread');
return $query->execute()
->fetchField();
}
......@@ -99,7 +99,7 @@ public function getMaxThreadPerThread(CommentInterface $comment) {
->condition('entity_type', $comment->getCommentedEntityTypeId())
->condition('thread', $comment->getParentComment()->getThread() . '.%', 'LIKE')
->condition('default_langcode', 1);
$query->addExpression('MAX(thread)', 'thread');
$query->addExpression('MAX([thread])', 'thread');
return $query->execute()
->fetchField();
}
......@@ -112,7 +112,7 @@ public function getDisplayOrdinal(CommentInterface $comment, $comment_mode, $div
// This is the 0-based display ordinal.
$data_table = $this->getDataTable();
$query = $this->database->select($data_table, 'c1');
$query->innerJoin($data_table, 'c2', 'c2.entity_id = c1.entity_id AND c2.entity_type = c1.entity_type AND c2.field_name = c1.field_name');
$query->innerJoin($data_table, 'c2', '[c2].[entity_id] = [c1].[entity_id] AND [c2].[entity_type] = [c1].[entity_type] AND [c2].[field_name] = [c1].[field_name]');
$query->addExpression('COUNT(*)', 'count');
$query->condition('c2.cid', $comment->id());
if (!$this->currentUser->hasPermission('administer comments')) {
......@@ -129,7 +129,7 @@ public function getDisplayOrdinal(CommentInterface $comment, $comment_mode, $div
// For threaded comments, the c.thread column is used for ordering. We can
// use the sorting code for comparison, but must remove the trailing
// slash.
$query->where('SUBSTRING(c1.thread, 1, (LENGTH(c1.thread) - 1)) < SUBSTRING(c2.thread, 1, (LENGTH(c2.thread) - 1))');
$query->where('SUBSTRING([c1].[thread], 1, (LENGTH([c1].[thread]) - 1)) < SUBSTRING([c2].[thread], 1, (LENGTH([c2].[thread]) - 1))');
}
$query->condition('c1.default_langcode', 1);
......@@ -173,7 +173,7 @@ public function getNewCommentPageNumber($total_comments, $new_comments, Fieldabl
// 2. Find the first thread.
$first_thread_query = $this->database->select($unread_threads_query, 'thread');
$first_thread_query->addExpression('SUBSTRING(thread, 1, (LENGTH(thread) - 1))', 'torder');
$first_thread_query->addExpression('SUBSTRING([thread], 1, (LENGTH([thread]) - 1))', 'torder');
$first_thread = $first_thread_query
->fields('thread', ['thread'])
->orderBy('torder')
......@@ -185,12 +185,12 @@ public function getNewCommentPageNumber($total_comments, $new_comments, Fieldabl
$first_thread = substr($first_thread, 0, -1);
// Find the number of the first comment of the first unread thread.
$count = $this->database->query('SELECT COUNT(*) FROM {' . $data_table . '} WHERE entity_id = :entity_id
AND entity_type = :entity_type
AND field_name = :field_name
AND status = :status
AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread
AND default_langcode = 1', [
$count = $this->database->query('SELECT COUNT(*) FROM {' . $data_table . '} WHERE [entity_id] = :entity_id
AND [entity_type] = :entity_type
AND [field_name] = :field_name
AND [status] = :status
AND SUBSTRING([thread], 1, (LENGTH([thread]) - 1)) < :thread
AND [default_langcode] = 1', [
':status' => CommentInterface::PUBLISHED,
':entity_id' => $entity->id(),
':field_name' => $field_name,
......@@ -321,7 +321,7 @@ public function loadThread(EntityInterface $entity, $field_name, $mode, $comment
// See comment above. Analysis reveals that this doesn't cost too
// much. It scales much much better than having the whole comment
// structure.
$query->addExpression('SUBSTRING(c.thread, 1, (LENGTH(c.thread) - 1))', 'torder');
$query->addExpression('SUBSTRING([c].[thread], 1, (LENGTH([c].[thread]) - 1))', 'torder');
$query->orderBy('torder', 'ASC');
}
......
......@@ -73,13 +73,13 @@ public function entityQueryAlter(SelectInterface $query) {
if (!isset($tables['comment_field_data']['alias'])) {
// If no conditions join against the comment data table, it should be
// joined manually to allow node access processing.
$query->innerJoin($data_table, NULL, "base_table.cid = $data_table.cid AND $data_table.default_langcode = 1");
$query->innerJoin($data_table, NULL, "[base_table].[cid] = [$data_table].[cid] AND [$data_table].[default_langcode] = 1");
}
// The Comment module doesn't implement any proper comment access,
// and as a consequence doesn't make sure that comments cannot be viewed
// when the user doesn't have access to the node.
$node_alias = $query->innerJoin('node_field_data', 'n', '%alias.nid = ' . $data_table . '.entity_id AND ' . $data_table . ".entity_type = 'node'");
$node_alias = $query->innerJoin('node_field_data', 'n', "[%alias].[nid] = [$data_table].[entity_id] AND [$data_table].[entity_type] = 'node'");
// Pass the query to the node access control.
$this->reAlterQuery($query, 'node_access', $node_alias);
......
......@@ -24,7 +24,7 @@ public function query() {
'comment', 'hostname', 'timestamp', 'status', 'thread', 'name',
'mail', 'homepage', 'format',
]);
$query->innerJoin('node', 'n', 'c.nid = n.nid');
$query->innerJoin('node', 'n', '[c].[nid] = [n].[nid]');
$query->fields('n', ['type', 'language']);
$query->orderBy('c.timestamp');
return $query;
......
......@@ -20,7 +20,7 @@ class Comment extends FieldableEntity {
*/
public function query() {
$query = $this->select('comment', 'c')->fields('c');
$query->innerJoin('node', 'n', 'c.nid = n.nid');
$query->innerJoin('node', 'n', '[c].[nid] = [n].[nid]');
$query->addField('n', 'type', 'node_type');
$query->orderBy('c.created');
return $query;
......
......@@ -27,8 +27,8 @@ public function query() {
->condition('et.entity_type', 'comment')
->condition('et.source', '', '<>');
$query->innerJoin('comment', 'c', 'c.cid = et.entity_id');
$query->innerJoin('node', 'n', 'n.nid = c.nid');
$query->innerJoin('comment', 'c', '[c].[cid] = [et].[entity_id]');
$query->innerJoin('node', 'n', '[n].[nid] = [c].[nid]');
$query->addField('n', 'type', 'node_type');
......
......@@ -53,7 +53,7 @@ public function title() {
$title = \Drupal::config('user.settings')->get('anonymous');
}
else {
$title = $this->database->query('SELECT name FROM {users_field_data} WHERE uid = :uid AND default_langcode = 1', [':uid' => $this->argument])->fetchField();
$title = $this->database->query('SELECT [name] FROM {users_field_data} WHERE [uid] = :uid AND [default_langcode] = 1', [':uid' => $this->argument])->fetchField();
}
if (empty($title)) {
return $this->t('No user');
......@@ -87,7 +87,7 @@ public function query($group_by = FALSE) {
$entity_id = $this->definition['entity_id'];
$entity_type = $this->definition['entity_type'];
$subselect->where("c.entity_id = $this->tableAlias.$entity_id");
$subselect->where("[c].[entity_id] = [$this->tableAlias].[$entity_id]");
$subselect->condition('c.entity_type', $entity_type);
$condition = ($this->view->query->getConnection()->condition('OR'))
......
......@@ -155,9 +155,9 @@ public function preRender(&$values) {
}
if ($nids) {
$result = $this->database->query("SELECT n.nid, COUNT(c.cid) AS num_comments FROM {node} n INNER JOIN {comment_field_data} c ON n.nid = c.entity_id AND c.entity_type = 'node' AND c.default_langcode = 1
LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = :h_uid WHERE n.nid IN ( :nids[] )
AND c.changed > GREATEST(COALESCE(h.timestamp, :timestamp1), :timestamp2) AND c.status = :status GROUP BY n.nid", [
$result = $this->database->query("SELECT [n].[nid], COUNT([c].[cid]) AS [num_comments] FROM {node} [n] INNER JOIN {comment_field_data} [c] ON [n].[nid] = [c].[entity_id] AND [c].[entity_type] = 'node' AND [c].[default_langcode] = 1
LEFT JOIN {history} [h] ON [h].[nid] = [n].[nid] AND [h].[uid] = :h_uid WHERE [n].[nid] IN ( :nids[] )
AND [c].[changed] > GREATEST(COALESCE([h].[timestamp], :timestamp1), :timestamp2) AND [c].[status] = :status GROUP BY [n].[nid]", [
':status' => CommentInterface::PUBLISHED,
':h_uid' => $user->id(),
':nids[]' => $nids,
......
......@@ -24,7 +24,7 @@ public function query() {
$entity_id = $this->definition['entity_id'];
$entity_type = $this->definition['entity_type'];
$subselect->where("c.entity_id = $this->tableAlias.$entity_id");
$subselect->where("[c].[entity_id] = [$this->tableAlias].[$entity_id]");
$subselect->condition('c.entity_type', $entity_type);
$condition = ($this->view->query->getConnection()->condition('OR'))
......
......@@ -21,8 +21,8 @@ public function query() {
$query = parent::query();
$query->fields('i18n', ['property'])
->fields('lt', ['lid', 'translation', 'language']);
$query->leftJoin('i18n_strings', 'i18n', 'i18n.objectid = pf.name');
$query->innerJoin('locales_target', 'lt', 'lt.lid = i18n.lid');
$query->leftJoin('i18n_strings', 'i18n', '[i18n].[objectid] = [pf].[name]');
$query->innerJoin('locales_target', 'lt', '[lt].[lid] = [i18n].[lid]');
return $query;
}
......
......@@ -71,7 +71,7 @@ protected function getPropertyNotInRowTranslation(Row $row, $property_not_in_row
->fields('i18n', ['lid'])
->condition('i18n.property', $property_not_in_row)
->condition('i18n.objectid', $object_id);
$query->leftJoin('locales_target', 'lt', 'i18n.lid = lt.lid');
$query->leftJoin('locales_target', 'lt', '[i18n].[lid] = [lt].[lid]');
$query->condition('lt.language', $language);
$query->addField('lt', 'translation');
$results = $query->execute()->fetchAssoc();
......
......@@ -90,7 +90,7 @@ function dblog_cron() {
* List of uniquely defined database log message types.
*/
function _dblog_get_message_types() {
return \Drupal::database()->query('SELECT DISTINCT(type) FROM {watchdog} ORDER BY type')
return \Drupal::database()->query('SELECT DISTINCT([type]) FROM {watchdog} ORDER BY [type]')
->fetchAllKeyed(0, 0);
}
......
......@@ -173,7 +173,7 @@ public function overview() {
'variables',
'link',
]);
$query->leftJoin('users_field_data', 'ufd', 'w.uid = ufd.uid');
$query->leftJoin('users_field_data', 'ufd', '[w].[uid] = [ufd].[uid]');
if (!empty($filter['where'])) {
$query->where($filter['where'], $filter['args']);
......@@ -248,7 +248,7 @@ public function overview() {
* If no event found for the given ID.
*/
public function eventDetails($event_id) {
$dblog = $this->database->query('SELECT w.*, u.uid FROM {watchdog} w LEFT JOIN {users} u ON u.uid = w.uid WHERE w.wid = :id', [':id' => $event_id])->fetchObject();
$dblog = $this->database->query('SELECT [w].*, [u].[uid] FROM {watchdog} [w] LEFT JOIN {users} [u] ON [u].[uid] = [w].[uid] WHERE [w].[wid] = :id', [':id' => $event_id])->fetchObject();
if (empty($dblog)) {
throw new NotFoundHttpException();
......@@ -423,13 +423,13 @@ public function topLogMessages($type) {
];
$count_query = $this->database->select('watchdog');
$count_query->addExpression('COUNT(DISTINCT(message))');
$count_query->addExpression('COUNT(DISTINCT([message]))');
$count_query->condition('type', $type);
$query = $this->database->select('watchdog', 'w')
->extend('\Drupal\Core\Database\Query\PagerSelectExtender')
->extend('\Drupal\Core\Database\Query\TableSortExtender');
$query->addExpression('COUNT(wid)', 'count');
$query->addExpression('COUNT([wid])', 'count');
$query = $query
->fields('w', ['message', 'variables'])
->condition('w.type', $type)
......
......@@ -39,7 +39,7 @@ class DBLogResource extends ResourceBase {
*/
public function get($id = NULL) {
if ($id) {
$record = Database::getConnection()->query("SELECT * FROM {watchdog} WHERE wid = :wid", [':wid' => $id])
$record = Database::getConnection()->query("SELECT * FROM {watchdog} WHERE [wid] = :wid", [':wid' => $id])
->fetchAssoc();
if (!empty($record)) {
return new ResourceResponse($record);
......
......@@ -124,7 +124,7 @@ public function testLogEventPage() {
];
\Drupal::service('logger.dblog')->log(RfcLogLevel::NOTICE, 'Test message', $context);
$query = Database::getConnection()->select('watchdog');
$query->addExpression('MAX(wid)');
$query->addExpression('MAX([wid])');
$wid = $query->execute()->fetchField();
// Verify the links appear correctly.
......@@ -157,7 +157,7 @@ public function test403LogEventPage() {
$query = Database::getConnection()->select('watchdog')
->condition('type', 'access denied');
$query->addExpression('MAX(wid)');
$query->addExpression('MAX([wid])');
$wid = $query->execute()->fetchField();
$this->drupalGet('admin/reports/dblog/event/' . $wid);
......@@ -214,7 +214,7 @@ public function testLogEventPageWithMissingInfo() {
'referer' => NULL,
]);
$query = $connection->select('watchdog');
$query->addExpression('MAX(wid)');
$query->addExpression('MAX([wid])');
$wid = $query->execute()->fetchField();
$this->drupalGet('admin/reports/dblog/event/' . $wid);
......@@ -230,7 +230,7 @@ public function testLogEventPageWithMissingInfo() {
'request_uri' => $request_uri,
]);
$query = $connection->select('watchdog');
$query->addExpression('MAX(wid)');
$query->addExpression('MAX([wid])');
$wid = $query->execute()->fetchField();
$this->drupalGet('admin/reports/dblog/event/' . $wid);
......@@ -332,7 +332,7 @@ private function verifyReports($response = 200) {
// View the database log event page.
$query = Database::getConnection()->select('watchdog');
$query->addExpression('MIN(wid)');
$query->addExpression('MIN([wid])');
$wid = $query->execute()->fetchField();
$this->drupalGet('admin/reports/dblog/event/' . $wid);
$this->assertSession()->statusCodeEquals($response);
......@@ -347,7 +347,7 @@ private function verifyReports($response = 200) {
private function verifyBreadcrumbs() {
// View the database log event page.
$query = Database::getConnection()->select('watchdog');
$query->addExpression('MIN(wid)');
$query->addExpression('MIN([wid])');
$wid = $query->execute()->fetchField();
$this->drupalGet('admin/reports/dblog/event/' . $wid);
$xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a';
......@@ -817,7 +817,7 @@ public function testTemporaryUser() {
// Generate a single watchdog entry.