r77724 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77723‎ | r77724 | r77725 >
Date:15:35, 4 December 2010
Author:dantman
Status:ok
Tags:
Comment:
MySQL is the only database which quotes identifiers primarily using backticks. Move the backtick based addIdentifierQuotes implementation from the generic into DatabaseMysql and take the duplicated implementation used by oracle, sqlite, ibm_db2, postgresql, and mssql and remove it from all of them migrating it to the generic Database class as the default.
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/DatabaseMysql.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)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseMysql.php
@@ -322,6 +322,13 @@
323323 return $sQuoted;
324324 }
325325
 326+ /**
 327+ * MySQL uses `backticks` for identifier quoting instead of the sql standard "double quotes".
 328+ */
 329+ public function addIdentifierQuotes( $s ) {
 330+ return "`" . $this->strencode( $s ) . "`";
 331+ }
 332+
326333 function ping() {
327334 $ping = mysql_ping( $this->mConn );
328335 if ( $ping ) {
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -1125,10 +1125,6 @@
11261126 return "'" . $this->strencode( $s ) . "'";
11271127 }
11281128
1129 - function addIdentifierQuotes( $s ) {
1130 - return '"' . str_replace( '"', '""', $s ) . '"';
1131 - }
1132 -
11331129 function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) {
11341130 global $wgContLang;
11351131
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -1300,10 +1300,6 @@
13011301 return "'" . pg_escape_string( $this->mConn, $s ) . "'";
13021302 }
13031303
1304 - function addIdentifierQuotes( $s ) {
1305 - return '"' . str_replace( '"', '""', $s ) . '"';
1306 - }
1307 -
13081304 /**
13091305 * Postgres specific version of replaceVars.
13101306 * Calls the parent version in Database.php
Index: trunk/phase3/includes/db/DatabaseIbm_db2.php
@@ -647,10 +647,6 @@
648648 }
649649 }
650650
651 - public function addIdentifierQuotes( $s ) {
652 - return '"' . str_replace( '"', '""', $s ) . '"';
653 - }
654 -
655651 /**
656652 * Verifies that a DB2 column/field type is numeric
657653 *
Index: trunk/phase3/includes/db/Database.php
@@ -1695,12 +1695,13 @@
16961696 }
16971697
16981698 /**
1699 - * Quotes a string using `backticks` for things like database, table, and field
1700 - * names, other databases which use something other than backticks can replace
1701 - * this with something else
 1699+ * Quotes an identifier using `backticks` or "double quotes" depending on the database type.
 1700+ * MySQL uses `backticks` while basically everything else uses double quotes.
 1701+ * Since MySQL is the odd one out here the double quotes are our generic
 1702+ * and we implement backticks in DatabaseMysql.
17021703 */
17031704 public function addIdentifierQuotes( $s ) {
1704 - return "`" . $this->strencode( $s ) . "`";
 1705+ return '"' . str_replace( '"', '""', $s ) . '"';
17051706 }
17061707
17071708 /**
Index: trunk/phase3/includes/db/DatabaseMssql.php
@@ -997,10 +997,6 @@
998998 }
999999 }
10001000
1001 - function addIdentifierQuotes( $s ) {
1002 - return "'" . str_replace( "'", "''", $s ) . "'";
1003 - }
1004 -
10051001 function selectDB( $db ) {
10061002 return ( $this->query( "SET DATABASE $db" ) !== false );
10071003 }
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -530,10 +530,6 @@
531531 }
532532 }
533533
534 - function addIdentifierQuotes( $s ) {
535 - return '"' . str_replace( '"', '""', $s ) . '"';
536 - }
537 -
538534 function buildLike() {
539535 $params = func_get_args();
540536 if ( count( $params ) > 0 && is_array( $params[0] ) ) {

Status & tagging log