r77720 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77719‎ | r77720 | r77721 >
Date:15:14, 4 December 2010
Author:dantman
Status:resolved (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseIbm_db2.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMssql.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)
  • /trunk/phase3/includes/installer/PostgresInstaller.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -1125,7 +1125,7 @@
11261126 return "'" . $this->strencode( $s ) . "'";
11271127 }
11281128
1129 - function quote_ident( $s ) {
 1129+ function addIdentifierQuotes( $s ) {
11301130 return '"' . str_replace( '"', '""', $s ) . '"';
11311131 }
11321132
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -209,7 +209,7 @@
210210 && preg_match( '/^\w+$/', $wgDBmwschema )
211211 && preg_match( '/^\w+$/', $wgDBts2schema )
212212 ) {
213 - $safeschema = $this->quote_ident( $wgDBmwschema );
 213+ $safeschema = $this->addIdentifierQuotes( $wgDBmwschema );
214214 $this->doQuery( "SET search_path = $safeschema, $wgDBts2schema, public" );
215215 }
216216
@@ -238,7 +238,7 @@
239239 }
240240 print 'version ' . htmlspecialchars( $this->numeric_version ) . " is OK.</li>\n";
241241
242 - $safeuser = $this->quote_ident( $wgDBuser );
 242+ $safeuser = $this->addIdentifierQuotes( $wgDBuser );
243243 // Are we connecting as a superuser for the first time?
244244 if ( $superuser ) {
245245 // Are we really a superuser? Check out our rights
@@ -284,7 +284,7 @@
285285 dieout( );
286286 }
287287 print '<li>Creating database <b>' . htmlspecialchars( $wgDBname ) . '</b>...';
288 - $safename = $this->quote_ident( $wgDBname );
 288+ $safename = $this->addIdentifierQuotes( $wgDBname );
289289 $SQL = "CREATE DATABASE $safename OWNER $safeuser ";
290290 $this->doQuery( $SQL );
291291 print "OK</li>\n";
@@ -337,7 +337,7 @@
338338
339339 // Setup the schema for this user if needed
340340 $result = $this->schemaExists( $wgDBmwschema );
341 - $safeschema = $this->quote_ident( $wgDBmwschema );
 341+ $safeschema = $this->addIdentifierQuotes( $wgDBmwschema );
342342 if ( !$result ) {
343343 print '<li>Creating schema <b>' . htmlspecialchars( $wgDBmwschema ) . '</b> ...';
344344 $result = $this->doQuery( "CREATE SCHEMA $safeschema AUTHORIZATION $safeuser" );
@@ -398,7 +398,7 @@
399399 // Let's check all four, just to be safe
400400 error_reporting( 0 );
401401 $ts2tables = array( 'cfg', 'cfgmap', 'dict', 'parser' );
402 - $safetsschema = $this->quote_ident( $wgDBts2schema );
 402+ $safetsschema = $this->addIdentifierQuotes( $wgDBts2schema );
403403 foreach ( $ts2tables as $tname ) {
404404 $SQL = "SELECT count(*) FROM $safetsschema.pg_ts_$tname";
405405 $res = $this->doQuery( $SQL );
@@ -466,7 +466,7 @@
467467 if ( !$result ) {
468468 print '<li>Creating schema <b>' . htmlspecialchars( $wgDBmwschema ) . '</b> ...';
469469 error_reporting( 0 );
470 - $safeschema = $this->quote_ident( $wgDBmwschema );
 470+ $safeschema = $this->addIdentifierQuotes( $wgDBmwschema );
471471 $result = $this->doQuery( "CREATE SCHEMA $safeschema" );
472472 error_reporting( E_ALL );
473473 if ( !$result ) {
@@ -521,9 +521,9 @@
522522
523523 // Fix up the search paths if needed
524524 print '<li>Setting the search path for user "' . htmlspecialchars( $wgDBuser ) . '" ...';
525 - $path = $this->quote_ident( $wgDBmwschema );
 525+ $path = $this->addIdentifierQuotes( $wgDBmwschema );
526526 if ( $wgDBts2schema !== $wgDBmwschema ) {
527 - $path .= ', '. $this->quote_ident( $wgDBts2schema );
 527+ $path .= ', '. $this->addIdentifierQuotes( $wgDBts2schema );
528528 }
529529 if ( $wgDBmwschema !== 'public' && $wgDBts2schema !== 'public' ) {
530530 $path .= ', public';
@@ -1300,7 +1300,7 @@
13011301 return "'" . pg_escape_string( $this->mConn, $s ) . "'";
13021302 }
13031303
1304 - function quote_ident( $s ) {
 1304+ function addIdentifierQuotes( $s ) {
13051305 return '"' . str_replace( '"', '""', $s ) . '"';
13061306 }
13071307
Index: trunk/phase3/includes/db/DatabaseIbm_db2.php
@@ -647,6 +647,10 @@
648648 }
649649 }
650650
 651+ public function addIdentifierQuotes( $s ) {
 652+ return '"' . str_replace( '"', '""', $s ) . '"';
 653+ }
 654+
651655 /**
652656 * Verifies that a DB2 column/field type is numeric
653657 *
Index: trunk/phase3/includes/db/Database.php
@@ -1699,11 +1699,22 @@
17001700 * names, other databases which use something other than backticks can replace
17011701 * this with something else
17021702 */
1703 - function quote_ident( $s ) {
 1703+ public function addIdentifierQuotes( $s ) {
17041704 return "`" . $this->strencode( $s ) . "`";
17051705 }
17061706
17071707 /**
 1708+ * Backwards compatibility, identifier quoting originated in DatabasePostgres
 1709+ * which used quote_ident which does not follow our naming conventions
 1710+ * was renamed to addIdentifierQuotes.
 1711+ * @deprecated use addIdentifierQuotes
 1712+ */
 1713+ function quote_ident( $s ) {
 1714+ wfDeprecated( __METHOD__ );
 1715+ return $this->addIdentifierQuotes( $s );
 1716+ }
 1717+
 1718+ /**
17081719 * Escape string for safe LIKE usage.
17091720 * WARNING: you should almost never use this function directly,
17101721 * instead use buildLike() that escapes everything automatically
@@ -2516,7 +2527,7 @@
25172528 *
25182529 * '{$var}' should be used for text and is passed through the database's addQuotes method
25192530 * `{$var}` should be used for identifiers (eg: table and database names), it is passed through
2520 - * the database's quote_ident method which can be overridden if the database
 2531+ * the database's addIdentifierQuotes method which can be overridden if the database
25212532 * uses something other than backticks.
25222533 * / *$var* / is just encoded, besides traditional dbprefix and tableoptions it's use should be avoided
25232534 *
@@ -2528,7 +2539,7 @@
25292540 foreach ( $varnames as $var ) {
25302541 if ( isset( $GLOBALS[$var] ) ) {
25312542 $ins = str_replace( '\'{$' . $var . '}\'', $this->addQuotes( $GLOBALS[$var] ), $ins ); // replace '{$var}'
2532 - $ins = str_replace( '`{$' . $var . '}`', $this->quote_ident( $GLOBALS[$var] ), $ins ); // replace `{$var}`
 2543+ $ins = str_replace( '`{$' . $var . '}`', $this->addIdentifierQuotes( $GLOBALS[$var] ), $ins ); // replace `{$var}`
25332544 $ins = str_replace( '/*$' . $var . '*/', $this->strencode( $GLOBALS[$var] ) , $ins ); // replace /*$var*/
25342545 }
25352546 }
Index: trunk/phase3/includes/db/DatabaseMssql.php
@@ -460,14 +460,14 @@
461461 $sql .= ',';
462462 }
463463 if ( is_string( $value ) ) {
464 - $sql .= $this->quote_ident( $value );
 464+ $sql .= $this->addIdentifierQuotes( $value );
465465 } elseif ( is_null( $value ) ) {
466466 $sql .= 'null';
467467 } elseif ( is_array( $value ) || is_object( $value ) ) {
468468 if ( is_object( $value ) && strtolower( get_class( $value ) ) == 'blob' ) {
469 - $sql .= $this->quote_ident( $value->fetch() );
 469+ $sql .= $this->addIdentifierQuotes( $value->fetch() );
470470 } else {
471 - $sql .= $this->quote_ident( serialize( $value ) );
 471+ $sql .= $this->addIdentifierQuotes( serialize( $value ) );
472472 }
473473 } else {
474474 $sql .= $value;
@@ -997,7 +997,7 @@
998998 }
999999 }
10001000
1001 - function quote_ident( $s ) {
 1001+ function addIdentifierQuotes( $s ) {
10021002 return "'" . str_replace( "'", "''", $s ) . "'";
10031003 }
10041004
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -530,7 +530,7 @@
531531 }
532532 }
533533
534 - function quote_ident( $s ) {
 534+ function addIdentifierQuotes( $s ) {
535535 return '"' . str_replace( '"', '""', $s ) . '"';
536536 }
537537
Index: trunk/phase3/includes/installer/PostgresInstaller.php
@@ -127,7 +127,7 @@
128128 // If not, Postgres will happily and silently go to the next search_path item
129129 $schema = $this->getVar( 'wgDBmwschema' );
130130 $ctest = 'mediawiki_test_table';
131 - $safeschema = $conn->quote_ident( $schema );
 131+ $safeschema = $conn->addIdentifierQuotes( $schema );
132132 if ( $conn->tableExists( $ctest, $schema ) ) {
133133 $conn->doQuery( "DROP TABLE $safeschema.$ctest" );
134134 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r77713Fix a bug in the installer caused by r77487 creating installer sql statements...dantman09:27, 4 December 2010

Comments

#Comment by Platonides (talk | contribs)   22:59, 4 December 2010

I don't think we need a BC quote_ident for a method which wasn't available on all database backends.

#Comment by 😂 (talk | contribs)   03:11, 6 December 2010

+1

#Comment by Dantman (talk | contribs)   03:44, 6 December 2010

It was present in sqlite, oracle, posgres, and mssql. posgres and mssql actively use it. And I've found that posgtres code outside of the database class itself made use of it, so there's a possibility that it was used by 3rd party extensions outside of the repo. We might as well leave a deprecated method for one release. Putting it in the generic just means we don't have to re-implement the compat in sqlite, oracle, posgres, and mssql classes.

#Comment by 😂 (talk | contribs)   17:12, 29 December 2010

Code duplication was resolved in r77724. Back-compat wrapper is harmless and can probably be removed in a version anyway.

Status & tagging log