3 * This is the Postgres database abstraction layer.
9 class PostgresField implements Field {
10 private $name, $tablename, $type, $nullable, $max_length, $deferred, $deferrable, $conname;
12 static function fromText($db, $table, $field) {
17 attnotnull, attlen, COALESCE(conname, '') AS conname,
18 COALESCE(condeferred, 'f') AS deferred,
19 COALESCE(condeferrable, 'f') AS deferrable,
20 CASE WHEN typname = 'int2' THEN 'smallint'
21 WHEN typname = 'int4' THEN 'integer'
22 WHEN typname = 'int8' THEN 'bigint'
23 WHEN typname = 'bpchar' THEN 'char'
24 ELSE typname END AS typname
26 JOIN pg_namespace n ON (n.oid = c.relnamespace)
27 JOIN pg_attribute a ON (a.attrelid = c.oid)
28 JOIN pg_type t ON (t.oid = a.atttypid)
29 LEFT JOIN pg_constraint o ON (o.conrelid = c.oid AND a.attnum = ANY(o.conkey) AND o.contype = 'f')
36 $table = $db->tableName( $table );
39 $db->addQuotes( $wgDBmwschema ),
40 $db->addQuotes( $table ),
41 $db->addQuotes( $field )
44 $row = $db->fetchObject( $res );
48 $n = new PostgresField;
49 $n->type = $row->typname;
50 $n->nullable = ( $row->attnotnull == 'f' );
52 $n->tablename = $table;
53 $n->max_length = $row->attlen;
54 $n->deferrable = ( $row->deferrable == 't' );
55 $n->deferred = ( $row->deferred == 't' );
56 $n->conname = $row->conname;
64 function tableName() {
65 return $this->tablename;
72 function isNullable() {
73 return $this->nullable;
76 function maxLength() {
77 return $this->max_length;
80 function is_deferrable() {
81 return $this->deferrable;
84 function is_deferred() {
85 return $this->deferred;
89 return $this->conname;
97 class DatabasePostgres extends DatabaseBase {
98 var $mInsertId = null;
99 var $mLastResult = null;
100 var $numeric_version = null;
101 var $mAffectedRows = null;
107 function cascadingDeletes() {
110 function cleanupTriggers() {
113 function strictIPs() {
116 function realTimestamps() {
119 function implicitGroupby() {
122 function implicitOrderby() {
125 function searchableIPs() {
128 function functionalIndexes() {
132 function hasConstraint( $name ) {
133 global $wgDBmwschema;
134 $SQL = "SELECT 1 FROM pg_catalog.pg_constraint c, pg_catalog.pg_namespace n WHERE c.connamespace = n.oid AND conname = '" .
135 pg_escape_string( $this->mConn, $name ) . "' AND n.nspname = '" . pg_escape_string( $this->mConn, $wgDBmwschema ) ."'";
136 $res = $this->doQuery( $SQL );
137 return $this->numRows( $res );
140 static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) {
141 return new DatabasePostgres( $server, $user, $password, $dbName, $flags );
145 * Usually aborts on failure
147 function open( $server, $user, $password, $dbName ) {
148 # Test for Postgres support, to avoid suppressed fatal error
149 if ( !function_exists( 'pg_connect' ) ) {
150 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" );
155 if ( !strlen( $user ) ) { # e.g. the class is being loaded
159 $this->mServer = $server;
160 $this->mPort = $port = $wgDBport;
161 $this->mUser = $user;
162 $this->mPassword = $password;
163 $this->mDBname = $dbName;
165 $connectVars = array(
168 'password' => $password
170 if ( $server != false && $server != '' ) {
171 $connectVars['host'] = $server;
173 if ( $port != false && $port != '' ) {
174 $connectVars['port'] = $port;
176 $connectString = $this->makeConnectionString( $connectVars, PGSQL_CONNECT_FORCE_NEW );
178 $this->installErrorHandler();
179 $this->mConn = pg_connect( $connectString );
180 $phpError = $this->restoreErrorHandler();
182 if ( !$this->mConn ) {
183 wfDebug( "DB connection error\n" );
184 wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" );
185 wfDebug( $this->lastError() . "\n" );
186 throw new DBConnectionError( $this, str_replace( "\n", ' ', $phpError ) );
189 $this->mOpened = true;
191 global $wgCommandLineMode;
192 # If called from the command-line (e.g. importDump), only show errors
193 if ( $wgCommandLineMode ) {
194 $this->doQuery( "SET client_min_messages = 'ERROR'" );
197 $this->doQuery( "SET client_encoding='UTF8'" );
199 global $wgDBmwschema, $wgDBts2schema;
200 if ( isset( $wgDBmwschema ) && isset( $wgDBts2schema )
201 && $wgDBmwschema !== 'mediawiki'
202 && preg_match( '/^\w+$/', $wgDBmwschema )
203 && preg_match( '/^\w+$/', $wgDBts2schema )
205 $safeschema = $this->addIdentifierQuotes( $wgDBmwschema );
206 $this->doQuery( "SET search_path = $safeschema, $wgDBts2schema, public" );
212 function makeConnectionString( $vars ) {
214 foreach ( $vars as $name => $value ) {
215 $s .= "$name='" . str_replace( "'", "\\'", $value ) . "' ";
221 * Closes a database connection, if it is open
222 * Returns success, true if already closed
225 $this->mOpened = false;
226 if ( $this->mConn ) {
227 return pg_close( $this->mConn );
233 function doQuery( $sql ) {
234 if ( function_exists( 'mb_convert_encoding' ) ) {
235 $sql = mb_convert_encoding( $sql, 'UTF-8' );
237 $this->mLastResult = pg_query( $this->mConn, $sql );
238 $this->mAffectedRows = null; // use pg_affected_rows(mLastResult)
239 return $this->mLastResult;
242 function queryIgnore( $sql, $fname = 'DatabasePostgres::queryIgnore' ) {
243 return $this->query( $sql, $fname, true );
246 function freeResult( $res ) {
247 if ( $res instanceof ResultWrapper ) {
250 if ( !@pg_free_result( $res ) ) {
251 throw new DBUnexpectedError( $this, "Unable to free Postgres result\n" );
255 function fetchObject( $res ) {
256 if ( $res instanceof ResultWrapper ) {
259 @$row = pg_fetch_object( $res );
260 # FIXME: HACK HACK HACK HACK debug
263 # hashar : not sure if the following test really trigger if the object
265 if( pg_last_error( $this->mConn ) ) {
266 throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) );
271 function fetchRow( $res ) {
272 if ( $res instanceof ResultWrapper ) {
275 @$row = pg_fetch_array( $res );
276 if( pg_last_error( $this->mConn ) ) {
277 throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) );
282 function numRows( $res ) {
283 if ( $res instanceof ResultWrapper ) {
286 @$n = pg_num_rows( $res );
287 if( pg_last_error( $this->mConn ) ) {
288 throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn ) ) );
293 function numFields( $res ) {
294 if ( $res instanceof ResultWrapper ) {
297 return pg_num_fields( $res );
300 function fieldName( $res, $n ) {
301 if ( $res instanceof ResultWrapper ) {
304 return pg_field_name( $res, $n );
308 * This must be called after nextSequenceVal
310 function insertId() {
311 return $this->mInsertId;
314 function dataSeek( $res, $row ) {
315 if ( $res instanceof ResultWrapper ) {
318 return pg_result_seek( $res, $row );
321 function lastError() {
322 if ( $this->mConn ) {
323 return pg_last_error();
325 return 'No database connection';
328 function lastErrno() {
329 return pg_last_error() ? 1 : 0;
332 function affectedRows() {
333 if ( !is_null( $this->mAffectedRows ) ) {
334 // Forced result for simulated queries
335 return $this->mAffectedRows;
337 if( empty( $this->mLastResult ) ) {
340 return pg_affected_rows( $this->mLastResult );
344 * Estimate rows in dataset
345 * Returns estimated count, based on EXPLAIN output
346 * This is not necessarily an accurate estimate, so use sparingly
347 * Returns -1 if count cannot be found
348 * Takes same arguments as Database::select()
350 function estimateRowCount( $table, $vars = '*', $conds='', $fname = 'DatabasePostgres::estimateRowCount', $options = array() ) {
351 $options['EXPLAIN'] = true;
352 $res = $this->select( $table, $vars, $conds, $fname, $options );
355 $row = $this->fetchRow( $res );
357 if( preg_match( '/rows=(\d+)/', $row[0], $count ) ) {
365 * Returns information about an index
366 * If errors are explicitly ignored, returns NULL on failure
368 function indexInfo( $table, $index, $fname = 'DatabasePostgres::indexInfo' ) {
369 $sql = "SELECT indexname FROM pg_indexes WHERE tablename='$table'";
370 $res = $this->query( $sql, $fname );
374 foreach ( $res as $row ) {
375 if ( $row->indexname == $this->indexName( $index ) ) {
382 function indexUnique( $table, $index, $fname = 'DatabasePostgres::indexUnique' ) {
383 $sql = "SELECT indexname FROM pg_indexes WHERE tablename='{$table}'".
384 " AND indexdef LIKE 'CREATE UNIQUE%(" .
385 $this->strencode( $this->indexName( $index ) ) .
387 $res = $this->query( $sql, $fname );
391 foreach ( $res as $row ) {
398 * INSERT wrapper, inserts an array into a table
400 * $args may be a single associative array, or an array of these with numeric keys,
401 * for multi-row insert (Postgres version 8.2 and above only).
403 * @param $table String: Name of the table to insert to.
404 * @param $args Array: Items to insert into the table.
405 * @param $fname String: Name of the function, for profiling
406 * @param $options String or Array. Valid options: IGNORE
408 * @return bool Success of insert operation. IGNORE always returns true.
410 function insert( $table, $args, $fname = 'DatabasePostgres::insert', $options = array() ) {
411 if ( !count( $args ) ) {
415 $table = $this->tableName( $table );
416 if (! isset( $this->numeric_version ) ) {
417 $this->getServerVersion();
420 if ( !is_array( $options ) ) {
421 $options = array( $options );
424 if ( isset( $args[0] ) && is_array( $args[0] ) ) {
426 $keys = array_keys( $args[0] );
429 $keys = array_keys( $args );
432 // If IGNORE is set, we use savepoints to emulate mysql's behavior
433 $ignore = in_array( 'IGNORE', $options ) ? 'mw' : '';
435 // If we are not in a transaction, we need to be for savepoint trickery
438 if ( !$this->mTrxLevel ) {
442 $olde = error_reporting( 0 );
443 // For future use, we may want to track the number of actual inserts
444 // Right now, insert (all writes) simply return true/false
445 $numrowsinserted = 0;
448 $sql = "INSERT INTO $table (" . implode( ',', $keys ) . ') VALUES ';
451 if ( $this->numeric_version >= 8.2 && !$ignore ) {
453 foreach ( $args as $row ) {
459 $sql .= '(' . $this->makeList( $row ) . ')';
461 $res = (bool)$this->query( $sql, $fname, $ignore );
465 foreach ( $args as $row ) {
467 $tempsql .= '(' . $this->makeList( $row ) . ')';
470 pg_query( $this->mConn, "SAVEPOINT $ignore" );
473 $tempres = (bool)$this->query( $tempsql, $fname, $ignore );
476 $bar = pg_last_error();
477 if ( $bar != false ) {
478 pg_query( $this->mConn, "ROLLBACK TO $ignore" );
480 pg_query( $this->mConn, "RELEASE $ignore" );
485 // If any of them fail, we fail overall for this function call
486 // Note that this will be ignored if IGNORE is set
493 // Not multi, just a lone insert
495 pg_query($this->mConn, "SAVEPOINT $ignore");
498 $sql .= '(' . $this->makeList( $args ) . ')';
499 $res = (bool)$this->query( $sql, $fname, $ignore );
501 $bar = pg_last_error();
502 if ( $bar != false ) {
503 pg_query( $this->mConn, "ROLLBACK TO $ignore" );
505 pg_query( $this->mConn, "RELEASE $ignore" );
511 $olde = error_reporting( $olde );
516 // Set the affected row count for the whole operation
517 $this->mAffectedRows = $numrowsinserted;
519 // IGNORE always returns true
527 * INSERT SELECT wrapper
528 * $varMap must be an associative array of the form array( 'dest1' => 'source1', ...)
529 * Source items may be literals rather then field names, but strings should be quoted with Database::addQuotes()
530 * $conds may be "*" to copy the whole table
531 * srcTable may be an array of tables.
532 * @todo FIXME: implement this a little better (seperate select/insert)?
534 function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = 'DatabasePostgres::insertSelect',
535 $insertOptions = array(), $selectOptions = array() )
537 $destTable = $this->tableName( $destTable );
539 // If IGNORE is set, we use savepoints to emulate mysql's behavior
540 $ignore = in_array( 'IGNORE', $insertOptions ) ? 'mw' : '';
542 if( is_array( $insertOptions ) ) {
543 $insertOptions = implode( ' ', $insertOptions );
545 if( !is_array( $selectOptions ) ) {
546 $selectOptions = array( $selectOptions );
548 list( $startOpts, $useIndex, $tailOpts ) = $this->makeSelectOptions( $selectOptions );
549 if( is_array( $srcTable ) ) {
550 $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) );
552 $srcTable = $this->tableName( $srcTable );
555 // If we are not in a transaction, we need to be for savepoint trickery
558 if( !$this->mTrxLevel ) {
562 $olde = error_reporting( 0 );
563 $numrowsinserted = 0;
564 pg_query( $this->mConn, "SAVEPOINT $ignore");
567 $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' .
568 " SELECT $startOpts " . implode( ',', $varMap ) .
569 " FROM $srcTable $useIndex";
571 if ( $conds != '*' ) {
572 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
575 $sql .= " $tailOpts";
577 $res = (bool)$this->query( $sql, $fname, $ignore );
579 $bar = pg_last_error();
580 if( $bar != false ) {
581 pg_query( $this->mConn, "ROLLBACK TO $ignore" );
583 pg_query( $this->mConn, "RELEASE $ignore" );
586 $olde = error_reporting( $olde );
591 // Set the affected row count for the whole operation
592 $this->mAffectedRows = $numrowsinserted;
594 // IGNORE always returns true
601 function tableName( $name ) {
602 # Replace reserved words with better ones
607 return 'pagecontent';
614 * Return the next in a sequence, save the value for retrieval via insertId()
616 function nextSequenceValue( $seqName ) {
617 $safeseq = str_replace( "'", "''", $seqName );
618 $res = $this->query( "SELECT nextval('$safeseq')" );
619 $row = $this->fetchRow( $res );
620 $this->mInsertId = $row[0];
621 return $this->mInsertId;
625 * Return the current value of a sequence. Assumes it has been nextval'ed in this session.
627 function currentSequenceValue( $seqName ) {
628 $safeseq = str_replace( "'", "''", $seqName );
629 $res = $this->query( "SELECT currval('$safeseq')" );
630 $row = $this->fetchRow( $res );
636 * REPLACE query wrapper
637 * Postgres simulates this with a DELETE followed by INSERT
638 * $row is the row to insert, an associative array
639 * $uniqueIndexes is an array of indexes. Each element may be either a
640 * field name or an array of field names
642 * It may be more efficient to leave off unique indexes which are unlikely to collide.
643 * However if you do this, you run the risk of encountering errors which wouldn't have
646 function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabasePostgres::replace' ) {
647 $table = $this->tableName( $table );
649 if ( count( $rows ) == 0 ) {
654 if ( !is_array( reset( $rows ) ) ) {
655 $rows = array( $rows );
658 foreach( $rows as $row ) {
659 # Delete rows which collide
660 if ( $uniqueIndexes ) {
661 $sql = "DELETE FROM $table WHERE ";
663 foreach ( $uniqueIndexes as $index ) {
670 if ( is_array( $index ) ) {
672 foreach ( $index as $col ) {
678 $sql .= $col.'=' . $this->addQuotes( $row[$col] );
681 $sql .= $index.'=' . $this->addQuotes( $row[$index] );
685 $this->query( $sql, $fname );
689 $sql = "INSERT INTO $table (" . $this->makeList( array_keys( $row ), LIST_NAMES ) .') VALUES (' .
690 $this->makeList( $row, LIST_COMMA ) . ')';
691 $this->query( $sql, $fname );
695 # DELETE where the condition is a join
696 function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabasePostgres::deleteJoin' ) {
698 throw new DBUnexpectedError( $this, 'DatabasePostgres::deleteJoin() called with empty $conds' );
701 $delTable = $this->tableName( $delTable );
702 $joinTable = $this->tableName( $joinTable );
703 $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable ";
704 if ( $conds != '*' ) {
705 $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
709 $this->query( $sql, $fname );
712 # Returns the size of a text field, or -1 for "unlimited"
713 function textFieldSize( $table, $field ) {
714 $table = $this->tableName( $table );
715 $sql = "SELECT t.typname as ftype,a.atttypmod as size
716 FROM pg_class c, pg_attribute a, pg_type t
717 WHERE relname='$table' AND a.attrelid=c.oid AND
718 a.atttypid=t.oid and a.attname='$field'";
719 $res =$this->query( $sql );
720 $row = $this->fetchObject( $res );
721 if ( $row->ftype == 'varchar' ) {
722 $size = $row->size - 4;
729 function limitResult( $sql, $limit, $offset = false ) {
730 return "$sql LIMIT $limit " . ( is_numeric( $offset ) ? " OFFSET {$offset} " : '' );
733 function wasDeadlock() {
734 return $this->lastErrno() == '40P01';
737 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabasePostgres::duplicateTableStructure' ) {
738 return $this->query( 'CREATE ' . ( $temporary ? 'TEMPORARY ' : '' ) . " TABLE $newName (LIKE $oldName INCLUDING DEFAULTS)", $fname );
741 function timestamp( $ts = 0 ) {
742 return wfTimestamp( TS_POSTGRES, $ts );
746 * Return aggregated value function call
748 function aggregateValue( $valuedata, $valuename = 'value' ) {
753 * @return string wikitext of a link to the server software's web site
755 public static function getSoftwareLink() {
756 return '[http://www.postgresql.org/ PostgreSQL]';
760 * @return string Version information from the database
762 function getServerVersion() {
763 if ( !isset( $this->numeric_version ) ) {
764 $versionInfo = pg_version( $this->mConn );
765 if ( version_compare( $versionInfo['client'], '7.4.0', 'lt' ) ) {
766 // Old client, abort install
767 $this->numeric_version = '7.3 or earlier';
768 } elseif ( isset( $versionInfo['server'] ) ) {
770 $this->numeric_version = $versionInfo['server'];
772 // Bug 16937: broken pgsql extension from PHP<5.3
773 $this->numeric_version = pg_parameter_status( $this->mConn, 'server_version' );
776 return $this->numeric_version;
780 * Query whether a given relation exists (in the given schema, or the
781 * default mw one if not given)
783 function relationExists( $table, $types, $schema = false ) {
784 global $wgDBmwschema;
785 if ( !is_array( $types ) ) {
786 $types = array( $types );
789 $schema = $wgDBmwschema;
791 $etable = $this->addQuotes( $table );
792 $eschema = $this->addQuotes( $schema );
793 $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
794 . "WHERE c.relnamespace = n.oid AND c.relname = $etable AND n.nspname = $eschema "
795 . "AND c.relkind IN ('" . implode( "','", $types ) . "')";
796 $res = $this->query( $SQL );
797 $count = $res ? $res->numRows() : 0;
802 * For backward compatibility, this function checks both tables and
805 function tableExists( $table, $schema = false ) {
806 return $this->relationExists( $table, array( 'r', 'v' ), $schema );
809 function sequenceExists( $sequence, $schema = false ) {
810 return $this->relationExists( $sequence, 'S', $schema );
813 function triggerExists( $table, $trigger ) {
814 global $wgDBmwschema;
817 SELECT 1 FROM pg_class, pg_namespace, pg_trigger
818 WHERE relnamespace=pg_namespace.oid AND relkind='r'
819 AND tgrelid=pg_class.oid
820 AND nspname=%s AND relname=%s AND tgname=%s
825 $this->addQuotes( $wgDBmwschema ),
826 $this->addQuotes( $table ),
827 $this->addQuotes( $trigger )
833 $rows = $res->numRows();
837 function ruleExists( $table, $rule ) {
838 global $wgDBmwschema;
839 $exists = $this->selectField( 'pg_rules', 'rulename',
842 'tablename' => $table,
843 'schemaname' => $wgDBmwschema
846 return $exists === $rule;
849 function constraintExists( $table, $constraint ) {
850 global $wgDBmwschema;
851 $SQL = sprintf( "SELECT 1 FROM information_schema.table_constraints ".
852 "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s",
853 $this->addQuotes( $wgDBmwschema ),
854 $this->addQuotes( $table ),
855 $this->addQuotes( $constraint )
857 $res = $this->query( $SQL );
861 $rows = $res->numRows();
866 * Query whether a given schema exists. Returns true if it does, false if it doesn't.
868 function schemaExists( $schema ) {
869 $exists = $this->selectField( '"pg_catalog"."pg_namespace"', 1,
870 array( 'nspname' => $schema ), __METHOD__ );
871 return (bool)$exists;
875 * Returns true if a given role (i.e. user) exists, false otherwise.
877 function roleExists( $roleName ) {
878 $exists = $this->selectField( '"pg_catalog"."pg_roles"', 1,
879 array( 'rolname' => $roleName ), __METHOD__ );
880 return (bool)$exists;
883 function fieldInfo( $table, $field ) {
884 return PostgresField::fromText( $this, $table, $field );
888 * pg_field_type() wrapper
890 function fieldType( $res, $index ) {
891 if ( $res instanceof ResultWrapper ) {
894 return pg_field_type( $res, $index );
897 /* Not even sure why this is used in the main codebase... */
898 function limitResultForUpdate( $sql, $num ) {
902 function encodeBlob( $b ) {
903 return new Blob( pg_escape_bytea( $this->mConn, $b ) );
906 function decodeBlob( $b ) {
907 if ( $b instanceof Blob ) {
910 return pg_unescape_bytea( $b );
913 function strencode( $s ) { # Should not be called by us
914 return pg_escape_string( $this->mConn, $s );
917 function addQuotes( $s ) {
918 if ( is_null( $s ) ) {
920 } elseif ( is_bool( $s ) ) {
922 } elseif ( $s instanceof Blob ) {
923 return "'" . $s->fetch( $s ) . "'";
925 return "'" . pg_escape_string( $this->mConn, $s ) . "'";
929 * Postgres specific version of replaceVars.
930 * Calls the parent version in Database.php
934 * @param $ins String: SQL string, read from a stream (usually tables.sql)
936 * @return string SQL string
938 protected function replaceVars( $ins ) {
939 $ins = parent::replaceVars( $ins );
941 if ( $this->numeric_version >= 8.3 ) {
942 // Thanks for not providing backwards-compatibility, 8.3
943 $ins = preg_replace( "/to_tsvector\s*\(\s*'default'\s*,/", 'to_tsvector(', $ins );
946 if ( $this->numeric_version <= 8.1 ) { // Our minimum version
947 $ins = str_replace( 'USING gin', 'USING gist', $ins );
954 * Various select options
958 * @param $options Array: an associative array of options to be turned into
959 * an SQL query, valid keys are listed in the function.
962 function makeSelectOptions( $options ) {
963 $preLimitTail = $postLimitTail = '';
964 $startOpts = $useIndex = '';
966 $noKeyOptions = array();
967 foreach ( $options as $key => $option ) {
968 if ( is_numeric( $key ) ) {
969 $noKeyOptions[$option] = true;
973 if ( isset( $options['GROUP BY'] ) ) {
974 $preLimitTail .= ' GROUP BY ' . $options['GROUP BY'];
976 if ( isset( $options['HAVING'] ) ) {
977 $preLimitTail .= " HAVING {$options['HAVING']}";
979 if ( isset( $options['ORDER BY'] ) ) {
980 $preLimitTail .= ' ORDER BY ' . $options['ORDER BY'];
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';
1019 } // end DatabasePostgres class