From aae05c49f84c734b0d920063b92f01d166050fa9 Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Sat, 4 Dec 2010 15:35:36 +0000 Subject: [PATCH] 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. --- includes/db/Database.php | 9 +++++---- includes/db/DatabaseIbm_db2.php | 4 ---- includes/db/DatabaseMssql.php | 4 ---- includes/db/DatabaseMysql.php | 7 +++++++ includes/db/DatabaseOracle.php | 4 ---- includes/db/DatabasePostgres.php | 4 ---- includes/db/DatabaseSqlite.php | 4 ---- 7 files changed, 12 insertions(+), 24 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 7248bb9985..6d4ba86232 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1695,12 +1695,13 @@ abstract class DatabaseBase implements DatabaseType { } /** - * Quotes a string using `backticks` for things like database, table, and field - * names, other databases which use something other than backticks can replace - * this with something else + * Quotes an identifier using `backticks` or "double quotes" depending on the database type. + * MySQL uses `backticks` while basically everything else uses double quotes. + * Since MySQL is the odd one out here the double quotes are our generic + * and we implement backticks in DatabaseMysql. */ public function addIdentifierQuotes( $s ) { - return "`" . $this->strencode( $s ) . "`"; + return '"' . str_replace( '"', '""', $s ) . '"'; } /** diff --git a/includes/db/DatabaseIbm_db2.php b/includes/db/DatabaseIbm_db2.php index f49ff8eca1..a3a6829b77 100644 --- a/includes/db/DatabaseIbm_db2.php +++ b/includes/db/DatabaseIbm_db2.php @@ -647,10 +647,6 @@ 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 b51f7823b4..4f09069f3e 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -997,10 +997,6 @@ class DatabaseMssql extends DatabaseBase { } } - function addIdentifierQuotes( $s ) { - return "'" . str_replace( "'", "''", $s ) . "'"; - } - function selectDB( $db ) { return ( $this->query( "SET DATABASE $db" ) !== false ); } diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index bc41cb1477..2b2c96938d 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -322,6 +322,13 @@ class DatabaseMysql extends DatabaseBase { return $sQuoted; } + /** + * MySQL uses `backticks` for identifier quoting instead of the sql standard "double quotes". + */ + public function addIdentifierQuotes( $s ) { + return "`" . $this->strencode( $s ) . "`"; + } + function ping() { $ping = mysql_ping( $this->mConn ); if ( $ping ) { diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index b5d67dd0d8..c5f6a3d675 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -1125,10 +1125,6 @@ class DatabaseOracle extends DatabaseBase { return "'" . $this->strencode( $s ) . "'"; } - function addIdentifierQuotes( $s ) { - return '"' . str_replace( '"', '""', $s ) . '"'; - } - function selectRow( $table, $vars, $conds, $fname = 'DatabaseOracle::selectRow', $options = array(), $join_conds = array() ) { global $wgContLang; diff --git a/includes/db/DatabasePostgres.php b/includes/db/DatabasePostgres.php index 55385f0c4d..96f7eaea9e 100644 --- a/includes/db/DatabasePostgres.php +++ b/includes/db/DatabasePostgres.php @@ -1300,10 +1300,6 @@ SQL; return "'" . pg_escape_string( $this->mConn, $s ) . "'"; } - function addIdentifierQuotes( $s ) { - return '"' . str_replace( '"', '""', $s ) . '"'; - } - /** * Postgres specific version of replaceVars. * Calls the parent version in Database.php diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 6fb59f7d03..52637a23a9 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -530,10 +530,6 @@ class DatabaseSqlite extends DatabaseBase { } } - function addIdentifierQuotes( $s ) { - return '"' . str_replace( '"', '""', $s ) . '"'; - } - function buildLike() { $params = func_get_args(); if ( count( $params ) > 0 && is_array( $params[0] ) ) { -- 2.20.1