r85888 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85887‎ | r85888 | r85889 >
Date:17:00, 12 April 2011
Author:platonides
Status:resolved (Comments)
Tags:
Comment:
Add parameter to tableName() to get the bare table name.
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/Database.php
@@ -1513,9 +1513,11 @@
15141514 * when calling query() directly.
15151515 *
15161516 * @param $name String: database table name
 1517+ * @param $quoted Boolean: Automatically pass the table name through
 1518+ * addIdentifierQuotes() so that it can be used in a query.
15171519 * @return String: full database name
15181520 */
1519 - function tableName( $name ) {
 1521+ function tableName( $name, $quoted = true ) {
15201522 global $wgSharedDB, $wgSharedPrefix, $wgSharedTables;
15211523 # Skip the entire process when we have a string quoted on both ends.
15221524 # Note that we check the end so that we will still quote any use of
@@ -1561,10 +1563,10 @@
15621564
15631565 # Quote the $database and $table and apply the prefix if not quoted.
15641566 if ( isset( $database ) ) {
1565 - $database = ( $this->isQuotedIdentifier( $database ) ? $database : $this->addIdentifierQuotes( $database ) );
 1567+ $database = ( !$quoted || $this->isQuotedIdentifier( $database ) ? $database : $this->addIdentifierQuotes( $database ) );
15661568 $prefix = '';
15671569 }
1568 - $table = ( $this->isQuotedIdentifier( $table ) ? $table : $this->addIdentifierQuotes( "{$prefix}{$table}" ) );
 1570+ $table = ( !$quoted || $this->isQuotedIdentifier( $table ) ? $table : $this->addIdentifierQuotes( "{$prefix}{$table}" ) );
15691571
15701572 # Merge our database and table into our final table name.
15711573 $tableName = ( isset( $database ) ? "{$database}.{$table}" : "{$table}" );

Follow-up revisions

RevisionCommit summaryAuthorDate
r85905Follow up r85888platonides18:52, 12 April 2011
r85907Follow up r85888: Add the parameter to DatabasePostgres.php and DatabaseOracl...platonides18:59, 12 April 2011
r96369Fixme on r85888: boolean params are evil, use a nice simple string instead :)demon20:44, 6 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85884Abstract tableName() by adding new function isQuotedIdentifier() to databases....platonides16:34, 12 April 2011

Comments

#Comment by Krinkle (talk | contribs)   17:14, 12 April 2011
(2 lines skipped) [12-Apr-2011 17:13:49] PHP Strict Standards:  Declaration of DatabaseSqlite::tableName() should be compatible with that of DatabaseBase::tableName() in /www/w/includes/AutoLoader.php on line 843

The argument is not added to DatabaseSqlite::tableName(). Perhaps others as well

#Comment by Platonides (talk | contribs)   18:59, 12 April 2011

Sqlite done in r85906.

DatabaseMssql.php, DatabasePostgres.php and DatabaseOracle.php in r85907.

#Comment by Brion VIBBER (talk | contribs)   23:04, 21 June 2011

Rather than a bare boolean parameter (what does $db->tableName('foo', true) mean in context? I'm getting the table name for 'foo' with....... some kind of option that does..... what?) please use symbolic class constants for the values, eg: $db->tableName('foo', Database::QUOTED_NAME) vs $db->tableName('foo', Database::RAW_NAME) or something.

Status & tagging log