static function fromText( $db, $table, $field ) {
$q = <<<SQL
SELECT
- attnotnull, attlen, COALESCE(conname, '') AS conname,
+ attnotnull, attlen, conname AS conname,
COALESCE(condeferred, 'f') AS deferred,
COALESCE(condeferrable, 'f') AS deferrable,
CASE WHEN typname = 'int2' THEN 'smallint'
function hasConstraint( $name ) {
$SQL = "SELECT 1 FROM pg_catalog.pg_constraint c, pg_catalog.pg_namespace n WHERE c.connamespace = n.oid AND conname = '" .
- pg_escape_string( $this->mConn, $name ) . "' AND n.nspname = '" . pg_escape_string( $this->mConn, $this->mConn->getCoreSchema() ) ."'";
+ pg_escape_string( $this->mConn, $name ) . "' AND n.nspname = '" . pg_escape_string( $this->mConn, $this->getCoreSchema() ) ."'";
$res = $this->doQuery( $SQL );
return $this->numRows( $res );
}
}
protected function doQuery( $sql ) {
- global $wgDebugDBTransactions;
if ( function_exists( 'mb_convert_encoding' ) ) {
$sql = mb_convert_encoding( $sql, 'UTF-8' );
}
# Replace reserved words with better ones
switch( $name ) {
case 'user':
- return 'mwuser';
+ return $this->realTableName( 'mwuser', $format );
case 'text':
- return 'pagecontent';
+ return $this->realTableName( 'pagecontent', $format );
default:
- return parent::tableName( $name, $format );
+ return $this->realTableName( $name, $format );
}
}
+ /* Don't cheat on installer */
+ function realTableName( $name, $format = 'quoted' ) {
+ return parent::tableName( $name, $format );
+ }
+
/**
* Return the next in a sequence, save the value for retrieval via insertId()
* @return null
return wfTimestamp( TS_POSTGRES, $ts );
}
-
/*
* Posted by cc[plus]php[at]c2se[dot]com on 25-Mar-2009 09:12
* to http://www.php.net/manual/en/ref.pgsql.php
- *
- * Parsing a postgres array can be a tricky problem, he's my
- * take on this, it handles multi-dimensional arrays plus
- * escaping using a nasty regexp to determine the limits of each
- * data-item.
+ *
+ * Parsing a postgres array can be a tricky problem, he's my
+ * take on this, it handles multi-dimensional arrays plus
+ * escaping using a nasty regexp to determine the limits of each
+ * data-item.
*
* This should really be handled by PHP PostgreSQL module
*
* @since 1.20
- * @param text string: postgreql array returned in a text form like {a,b}
- * @param output string
- * @param limit int
- * @param offset int
+ * @param $text string: postgreql array returned in a text form like {a,b}
+ * @param $output string
+ * @param $limit int
+ * @param $offset int
* @return string
*/
-
function pg_array_parse( $text, &$output, $limit = false, $offset = 1 ) {
if( false === $limit ) {
$limit = strlen( $text )-1;
$output = array();
}
- if( '{}' != $text )
+ if( '{}' == $text ) {
+ return $output;
+ }
do {
if ( '{' != $text{$offset} ) {
preg_match( "/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/",
$output[] = ( '"' != $match[1]{0}
? $match[1]
: stripcslashes( substr( $match[1], 1, -1 ) ) );
- if ( '},' == $match[3] )
+ if ( '},' == $match[3] ) {
return $output;
- } else
- $offset = $this->pg_array_parse( $text, $output[], $limit, $offset+1 );
+ }
+ } else {
+ $offset = $this->pg_array_parse( $text, $output, $limit, $offset+1 );
+ }
} while ( $limit > $offset );
return $output;
}
return explode(",", $row[0]);
}
- function setSearchPath( $search_path ) {
/**
* Update search_path, values should already be sanitized
* Values may contain magic keywords like "$user"
* @since 1.20
*
- * @param array list of schemas to be searched by default
+ * @param $search_path array list of schemas to be searched by default
*/
+ function setSearchPath( $search_path ) {
$this->query( "SET search_path = " . implode(", ", $search_path) );
}
wfDebug("Schema \"" . $desired_schema . "\" already in the search path\n");
} else {
/**
- * Apped our schema (e.g. 'mediawiki') in front
+ * Append our schema (e.g. 'mediawiki') in front
* of the search path
* Fixes bug 15816
*/
array_unshift( $search_path,
$this->addIdentifierQuotes( $desired_schema ));
$this->setSearchPath( $search_path );
+ $this->mCoreSchema = $desired_schema;
wfDebug("Schema \"" . $desired_schema . "\" added to the search path\n");
}
} else {
if ( !$schema ) {
$schema = $this->getCoreSchema();
}
- $table = $this->tableName( $table, 'raw' );
+ $table = $this->realTableName( $table, 'raw' );
$etable = $this->addQuotes( $table );
$eschema = $this->addQuotes( $schema );
$SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "