summaryrefslogtreecommitdiffstats
path: root/lib/private/db/querybuilder
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-12-09 11:09:02 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2015-12-09 11:09:02 +0100
commitbef6344b277186e37cd02a4af74f270d97435d40 (patch)
tree0c364d898210348e0fcb35f4ae14357636b08765 /lib/private/db/querybuilder
parent5c0be3b565035f173b611f82e0b7ba6bd386b2e0 (diff)
downloadnextcloud-server-bef6344b277186e37cd02a4af74f270d97435d40.tar.gz
nextcloud-server-bef6344b277186e37cd02a4af74f270d97435d40.zip
Do not quote the table name for lastInsertId()
Diffstat (limited to 'lib/private/db/querybuilder')
-rw-r--r--lib/private/db/querybuilder/querybuilder.php28
1 files changed, 22 insertions, 6 deletions
diff --git a/lib/private/db/querybuilder/querybuilder.php b/lib/private/db/querybuilder/querybuilder.php
index 741da4efc27..a4cbb5abd76 100644
--- a/lib/private/db/querybuilder/querybuilder.php
+++ b/lib/private/db/querybuilder/querybuilder.php
@@ -40,6 +40,9 @@ class QueryBuilder implements IQueryBuilder {
/** @var bool */
private $automaticTablePrefix = true;
+ /** @var string */
+ protected $lastInsertedTable;
+
/**
* Initializes a new QueryBuilder.
*
@@ -445,6 +448,8 @@ class QueryBuilder implements IQueryBuilder {
$this->getTableName($insert)
);
+ $this->lastInsertedTable = $insert;
+
return $this;
}
@@ -1051,10 +1056,10 @@ class QueryBuilder implements IQueryBuilder {
* @throws \BadMethodCallException When being called before an insert query has been run.
*/
public function getLastInsertId() {
- $from = $this->getQueryPart('from');
-
- if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && !empty($from)) {
- return (int) $this->connection->lastInsertId($from['table']);
+ if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::INSERT && $this->lastInsertedTable) {
+ // lastInsertId() needs the prefix but no quotes
+ $table = $this->prefixTableName($this->lastInsertedTable);
+ return (int) $this->connection->lastInsertId($table);
}
throw new \BadMethodCallException('Invalid call to getLastInsertId without using insert() before.');
@@ -1067,11 +1072,22 @@ class QueryBuilder implements IQueryBuilder {
* @return string
*/
public function getTableName($table) {
+ $table = $this->prefixTableName($table);
+ return $this->helper->quoteColumnName($table);
+ }
+
+ /**
+ * Returns the table name with database prefix as needed by the implementation
+ *
+ * @param string $table
+ * @return string
+ */
+ protected function prefixTableName($table) {
if ($this->automaticTablePrefix === false || strpos($table, '*PREFIX*') === 0) {
- return $this->helper->quoteColumnName($table);
+ return $table;
}
- return $this->helper->quoteColumnName('*PREFIX*' . $table);
+ return '*PREFIX*' . $table;
}
/**