25use Wikimedia\WaitConditionLoop;
38 private $numericVersion;
41 private $lastResultHandle;
52 $this->port = intval( $params[
'port'] ??
null );
53 parent::__construct( $params );
62 $params[
'topologyRole'],
72 protected function open( $server, $user, $password, $db, $schema, $tablePrefix ) {
73 if ( !function_exists(
'pg_connect' ) ) {
75 "Postgres functions missing, have you compiled PHP with the --with-pgsql\n" .
76 "option? (Note: if you recently installed PHP, you may need to restart your\n" .
77 "webserver and database)"
81 $this->
close( __METHOD__ );
86 'dbname' => ( $db !==
null && $db !==
'' ) ? $db :
'postgres',
88 'password' => $password
90 if ( $server !==
null && $server !==
'' ) {
91 $connectVars[
'host'] = $server;
93 if ( $this->port > 0 ) {
94 $connectVars[
'port'] = $this->port;
97 $connectVars[
'sslmode'] =
'require';
99 $connectString = $this->makeConnectionString( $connectVars );
103 $this->conn = pg_connect( $connectString, PGSQL_CONNECT_FORCE_NEW ) ?:
null;
104 }
catch ( RuntimeException $e ) {
110 if ( !$this->conn ) {
119 'client_encoding' =>
'UTF8',
120 'datestyle' =>
'ISO, YMD',
122 'standard_conforming_strings' =>
'on',
123 'bytea_output' =>
'escape',
124 'client_min_messages' =>
'ERROR'
126 foreach ( $variables as $var => $val ) {
127 $sql =
'SET ' . $this->platform->addIdentifierQuotes( $var ) .
' = ' . $this->
addQuotes( $val );
128 $query =
new Query( $sql, self::QUERY_NO_RETRY | self::QUERY_CHANGE_TRX,
'SET', [] );
129 $this->
query( $query, __METHOD__ );
132 $this->currentDomain =
new DatabaseDomain( $db, $schema, $tablePrefix );
133 $this->platform->setCurrentDomain( $this->currentDomain );
134 }
catch ( RuntimeException $e ) {
145 if ( $database ===
null ) {
148 $this->currentDomain->getDatabase(),
149 $domain->
getSchema() ?? $this->currentDomain->getSchema(),
152 $this->platform->setCurrentDomain( $this->currentDomain );
153 } elseif ( $this->
getDBname() !== $database ) {
157 $this->connectionParams[self::CONN_HOST],
158 $this->connectionParams[self::CONN_USER],
159 $this->connectionParams[self::CONN_PASSWORD],
165 $this->currentDomain = $domain;
166 $this->platform->setCurrentDomain( $this->currentDomain );
176 private function makeConnectionString( $vars ) {
178 foreach ( $vars as $name => $value ) {
179 $s .=
"$name='" . str_replace( [
"\\",
"'" ], [
"\\\\",
"\\'" ], $value ) .
"' ";
186 return $this->conn ? pg_close( $this->conn ) :
true;
192 $sql = mb_convert_encoding( $sql,
'UTF-8' );
194 while ( $priorRes = pg_get_result(
$conn ) ) {
195 pg_free_result( $priorRes );
198 if ( pg_send_query(
$conn, $sql ) ===
false ) {
199 throw new DBUnexpectedError( $this,
"Unable to post new query to PostgreSQL\n" );
204 $pgRes = pg_get_result(
$conn );
205 $this->lastResultHandle = $pgRes;
206 $res = pg_result_error( $pgRes ) ? false : $pgRes;
208 return new QueryStatus(
209 is_bool( $res ) ? $res : new PostgresResultWrapper( $this,
$conn, $res ),
210 $pgRes ? pg_affected_rows( $pgRes ) : 0,
220 PGSQL_DIAG_MESSAGE_PRIMARY,
221 PGSQL_DIAG_MESSAGE_DETAIL,
222 PGSQL_DIAG_MESSAGE_HINT,
223 PGSQL_DIAG_STATEMENT_POSITION,
224 PGSQL_DIAG_INTERNAL_POSITION,
225 PGSQL_DIAG_INTERNAL_QUERY,
227 PGSQL_DIAG_SOURCE_FILE,
228 PGSQL_DIAG_SOURCE_LINE,
229 PGSQL_DIAG_SOURCE_FUNCTION
231 foreach ( $diags as $d ) {
232 $this->logger->debug( sprintf(
"PgSQL ERROR(%d): %s",
233 $d, pg_result_error_field( $this->lastResultHandle, $d ) ) );
242 $qs = $this->doSingleStatementQuery(
"SELECT lastval() AS id" );
244 return $qs->res ? (int)$qs->res->fetchRow()[
'id'] : 0;
249 if ( $this->lastResultHandle ) {
250 return pg_result_error( $this->lastResultHandle );
252 return pg_last_error() ?: $this->lastConnectError;
256 return $this->getLastPHPError() ?:
'No database connection';
260 if ( $this->lastResultHandle ) {
261 $lastErrno = pg_result_error_field( $this->lastResultHandle, PGSQL_DIAG_SQLSTATE );
262 if ( $lastErrno !==
false ) {
286 $fname = __METHOD__, $options = [], $join_conds = []
288 $conds = $this->platform->normalizeConditions( $conds, $fname );
289 $column = $this->platform->extractSingleFieldFromList( $var );
290 if ( is_string( $column ) && !in_array( $column, [
'*',
'1' ] ) ) {
291 $conds[] =
"$column IS NOT NULL";
294 $options[
'EXPLAIN'] =
true;
295 $res = $this->select( $table, $var, $conds, $fname, $options, $join_conds );
298 $row = $res->fetchRow();
300 if ( preg_match(
'/rows=(\d+)/', $row[0], $count ) ) {
301 $rows = (int)$count[1];
308 public function indexInfo( $table, $index, $fname = __METHOD__ ) {
310 "SELECT indexname FROM pg_indexes WHERE tablename='$table'",
311 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
315 $res = $this->query( $query );
319 foreach ( $res as $row ) {
320 if ( $row->indexname == $this->platform->indexName( $index ) ) {
329 if ( $schema ===
false ) {
330 $schemas = $this->getCoreSchemas();
332 $schemas = [ $schema ];
335 $eindex = $this->addQuotes( $index );
337 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
338 foreach ( $schemas as $schema ) {
339 $eschema = $this->addQuotes( $schema );
344 $sql = <<<__INDEXATTR__
348 i.indoption[s.g] as option,
351 (SELECT generate_series(array_lower(isub.indkey,1), array_upper(isub.indkey,1)) AS g
355 ON cis.oid=isub.indexrelid
357 ON cis.relnamespace = ns.oid
358 WHERE cis.relname=$eindex AND ns.nspname=$eschema) AS s,
364 ON ci.oid=i.indexrelid
366 ON ct.oid = i.indrelid
368 ON ci.relnamespace = n.oid
370 ci.relname=$eindex AND n.nspname=$eschema
371 AND attrelid = ct.oid
372 AND i.indkey[s.g] = attnum
373 AND i.indclass[s.g] = opcls.oid
374 AND pg_am.oid = opcls.opcmethod
376 $query =
new Query( $sql, $flags,
'SELECT', [
'pg_index',
'pg_class',
'pg_namespace' ] );
377 $res = $this->query( $query, __METHOD__ );
380 foreach ( $res as $row ) {
393 public function indexUnique( $table, $index, $fname = __METHOD__ ) {
394 $sql =
"SELECT indexname FROM pg_indexes WHERE tablename='{$table}'" .
395 " AND indexdef LIKE 'CREATE UNIQUE%(" .
396 $this->strencode( $this->platform->indexName( $index ) ) .
398 $query =
new Query( $sql, self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
'SELECT', [
'pg_indexes' ] );
399 $res = $this->query( $query, $fname );
400 return $res && $res->numRows() > 0;
427 array $insertOptions,
428 array $selectOptions,
431 if ( in_array(
'IGNORE', $insertOptions ) ) {
433 $destTableEnc = $this->tableName( $destTable );
435 $selectSql = $this->selectSQLText(
437 array_values( $varMap ),
444 $sql =
"INSERT INTO $destTableEnc (" . implode(
',', array_keys( $varMap ) ) .
') ' .
445 $selectSql .
' ON CONFLICT DO NOTHING';
446 $query =
new Query( $sql, self::QUERY_CHANGE_ROWS,
'INSERT', [ $destTable, $srcTable ] );
447 $this->query( $query, $fname );
449 parent::doInsertSelectNative( $destTable, $srcTable, $varMap, $conds, $fname,
450 $insertOptions, $selectOptions, $selectJoinConds );
460 return parent::tableName( $name, $format );
474 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
475 $encTable = $this->addQuotes( $table );
476 foreach ( $this->getCoreSchemas() as $schema ) {
477 $encSchema = $this->addQuotes( $schema );
478 $sql =
"SELECT column_name,udt_name " .
479 "FROM information_schema.columns " .
480 "WHERE table_name = $encTable AND table_schema = $encSchema";
481 $query =
new Query( $sql, $flags,
'SELECT', [ $table ] );
482 $res = $this->query( $query, __METHOD__ );
483 if ( $res->numRows() ) {
484 foreach ( $res as $row ) {
485 $typesByColumn[$row->column_name] = $row->udt_name;
491 return $typesByColumn;
495 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
496 $encTable = $this->tableName( $table );
497 $sql =
"SELECT t.typname as ftype,a.atttypmod as size
498 FROM pg_class c, pg_attribute a, pg_type t
499 WHERE relname='$encTable' AND a.attrelid=c.oid AND
500 a.atttypid=t.oid and a.attname='$field'";
501 $query =
new Query( $sql, $flags,
'SELECT', [ $table ] );
502 $res = $this->query( $query, __METHOD__ );
503 $row = $res->fetchObject();
504 if ( $row->ftype ==
'varchar' ) {
505 $size = $row->size - 4;
515 return $this->lastErrno() ===
'40P01';
520 static $codes = [
'08000',
'08003',
'08006',
'08001',
'08004',
'57P01',
'57P03',
'53300' ];
522 return in_array( $errno, $codes,
true );
527 return ( $errno ===
'57014' );
535 $oldName, $newName, $temporary =
false, $fname = __METHOD__
537 $newNameE = $this->platform->addIdentifierQuotes( $newName );
538 $oldNameE = $this->platform->addIdentifierQuotes( $oldName );
540 $temporary = $temporary ?
'TEMPORARY' :
'';
542 "CREATE $temporary TABLE $newNameE " .
543 "(LIKE $oldNameE INCLUDING DEFAULTS INCLUDING INDEXES)",
544 self::QUERY_PSEUDO_PERMANENT | self::QUERY_CHANGE_SCHEMA,
548 $ret = $this->query( $query, $fname );
553 $sql =
'SELECT attname FROM pg_class c'
554 .
' JOIN pg_namespace n ON (n.oid = c.relnamespace)'
555 .
' JOIN pg_attribute a ON (a.attrelid = c.oid)'
556 .
' JOIN pg_attrdef d ON (c.oid=d.adrelid and a.attnum=d.adnum)'
557 .
' WHERE relkind = \'r\''
558 .
' AND nspname = ' . $this->addQuotes( $this->getCoreSchema() )
559 .
' AND relname = ' . $this->addQuotes( $oldName )
560 .
' AND pg_get_expr(adbin, adrelid) LIKE \'nextval(%\'';
563 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
565 [
'pg_class',
'pg_namespace',
'pg_attribute',
'pg_attrdef' ]
568 $res = $this->query( $query, $fname );
569 $row = $res->fetchObject();
571 $field = $row->attname;
572 $newSeq =
"{$newName}_{$field}_seq";
573 $fieldE = $this->platform->addIdentifierQuotes( $field );
574 $newSeqE = $this->platform->addIdentifierQuotes( $newSeq );
575 $newSeqQ = $this->addQuotes( $newSeq );
577 "CREATE $temporary SEQUENCE $newSeqE OWNED BY $newNameE.$fieldE",
578 self::QUERY_CHANGE_SCHEMA,
582 $this->query( $query, $fname );
584 "ALTER TABLE $newNameE ALTER COLUMN $fieldE SET DEFAULT nextval({$newSeqQ}::regclass)",
585 self::QUERY_CHANGE_SCHEMA,
589 $this->query( $query, $fname );
596 $encTables = $this->tableNamesN( ...$tables );
598 "TRUNCATE TABLE " . implode(
',', $encTables ) .
" RESTART IDENTITY",
599 self::QUERY_CHANGE_SCHEMA,
603 $this->query( $query, $fname );
612 public function listTables( $prefix =
'', $fname = __METHOD__ ) {
613 $eschemas = implode(
',', array_map( [ $this,
'addQuotes' ], $this->getCoreSchemas() ) );
615 "SELECT DISTINCT tablename FROM pg_tables WHERE schemaname IN ($eschemas)",
616 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
620 $result = $this->query( $query, $fname );
623 foreach ( $result as $table ) {
624 $vars = get_object_vars( $table );
625 $table = array_pop( $vars );
626 if ( $prefix ==
'' || strpos( $table, $prefix ) === 0 ) {
627 $endArray[] = $table;
652 private function pg_array_parse( $text, &$output, $limit =
false, $offset = 1 ) {
653 if ( $limit ===
false ) {
654 $limit = strlen( $text ) - 1;
657 if ( $text ==
'{}' ) {
661 if ( $text[$offset] !=
'{' ) {
662 preg_match(
"/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/",
663 $text, $match, 0, $offset );
664 $offset += strlen( $match[0] );
665 $output[] = ( $match[1][0] !=
'"'
667 : stripcslashes( substr( $match[1], 1, -1 ) ) );
668 if ( $match[3] ==
'},' ) {
672 $offset = $this->pg_array_parse( $text, $output, $limit, $offset + 1 );
674 }
while ( $limit > $offset );
680 return '[{{int:version-db-postgres-url}} PostgreSQL]';
692 "SELECT current_schema()",
693 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
696 $res = $this->query( $query, __METHOD__ );
697 $row = $res->fetchRow();
714 "SELECT current_schemas(false)",
715 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
718 $res = $this->query( $query, __METHOD__ );
719 $row = $res->fetchRow();
724 return $this->pg_array_parse( $row[0], $schemas );
739 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
742 $res = $this->query( $query, __METHOD__ );
743 $row = $res->fetchRow();
747 return explode(
",", $row[0] );
757 private function setSearchPath( $search_path ) {
759 "SET search_path = " . implode(
", ", $search_path ),
760 self::QUERY_CHANGE_TRX,
763 $this->query( $query, __METHOD__ );
781 if ( $this->trxLevel() ) {
786 __METHOD__ .
": a transaction is currently active"
790 if ( $this->schemaExists( $desiredSchema ) ) {
791 if ( in_array( $desiredSchema, $this->getSchemas() ) ) {
792 $this->platform->setCoreSchema( $desiredSchema );
793 $this->logger->debug(
794 "Schema \"" . $desiredSchema .
"\" already in the search path\n" );
797 $search_path = $this->getSearchPath();
798 array_unshift( $search_path, $this->platform->addIdentifierQuotes( $desiredSchema ) );
799 $this->setSearchPath( $search_path );
800 $this->platform->setCoreSchema( $desiredSchema );
801 $this->logger->debug(
802 "Schema \"" . $desiredSchema .
"\" added to the search path\n" );
805 $this->platform->setCoreSchema( $this->getCurrentSchema() );
806 $this->logger->debug(
807 "Schema \"" . $desiredSchema .
"\" not found, using current \"" .
808 $this->getCoreSchema() .
"\"\n" );
819 return $this->platform->getCoreSchema();
829 if ( $this->tempSchema ) {
830 return [ $this->tempSchema, $this->getCoreSchema() ];
833 "SELECT nspname FROM pg_catalog.pg_namespace n WHERE n.oid = pg_my_temp_schema()",
834 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
838 $res = $this->query( $query, __METHOD__ );
839 $row = $res->fetchObject();
841 $this->tempSchema = $row->nspname;
842 return [ $this->tempSchema, $this->getCoreSchema() ];
845 return [ $this->getCoreSchema() ];
849 if ( !isset( $this->numericVersion ) ) {
850 $conn = $this->getBindingHandle();
851 $versionInfo = pg_version( $conn );
852 if ( version_compare( $versionInfo[
'client'],
'7.4.0',
'lt' ) ) {
854 $this->numericVersion =
'7.3 or earlier';
855 } elseif ( isset( $versionInfo[
'server'] ) ) {
857 $this->numericVersion = $versionInfo[
'server'];
860 $this->numericVersion = pg_parameter_status( $conn,
'server_version' );
864 return $this->numericVersion;
875 private function relationExists( $table, $types, $schema =
false ) {
876 if ( !is_array( $types ) ) {
879 if ( $schema ===
false ) {
880 $schemas = $this->getCoreSchemas();
882 $schemas = [ $schema ];
884 $table = $this->realTableName( $table,
'raw' );
885 $etable = $this->addQuotes( $table );
886 foreach ( $schemas as $schema ) {
887 $eschema = $this->addQuotes( $schema );
888 $sql =
"SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
889 .
"WHERE c.relnamespace = n.oid AND c.relname = $etable AND n.nspname = $eschema "
890 .
"AND c.relkind IN ('" . implode(
"','", $types ) .
"')";
893 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
897 $res = $this->query( $query, __METHOD__ );
898 if ( $res && $res->numRows() ) {
913 public function tableExists( $table, $fname = __METHOD__, $schema =
false ) {
914 return $this->relationExists( $table, [
'r',
'v' ], $schema );
918 return $this->relationExists( $sequence,
'S', $schema );
922 foreach ( $this->getCoreSchemas() as $schema ) {
923 $sql = sprintf(
"SELECT 1 FROM information_schema.table_constraints " .
924 "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s",
925 $this->addQuotes( $schema ),
926 $this->addQuotes( $table ),
927 $this->addQuotes( $constraint )
931 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
935 $res = $this->query( $query, __METHOD__ );
936 if ( $res && $res->numRows() ) {
949 if ( !strlen( $schema ??
'' ) ) {
953 "SELECT 1 FROM pg_catalog.pg_namespace " .
954 "WHERE nspname = " . $this->addQuotes( $schema ) .
" LIMIT 1",
955 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
959 $res = $this->query( $query, __METHOD__ );
961 return ( $res->numRows() > 0 );
971 "SELECT 1 FROM pg_catalog.pg_roles " .
972 "WHERE rolname = " . $this->addQuotes( $roleName ) .
" LIMIT 1",
973 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
977 $res = $this->query( $query, __METHOD__ );
979 return ( $res->numRows() > 0 );
992 $conn = $this->getBindingHandle();
994 return new PostgresBlob( pg_escape_bytea( $conn, $b ) );
1000 } elseif ( $b instanceof
Blob ) {
1004 return pg_unescape_bytea( $b );
1009 return pg_escape_string( $this->getBindingHandle(), (
string)$s );
1013 $conn = $this->getBindingHandle();
1015 if ( $s ===
null ) {
1017 } elseif ( is_bool( $s ) ) {
1018 return (
string)intval( $s );
1019 } elseif ( is_int( $s ) ) {
1021 } elseif ( $s instanceof
Blob ) {
1025 $s = pg_escape_bytea( $conn, $s->fetch() );
1032 return "'" . pg_escape_string( $conn, (
string)$s ) .
"'";
1036 # Allow dollar quoting for function declarations
1037 if ( str_starts_with( $newLine,
'$mw$' ) ) {
1038 if ( $this->delimiter ) {
1039 $this->delimiter =
false;
1041 $this->delimiter =
';';
1045 return parent::streamStatementEnd( $sql, $newLine );
1050 $this->platform->lockIsFreeSQLText( $lockName ),
1051 self::QUERY_CHANGE_LOCKS,
1054 $res = $this->query( $query, $method );
1055 $row = $res->fetchObject();
1057 return ( $row->unlocked ===
't' );
1060 public function doLock(
string $lockName,
string $method,
int $timeout ) {
1062 $this->platform->lockSQLText( $lockName, $timeout ),
1063 self::QUERY_CHANGE_LOCKS,
1068 $loop =
new WaitConditionLoop(
1069 function () use ( $query, $method, &$acquired ) {
1070 $res = $this->query( $query, $method );
1071 $row = $res->fetchObject();
1073 if ( $row->acquired !==
null ) {
1074 $acquired = (float)$row->acquired;
1076 return WaitConditionLoop::CONDITION_REACHED;
1079 return WaitConditionLoop::CONDITION_CONTINUE;
1088 public function doUnlock(
string $lockName,
string $method ) {
1090 $this->platform->unlockSQLText( $lockName ),
1091 self::QUERY_CHANGE_LOCKS,
1094 $result = $this->query( $query, $method );
1095 $row = $result->fetchObject();
1097 return ( $row->released ===
't' );
1101 $flags = self::QUERY_CHANGE_LOCKS | self::QUERY_NO_RETRY;
1104 $sql =
"SELECT pg_advisory_unlock_all()";
1105 $query =
new Query( $sql, $flags,
'UNLOCK' );
1106 $qs = $this->executeQuery( $query, __METHOD__, $flags );
1107 if ( $qs->res ===
false ) {
1108 $this->reportQueryError( $qs->message, $qs->code, $sql, $fname,
true );
1114 "SHOW default_transaction_read_only",
1115 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
1118 $res = $this->query( $query, __METHOD__ );
1119 $row = $res->fetchObject();
1121 return $row && strtolower( $row->default_transaction_read_only ) ===
'on';
1127 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
1128 $encTable = $this->addQuotes( $this->realTableName( $table,
'raw' ) );
1129 foreach ( $this->getCoreSchemas() as $schema ) {
1130 $encSchema = $this->addQuotes( $schema );
1132 "SELECT column_name,data_type,column_default " .
1133 "FROM information_schema.columns " .
1134 "WHERE table_name = $encTable AND table_schema = $encSchema",
1135 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
1138 $res = $this->query( $query, __METHOD__ );
1139 if ( $res->numRows() ) {
1140 foreach ( $res as $row ) {
1142 $row->column_default !==
null &&
1143 str_starts_with( $row->column_default,
"nextval(" ) &&
1144 in_array( $row->data_type, [
'integer',
'bigint' ],
true )
1146 $column = $row->column_name;
1157 return [ self::ATTR_SCHEMAS_AS_TABLE_GROUPS =>
true ];
Class to handle database/schema/prefix specifications for IDatabase.
Postgres database abstraction layer.
getCoreSchemas()
Return schema names for temporary tables and core application tables.
determineCoreSchema( $desiredSchema)
Determine default schema for the current application Adjust this session schema search path if desire...
duplicateTableStructure( $oldName, $newName, $temporary=false, $fname=__METHOD__)
Creates a new table with structure copied from existing table.Note that unlike most database abstract...
isQueryTimeoutError( $errno)
Checks whether the cause of the error is detected to be a timeout.
fieldInfo( $table, $field)
doLock(string $lockName, string $method, int $timeout)
isKnownStatementRollbackError( $errno)
indexAttributes( $index, $schema=false)
PostgresPlatform $platform
databasesAreIndependent()
Returns true if DBs are assumed to be on potentially different servers.In systems like mysql/mariadb,...
doUnlock(string $lockName, string $method)
doSingleStatementQuery(string $sql)
Run a query and return a QueryStatus instance with the query result information.
streamStatementEnd(&$sql, &$newLine)
Called by sourceStream() to check if we've reached a statement end.
doLockIsFree(string $lockName, string $method)
nextSequenceValue( $seqName)
Deprecated method, calls should be removed.
doSelectDomain(DatabaseDomain $domain)
roleExists( $roleName)
Returns true if a given role (i.e.
getSchemas()
Return list of schemas which are accessible without schema name This is list does not contain magic k...
indexInfo( $table, $index, $fname=__METHOD__)
Get information about an index into an object.
schemaExists( $schema)
Query whether a given schema exists.
estimateRowCount( $table, $var=' *', $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Estimate rows in dataset Returns estimated count, based on EXPLAIN output This is not necessarily an ...
getInsertIdColumnForUpsert( $table)
lastError()
Get the RDBMS-specific error description from the last attempted query statement.
addQuotes( $s)
Escape and quote a raw value string for use in a SQL query.string -taint noneto override
sequenceExists( $sequence, $schema=false)
wasDeadlock()
Determines if the last failure was due to a deadlock.Note that during a deadlock, the prior transacti...
__construct(array $params)
doTruncate(array $tables, $fname)
lastErrno()
Get the RDBMS-specific error code from the last attempted query statement.
getCoreSchema()
Return schema name for core application tables.
strencode( $s)
Wrapper for addslashes()
lastInsertId()
Get a row ID from the last insert statement to implicitly assign one within the session.
isConnectionError( $errno)
Do not use this method outside of Database/DBError classes.
indexUnique( $table, $index, $fname=__METHOD__)
Determines if a given index is unique.boolto override
open( $server, $user, $password, $db, $schema, $tablePrefix)
Open a new connection to the database (closing any existing one)
getServerVersion()
A string describing the current software version, like from mysql_get_server_info()
textFieldSize( $table, $field)
Returns the size of a text field, or -1 for "unlimited".intto override
getCurrentSchema()
Return current schema (executes SELECT current_schema()) Needs transaction.
getSearchPath()
Return search patch for schemas This is different from getSchemas() since it contain magic keywords (...
tableExists( $table, $fname=__METHOD__, $schema=false)
For backward compatibility, this function checks both tables and views.
decodeBlob( $b)
Some DBMSs return a special placeholder object representing blob fields in result objects....
encodeBlob( $b)
Some DBMSs have a special format for inserting into blob fields, they don't allow simple quoted strin...
realTableName( $name, $format='quoted')
closeConnection()
Closes underlying database connection.
getValueTypesForWithClause( $table)
constraintExists( $table, $constraint)
getType()
Get the RDBMS type of the server (e.g.
doFlushSession( $fname)
Reset the server-side session state for named locks and table locks.
listTables( $prefix='', $fname=__METHOD__)
getSoftwareLink()
Returns a wikitext style link to the DB's website (e.g.
doInsertSelectNative( $destTable, $srcTable, array $varMap, $conds, $fname, array $insertOptions, array $selectOptions, $selectJoinConds)
INSERT SELECT wrapper $varMap must be an associative array of the form [ 'dest1' => 'source1',...
serverIsReadOnly()
bool Whether this DB server is running in server-side read-only mode query} 1.28to override
static fromText(DatabasePostgres $db, $table, $field)