Skip to content

Commit ccaf94b

Browse files
KurantjeReLater
andauthored
Update Table.php (#39489)
* Update Table.php Query requires back-quoted table name to acommodate for table names with special characters. * quoteName in methods checkIn(), checkOut() See #39489 (comment) * quoteName in all mysql table references Legal table names with special characters throw exceptions. QuoteName each query avoids fixes this Co-authored-by: ReLater <[email protected]>
1 parent 778ca2e commit ccaf94b

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

libraries/src/Table/Table.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ public function load($keys = null, $reset = true)
731731
// Initialise the query.
732732
$query = $this->_db->getQuery(true)
733733
->select('*')
734-
->from($this->_tbl);
734+
->from($this->_db->quoteName($this->_tbl));
735735
$fields = array_keys($this->getProperties());
736736

737737
foreach ($keys as $field => $value) {
@@ -1038,7 +1038,7 @@ public function delete($pk = null)
10381038

10391039
// Delete the row by primary key.
10401040
$query = $this->_db->getQuery(true)
1041-
->delete($this->_tbl);
1041+
->delete($this->_db->quoteName($this->_tbl));
10421042
$this->appendPrimaryKeys($query, $pk);
10431043

10441044
$this->_db->setQuery($query);
@@ -1119,7 +1119,7 @@ public function checkOut($userId, $pk = null)
11191119

11201120
// Check the row out by primary key.
11211121
$query = $this->_db->getQuery(true)
1122-
->update($this->_tbl)
1122+
->update($this->_db->quoteName($this->_tbl))
11231123
->set($this->_db->quoteName($checkedOutField) . ' = ' . (int) $userId)
11241124
->set($this->_db->quoteName($checkedOutTimeField) . ' = ' . $this->_db->quote($time));
11251125
$this->appendPrimaryKeys($query, $pk);
@@ -1200,7 +1200,7 @@ public function checkIn($pk = null)
12001200

12011201
// Check the row in by primary key.
12021202
$query = $this->_db->getQuery(true)
1203-
->update($this->_tbl)
1203+
->update($this->_db->quoteName($this->_tbl))
12041204
->set($this->_db->quoteName($checkedOutField) . ' = ' . $nullID)
12051205
->set($this->_db->quoteName($checkedOutTimeField) . ' = ' . $nullDate);
12061206
$this->appendPrimaryKeys($query, $pk);
@@ -1246,7 +1246,7 @@ public function hasPrimaryKey()
12461246
} else {
12471247
$query = $this->_db->getQuery(true)
12481248
->select('COUNT(*)')
1249-
->from($this->_tbl);
1249+
->from($this->_db->quoteName($this->_tbl));
12501250
$this->appendPrimaryKeys($query);
12511251

12521252
$this->_db->setQuery($query);
@@ -1312,7 +1312,7 @@ public function hit($pk = null)
13121312

13131313
// Check the row in by primary key.
13141314
$query = $this->_db->getQuery(true)
1315-
->update($this->_tbl)
1315+
->update($this->_db->quoteName($this->_tbl))
13161316
->set($this->_db->quoteName($hitsField) . ' = (' . $this->_db->quoteName($hitsField) . ' + 1)');
13171317
$this->appendPrimaryKeys($query, $pk);
13181318
$this->_db->setQuery($query);
@@ -1399,7 +1399,7 @@ public function getNextOrder($where = '')
13991399
// Get the largest ordering value for a given where clause.
14001400
$query = $this->_db->getQuery(true)
14011401
->select('MAX(' . $this->_db->quoteName($this->getColumnAlias('ordering')) . ')')
1402-
->from($this->_tbl);
1402+
->from($this->_db->quoteName($this->_tbl));
14031403

14041404
if ($where) {
14051405
$query->where($where);
@@ -1454,11 +1454,11 @@ public function reorder($where = '')
14541454
$quotedOrderingField = $this->_db->quoteName($this->getColumnAlias('ordering'));
14551455

14561456
$subquery = $this->_db->getQuery(true)
1457-
->from($this->_tbl)
1457+
->from($this->_db->quoteName($this->_tbl))
14581458
->selectRowNumber($quotedOrderingField, 'new_ordering');
14591459

14601460
$query = $this->_db->getQuery(true)
1461-
->update($this->_tbl)
1461+
->update($this->_db->quoteName($this->_tbl))
14621462
->set($quotedOrderingField . ' = sq.new_ordering');
14631463

14641464
$innerOn = array();
@@ -1543,7 +1543,7 @@ public function move($delta, $where = '')
15431543

15441544
// Select the primary key and ordering values from the table.
15451545
$query->select(implode(',', $this->_tbl_keys) . ', ' . $quotedOrderingField)
1546-
->from($this->_tbl);
1546+
->from($this->_db->quoteName($this->_tbl));
15471547

15481548
// If the movement delta is negative move the row up.
15491549
if ($delta < 0) {
@@ -1581,15 +1581,15 @@ public function move($delta, $where = '')
15811581
if (!empty($row)) {
15821582
// Update the ordering field for this instance to the row's ordering value.
15831583
$query->clear()
1584-
->update($this->_tbl)
1584+
->update($this->_db->quoteName($this->_tbl))
15851585
->set($quotedOrderingField . ' = ' . (int) $row->$orderingField);
15861586
$this->appendPrimaryKeys($query);
15871587
$this->_db->setQuery($query);
15881588
$this->_db->execute();
15891589

15901590
// Update the ordering field for the row to this instance's ordering value.
15911591
$query->clear()
1592-
->update($this->_tbl)
1592+
->update($this->_db->quoteName($this->_tbl))
15931593
->set($quotedOrderingField . ' = ' . (int) $this->$orderingField);
15941594
$this->appendPrimaryKeys($query, $row);
15951595
$this->_db->setQuery($query);
@@ -1600,7 +1600,7 @@ public function move($delta, $where = '')
16001600
} else {
16011601
// Update the ordering field for this instance.
16021602
$query->clear()
1603-
->update($this->_tbl)
1603+
->update($this->_db->quoteName($this->_tbl))
16041604
->set($quotedOrderingField . ' = ' . (int) $this->$orderingField);
16051605
$this->appendPrimaryKeys($query);
16061606
$this->_db->setQuery($query);
@@ -1689,7 +1689,7 @@ public function publish($pks = null, $state = 1, $userId = 0)
16891689
foreach ($pks as $pk) {
16901690
// Update the publishing state for rows with the given primary keys.
16911691
$query = $this->_db->getQuery(true)
1692-
->update($this->_tbl)
1692+
->update($this->_db->quoteName($this->_tbl))
16931693
->set($this->_db->quoteName($publishedField) . ' = ' . (int) $state);
16941694

16951695
// If publishing, set published date/time if not previously set

0 commit comments

Comments
 (0)