* 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,
*
* '{$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
*
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*/
}
}
}
}
+ public function addIdentifierQuotes( $s ) {
+ return '"' . str_replace( '"', '""', $s ) . '"';
+ }
+
/**
* Verifies that a DB2 column/field type is numeric
*
$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;
}
}
- function quote_ident( $s ) {
+ function addIdentifierQuotes( $s ) {
return "'" . str_replace( "'", "''", $s ) . "'";
}
return "'" . $this->strencode( $s ) . "'";
}
- function quote_ident( $s ) {
+ function addIdentifierQuotes( $s ) {
return '"' . str_replace( '"', '""', $s ) . '"';
}
&& 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" );
}
}
print 'version ' . htmlspecialchars( $this->numeric_version ) . " is OK.</li>\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
dieout( );
}
print '<li>Creating database <b>' . htmlspecialchars( $wgDBname ) . '</b>...';
- $safename = $this->quote_ident( $wgDBname );
+ $safename = $this->addIdentifierQuotes( $wgDBname );
$SQL = "CREATE DATABASE $safename OWNER $safeuser ";
$this->doQuery( $SQL );
print "OK</li>\n";
// Setup the schema for this user if needed
$result = $this->schemaExists( $wgDBmwschema );
- $safeschema = $this->quote_ident( $wgDBmwschema );
+ $safeschema = $this->addIdentifierQuotes( $wgDBmwschema );
if ( !$result ) {
print '<li>Creating schema <b>' . htmlspecialchars( $wgDBmwschema ) . '</b> ...';
$result = $this->doQuery( "CREATE SCHEMA $safeschema AUTHORIZATION $safeuser" );
// 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 );
if ( !$result ) {
print '<li>Creating schema <b>' . htmlspecialchars( $wgDBmwschema ) . '</b> ...';
error_reporting( 0 );
- $safeschema = $this->quote_ident( $wgDBmwschema );
+ $safeschema = $this->addIdentifierQuotes( $wgDBmwschema );
$result = $this->doQuery( "CREATE SCHEMA $safeschema" );
error_reporting( E_ALL );
if ( !$result ) {
// Fix up the search paths if needed
print '<li>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';
return "'" . pg_escape_string( $this->mConn, $s ) . "'";
}
- function quote_ident( $s ) {
+ function addIdentifierQuotes( $s ) {
return '"' . str_replace( '"', '""', $s ) . '"';
}
}
}
- function quote_ident( $s ) {
+ function addIdentifierQuotes( $s ) {
return '"' . str_replace( '"', '""', $s ) . '"';
}
// 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" );
}