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 return pg_close( $this->mConn
);
252 protected function doQuery( $sql ) {
253 if ( function_exists( 'mb_convert_encoding' ) ) {
254 $sql = mb_convert_encoding( $sql, 'UTF-8' );
256 $this->mLastResult
= pg_query( $this->mConn
, $sql );
257 $this->mAffectedRows
= null; // use pg_affected_rows(mLastResult)
258 return $this->mLastResult
;
261 function queryIgnore( $sql, $fname = 'DatabasePostgres::queryIgnore' ) {
262 return $this->query( $sql, $fname, true );
265 function freeResult( $res ) {
266 if ( $res instanceof ResultWrapper
) {
269 wfSuppressWarnings();
270 $ok = pg_free_result( $res );
273 throw new DBUnexpectedError( $this, "Unable to free Postgres result\n" );
277 function fetchObject( $res ) {
278 if ( $res instanceof ResultWrapper
) {
281 wfSuppressWarnings();
282 $row = pg_fetch_object( $res );
284 # @todo FIXME: HACK HACK HACK HACK debug
286 # @todo hashar: not sure if the following test really trigger if the object
288 if( pg_last_error( $this->mConn
) ) {
289 throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn
) ) );
294 function fetchRow( $res ) {
295 if ( $res instanceof ResultWrapper
) {
298 wfSuppressWarnings();
299 $row = pg_fetch_array( $res );
301 if( pg_last_error( $this->mConn
) ) {
302 throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn
) ) );
307 function numRows( $res ) {
308 if ( $res instanceof ResultWrapper
) {
311 wfSuppressWarnings();
312 $n = pg_num_rows( $res );
314 if( pg_last_error( $this->mConn
) ) {
315 throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn
) ) );
320 function numFields( $res ) {
321 if ( $res instanceof ResultWrapper
) {
324 return pg_num_fields( $res );
327 function fieldName( $res, $n ) {
328 if ( $res instanceof ResultWrapper
) {
331 return pg_field_name( $res, $n );
335 * This must be called after nextSequenceVal
338 function insertId() {
339 return $this->mInsertId
;
342 function dataSeek( $res, $row ) {
343 if ( $res instanceof ResultWrapper
) {
346 return pg_result_seek( $res, $row );
349 function lastError() {
350 if ( $this->mConn
) {
351 return pg_last_error();
353 return 'No database connection';
356 function lastErrno() {
357 return pg_last_error() ?
1 : 0;
360 function affectedRows() {
361 if ( !is_null( $this->mAffectedRows
) ) {
362 // Forced result for simulated queries
363 return $this->mAffectedRows
;
365 if( empty( $this->mLastResult
) ) {
368 return pg_affected_rows( $this->mLastResult
);
372 * Estimate rows in dataset
373 * Returns estimated count, based on EXPLAIN output
374 * This is not necessarily an accurate estimate, so use sparingly
375 * Returns -1 if count cannot be found
376 * Takes same arguments as Database::select()
379 function estimateRowCount( $table, $vars = '*', $conds='', $fname = 'DatabasePostgres::estimateRowCount', $options = array() ) {
380 $options['EXPLAIN'] = true;
381 $res = $this->select( $table, $vars, $conds, $fname, $options );
384 $row = $this->fetchRow( $res );
386 if( preg_match( '/rows=(\d+)/', $row[0], $count ) ) {
394 * Returns information about an index
395 * If errors are explicitly ignored, returns NULL on failure
398 function indexInfo( $table, $index, $fname = 'DatabasePostgres::indexInfo' ) {
399 $sql = "SELECT indexname FROM pg_indexes WHERE tablename='$table'";
400 $res = $this->query( $sql, $fname );
404 foreach ( $res as $row ) {
405 if ( $row->indexname
== $this->indexName( $index ) ) {
412 function indexUnique( $table, $index, $fname = 'DatabasePostgres::indexUnique' ) {
413 $sql = "SELECT indexname FROM pg_indexes WHERE tablename='{$table}'".
414 " AND indexdef LIKE 'CREATE UNIQUE%(" .
415 $this->strencode( $this->indexName( $index ) ) .
417 $res = $this->query( $sql, $fname );
421 foreach ( $res as $row ) {
428 * INSERT wrapper, inserts an array into a table
430 * $args may be a single associative array, or an array of these with numeric keys,
431 * for multi-row insert (Postgres version 8.2 and above only).
433 * @param $table String: Name of the table to insert to.
434 * @param $args Array: Items to insert into the table.
435 * @param $fname String: Name of the function, for profiling
436 * @param $options String or Array. Valid options: IGNORE
438 * @return bool Success of insert operation. IGNORE always returns true.
440 function insert( $table, $args, $fname = 'DatabasePostgres::insert', $options = array() ) {
441 if ( !count( $args ) ) {
445 $table = $this->tableName( $table );
446 if (! isset( $this->numeric_version
) ) {
447 $this->getServerVersion();
450 if ( !is_array( $options ) ) {
451 $options = array( $options );
454 if ( isset( $args[0] ) && is_array( $args[0] ) ) {
456 $keys = array_keys( $args[0] );
459 $keys = array_keys( $args );
462 // If IGNORE is set, we use savepoints to emulate mysql's behavior
463 $ignore = in_array( 'IGNORE', $options ) ?
'mw' : '';
465 // If we are not in a transaction, we need to be for savepoint trickery
468 if ( !$this->mTrxLevel
) {
469 $this->begin( __METHOD__
);
472 $olde = error_reporting( 0 );
473 // For future use, we may want to track the number of actual inserts
474 // Right now, insert (all writes) simply return true/false
475 $numrowsinserted = 0;
478 $sql = "INSERT INTO $table (" . implode( ',', $keys ) . ') VALUES ';
481 if ( $this->numeric_version
>= 8.2 && !$ignore ) {
483 foreach ( $args as $row ) {
489 $sql .= '(' . $this->makeList( $row ) . ')';
491 $res = (bool)$this->query( $sql, $fname, $ignore );
495 foreach ( $args as $row ) {
497 $tempsql .= '(' . $this->makeList( $row ) . ')';
500 pg_query( $this->mConn
, "SAVEPOINT $ignore" );
503 $tempres = (bool)$this->query( $tempsql, $fname, $ignore );
506 $bar = pg_last_error();
507 if ( $bar != false ) {
508 pg_query( $this->mConn
, "ROLLBACK TO $ignore" );
510 pg_query( $this->mConn
, "RELEASE $ignore" );
515 // If any of them fail, we fail overall for this function call
516 // Note that this will be ignored if IGNORE is set
523 // Not multi, just a lone insert
525 pg_query($this->mConn
, "SAVEPOINT $ignore");
528 $sql .= '(' . $this->makeList( $args ) . ')';
529 $res = (bool)$this->query( $sql, $fname, $ignore );
531 $bar = pg_last_error();
532 if ( $bar != false ) {
533 pg_query( $this->mConn
, "ROLLBACK TO $ignore" );
535 pg_query( $this->mConn
, "RELEASE $ignore" );
541 $olde = error_reporting( $olde );
543 $this->commit( __METHOD__
);
546 // Set the affected row count for the whole operation
547 $this->mAffectedRows
= $numrowsinserted;
549 // IGNORE always returns true
557 * INSERT SELECT wrapper
558 * $varMap must be an associative array of the form array( 'dest1' => 'source1', ...)
559 * Source items may be literals rather then field names, but strings should be quoted with Database::addQuotes()
560 * $conds may be "*" to copy the whole table
561 * srcTable may be an array of tables.
562 * @todo FIXME: Implement this a little better (seperate select/insert)?
565 function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = 'DatabasePostgres::insertSelect',
566 $insertOptions = array(), $selectOptions = array() )
568 $destTable = $this->tableName( $destTable );
570 // If IGNORE is set, we use savepoints to emulate mysql's behavior
571 $ignore = in_array( 'IGNORE', $insertOptions ) ?
'mw' : '';
573 if( is_array( $insertOptions ) ) {
574 $insertOptions = implode( ' ', $insertOptions ); // FIXME: This is unused
576 if( !is_array( $selectOptions ) ) {
577 $selectOptions = array( $selectOptions );
579 list( $startOpts, $useIndex, $tailOpts ) = $this->makeSelectOptions( $selectOptions );
580 if( is_array( $srcTable ) ) {
581 $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) );
583 $srcTable = $this->tableName( $srcTable );
586 // If we are not in a transaction, we need to be for savepoint trickery
589 if( !$this->mTrxLevel
) {
590 $this->begin( __METHOD__
);
593 $olde = error_reporting( 0 );
594 $numrowsinserted = 0;
595 pg_query( $this->mConn
, "SAVEPOINT $ignore");
598 $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' .
599 " SELECT $startOpts " . implode( ',', $varMap ) .
600 " FROM $srcTable $useIndex";
602 if ( $conds != '*' ) {
603 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND
);
606 $sql .= " $tailOpts";
608 $res = (bool)$this->query( $sql, $fname, $ignore );
610 $bar = pg_last_error();
611 if( $bar != false ) {
612 pg_query( $this->mConn
, "ROLLBACK TO $ignore" );
614 pg_query( $this->mConn
, "RELEASE $ignore" );
617 $olde = error_reporting( $olde );
619 $this->commit( __METHOD__
);
622 // Set the affected row count for the whole operation
623 $this->mAffectedRows
= $numrowsinserted;
625 // IGNORE always returns true
632 function tableName( $name, $format = 'quoted' ) {
633 # Replace reserved words with better ones
638 return 'pagecontent';
640 return parent
::tableName( $name, $format );
645 * Return the next in a sequence, save the value for retrieval via insertId()
648 function nextSequenceValue( $seqName ) {
649 $safeseq = str_replace( "'", "''", $seqName );
650 $res = $this->query( "SELECT nextval('$safeseq')" );
651 $row = $this->fetchRow( $res );
652 $this->mInsertId
= $row[0];
653 return $this->mInsertId
;
657 * Return the current value of a sequence. Assumes it has been nextval'ed in this session.
660 function currentSequenceValue( $seqName ) {
661 $safeseq = str_replace( "'", "''", $seqName );
662 $res = $this->query( "SELECT currval('$safeseq')" );
663 $row = $this->fetchRow( $res );
668 # Returns the size of a text field, or -1 for "unlimited"
669 function textFieldSize( $table, $field ) {
670 $table = $this->tableName( $table );
671 $sql = "SELECT t.typname as ftype,a.atttypmod as size
672 FROM pg_class c, pg_attribute a, pg_type t
673 WHERE relname='$table' AND a.attrelid=c.oid AND
674 a.atttypid=t.oid and a.attname='$field'";
675 $res =$this->query( $sql );
676 $row = $this->fetchObject( $res );
677 if ( $row->ftype
== 'varchar' ) {
678 $size = $row->size
- 4;
685 function limitResult( $sql, $limit, $offset = false ) {
686 return "$sql LIMIT $limit " . ( is_numeric( $offset ) ?
" OFFSET {$offset} " : '' );
689 function wasDeadlock() {
690 return $this->lastErrno() == '40P01';
693 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabasePostgres::duplicateTableStructure' ) {
694 $newName = $this->addIdentifierQuotes( $newName );
695 $oldName = $this->addIdentifierQuotes( $oldName );
696 return $this->query( 'CREATE ' . ( $temporary ?
'TEMPORARY ' : '' ) . " TABLE $newName (LIKE $oldName INCLUDING DEFAULTS)", $fname );
699 function listTables( $prefix = null, $fname = 'DatabasePostgres::listTables' ) {
700 global $wgDBmwschema;
701 $eschema = $this->addQuotes( $wgDBmwschema );
702 $result = $this->query( "SELECT tablename FROM pg_tables WHERE schemaname = $eschema", $fname );
706 foreach( $result as $table ) {
707 $vars = get_object_vars($table);
708 $table = array_pop( $vars );
709 if( !$prefix ||
strpos( $table, $prefix ) === 0 ) {
710 $endArray[] = $table;
717 function timestamp( $ts = 0 ) {
718 return wfTimestamp( TS_POSTGRES
, $ts );
722 * Return aggregated value function call
724 function aggregateValue( $valuedata, $valuename = 'value' ) {
729 * @return string wikitext of a link to the server software's web site
731 public static function getSoftwareLink() {
732 return '[http://www.postgresql.org/ PostgreSQL]';
736 * @return string Version information from the database
738 function getServerVersion() {
739 if ( !isset( $this->numeric_version
) ) {
740 $versionInfo = pg_version( $this->mConn
);
741 if ( version_compare( $versionInfo['client'], '7.4.0', 'lt' ) ) {
742 // Old client, abort install
743 $this->numeric_version
= '7.3 or earlier';
744 } elseif ( isset( $versionInfo['server'] ) ) {
746 $this->numeric_version
= $versionInfo['server'];
748 // Bug 16937: broken pgsql extension from PHP<5.3
749 $this->numeric_version
= pg_parameter_status( $this->mConn
, 'server_version' );
752 return $this->numeric_version
;
756 * Query whether a given relation exists (in the given schema, or the
757 * default mw one if not given)
760 function relationExists( $table, $types, $schema = false ) {
761 global $wgDBmwschema;
762 if ( !is_array( $types ) ) {
763 $types = array( $types );
766 $schema = $wgDBmwschema;
768 $table = $this->tableName( $table, 'raw' );
769 $etable = $this->addQuotes( $table );
770 $eschema = $this->addQuotes( $schema );
771 $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
772 . "WHERE c.relnamespace = n.oid AND c.relname = $etable AND n.nspname = $eschema "
773 . "AND c.relkind IN ('" . implode( "','", $types ) . "')";
774 $res = $this->query( $SQL );
775 $count = $res ?
$res->numRows() : 0;
780 * For backward compatibility, this function checks both tables and
784 function tableExists( $table, $fname = __METHOD__
, $schema = false ) {
785 return $this->relationExists( $table, array( 'r', 'v' ), $schema );
788 function sequenceExists( $sequence, $schema = false ) {
789 return $this->relationExists( $sequence, 'S', $schema );
792 function triggerExists( $table, $trigger ) {
793 global $wgDBmwschema;
796 SELECT 1 FROM pg_class, pg_namespace, pg_trigger
797 WHERE relnamespace=pg_namespace.oid AND relkind='r'
798 AND tgrelid=pg_class.oid
799 AND nspname=%s AND relname=%s AND tgname=%s
804 $this->addQuotes( $wgDBmwschema ),
805 $this->addQuotes( $table ),
806 $this->addQuotes( $trigger )
812 $rows = $res->numRows();
816 function ruleExists( $table, $rule ) {
817 global $wgDBmwschema;
818 $exists = $this->selectField( 'pg_rules', 'rulename',
821 'tablename' => $table,
822 'schemaname' => $wgDBmwschema
825 return $exists === $rule;
828 function constraintExists( $table, $constraint ) {
829 global $wgDBmwschema;
830 $SQL = sprintf( "SELECT 1 FROM information_schema.table_constraints ".
831 "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s",
832 $this->addQuotes( $wgDBmwschema ),
833 $this->addQuotes( $table ),
834 $this->addQuotes( $constraint )
836 $res = $this->query( $SQL );
840 $rows = $res->numRows();
845 * Query whether a given schema exists. Returns true if it does, false if it doesn't.
848 function schemaExists( $schema ) {
849 $exists = $this->selectField( '"pg_catalog"."pg_namespace"', 1,
850 array( 'nspname' => $schema ), __METHOD__
);
851 return (bool)$exists;
855 * Returns true if a given role (i.e. user) exists, false otherwise.
858 function roleExists( $roleName ) {
859 $exists = $this->selectField( '"pg_catalog"."pg_roles"', 1,
860 array( 'rolname' => $roleName ), __METHOD__
);
861 return (bool)$exists;
864 function fieldInfo( $table, $field ) {
865 return PostgresField
::fromText( $this, $table, $field );
869 * pg_field_type() wrapper
872 function fieldType( $res, $index ) {
873 if ( $res instanceof ResultWrapper
) {
876 return pg_field_type( $res, $index );
879 /* Not even sure why this is used in the main codebase... */
880 function limitResultForUpdate( $sql, $num ) {
888 function encodeBlob( $b ) {
889 return new Blob( pg_escape_bytea( $this->mConn
, $b ) );
892 function decodeBlob( $b ) {
893 if ( $b instanceof Blob
) {
896 return pg_unescape_bytea( $b );
899 function strencode( $s ) { # Should not be called by us
900 return pg_escape_string( $this->mConn
, $s );
904 * @param $s null|bool|Blob
907 function addQuotes( $s ) {
908 if ( is_null( $s ) ) {
910 } elseif ( is_bool( $s ) ) {
912 } elseif ( $s instanceof Blob
) {
913 return "'" . $s->fetch( $s ) . "'";
915 return "'" . pg_escape_string( $this->mConn
, $s ) . "'";
919 * Postgres specific version of replaceVars.
920 * Calls the parent version in Database.php
924 * @param $ins String: SQL string, read from a stream (usually tables.sql)
926 * @return string SQL string
928 protected function replaceVars( $ins ) {
929 $ins = parent
::replaceVars( $ins );
931 if ( $this->numeric_version
>= 8.3 ) {
932 // Thanks for not providing backwards-compatibility, 8.3
933 $ins = preg_replace( "/to_tsvector\s*\(\s*'default'\s*,/", 'to_tsvector(', $ins );
936 if ( $this->numeric_version
<= 8.1 ) { // Our minimum version
937 $ins = str_replace( 'USING gin', 'USING gist', $ins );
944 * Various select options
948 * @param $options Array: an associative array of options to be turned into
949 * an SQL query, valid keys are listed in the function.
952 function makeSelectOptions( $options ) {
953 $preLimitTail = $postLimitTail = '';
954 $startOpts = $useIndex = '';
956 $noKeyOptions = array();
957 foreach ( $options as $key => $option ) {
958 if ( is_numeric( $key ) ) {
959 $noKeyOptions[$option] = true;
963 if ( isset( $options['GROUP BY'] ) ) {
964 $gb = is_array( $options['GROUP BY'] )
965 ?
implode( ',', $options['GROUP BY'] )
966 : $options['GROUP BY'];
967 $preLimitTail .= " GROUP BY {$gb}";
970 if ( isset( $options['HAVING'] ) ) {
971 $preLimitTail .= " HAVING {$options['HAVING']}";
974 if ( isset( $options['ORDER BY'] ) ) {
975 $ob = is_array( $options['ORDER BY'] )
976 ?
implode( ',', $options['ORDER BY'] )
977 : $options['ORDER BY'];
978 $preLimitTail .= " ORDER BY {$ob}";
981 //if ( isset( $options['LIMIT'] ) ) {
982 // $tailOpts .= $this->limitResult( '', $options['LIMIT'],
983 // isset( $options['OFFSET'] ) ? $options['OFFSET']
987 if ( isset( $noKeyOptions['FOR UPDATE'] ) ) {
988 $postLimitTail .= ' FOR UPDATE';
990 if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) {
991 $postLimitTail .= ' LOCK IN SHARE MODE';
993 if ( isset( $noKeyOptions['DISTINCT'] ) ||
isset( $noKeyOptions['DISTINCTROW'] ) ) {
994 $startOpts .= 'DISTINCT';
997 return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail );
1000 function setFakeMaster( $enabled = true ) {}
1002 function getDBname() {
1003 return $this->mDBname
;
1006 function getServer() {
1007 return $this->mServer
;
1010 function buildConcat( $stringList ) {
1011 return implode( ' || ', $stringList );
1014 public function getSearchEngine() {
1015 return 'SearchPostgres';
1018 public function streamStatementEnd( &$sql, &$newLine ) {
1019 # Allow dollar quoting for function declarations
1020 if ( substr( $newLine, 0, 4 ) == '$mw$' ) {
1021 if ( $this->delimiter
) {
1022 $this->delimiter
= false;
1025 $this->delimiter
= ';';
1028 return parent
::streamStatementEnd( $sql, $newLine );
1030 } // end DatabasePostgres class