summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@owncloud.com>2015-12-08 09:57:38 +0100
committerJoas Schilling <nickvergessen@owncloud.com>2015-12-08 11:04:28 +0100
commit9f9884930609addad3e37325731fb5406dd3aa44 (patch)
tree27adaa156fa4e393b7b91454fe6a35b58b4d577a
parenta3391248e46bbc389dc1880f7ae50aa5dade8731 (diff)
downloadnextcloud-server-9f9884930609addad3e37325731fb5406dd3aa44.tar.gz
nextcloud-server-9f9884930609addad3e37325731fb5406dd3aa44.zip
Add a method to the get "to use" table and column name
-rw-r--r--lib/private/db/querybuilder/querybuilder.php19
-rw-r--r--lib/private/db/querybuilder/quotehelper.php2
-rw-r--r--lib/public/db/querybuilder/iquerybuilder.php19
-rw-r--r--tests/lib/db/querybuilder/querybuildertest.php22
4 files changed, 59 insertions, 3 deletions
diff --git a/lib/private/db/querybuilder/querybuilder.php b/lib/private/db/querybuilder/querybuilder.php
index b874f5c9911..741da4efc27 100644
--- a/lib/private/db/querybuilder/querybuilder.php
+++ b/lib/private/db/querybuilder/querybuilder.php
@@ -1061,14 +1061,31 @@ class QueryBuilder implements IQueryBuilder {
}
/**
+ * Returns the table name quoted and with database prefix as needed by the implementation
+ *
* @param string $table
* @return string
*/
- private function getTableName($table) {
+ public function getTableName($table) {
if ($this->automaticTablePrefix === false || strpos($table, '*PREFIX*') === 0) {
return $this->helper->quoteColumnName($table);
}
return $this->helper->quoteColumnName('*PREFIX*' . $table);
}
+
+ /**
+ * Returns the column name quoted and with table alias prefix as needed by the implementation
+ *
+ * @param string $column
+ * @param string $tableAlias
+ * @return string
+ */
+ public function getColumnName($column, $tableAlias = '') {
+ if ($tableAlias !== '') {
+ $tableAlias .= '.';
+ }
+
+ return $this->helper->quoteColumnName($tableAlias . $column);
+ }
}
diff --git a/lib/private/db/querybuilder/quotehelper.php b/lib/private/db/querybuilder/quotehelper.php
index 4b62fee6a6c..5ceb76bbf93 100644
--- a/lib/private/db/querybuilder/quotehelper.php
+++ b/lib/private/db/querybuilder/quotehelper.php
@@ -61,7 +61,7 @@ class QuoteHelper {
}
if (substr_count($string, '.')) {
- list($alias, $columnName) = explode('.', $string);
+ list($alias, $columnName) = explode('.', $string, 2);
if ($columnName === '*') {
return $string;
diff --git a/lib/public/db/querybuilder/iquerybuilder.php b/lib/public/db/querybuilder/iquerybuilder.php
index 1ff1077d53f..dd3ee7da5f5 100644
--- a/lib/public/db/querybuilder/iquerybuilder.php
+++ b/lib/public/db/querybuilder/iquerybuilder.php
@@ -820,4 +820,23 @@ interface IQueryBuilder {
* @since 9.0.0
*/
public function getLastInsertId();
+
+ /**
+ * Returns the table name quoted and with database prefix as needed by the implementation
+ *
+ * @param string $table
+ * @return string
+ * @since 9.0.0
+ */
+ public function getTableName($table);
+
+ /**
+ * Returns the column name quoted and with table alias prefix as needed by the implementation
+ *
+ * @param string $column
+ * @param string $tableAlias
+ * @return string
+ * @since 9.0.0
+ */
+ public function getColumnName($column, $tableAlias = '');
}
diff --git a/tests/lib/db/querybuilder/querybuildertest.php b/tests/lib/db/querybuilder/querybuildertest.php
index b52fbd7c283..c8e029d9e40 100644
--- a/tests/lib/db/querybuilder/querybuildertest.php
+++ b/tests/lib/db/querybuilder/querybuildertest.php
@@ -1165,7 +1165,27 @@ class QueryBuilderTest extends \Test\TestCase {
$this->assertSame(
$expected,
- $this->invokePrivate($this->queryBuilder, 'getTableName', [$tableName])
+ $this->queryBuilder->getTableName($tableName)
+ );
+ }
+
+ public function dataGetColumnName() {
+ return [
+ ['column', '', '`column`'],
+ ['column', 'a', 'a.`column`'],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetColumnName
+ * @param string $column
+ * @param string $prefix
+ * @param string $expected
+ */
+ public function testGetColumnName($column, $prefix, $expected) {
+ $this->assertSame(
+ $expected,
+ $this->queryBuilder->getColumnName($column, $prefix)
);
}
}