From 692ad26f682ae09805c0aafdbb86faafab555c72 Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Sat, 4 Dec 2010 15:14:08 +0000 Subject: [PATCH] Followup to r77713, rename quote_ident to addIdentifierQuotes to follow naming conventions better. While I'm at it adding a missing addIdentifierQuotes implementation for Ibm_db2. --- includes/db/Database.php | 17 ++++++++++++++--- includes/db/DatabaseIbm_db2.php | 4 ++++ includes/db/DatabaseMssql.php | 8 ++++---- includes/db/DatabaseOracle.php | 2 +- includes/db/DatabasePostgres.php | 18 +++++++++--------- includes/db/DatabaseSqlite.php | 2 +- includes/installer/PostgresInstaller.php | 2 +- 7 files changed, 34 insertions(+), 19 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index e74d06efa6..7248bb9985 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1699,10 +1699,21 @@ abstract class DatabaseBase implements DatabaseType { * names, other databases which use something other than backticks can replace * this with something else */ - function quote_ident( $s ) { + public function addIdentifierQuotes( $s ) { return "`" . $this->strencode( $s ) . "`"; } + /** + * Backwards compatibility, identifier quoting originated in DatabasePostgres + * which used quote_ident which does not follow our naming conventions + * was renamed to addIdentifierQuotes. + * @deprecated use addIdentifierQuotes + */ + function quote_ident( $s ) { + wfDeprecated( __METHOD__ ); + return $this->addIdentifierQuotes( $s ); + } + /** * Escape string for safe LIKE usage. * WARNING: you should almost never use this function directly, @@ -2516,7 +2527,7 @@ abstract class DatabaseBase implements DatabaseType { * * '{$var}' should be used for text and is passed through the database's addQuotes method * `{$var}` should be used for identifiers (eg: table and database names), it is passed through - * the database's quote_ident method which can be overridden if the database + * the database's addIdentifierQuotes method which can be overridden if the database * uses something other than backticks. * / *$var* / is just encoded, besides traditional dbprefix and tableoptions it's use should be avoided * @@ -2528,7 +2539,7 @@ abstract class DatabaseBase implements DatabaseType { foreach ( $varnames as $var ) { if ( isset( $GLOBALS[$var] ) ) { $ins = str_replace( '\'{$' . $var . '}\'', $this->addQuotes( $GLOBALS[$var] ), $ins ); // replace '{$var}' - $ins = str_replace( '`{$' . $var . '}`', $this->quote_ident( $GLOBALS[$var] ), $ins ); // replace `{$var}` + $ins = str_replace( '`{$' . $var . '}`', $this->addIdentifierQuotes( $GLOBALS[$var] ), $ins ); // replace `{$var}` $ins = str_replace( '/*$' . $var . '*/', $this->strencode( $GLOBALS[$var] ) , $ins ); // replace /*$var*/ } } diff --git a/includes/db/DatabaseIbm_db2.php b/includes/db/DatabaseIbm_db2.php index a3a6829b77..f49ff8eca1 100644 --- a/includes/db/DatabaseIbm_db2.php +++ b/includes/db/DatabaseIbm_db2.php @@ -647,6 +647,10 @@ EOF; } } + public function addIdentifierQuotes( $s ) { + return '"' . str_replace( '"', '""', $s ) . '"'; + } + /** * Verifies that a DB2 column/field type is numeric * diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index 1be97c0a2e..b51f7823b4 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -460,14 +460,14 @@ class DatabaseMssql extends DatabaseBase { $sql .= ','; } if ( is_string( $value ) ) { - $sql .= $this->quote_ident( $value ); + $sql .= $this->addIdentifierQuotes( $value ); } elseif ( is_null( $value ) ) { $sql .= 'null'; } elseif ( is_array( $value ) || is_object( $value ) ) { if ( is_object( $value ) && strtolower( get_class( $value ) ) == 'blob' ) { - $sql .= $this->quote_ident( $value->fetch() ); + $sql .= $this->addIdentifierQuotes( $value->fetch() ); } else { - $sql .= $this->quote_ident( serialize( $value ) ); + $sql .= $this->addIdentifierQuotes( serialize( $value ) ); } } else { $sql .= $value; @@ -997,7 +997,7 @@ class DatabaseMssql extends DatabaseBase { } } - function quote_ident( $s ) { + function addIdentifierQuotes( $s ) { return "'" . str_replace( "'", "''", $s ) . "'"; } diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 876188d123..b5d67dd0d8 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -1125,7 +1125,7 @@ class DatabaseOracle extends DatabaseBase { return "'" . $this->strencode( $s ) . "'"; } - function quote_ident( $s ) { + function addIdentifierQuotes( $s ) { return '"' . str_replace( '"', '""', $s ) . '"'; } diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index ea768e28df..55385f0c4d 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -209,7 +209,7 @@ class DatabasePostgres extends DatabaseBase { && preg_match( '/^\w+$/', $wgDBmwschema ) && preg_match( '/^\w+$/', $wgDBts2schema ) ) { - $safeschema = $this->quote_ident( $wgDBmwschema ); + $safeschema = $this->addIdentifierQuotes( $wgDBmwschema ); $this->doQuery( "SET search_path = $safeschema, $wgDBts2schema, public" ); } @@ -238,7 +238,7 @@ class DatabasePostgres extends DatabaseBase { } print 'version ' . htmlspecialchars( $this->numeric_version ) . " is OK.\n"; - $safeuser = $this->quote_ident( $wgDBuser ); + $safeuser = $this->addIdentifierQuotes( $wgDBuser ); // Are we connecting as a superuser for the first time? if ( $superuser ) { // Are we really a superuser? Check out our rights @@ -284,7 +284,7 @@ class DatabasePostgres extends DatabaseBase { dieout( ); } print '
  • Creating database ' . htmlspecialchars( $wgDBname ) . '...'; - $safename = $this->quote_ident( $wgDBname ); + $safename = $this->addIdentifierQuotes( $wgDBname ); $SQL = "CREATE DATABASE $safename OWNER $safeuser "; $this->doQuery( $SQL ); print "OK
  • \n"; @@ -337,7 +337,7 @@ class DatabasePostgres extends DatabaseBase { // Setup the schema for this user if needed $result = $this->schemaExists( $wgDBmwschema ); - $safeschema = $this->quote_ident( $wgDBmwschema ); + $safeschema = $this->addIdentifierQuotes( $wgDBmwschema ); if ( !$result ) { print '
  • Creating schema ' . htmlspecialchars( $wgDBmwschema ) . ' ...'; $result = $this->doQuery( "CREATE SCHEMA $safeschema AUTHORIZATION $safeuser" ); @@ -398,7 +398,7 @@ class DatabasePostgres extends DatabaseBase { // Let's check all four, just to be safe error_reporting( 0 ); $ts2tables = array( 'cfg', 'cfgmap', 'dict', 'parser' ); - $safetsschema = $this->quote_ident( $wgDBts2schema ); + $safetsschema = $this->addIdentifierQuotes( $wgDBts2schema ); foreach ( $ts2tables as $tname ) { $SQL = "SELECT count(*) FROM $safetsschema.pg_ts_$tname"; $res = $this->doQuery( $SQL ); @@ -466,7 +466,7 @@ class DatabasePostgres extends DatabaseBase { if ( !$result ) { print '
  • Creating schema ' . htmlspecialchars( $wgDBmwschema ) . ' ...'; error_reporting( 0 ); - $safeschema = $this->quote_ident( $wgDBmwschema ); + $safeschema = $this->addIdentifierQuotes( $wgDBmwschema ); $result = $this->doQuery( "CREATE SCHEMA $safeschema" ); error_reporting( E_ALL ); if ( !$result ) { @@ -521,9 +521,9 @@ class DatabasePostgres extends DatabaseBase { // Fix up the search paths if needed print '
  • Setting the search path for user "' . htmlspecialchars( $wgDBuser ) . '" ...'; - $path = $this->quote_ident( $wgDBmwschema ); + $path = $this->addIdentifierQuotes( $wgDBmwschema ); if ( $wgDBts2schema !== $wgDBmwschema ) { - $path .= ', '. $this->quote_ident( $wgDBts2schema ); + $path .= ', '. $this->addIdentifierQuotes( $wgDBts2schema ); } if ( $wgDBmwschema !== 'public' && $wgDBts2schema !== 'public' ) { $path .= ', public'; @@ -1300,7 +1300,7 @@ SQL; return "'" . pg_escape_string( $this->mConn, $s ) . "'"; } - function quote_ident( $s ) { + function addIdentifierQuotes( $s ) { return '"' . str_replace( '"', '""', $s ) . '"'; } diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 5bc36cef8c..6fb59f7d03 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -530,7 +530,7 @@ class DatabaseSqlite extends DatabaseBase { } } - function quote_ident( $s ) { + function addIdentifierQuotes( $s ) { return '"' . str_replace( '"', '""', $s ) . '"'; } diff --git a/includes/installer/PostgresInstaller.php b/includes/installer/PostgresInstaller.php index 5851bb16ad..9d832f94ab 100644 --- a/includes/installer/PostgresInstaller.php +++ b/includes/installer/PostgresInstaller.php @@ -127,7 +127,7 @@ class PostgresInstaller extends DatabaseInstaller { // If not, Postgres will happily and silently go to the next search_path item $schema = $this->getVar( 'wgDBmwschema' ); $ctest = 'mediawiki_test_table'; - $safeschema = $conn->quote_ident( $schema ); + $safeschema = $conn->addIdentifierQuotes( $schema ); if ( $conn->tableExists( $ctest, $schema ) ) { $conn->doQuery( "DROP TABLE $safeschema.$ctest" ); } -- 2.20.1