3 * This is the Postgres database abstraction layer.
9 class PostgresField
implements Field
{
10 private $name, $tablename, $type, $nullable, $max_length, $deferred, $deferrable, $conname;
13 * @param $db DatabaseBase
16 * @return null|PostgresField
18 static function fromText( $db, $table, $field ) {
23 attnotnull, attlen, COALESCE(conname, '') AS conname,
24 COALESCE(condeferred, 'f') AS deferred,
25 COALESCE(condeferrable, 'f') AS deferrable,
26 CASE WHEN typname = 'int2' THEN 'smallint'
27 WHEN typname = 'int4' THEN 'integer'
28 WHEN typname = 'int8' THEN 'bigint'
29 WHEN typname = 'bpchar' THEN 'char'
30 ELSE typname END AS typname
32 JOIN pg_namespace n ON (n.oid = c.relnamespace)
33 JOIN pg_attribute a ON (a.attrelid = c.oid)
34 JOIN pg_type t ON (t.oid = a.atttypid)
35 LEFT JOIN pg_constraint o ON (o.conrelid = c.oid AND a.attnum = ANY(o.conkey) AND o.contype = 'f')
42 $table = $db->tableName( $table, 'raw' );
45 $db->addQuotes( $wgDBmwschema ),
46 $db->addQuotes( $table ),
47 $db->addQuotes( $field )
50 $row = $db->fetchObject( $res );
54 $n = new PostgresField
;
55 $n->type
= $row->typname
;
56 $n->nullable
= ( $row->attnotnull
== 'f' );
58 $n->tablename
= $table;
59 $n->max_length
= $row->attlen
;
60 $n->deferrable
= ( $row->deferrable
== 't' );
61 $n->deferred
= ( $row->deferred
== 't' );
62 $n->conname
= $row->conname
;
70 function tableName() {
71 return $this->tablename
;
78 function isNullable() {
79 return $this->nullable
;
82 function maxLength() {
83 return $this->max_length
;
86 function is_deferrable() {
87 return $this->deferrable
;
90 function is_deferred() {
91 return $this->deferred
;
95 return $this->conname
;
103 class DatabasePostgres
extends DatabaseBase
{
104 var $mInsertId = null;
105 var $mLastResult = null;
106 var $numeric_version = null;
107 var $mAffectedRows = null;
113 function cascadingDeletes() {
116 function cleanupTriggers() {
119 function strictIPs() {
122 function realTimestamps() {
125 function implicitGroupby() {
128 function implicitOrderby() {
131 function searchableIPs() {
134 function functionalIndexes() {
138 function hasConstraint( $name ) {
139 global $wgDBmwschema;
140 $SQL = "SELECT 1 FROM pg_catalog.pg_constraint c, pg_catalog.pg_namespace n WHERE c.connamespace = n.oid AND conname = '" .
141 pg_escape_string( $this->mConn
, $name ) . "' AND n.nspname = '" . pg_escape_string( $this->mConn
, $wgDBmwschema ) ."'";
142 $res = $this->doQuery( $SQL );
143 return $this->numRows( $res );
147 * Usually aborts on failure
148 * @return DatabaseBase|null
150 function open( $server, $user, $password, $dbName ) {
151 # Test for Postgres support, to avoid suppressed fatal error
152 if ( !function_exists( 'pg_connect' ) ) {
153 throw new DBConnectionError( $this, "Postgres functions missing, have you compiled PHP with the --with-pgsql option?\n (Note: if you recently installed PHP, you may need to restart your webserver and database)\n" );
158 if ( !strlen( $user ) ) { # e.g. the class is being loaded
163 $this->mServer
= $server;
165 $this->mUser
= $user;
166 $this->mPassword
= $password;
167 $this->mDBname
= $dbName;
169 $connectVars = array(
172 'password' => $password
174 if ( $server != false && $server != '' ) {
175 $connectVars['host'] = $server;
177 if ( $port != false && $port != '' ) {
178 $connectVars['port'] = $port;
180 $connectString = $this->makeConnectionString( $connectVars, PGSQL_CONNECT_FORCE_NEW
);
182 $this->installErrorHandler();
183 $this->mConn
= pg_connect( $connectString );
184 $phpError = $this->restoreErrorHandler();
186 if ( !$this->mConn
) {
187 wfDebug( "DB connection error\n" );
188 wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" );
189 wfDebug( $this->lastError() . "\n" );
190 throw new DBConnectionError( $this, str_replace( "\n", ' ', $phpError ) );
193 $this->mOpened
= true;
195 global $wgCommandLineMode;
196 # If called from the command-line (e.g. importDump), only show errors
197 if ( $wgCommandLineMode ) {
198 $this->doQuery( "SET client_min_messages = 'ERROR'" );
201 $this->query( "SET client_encoding='UTF8'", __METHOD__
);
202 $this->query( "SET datestyle = 'ISO, YMD'", __METHOD__
);
203 $this->query( "SET timezone = 'GMT'", __METHOD__
);
204 $this->query( "SET standard_conforming_strings = on", __METHOD__
);
206 global $wgDBmwschema;
207 if ( $this->schemaExists( $wgDBmwschema ) ) {
208 $safeschema = $this->addIdentifierQuotes( $wgDBmwschema );
209 $this->doQuery( "SET search_path = $safeschema" );
211 $this->doQuery( "SET search_path = public" );
218 * Postgres doesn't support selectDB in the same way MySQL does. So if the
219 * DB name doesn't match the open connection, open a new one
222 function selectDB( $db ) {
223 if ( $this->mDBname
!== $db ) {
224 return (bool)$this->open( $this->mServer
, $this->mUser
, $this->mPassword
, $db );
230 function makeConnectionString( $vars ) {
232 foreach ( $vars as $name => $value ) {
233 $s .= "$name='" . str_replace( "'", "\\'", $value ) . "' ";
239 * Closes a database connection, if it is open
240 * Returns success, true if already closed
244 $this->mOpened
= false;
245 if ( $this->mConn
) {
246 $ret = pg_close( $this->mConn
);
254 protected function doQuery( $sql ) {
255 if ( function_exists( 'mb_convert_encoding' ) ) {
256 $sql = mb_convert_encoding( $sql, 'UTF-8' );
258 $this->mLastResult
= pg_query( $this->mConn
, $sql );
259 $this->mAffectedRows
= null; // use pg_affected_rows(mLastResult)
260 return $this->mLastResult
;
263 function queryIgnore( $sql, $fname = 'DatabasePostgres::queryIgnore' ) {
264 return $this->query( $sql, $fname, true );
267 function freeResult( $res ) {
268 if ( $res instanceof ResultWrapper
) {
271 wfSuppressWarnings();
272 $ok = pg_free_result( $res );
275 throw new DBUnexpectedError( $this, "Unable to free Postgres result\n" );
279 function fetchObject( $res ) {
280 if ( $res instanceof ResultWrapper
) {
283 wfSuppressWarnings();
284 $row = pg_fetch_object( $res );
286 # @todo FIXME: HACK HACK HACK HACK debug
288 # @todo hashar: not sure if the following test really trigger if the object
290 if( pg_last_error( $this->mConn
) ) {
291 throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn
) ) );
296 function fetchRow( $res ) {
297 if ( $res instanceof ResultWrapper
) {
300 wfSuppressWarnings();
301 $row = pg_fetch_array( $res );
303 if( pg_last_error( $this->mConn
) ) {
304 throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn
) ) );
309 function numRows( $res ) {
310 if ( $res instanceof ResultWrapper
) {
313 wfSuppressWarnings();
314 $n = pg_num_rows( $res );
316 if( pg_last_error( $this->mConn
) ) {
317 throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn
) ) );
322 function numFields( $res ) {
323 if ( $res instanceof ResultWrapper
) {
326 return pg_num_fields( $res );
329 function fieldName( $res, $n ) {
330 if ( $res instanceof ResultWrapper
) {
333 return pg_field_name( $res, $n );
337 * This must be called after nextSequenceVal
340 function insertId() {
341 return $this->mInsertId
;
344 function dataSeek( $res, $row ) {
345 if ( $res instanceof ResultWrapper
) {
348 return pg_result_seek( $res, $row );
351 function lastError() {
352 if ( $this->mConn
) {
353 return pg_last_error();
355 return 'No database connection';
358 function lastErrno() {
359 return pg_last_error() ?
1 : 0;
362 function affectedRows() {
363 if ( !is_null( $this->mAffectedRows
) ) {
364 // Forced result for simulated queries
365 return $this->mAffectedRows
;
367 if( empty( $this->mLastResult
) ) {
370 return pg_affected_rows( $this->mLastResult
);
374 * Estimate rows in dataset
375 * Returns estimated count, based on EXPLAIN output
376 * This is not necessarily an accurate estimate, so use sparingly
377 * Returns -1 if count cannot be found
378 * Takes same arguments as Database::select()
381 function estimateRowCount( $table, $vars = '*', $conds='', $fname = 'DatabasePostgres::estimateRowCount', $options = array() ) {
382 $options['EXPLAIN'] = true;
383 $res = $this->select( $table, $vars, $conds, $fname, $options );
386 $row = $this->fetchRow( $res );
388 if( preg_match( '/rows=(\d+)/', $row[0], $count ) ) {
396 * Returns information about an index
397 * If errors are explicitly ignored, returns NULL on failure
400 function indexInfo( $table, $index, $fname = 'DatabasePostgres::indexInfo' ) {
401 $sql = "SELECT indexname FROM pg_indexes WHERE tablename='$table'";
402 $res = $this->query( $sql, $fname );
406 foreach ( $res as $row ) {
407 if ( $row->indexname
== $this->indexName( $index ) ) {
414 function indexUnique( $table, $index, $fname = 'DatabasePostgres::indexUnique' ) {
415 $sql = "SELECT indexname FROM pg_indexes WHERE tablename='{$table}'".
416 " AND indexdef LIKE 'CREATE UNIQUE%(" .
417 $this->strencode( $this->indexName( $index ) ) .
419 $res = $this->query( $sql, $fname );
423 foreach ( $res as $row ) {
430 * INSERT wrapper, inserts an array into a table
432 * $args may be a single associative array, or an array of these with numeric keys,
433 * for multi-row insert (Postgres version 8.2 and above only).
435 * @param $table String: Name of the table to insert to.
436 * @param $args Array: Items to insert into the table.
437 * @param $fname String: Name of the function, for profiling
438 * @param $options String or Array. Valid options: IGNORE
440 * @return bool Success of insert operation. IGNORE always returns true.
442 function insert( $table, $args, $fname = 'DatabasePostgres::insert', $options = array() ) {
443 if ( !count( $args ) ) {
447 $table = $this->tableName( $table );
448 if (! isset( $this->numeric_version
) ) {
449 $this->getServerVersion();
452 if ( !is_array( $options ) ) {
453 $options = array( $options );
456 if ( isset( $args[0] ) && is_array( $args[0] ) ) {
458 $keys = array_keys( $args[0] );
461 $keys = array_keys( $args );
464 // If IGNORE is set, we use savepoints to emulate mysql's behavior
465 $ignore = in_array( 'IGNORE', $options ) ?
'mw' : '';
467 // If we are not in a transaction, we need to be for savepoint trickery
470 if ( !$this->mTrxLevel
) {
471 $this->begin( __METHOD__
);
474 $olde = error_reporting( 0 );
475 // For future use, we may want to track the number of actual inserts
476 // Right now, insert (all writes) simply return true/false
477 $numrowsinserted = 0;
480 $sql = "INSERT INTO $table (" . implode( ',', $keys ) . ') VALUES ';
483 if ( $this->numeric_version
>= 8.2 && !$ignore ) {
485 foreach ( $args as $row ) {
491 $sql .= '(' . $this->makeList( $row ) . ')';
493 $res = (bool)$this->query( $sql, $fname, $ignore );
497 foreach ( $args as $row ) {
499 $tempsql .= '(' . $this->makeList( $row ) . ')';
502 pg_query( $this->mConn
, "SAVEPOINT $ignore" );
505 $tempres = (bool)$this->query( $tempsql, $fname, $ignore );
508 $bar = pg_last_error();
509 if ( $bar != false ) {
510 pg_query( $this->mConn
, "ROLLBACK TO $ignore" );
512 pg_query( $this->mConn
, "RELEASE $ignore" );
517 // If any of them fail, we fail overall for this function call
518 // Note that this will be ignored if IGNORE is set
525 // Not multi, just a lone insert
527 pg_query($this->mConn
, "SAVEPOINT $ignore");
530 $sql .= '(' . $this->makeList( $args ) . ')';
531 $res = (bool)$this->query( $sql, $fname, $ignore );
533 $bar = pg_last_error();
534 if ( $bar != false ) {
535 pg_query( $this->mConn
, "ROLLBACK TO $ignore" );
537 pg_query( $this->mConn
, "RELEASE $ignore" );
543 $olde = error_reporting( $olde );
545 $this->commit( __METHOD__
);
548 // Set the affected row count for the whole operation
549 $this->mAffectedRows
= $numrowsinserted;
551 // IGNORE always returns true
559 * INSERT SELECT wrapper
560 * $varMap must be an associative array of the form array( 'dest1' => 'source1', ...)
561 * Source items may be literals rather then field names, but strings should be quoted with Database::addQuotes()
562 * $conds may be "*" to copy the whole table
563 * srcTable may be an array of tables.
564 * @todo FIXME: Implement this a little better (seperate select/insert)?
567 function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = 'DatabasePostgres::insertSelect',
568 $insertOptions = array(), $selectOptions = array() )
570 $destTable = $this->tableName( $destTable );
572 // If IGNORE is set, we use savepoints to emulate mysql's behavior
573 $ignore = in_array( 'IGNORE', $insertOptions ) ?
'mw' : '';
575 if( is_array( $insertOptions ) ) {
576 $insertOptions = implode( ' ', $insertOptions ); // FIXME: This is unused
578 if( !is_array( $selectOptions ) ) {
579 $selectOptions = array( $selectOptions );
581 list( $startOpts, $useIndex, $tailOpts ) = $this->makeSelectOptions( $selectOptions );
582 if( is_array( $srcTable ) ) {
583 $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) );
585 $srcTable = $this->tableName( $srcTable );
588 // If we are not in a transaction, we need to be for savepoint trickery
591 if( !$this->mTrxLevel
) {
592 $this->begin( __METHOD__
);
595 $olde = error_reporting( 0 );
596 $numrowsinserted = 0;
597 pg_query( $this->mConn
, "SAVEPOINT $ignore");
600 $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' .
601 " SELECT $startOpts " . implode( ',', $varMap ) .
602 " FROM $srcTable $useIndex";
604 if ( $conds != '*' ) {
605 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND
);
608 $sql .= " $tailOpts";
610 $res = (bool)$this->query( $sql, $fname, $ignore );
612 $bar = pg_last_error();
613 if( $bar != false ) {
614 pg_query( $this->mConn
, "ROLLBACK TO $ignore" );
616 pg_query( $this->mConn
, "RELEASE $ignore" );
619 $olde = error_reporting( $olde );
621 $this->commit( __METHOD__
);
624 // Set the affected row count for the whole operation
625 $this->mAffectedRows
= $numrowsinserted;
627 // IGNORE always returns true
634 function tableName( $name, $format = 'quoted' ) {
635 # Replace reserved words with better ones
640 return 'pagecontent';
642 return parent
::tableName( $name, $format );
647 * Return the next in a sequence, save the value for retrieval via insertId()
650 function nextSequenceValue( $seqName ) {
651 $safeseq = str_replace( "'", "''", $seqName );
652 $res = $this->query( "SELECT nextval('$safeseq')" );
653 $row = $this->fetchRow( $res );
654 $this->mInsertId
= $row[0];
655 return $this->mInsertId
;
659 * Return the current value of a sequence. Assumes it has been nextval'ed in this session.
662 function currentSequenceValue( $seqName ) {
663 $safeseq = str_replace( "'", "''", $seqName );
664 $res = $this->query( "SELECT currval('$safeseq')" );
665 $row = $this->fetchRow( $res );
670 # Returns the size of a text field, or -1 for "unlimited"
671 function textFieldSize( $table, $field ) {
672 $table = $this->tableName( $table );
673 $sql = "SELECT t.typname as ftype,a.atttypmod as size
674 FROM pg_class c, pg_attribute a, pg_type t
675 WHERE relname='$table' AND a.attrelid=c.oid AND
676 a.atttypid=t.oid and a.attname='$field'";
677 $res =$this->query( $sql );
678 $row = $this->fetchObject( $res );
679 if ( $row->ftype
== 'varchar' ) {
680 $size = $row->size
- 4;
687 function limitResult( $sql, $limit, $offset = false ) {
688 return "$sql LIMIT $limit " . ( is_numeric( $offset ) ?
" OFFSET {$offset} " : '' );
691 function wasDeadlock() {
692 return $this->lastErrno() == '40P01';
695 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabasePostgres::duplicateTableStructure' ) {
696 $newName = $this->addIdentifierQuotes( $newName );
697 $oldName = $this->addIdentifierQuotes( $oldName );
698 return $this->query( 'CREATE ' . ( $temporary ?
'TEMPORARY ' : '' ) . " TABLE $newName (LIKE $oldName INCLUDING DEFAULTS)", $fname );
701 function listTables( $prefix = null, $fname = 'DatabasePostgres::listTables' ) {
702 global $wgDBmwschema;
703 $eschema = $this->addQuotes( $wgDBmwschema );
704 $result = $this->query( "SELECT tablename FROM pg_tables WHERE schemaname = $eschema", $fname );
708 foreach( $result as $table ) {
709 $vars = get_object_vars($table);
710 $table = array_pop( $vars );
711 if( !$prefix ||
strpos( $table, $prefix ) === 0 ) {
712 $endArray[] = $table;
719 function timestamp( $ts = 0 ) {
720 return wfTimestamp( TS_POSTGRES
, $ts );
724 * Return aggregated value function call
726 function aggregateValue( $valuedata, $valuename = 'value' ) {
731 * @return string wikitext of a link to the server software's web site
733 public static function getSoftwareLink() {
734 return '[http://www.postgresql.org/ PostgreSQL]';
738 * @return string Version information from the database
740 function getServerVersion() {
741 if ( !isset( $this->numeric_version
) ) {
742 $versionInfo = pg_version( $this->mConn
);
743 if ( version_compare( $versionInfo['client'], '7.4.0', 'lt' ) ) {
744 // Old client, abort install
745 $this->numeric_version
= '7.3 or earlier';
746 } elseif ( isset( $versionInfo['server'] ) ) {
748 $this->numeric_version
= $versionInfo['server'];
750 // Bug 16937: broken pgsql extension from PHP<5.3
751 $this->numeric_version
= pg_parameter_status( $this->mConn
, 'server_version' );
754 return $this->numeric_version
;
758 * Query whether a given relation exists (in the given schema, or the
759 * default mw one if not given)
762 function relationExists( $table, $types, $schema = false ) {
763 global $wgDBmwschema;
764 if ( !is_array( $types ) ) {
765 $types = array( $types );
768 $schema = $wgDBmwschema;
770 $table = $this->tableName( $table, 'raw' );
771 $etable = $this->addQuotes( $table );
772 $eschema = $this->addQuotes( $schema );
773 $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
774 . "WHERE c.relnamespace = n.oid AND c.relname = $etable AND n.nspname = $eschema "
775 . "AND c.relkind IN ('" . implode( "','", $types ) . "')";
776 $res = $this->query( $SQL );
777 $count = $res ?
$res->numRows() : 0;
782 * For backward compatibility, this function checks both tables and
786 function tableExists( $table, $fname = __METHOD__
, $schema = false ) {
787 return $this->relationExists( $table, array( 'r', 'v' ), $schema );
790 function sequenceExists( $sequence, $schema = false ) {
791 return $this->relationExists( $sequence, 'S', $schema );
794 function triggerExists( $table, $trigger ) {
795 global $wgDBmwschema;
798 SELECT 1 FROM pg_class, pg_namespace, pg_trigger
799 WHERE relnamespace=pg_namespace.oid AND relkind='r'
800 AND tgrelid=pg_class.oid
801 AND nspname=%s AND relname=%s AND tgname=%s
806 $this->addQuotes( $wgDBmwschema ),
807 $this->addQuotes( $table ),
808 $this->addQuotes( $trigger )
814 $rows = $res->numRows();
818 function ruleExists( $table, $rule ) {
819 global $wgDBmwschema;
820 $exists = $this->selectField( 'pg_rules', 'rulename',
823 'tablename' => $table,
824 'schemaname' => $wgDBmwschema
827 return $exists === $rule;
830 function constraintExists( $table, $constraint ) {
831 global $wgDBmwschema;
832 $SQL = sprintf( "SELECT 1 FROM information_schema.table_constraints ".
833 "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s",
834 $this->addQuotes( $wgDBmwschema ),
835 $this->addQuotes( $table ),
836 $this->addQuotes( $constraint )
838 $res = $this->query( $SQL );
842 $rows = $res->numRows();
847 * Query whether a given schema exists. Returns true if it does, false if it doesn't.
850 function schemaExists( $schema ) {
851 $exists = $this->selectField( '"pg_catalog"."pg_namespace"', 1,
852 array( 'nspname' => $schema ), __METHOD__
);
853 return (bool)$exists;
857 * Returns true if a given role (i.e. user) exists, false otherwise.
860 function roleExists( $roleName ) {
861 $exists = $this->selectField( '"pg_catalog"."pg_roles"', 1,
862 array( 'rolname' => $roleName ), __METHOD__
);
863 return (bool)$exists;
866 function fieldInfo( $table, $field ) {
867 return PostgresField
::fromText( $this, $table, $field );
871 * pg_field_type() wrapper
874 function fieldType( $res, $index ) {
875 if ( $res instanceof ResultWrapper
) {
878 return pg_field_type( $res, $index );
881 /* Not even sure why this is used in the main codebase... */
882 function limitResultForUpdate( $sql, $num ) {
890 function encodeBlob( $b ) {
891 return new Blob( pg_escape_bytea( $this->mConn
, $b ) );
894 function decodeBlob( $b ) {
895 if ( $b instanceof Blob
) {
898 return pg_unescape_bytea( $b );
901 function strencode( $s ) { # Should not be called by us
902 return pg_escape_string( $this->mConn
, $s );
906 * @param $s null|bool|Blob
909 function addQuotes( $s ) {
910 if ( is_null( $s ) ) {
912 } elseif ( is_bool( $s ) ) {
914 } elseif ( $s instanceof Blob
) {
915 return "'" . $s->fetch( $s ) . "'";
917 return "'" . pg_escape_string( $this->mConn
, $s ) . "'";
921 * Postgres specific version of replaceVars.
922 * Calls the parent version in Database.php
926 * @param $ins String: SQL string, read from a stream (usually tables.sql)
928 * @return string SQL string
930 protected function replaceVars( $ins ) {
931 $ins = parent
::replaceVars( $ins );
933 if ( $this->numeric_version
>= 8.3 ) {
934 // Thanks for not providing backwards-compatibility, 8.3
935 $ins = preg_replace( "/to_tsvector\s*\(\s*'default'\s*,/", 'to_tsvector(', $ins );
938 if ( $this->numeric_version
<= 8.1 ) { // Our minimum version
939 $ins = str_replace( 'USING gin', 'USING gist', $ins );
946 * Various select options
950 * @param $options Array: an associative array of options to be turned into
951 * an SQL query, valid keys are listed in the function.
954 function makeSelectOptions( $options ) {
955 $preLimitTail = $postLimitTail = '';
956 $startOpts = $useIndex = '';
958 $noKeyOptions = array();
959 foreach ( $options as $key => $option ) {
960 if ( is_numeric( $key ) ) {
961 $noKeyOptions[$option] = true;
965 if ( isset( $options['GROUP BY'] ) ) {
966 $gb = is_array( $options['GROUP BY'] )
967 ?
implode( ',', $options['GROUP BY'] )
968 : $options['GROUP BY'];
969 $preLimitTail .= " GROUP BY {$gb}";
972 if ( isset( $options['HAVING'] ) ) {
973 $preLimitTail .= " HAVING {$options['HAVING']}";
976 if ( isset( $options['ORDER BY'] ) ) {
977 $ob = is_array( $options['ORDER BY'] )
978 ?
implode( ',', $options['ORDER BY'] )
979 : $options['ORDER BY'];
980 $preLimitTail .= " ORDER BY {$ob}";
983 //if ( isset( $options['LIMIT'] ) ) {
984 // $tailOpts .= $this->limitResult( '', $options['LIMIT'],
985 // isset( $options['OFFSET'] ) ? $options['OFFSET']
989 if ( isset( $noKeyOptions['FOR UPDATE'] ) ) {
990 $postLimitTail .= ' FOR UPDATE';
992 if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) {
993 $postLimitTail .= ' LOCK IN SHARE MODE';
995 if ( isset( $noKeyOptions['DISTINCT'] ) ||
isset( $noKeyOptions['DISTINCTROW'] ) ) {
996 $startOpts .= 'DISTINCT';
999 return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail );
1002 function setFakeMaster( $enabled = true ) {}
1004 function getDBname() {
1005 return $this->mDBname
;
1008 function getServer() {
1009 return $this->mServer
;
1012 function buildConcat( $stringList ) {
1013 return implode( ' || ', $stringList );
1016 public function getSearchEngine() {
1017 return 'SearchPostgres';
1020 public function streamStatementEnd( &$sql, &$newLine ) {
1021 # Allow dollar quoting for function declarations
1022 if ( substr( $newLine, 0, 4 ) == '$mw$' ) {
1023 if ( $this->delimiter
) {
1024 $this->delimiter
= false;
1027 $this->delimiter
= ';';
1030 return parent
::streamStatementEnd( $sql, $newLine );
1032 } // end DatabasePostgres class