Add a method to the get "to use" table and column name

remotes/origin/fix_emit_scanFiles
Joas Schilling 10 years ago
parent a3391248e4
commit 9f98849306
  1. 19
      lib/private/db/querybuilder/querybuilder.php
  2. 2
      lib/private/db/querybuilder/quotehelper.php
  3. 19
      lib/public/db/querybuilder/iquerybuilder.php
  4. 22
      tests/lib/db/querybuilder/querybuildertest.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);
}
}

@ -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;

@ -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 = '');
}

@ -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)
);
}
}

Loading…
Cancel
Save