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, false );
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
149 function open( $server, $user, $password, $dbName ) {
150 # Test for Postgres support, to avoid suppressed fatal error
151 if ( !function_exists( 'pg_connect' ) ) {
152 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" );
157 if ( !strlen( $user ) ) { # e.g. the class is being loaded
162 $this->mServer
= $server;
164 $this->mUser
= $user;
165 $this->mPassword
= $password;
166 $this->mDBname
= $dbName;
168 $connectVars = array(
171 'password' => $password
173 if ( $server != false && $server != '' ) {
174 $connectVars['host'] = $server;
176 if ( $port != false && $port != '' ) {
177 $connectVars['port'] = $port;
179 $connectString = $this->makeConnectionString( $connectVars, PGSQL_CONNECT_FORCE_NEW
);
181 $this->installErrorHandler();
182 $this->mConn
= pg_connect( $connectString );
183 $phpError = $this->restoreErrorHandler();
185 if ( !$this->mConn
) {
186 wfDebug( "DB connection error\n" );
187 wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" );
188 wfDebug( $this->lastError() . "\n" );
189 throw new DBConnectionError( $this, str_replace( "\n", ' ', $phpError ) );
192 $this->mOpened
= true;
194 global $wgCommandLineMode;
195 # If called from the command-line (e.g. importDump), only show errors
196 if ( $wgCommandLineMode ) {
197 $this->doQuery( "SET client_min_messages = 'ERROR'" );
200 $this->query( "SET client_encoding='UTF8'", __METHOD__
);
201 $this->query( "SET datestyle = 'ISO, YMD'", __METHOD__
);
202 $this->query( "SET timezone = 'GMT'", __METHOD__
);
204 global $wgDBmwschema;
205 if ( $this->schemaExists( $wgDBmwschema ) ) {
206 $safeschema = $this->addIdentifierQuotes( $wgDBmwschema );
207 $this->doQuery( "SET search_path = $safeschema" );
209 $this->doQuery( "SET search_path = public" );
216 * Postgres doesn't support selectDB in the same way MySQL does. So if the
217 * DB name doesn't match the open connection, open a new one
220 function selectDB( $db ) {
221 if ( $this->mDBname
!== $db ) {
222 return (bool)$this->open( $this->mServer
, $this->mUser
, $this->mPassword
, $db );
228 function makeConnectionString( $vars ) {
230 foreach ( $vars as $name => $value ) {
231 $s .= "$name='" . str_replace( "'", "\\'", $value ) . "' ";
237 * Closes a database connection, if it is open
238 * Returns success, true if already closed
241 $this->mOpened
= false;
242 if ( $this->mConn
) {
243 return pg_close( $this->mConn
);
249 protected function doQuery( $sql ) {
250 if ( function_exists( 'mb_convert_encoding' ) ) {
251 $sql = mb_convert_encoding( $sql, 'UTF-8' );
253 $this->mLastResult
= pg_query( $this->mConn
, $sql );
254 $this->mAffectedRows
= null; // use pg_affected_rows(mLastResult)
255 return $this->mLastResult
;
258 function queryIgnore( $sql, $fname = 'DatabasePostgres::queryIgnore' ) {
259 return $this->query( $sql, $fname, true );
262 function freeResult( $res ) {
263 if ( $res instanceof ResultWrapper
) {
266 if ( !@pg_free_result
( $res ) ) {
267 throw new DBUnexpectedError( $this, "Unable to free Postgres result\n" );
271 function fetchObject( $res ) {
272 if ( $res instanceof ResultWrapper
) {
275 @$row = pg_fetch_object( $res );
276 # @todo FIXME: HACK HACK HACK HACK debug
278 # @todo hashar: not sure if the following test really trigger if the object
280 if( pg_last_error( $this->mConn
) ) {
281 throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn
) ) );
286 function fetchRow( $res ) {
287 if ( $res instanceof ResultWrapper
) {
290 @$row = pg_fetch_array( $res );
291 if( pg_last_error( $this->mConn
) ) {
292 throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn
) ) );
297 function numRows( $res ) {
298 if ( $res instanceof ResultWrapper
) {
301 @$n = pg_num_rows( $res );
302 if( pg_last_error( $this->mConn
) ) {
303 throw new DBUnexpectedError( $this, 'SQL error: ' . htmlspecialchars( pg_last_error( $this->mConn
) ) );
308 function numFields( $res ) {
309 if ( $res instanceof ResultWrapper
) {
312 return pg_num_fields( $res );
315 function fieldName( $res, $n ) {
316 if ( $res instanceof ResultWrapper
) {
319 return pg_field_name( $res, $n );
323 * This must be called after nextSequenceVal
325 function insertId() {
326 return $this->mInsertId
;
329 function dataSeek( $res, $row ) {
330 if ( $res instanceof ResultWrapper
) {
333 return pg_result_seek( $res, $row );
336 function lastError() {
337 if ( $this->mConn
) {
338 return pg_last_error();
340 return 'No database connection';
343 function lastErrno() {
344 return pg_last_error() ?
1 : 0;
347 function affectedRows() {
348 if ( !is_null( $this->mAffectedRows
) ) {
349 // Forced result for simulated queries
350 return $this->mAffectedRows
;
352 if( empty( $this->mLastResult
) ) {
355 return pg_affected_rows( $this->mLastResult
);
359 * Estimate rows in dataset
360 * Returns estimated count, based on EXPLAIN output
361 * This is not necessarily an accurate estimate, so use sparingly
362 * Returns -1 if count cannot be found
363 * Takes same arguments as Database::select()
365 function estimateRowCount( $table, $vars = '*', $conds='', $fname = 'DatabasePostgres::estimateRowCount', $options = array() ) {
366 $options['EXPLAIN'] = true;
367 $res = $this->select( $table, $vars, $conds, $fname, $options );
370 $row = $this->fetchRow( $res );
372 if( preg_match( '/rows=(\d+)/', $row[0], $count ) ) {
380 * Returns information about an index
381 * If errors are explicitly ignored, returns NULL on failure
383 function indexInfo( $table, $index, $fname = 'DatabasePostgres::indexInfo' ) {
384 $sql = "SELECT indexname FROM pg_indexes WHERE tablename='$table'";
385 $res = $this->query( $sql, $fname );
389 foreach ( $res as $row ) {
390 if ( $row->indexname
== $this->indexName( $index ) ) {
397 function indexUnique( $table, $index, $fname = 'DatabasePostgres::indexUnique' ) {
398 $sql = "SELECT indexname FROM pg_indexes WHERE tablename='{$table}'".
399 " AND indexdef LIKE 'CREATE UNIQUE%(" .
400 $this->strencode( $this->indexName( $index ) ) .
402 $res = $this->query( $sql, $fname );
406 foreach ( $res as $row ) {
413 * INSERT wrapper, inserts an array into a table
415 * $args may be a single associative array, or an array of these with numeric keys,
416 * for multi-row insert (Postgres version 8.2 and above only).
418 * @param $table String: Name of the table to insert to.
419 * @param $args Array: Items to insert into the table.
420 * @param $fname String: Name of the function, for profiling
421 * @param $options String or Array. Valid options: IGNORE
423 * @return bool Success of insert operation. IGNORE always returns true.
425 function insert( $table, $args, $fname = 'DatabasePostgres::insert', $options = array() ) {
426 if ( !count( $args ) ) {
430 $table = $this->tableName( $table );
431 if (! isset( $this->numeric_version
) ) {
432 $this->getServerVersion();
435 if ( !is_array( $options ) ) {
436 $options = array( $options );
439 if ( isset( $args[0] ) && is_array( $args[0] ) ) {
441 $keys = array_keys( $args[0] );
444 $keys = array_keys( $args );
447 // If IGNORE is set, we use savepoints to emulate mysql's behavior
448 $ignore = in_array( 'IGNORE', $options ) ?
'mw' : '';
450 // If we are not in a transaction, we need to be for savepoint trickery
453 if ( !$this->mTrxLevel
) {
457 $olde = error_reporting( 0 );
458 // For future use, we may want to track the number of actual inserts
459 // Right now, insert (all writes) simply return true/false
460 $numrowsinserted = 0;
463 $sql = "INSERT INTO $table (" . implode( ',', $keys ) . ') VALUES ';
466 if ( $this->numeric_version
>= 8.2 && !$ignore ) {
468 foreach ( $args as $row ) {
474 $sql .= '(' . $this->makeList( $row ) . ')';
476 $res = (bool)$this->query( $sql, $fname, $ignore );
480 foreach ( $args as $row ) {
482 $tempsql .= '(' . $this->makeList( $row ) . ')';
485 pg_query( $this->mConn
, "SAVEPOINT $ignore" );
488 $tempres = (bool)$this->query( $tempsql, $fname, $ignore );
491 $bar = pg_last_error();
492 if ( $bar != false ) {
493 pg_query( $this->mConn
, "ROLLBACK TO $ignore" );
495 pg_query( $this->mConn
, "RELEASE $ignore" );
500 // If any of them fail, we fail overall for this function call
501 // Note that this will be ignored if IGNORE is set
508 // Not multi, just a lone insert
510 pg_query($this->mConn
, "SAVEPOINT $ignore");
513 $sql .= '(' . $this->makeList( $args ) . ')';
514 $res = (bool)$this->query( $sql, $fname, $ignore );
516 $bar = pg_last_error();
517 if ( $bar != false ) {
518 pg_query( $this->mConn
, "ROLLBACK TO $ignore" );
520 pg_query( $this->mConn
, "RELEASE $ignore" );
526 $olde = error_reporting( $olde );
531 // Set the affected row count for the whole operation
532 $this->mAffectedRows
= $numrowsinserted;
534 // IGNORE always returns true
542 * INSERT SELECT wrapper
543 * $varMap must be an associative array of the form array( 'dest1' => 'source1', ...)
544 * Source items may be literals rather then field names, but strings should be quoted with Database::addQuotes()
545 * $conds may be "*" to copy the whole table
546 * srcTable may be an array of tables.
547 * @todo FIXME: Implement this a little better (seperate select/insert)?
549 function insertSelect( $destTable, $srcTable, $varMap, $conds, $fname = 'DatabasePostgres::insertSelect',
550 $insertOptions = array(), $selectOptions = array() )
552 $destTable = $this->tableName( $destTable );
554 // If IGNORE is set, we use savepoints to emulate mysql's behavior
555 $ignore = in_array( 'IGNORE', $insertOptions ) ?
'mw' : '';
557 if( is_array( $insertOptions ) ) {
558 $insertOptions = implode( ' ', $insertOptions );
560 if( !is_array( $selectOptions ) ) {
561 $selectOptions = array( $selectOptions );
563 list( $startOpts, $useIndex, $tailOpts ) = $this->makeSelectOptions( $selectOptions );
564 if( is_array( $srcTable ) ) {
565 $srcTable = implode( ',', array_map( array( &$this, 'tableName' ), $srcTable ) );
567 $srcTable = $this->tableName( $srcTable );
570 // If we are not in a transaction, we need to be for savepoint trickery
573 if( !$this->mTrxLevel
) {
577 $olde = error_reporting( 0 );
578 $numrowsinserted = 0;
579 pg_query( $this->mConn
, "SAVEPOINT $ignore");
582 $sql = "INSERT INTO $destTable (" . implode( ',', array_keys( $varMap ) ) . ')' .
583 " SELECT $startOpts " . implode( ',', $varMap ) .
584 " FROM $srcTable $useIndex";
586 if ( $conds != '*' ) {
587 $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND
);
590 $sql .= " $tailOpts";
592 $res = (bool)$this->query( $sql, $fname, $ignore );
594 $bar = pg_last_error();
595 if( $bar != false ) {
596 pg_query( $this->mConn
, "ROLLBACK TO $ignore" );
598 pg_query( $this->mConn
, "RELEASE $ignore" );
601 $olde = error_reporting( $olde );
606 // Set the affected row count for the whole operation
607 $this->mAffectedRows
= $numrowsinserted;
609 // IGNORE always returns true
616 function tableName( $name, $quoted = true ) {
617 # Replace reserved words with better ones
622 return 'pagecontent';
624 return parent
::tableName( $name, $quoted );
629 * Return the next in a sequence, save the value for retrieval via insertId()
631 function nextSequenceValue( $seqName ) {
632 $safeseq = str_replace( "'", "''", $seqName );
633 $res = $this->query( "SELECT nextval('$safeseq')" );
634 $row = $this->fetchRow( $res );
635 $this->mInsertId
= $row[0];
636 return $this->mInsertId
;
640 * Return the current value of a sequence. Assumes it has been nextval'ed in this session.
642 function currentSequenceValue( $seqName ) {
643 $safeseq = str_replace( "'", "''", $seqName );
644 $res = $this->query( "SELECT currval('$safeseq')" );
645 $row = $this->fetchRow( $res );
651 * REPLACE query wrapper
652 * Postgres simulates this with a DELETE followed by INSERT
653 * $row is the row to insert, an associative array
654 * $uniqueIndexes is an array of indexes. Each element may be either a
655 * field name or an array of field names
657 * It may be more efficient to leave off unique indexes which are unlikely to collide.
658 * However if you do this, you run the risk of encountering errors which wouldn't have
661 function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabasePostgres::replace' ) {
662 $table = $this->tableName( $table );
664 if ( count( $rows ) == 0 ) {
669 if ( !is_array( reset( $rows ) ) ) {
670 $rows = array( $rows );
673 foreach( $rows as $row ) {
674 # Delete rows which collide
675 if ( $uniqueIndexes ) {
676 $sql = "DELETE FROM $table WHERE ";
678 foreach ( $uniqueIndexes as $index ) {
685 if ( is_array( $index ) ) {
687 foreach ( $index as $col ) {
693 $sql .= $col.'=' . $this->addQuotes( $row[$col] );
696 $sql .= $index.'=' . $this->addQuotes( $row[$index] );
700 $this->query( $sql, $fname );
704 $sql = "INSERT INTO $table (" . $this->makeList( array_keys( $row ), LIST_NAMES
) .') VALUES (' .
705 $this->makeList( $row, LIST_COMMA
) . ')';
706 $this->query( $sql, $fname );
710 # Returns the size of a text field, or -1 for "unlimited"
711 function textFieldSize( $table, $field ) {
712 $table = $this->tableName( $table );
713 $sql = "SELECT t.typname as ftype,a.atttypmod as size
714 FROM pg_class c, pg_attribute a, pg_type t
715 WHERE relname='$table' AND a.attrelid=c.oid AND
716 a.atttypid=t.oid and a.attname='$field'";
717 $res =$this->query( $sql );
718 $row = $this->fetchObject( $res );
719 if ( $row->ftype
== 'varchar' ) {
720 $size = $row->size
- 4;
727 function limitResult( $sql, $limit, $offset = false ) {
728 return "$sql LIMIT $limit " . ( is_numeric( $offset ) ?
" OFFSET {$offset} " : '' );
731 function wasDeadlock() {
732 return $this->lastErrno() == '40P01';
735 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabasePostgres::duplicateTableStructure' ) {
736 $newName = $this->addIdentifierQuotes( $newName );
737 $oldName = $this->addIdentifierQuotes( $oldName );
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 $table = $this->tableName( $table, false );
792 $etable = $this->addQuotes( $table );
793 $eschema = $this->addQuotes( $schema );
794 $SQL = "SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
795 . "WHERE c.relnamespace = n.oid AND c.relname = $etable AND n.nspname = $eschema "
796 . "AND c.relkind IN ('" . implode( "','", $types ) . "')";
797 $res = $this->query( $SQL );
798 $count = $res ?
$res->numRows() : 0;
803 * For backward compatibility, this function checks both tables and
806 function tableExists( $table, $schema = false ) {
807 return $this->relationExists( $table, array( 'r', 'v' ), $schema );
810 function sequenceExists( $sequence, $schema = false ) {
811 return $this->relationExists( $sequence, 'S', $schema );
814 function triggerExists( $table, $trigger ) {
815 global $wgDBmwschema;
818 SELECT 1 FROM pg_class, pg_namespace, pg_trigger
819 WHERE relnamespace=pg_namespace.oid AND relkind='r'
820 AND tgrelid=pg_class.oid
821 AND nspname=%s AND relname=%s AND tgname=%s
826 $this->addQuotes( $wgDBmwschema ),
827 $this->addQuotes( $table ),
828 $this->addQuotes( $trigger )
834 $rows = $res->numRows();
838 function ruleExists( $table, $rule ) {
839 global $wgDBmwschema;
840 $exists = $this->selectField( 'pg_rules', 'rulename',
843 'tablename' => $table,
844 'schemaname' => $wgDBmwschema
847 return $exists === $rule;
850 function constraintExists( $table, $constraint ) {
851 global $wgDBmwschema;
852 $SQL = sprintf( "SELECT 1 FROM information_schema.table_constraints ".
853 "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s",
854 $this->addQuotes( $wgDBmwschema ),
855 $this->addQuotes( $table ),
856 $this->addQuotes( $constraint )
858 $res = $this->query( $SQL );
862 $rows = $res->numRows();
867 * Query whether a given schema exists. Returns true if it does, false if it doesn't.
869 function schemaExists( $schema ) {
870 $exists = $this->selectField( '"pg_catalog"."pg_namespace"', 1,
871 array( 'nspname' => $schema ), __METHOD__
);
872 return (bool)$exists;
876 * Returns true if a given role (i.e. user) exists, false otherwise.
878 function roleExists( $roleName ) {
879 $exists = $this->selectField( '"pg_catalog"."pg_roles"', 1,
880 array( 'rolname' => $roleName ), __METHOD__
);
881 return (bool)$exists;
884 function fieldInfo( $table, $field ) {
885 return PostgresField
::fromText( $this, $table, $field );
889 * pg_field_type() wrapper
891 function fieldType( $res, $index ) {
892 if ( $res instanceof ResultWrapper
) {
895 return pg_field_type( $res, $index );
898 /* Not even sure why this is used in the main codebase... */
899 function limitResultForUpdate( $sql, $num ) {
907 function encodeBlob( $b ) {
908 return new Blob( pg_escape_bytea( $this->mConn
, $b ) );
911 function decodeBlob( $b ) {
912 if ( $b instanceof Blob
) {
915 return pg_unescape_bytea( $b );
918 function strencode( $s ) { # Should not be called by us
919 return pg_escape_string( $this->mConn
, $s );
923 * @param $s null|bool|Blob
926 function addQuotes( $s ) {
927 if ( is_null( $s ) ) {
929 } elseif ( is_bool( $s ) ) {
931 } elseif ( $s instanceof Blob
) {
932 return "'" . $s->fetch( $s ) . "'";
934 return "'" . pg_escape_string( $this->mConn
, $s ) . "'";
938 * Postgres specific version of replaceVars.
939 * Calls the parent version in Database.php
943 * @param $ins String: SQL string, read from a stream (usually tables.sql)
945 * @return string SQL string
947 protected function replaceVars( $ins ) {
948 $ins = parent
::replaceVars( $ins );
950 if ( $this->numeric_version
>= 8.3 ) {
951 // Thanks for not providing backwards-compatibility, 8.3
952 $ins = preg_replace( "/to_tsvector\s*\(\s*'default'\s*,/", 'to_tsvector(', $ins );
955 if ( $this->numeric_version
<= 8.1 ) { // Our minimum version
956 $ins = str_replace( 'USING gin', 'USING gist', $ins );
963 * Various select options
967 * @param $options Array: an associative array of options to be turned into
968 * an SQL query, valid keys are listed in the function.
971 function makeSelectOptions( $options ) {
972 $preLimitTail = $postLimitTail = '';
973 $startOpts = $useIndex = '';
975 $noKeyOptions = array();
976 foreach ( $options as $key => $option ) {
977 if ( is_numeric( $key ) ) {
978 $noKeyOptions[$option] = true;
982 if ( isset( $options['GROUP BY'] ) ) {
983 $gb = is_array( $options['GROUP BY'] )
984 ?
implode( ',', $options['GROUP BY'] )
985 : $options['GROUP BY'];
986 $preLimitTail .= " GROUP BY {$gb}";
989 if ( isset( $options['HAVING'] ) ) {
990 $preLimitTail .= " HAVING {$options['HAVING']}";
993 if ( isset( $options['ORDER BY'] ) ) {
994 $ob = is_array( $options['ORDER BY'] )
995 ?
implode( ',', $options['ORDER BY'] )
996 : $options['ORDER BY'];
997 $preLimitTail .= " ORDER BY {$ob}";
1000 //if ( isset( $options['LIMIT'] ) ) {
1001 // $tailOpts .= $this->limitResult( '', $options['LIMIT'],
1002 // isset( $options['OFFSET'] ) ? $options['OFFSET']
1006 if ( isset( $noKeyOptions['FOR UPDATE'] ) ) {
1007 $postLimitTail .= ' FOR UPDATE';
1009 if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) {
1010 $postLimitTail .= ' LOCK IN SHARE MODE';
1012 if ( isset( $noKeyOptions['DISTINCT'] ) ||
isset( $noKeyOptions['DISTINCTROW'] ) ) {
1013 $startOpts .= 'DISTINCT';
1016 return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail );
1019 function setFakeMaster( $enabled = true ) {}
1021 function getDBname() {
1022 return $this->mDBname
;
1025 function getServer() {
1026 return $this->mServer
;
1029 function buildConcat( $stringList ) {
1030 return implode( ' || ', $stringList );
1033 public function getSearchEngine() {
1034 return 'SearchPostgres';
1036 } // end DatabasePostgres class