From: Greg Sabino Mullane Date: Wed, 5 Jul 2006 03:59:54 +0000 (+0000) Subject: Rewrote all the quoting stuff, including decodeBlob support X-Git-Tag: 1.31.0-rc.0~56407 X-Git-Url: https://git.cyclocoop.org/?a=commitdiff_plain;ds=sidebyside;h=327f2430aeda49546f88284132acff133ff64bb9;p=lhc%2Fweb%2Fwiklou.git Rewrote all the quoting stuff, including decodeBlob support Add install check for plpgsql Overhaul nextSequenceValue Re-enable commit() --- diff --git a/includes/DatabasePostgres.php b/includes/DatabasePostgres.php index 5ba0d3b530..7d47ce54d6 100644 --- a/includes/DatabasePostgres.php +++ b/includes/DatabasePostgres.php @@ -85,18 +85,30 @@ class DatabasePostgres extends Database { $this->mOpened = true; ## If this is the initial connection, setup the schema stuff if (defined('MEDIAWIKI_INSTALL') and !defined('POSTGRES_SEARCHPATH')) { - global $wgDBmwschema, $wgDBts2schema; + global $wgDBmwschema, $wgDBts2schema, $wgDBname; ## Do we have the basic tsearch2 table? print "
  • Checking for tsearch2 ..."; if (! $this->tableExists("pg_ts_dict", $wgDBts2schema)) { - print "FAILED. Make sure tsearch2 is installed. See FAILED. Make sure tsearch2 is installed. See this article"; print " for instructions.
  • \n"; dieout(""); } print "OK\n"; + ## Do we have plpgsql installed? + print "
  • Checking for plpgsql ..."; + $SQL = "SELECT 1 FROM pg_catalog.pg_language WHERE lanname = 'plpgsql'"; + $res = $this->doQuery($SQL); + $rows = $this->numRows($this->doQuery($SQL)); + if ($rows < 1) { + print "FAILED. Make sure the language plpgsql is installed for the database $wgDBnamet
  • "; + ## XXX Better help + dieout(""); + } + print "OK\n"; + ## Does the schema already exist? Who owns it? $result = $this->schemaExists($wgDBmwschema); if (!$result) { @@ -298,17 +310,16 @@ class DatabasePostgres extends Database { } } - function strencode( $s ) { - return pg_escape_string( $s ); - } - /** * Return the next in a sequence, save the value for retrieval via insertId() */ function nextSequenceValue( $seqName ) { - $value = $this->selectField(''," nextval('" . $seqName . "')"); - $this->mInsertId = $value; - return $value; + $safeseq = preg_replace( "/'/", "''", $seqName ); + $res = $this->query( "SELECT nextval('$safeseq')" ); + $row = $this->fetchRow( $res ); + $this->mInsertId = $row[0]; + $this->freeResult( $res ); + return $this->mInsertId; } /** @@ -536,8 +547,6 @@ class DatabasePostgres extends Database { } function commit( $fname = 'Database::commit' ) { - ## XXX - return; $this->query( 'COMMIT', $fname ); $this->mTrxLevel = 0; } @@ -567,6 +576,27 @@ class DatabasePostgres extends Database { print " (table interwiki successfully populated)...\n"; } + function encodeBlob($b) { + return array('bytea',pg_escape_bytea($b)); + } + function decodeBlob($b) { + return pg_unescape_bytea( $b ); + } + + function strencode( $s ) { ## Should not be called by us + return pg_escape_string( $s ); + } + + function addQuotes( $s ) { + if ( is_null( $s ) ) { + return 'NULL'; + } else if (is_array( $s )) { ## Assume it is bytea data + return "E'$s[1]'"; + } + return "'" . pg_escape_string($s) . "'"; + return "E'" . pg_escape_string($s) . "'"; + } + } ?>