25use Wikimedia\WaitConditionLoop;
38 private $keywordTableMap;
40 private $numericVersion;
43 private $lastResultHandle;
56 $this->port = intval( $params[
'port'] ??
null );
58 if ( isset( $params[
'keywordTableMap'] ) ) {
60 'DatabasePostgres::__construct() is deprecated',
'1.37'
63 $this->keywordTableMap = $params[
'keywordTableMap'];
66 parent::__construct( $params );
75 $params[
'topologyRole'],
85 protected function open( $server, $user, $password, $db, $schema, $tablePrefix ) {
86 if ( !function_exists(
'pg_connect' ) ) {
88 "Postgres functions missing, have you compiled PHP with the --with-pgsql\n" .
89 "option? (Note: if you recently installed PHP, you may need to restart your\n" .
90 "webserver and database)"
94 $this->
close( __METHOD__ );
99 'dbname' => ( $db !==
null && $db !==
'' ) ? $db :
'postgres',
101 'password' => $password
103 if ( $server !==
null && $server !==
'' ) {
104 $connectVars[
'host'] = $server;
106 if ( $this->port > 0 ) {
107 $connectVars[
'port'] = $this->port;
110 $connectVars[
'sslmode'] =
'require';
112 $connectString = $this->makeConnectionString( $connectVars );
116 $this->conn = pg_connect( $connectString, PGSQL_CONNECT_FORCE_NEW ) ?:
null;
117 }
catch ( RuntimeException $e ) {
123 if ( !$this->conn ) {
132 'client_encoding' =>
'UTF8',
133 'datestyle' =>
'ISO, YMD',
135 'standard_conforming_strings' =>
'on',
136 'bytea_output' =>
'escape',
137 'client_min_messages' =>
'ERROR'
139 foreach ( $variables as $var => $val ) {
141 'SET ' . $this->platform->addIdentifierQuotes( $var ) .
' = ' . $this->addQuotes( $val ),
143 self::QUERY_NO_RETRY | self::QUERY_CHANGE_TRX
147 $this->currentDomain =
new DatabaseDomain( $db, $schema, $tablePrefix );
148 $this->platform->setCurrentDomain( $this->currentDomain );
149 }
catch ( RuntimeException $e ) {
160 if ( $database ===
null ) {
163 $this->currentDomain->getDatabase(),
164 $domain->
getSchema() ?? $this->currentDomain->getSchema(),
167 $this->platform->setCurrentDomain( $this->currentDomain );
168 } elseif ( $this->
getDBname() !== $database ) {
172 $this->connectionParams[self::CONN_HOST],
173 $this->connectionParams[self::CONN_USER],
174 $this->connectionParams[self::CONN_PASSWORD],
180 $this->currentDomain = $domain;
181 $this->platform->setCurrentDomain( $this->currentDomain );
191 private function makeConnectionString( $vars ) {
193 foreach ( $vars as $name => $value ) {
194 $s .=
"$name='" . str_replace( [
"\\",
"'" ], [
"\\\\",
"\\'" ], $value ) .
"' ";
201 return $this->conn ? pg_close( $this->conn ) :
true;
207 $sql = mb_convert_encoding( $sql,
'UTF-8' );
209 while ( $priorRes = pg_get_result(
$conn ) ) {
210 pg_free_result( $priorRes );
213 if ( pg_send_query(
$conn, $sql ) ===
false ) {
214 throw new DBUnexpectedError( $this,
"Unable to post new query to PostgreSQL\n" );
219 $pgRes = pg_get_result(
$conn );
220 $this->lastResultHandle = $pgRes;
221 $res = pg_result_error( $pgRes ) ? false : $pgRes;
223 return new QueryStatus(
232 $qsByStatementId = [];
234 $conn = $this->getBindingHandle();
236 while ( $pgResultSet = pg_get_result( $conn ) ) {
237 pg_free_result( $pgResultSet );
240 $combinedSql = mb_convert_encoding( implode(
";\n", $sqls ),
'UTF-8' );
241 pg_send_query( $conn, $combinedSql );
244 while ( ( $pgResultSet = pg_get_result( $conn ) ) !==
false ) {
245 $this->lastResultHandle = $pgResultSet;
247 $statementId = key( $sqls );
248 if ( $statementId !==
null ) {
249 if ( pg_result_error( $pgResultSet ) ) {
252 $res =
new PostgresResultWrapper( $this, $conn, $pgResultSet );
254 $qsByStatementId[$statementId] =
new QueryStatus(
256 pg_affected_rows( $pgResultSet ),
257 (
string)pg_result_error( $pgResultSet ),
258 pg_result_error_field( $pgResultSet, PGSQL_DIAG_SQLSTATE )
264 while ( ( $statementId = key( $sqls ) ) !==
null ) {
265 $qsByStatementId[$statementId] =
new QueryStatus(
false, 0,
'Query aborted', 0 );
269 return $qsByStatementId;
276 PGSQL_DIAG_MESSAGE_PRIMARY,
277 PGSQL_DIAG_MESSAGE_DETAIL,
278 PGSQL_DIAG_MESSAGE_HINT,
279 PGSQL_DIAG_STATEMENT_POSITION,
280 PGSQL_DIAG_INTERNAL_POSITION,
281 PGSQL_DIAG_INTERNAL_QUERY,
283 PGSQL_DIAG_SOURCE_FILE,
284 PGSQL_DIAG_SOURCE_LINE,
285 PGSQL_DIAG_SOURCE_FUNCTION
287 foreach ( $diags as $d ) {
288 $this->logger->debug( sprintf(
"PgSQL ERROR(%d): %s",
289 $d, pg_result_error_field( $this->lastResultHandle, $d ) ) );
297 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
299 $row =
$res->fetchRow();
302 return $row[0] ===
null ? null : (int)$row[0];
307 if ( $this->lastResultHandle ) {
308 return pg_result_error( $this->lastResultHandle );
310 return pg_last_error() ?: $this->lastConnectError;
314 return $this->getLastPHPError() ?:
'No database connection';
318 if ( $this->lastResultHandle ) {
319 $lastErrno = pg_result_error_field( $this->lastResultHandle, PGSQL_DIAG_SQLSTATE );
320 if ( $lastErrno !==
false ) {
329 if ( !$this->lastResultHandle ) {
333 return pg_affected_rows( $this->lastResultHandle );
352 $fname = __METHOD__, $options = [], $join_conds = []
354 $conds = $this->platform->normalizeConditions( $conds, $fname );
355 $column = $this->platform->extractSingleFieldFromList( $var );
356 if ( is_string( $column ) && !in_array( $column, [
'*',
'1' ] ) ) {
357 $conds[] =
"$column IS NOT NULL";
360 $options[
'EXPLAIN'] =
true;
361 $res = $this->select( $table, $var, $conds, $fname, $options, $join_conds );
364 $row =
$res->fetchRow();
366 if ( preg_match(
'/rows=(\d+)/', $row[0], $count ) ) {
367 $rows = (int)$count[1];
374 public function indexInfo( $table, $index, $fname = __METHOD__ ) {
376 "SELECT indexname FROM pg_indexes WHERE tablename='$table'",
378 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
383 foreach (
$res as $row ) {
384 if ( $row->indexname == $this->indexName( $index ) ) {
393 if ( $schema ===
false ) {
394 $schemas = $this->getCoreSchemas();
396 $schemas = [ $schema ];
399 $eindex = $this->addQuotes( $index );
401 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
402 foreach ( $schemas as $schema ) {
403 $eschema = $this->addQuotes( $schema );
408 $sql = <<<__INDEXATTR__
412 i.indoption[s.g] as option,
415 (SELECT generate_series(array_lower(isub.indkey,1), array_upper(isub.indkey,1)) AS g
419 ON cis.oid=isub.indexrelid
421 ON cis.relnamespace = ns.oid
422 WHERE cis.relname=$eindex AND ns.nspname=$eschema) AS s,
428 ON ci.oid=i.indexrelid
430 ON ct.oid = i.indrelid
432 ON ci.relnamespace = n.oid
434 ci.relname=$eindex AND n.nspname=$eschema
435 AND attrelid = ct.oid
436 AND i.indkey[s.g] = attnum
437 AND i.indclass[s.g] = opcls.oid
438 AND pg_am.oid = opcls.opcmethod
440 $res = $this->query( $sql, __METHOD__, $flags );
443 foreach (
$res as $row ) {
456 public function indexUnique( $table, $index, $fname = __METHOD__ ) {
457 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
458 $sql =
"SELECT indexname FROM pg_indexes WHERE tablename='{$table}'" .
459 " AND indexdef LIKE 'CREATE UNIQUE%(" .
460 $this->strencode( $this->indexName( $index ) ) .
462 $res = $this->query( $sql, $fname, $flags );
490 array $insertOptions,
491 array $selectOptions,
494 if ( in_array(
'IGNORE', $insertOptions ) ) {
496 $destTable = $this->tableName( $destTable );
498 $selectSql = $this->selectSQLText(
500 array_values( $varMap ),
507 $sql =
"INSERT INTO $destTable (" . implode(
',', array_keys( $varMap ) ) .
') ' .
508 $selectSql .
' ON CONFLICT DO NOTHING';
510 $this->query( $sql, $fname, self::QUERY_CHANGE_ROWS );
512 parent::doInsertSelectNative( $destTable, $srcTable, $varMap, $conds, $fname,
513 $insertOptions, $selectOptions, $selectJoinConds );
523 return parent::tableName( $name, $format );
538 "SELECT currval('" . str_replace(
"'",
"''", $seqName ) .
"')",
540 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
542 $row =
$res->fetchRow();
555 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
556 $encTable = $this->addQuotes( $table );
557 foreach ( $this->getCoreSchemas() as $schema ) {
558 $encSchema = $this->addQuotes( $schema );
559 $sql =
"SELECT column_name,udt_name " .
560 "FROM information_schema.columns " .
561 "WHERE table_name = $encTable AND table_schema = $encSchema";
562 $res = $this->query( $sql, __METHOD__, $flags );
563 if (
$res->numRows() ) {
564 foreach (
$res as $row ) {
565 $typesByColumn[$row->column_name] = $row->udt_name;
571 return $typesByColumn;
575 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
576 $encTable = $this->tableName( $table );
577 $sql =
"SELECT t.typname as ftype,a.atttypmod as size
578 FROM pg_class c, pg_attribute a, pg_type t
579 WHERE relname='$encTable' AND a.attrelid=c.oid AND
580 a.atttypid=t.oid and a.attname='$field'";
581 $res = $this->query( $sql, __METHOD__, $flags );
582 $row =
$res->fetchObject();
583 if ( $row->ftype ==
'varchar' ) {
584 $size = $row->size - 4;
594 return $this->lastErrno() ===
'40P01';
599 return $this->lastErrno() ===
'55P03';
604 static $codes = [
'08000',
'08003',
'08006',
'08001',
'08004',
'57P01',
'57P03',
'53300' ];
606 return in_array( $errno, $codes,
true );
611 return ( $errno ===
'57014' );
619 $oldName, $newName, $temporary =
false, $fname = __METHOD__
621 $newNameE = $this->platform->addIdentifierQuotes( $newName );
622 $oldNameE = $this->platform->addIdentifierQuotes( $oldName );
624 $temporary = $temporary ?
'TEMPORARY' :
'';
627 "CREATE $temporary TABLE $newNameE " .
628 "(LIKE $oldNameE INCLUDING DEFAULTS INCLUDING INDEXES)",
630 self::QUERY_PSEUDO_PERMANENT | self::QUERY_CHANGE_SCHEMA
637 'SELECT attname FROM pg_class c'
638 .
' JOIN pg_namespace n ON (n.oid = c.relnamespace)'
639 .
' JOIN pg_attribute a ON (a.attrelid = c.oid)'
640 .
' JOIN pg_attrdef d ON (c.oid=d.adrelid and a.attnum=d.adnum)'
641 .
' WHERE relkind = \'r\''
642 .
' AND nspname = ' . $this->addQuotes( $this->getCoreSchema() )
643 .
' AND relname = ' . $this->addQuotes( $oldName )
644 .
' AND pg_get_expr(adbin, adrelid) LIKE \'nextval(%\'',
646 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
648 $row =
$res->fetchObject();
650 $field = $row->attname;
651 $newSeq =
"{$newName}_{$field}_seq";
652 $fieldE = $this->platform->addIdentifierQuotes( $field );
653 $newSeqE = $this->platform->addIdentifierQuotes( $newSeq );
654 $newSeqQ = $this->addQuotes( $newSeq );
656 "CREATE $temporary SEQUENCE $newSeqE OWNED BY $newNameE.$fieldE",
658 self::QUERY_CHANGE_SCHEMA
661 "ALTER TABLE $newNameE ALTER COLUMN $fieldE SET DEFAULT nextval({$newSeqQ}::regclass)",
663 self::QUERY_CHANGE_SCHEMA
671 $encTables = $this->tableNamesN( ...$tables );
672 $sql =
"TRUNCATE TABLE " . implode(
',', $encTables ) .
" RESTART IDENTITY";
673 $this->query( $sql, $fname, self::QUERY_CHANGE_SCHEMA );
682 public function listTables( $prefix =
'', $fname = __METHOD__ ) {
683 $eschemas = implode(
',', array_map( [ $this,
'addQuotes' ], $this->getCoreSchemas() ) );
684 $result = $this->query(
685 "SELECT DISTINCT tablename FROM pg_tables WHERE schemaname IN ($eschemas)",
687 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
691 foreach ( $result as $table ) {
692 $vars = get_object_vars( $table );
693 $table = array_pop( $vars );
694 if ( $prefix ==
'' || strpos( $table, $prefix ) === 0 ) {
695 $endArray[] = $table;
720 private function pg_array_parse( $text, &$output, $limit =
false, $offset = 1 ) {
721 if ( $limit ===
false ) {
722 $limit = strlen( $text ) - 1;
725 if ( $text ==
'{}' ) {
729 if ( $text[$offset] !=
'{' ) {
730 preg_match(
"/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/",
731 $text, $match, 0, $offset );
732 $offset += strlen( $match[0] );
733 $output[] = ( $match[1][0] !=
'"'
735 : stripcslashes( substr( $match[1], 1, -1 ) ) );
736 if ( $match[3] ==
'},' ) {
740 $offset = $this->pg_array_parse( $text, $output, $limit, $offset + 1 );
742 }
while ( $limit > $offset );
748 return '[{{int:version-db-postgres-url}} PostgreSQL]';
760 "SELECT current_schema()",
762 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
764 $row =
$res->fetchRow();
781 "SELECT current_schemas(false)",
783 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
785 $row =
$res->fetchRow();
790 return $this->pg_array_parse( $row[0], $schemas );
806 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
808 $row =
$res->fetchRow();
812 return explode(
",", $row[0] );
822 private function setSearchPath( $search_path ) {
824 "SET search_path = " . implode(
", ", $search_path ),
826 self::QUERY_CHANGE_TRX
845 if ( $this->trxLevel() ) {
850 __METHOD__ .
": a transaction is currently active"
854 if ( $this->schemaExists( $desiredSchema ) ) {
855 if ( in_array( $desiredSchema, $this->getSchemas() ) ) {
856 $this->platform->setCoreSchema( $desiredSchema );
857 $this->logger->debug(
858 "Schema \"" . $desiredSchema .
"\" already in the search path\n" );
861 $search_path = $this->getSearchPath();
862 array_unshift( $search_path, $this->platform->addIdentifierQuotes( $desiredSchema ) );
863 $this->setSearchPath( $search_path );
864 $this->platform->setCoreSchema( $desiredSchema );
865 $this->logger->debug(
866 "Schema \"" . $desiredSchema .
"\" added to the search path\n" );
869 $this->platform->setCoreSchema( $this->getCurrentSchema() );
870 $this->logger->debug(
871 "Schema \"" . $desiredSchema .
"\" not found, using current \"" .
872 $this->getCoreSchema() .
"\"\n" );
883 return $this->platform->getCoreSchema();
893 if ( $this->tempSchema ) {
894 return [ $this->tempSchema, $this->getCoreSchema() ];
898 "SELECT nspname FROM pg_catalog.pg_namespace n WHERE n.oid = pg_my_temp_schema()",
900 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
902 $row =
$res->fetchObject();
904 $this->tempSchema = $row->nspname;
905 return [ $this->tempSchema, $this->getCoreSchema() ];
908 return [ $this->getCoreSchema() ];
912 if ( !isset( $this->numericVersion ) ) {
913 $conn = $this->getBindingHandle();
914 $versionInfo = pg_version( $conn );
915 if ( version_compare( $versionInfo[
'client'],
'7.4.0',
'lt' ) ) {
917 $this->numericVersion =
'7.3 or earlier';
918 } elseif ( isset( $versionInfo[
'server'] ) ) {
920 $this->numericVersion = $versionInfo[
'server'];
923 $this->numericVersion = pg_parameter_status( $conn,
'server_version' );
927 return $this->numericVersion;
938 private function relationExists( $table, $types, $schema =
false ) {
939 if ( !is_array( $types ) ) {
942 if ( $schema ===
false ) {
943 $schemas = $this->getCoreSchemas();
945 $schemas = [ $schema ];
947 $table = $this->realTableName( $table,
'raw' );
948 $etable = $this->addQuotes( $table );
949 foreach ( $schemas as $schema ) {
950 $eschema = $this->addQuotes( $schema );
951 $sql =
"SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
952 .
"WHERE c.relnamespace = n.oid AND c.relname = $etable AND n.nspname = $eschema "
953 .
"AND c.relkind IN ('" . implode(
"','", $types ) .
"')";
957 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
974 public function tableExists( $table, $fname = __METHOD__, $schema =
false ) {
975 return $this->relationExists( $table, [
'r',
'v' ], $schema );
979 return $this->relationExists( $sequence,
'S', $schema );
984 SELECT 1 FROM pg_class, pg_namespace, pg_trigger
985 WHERE relnamespace=pg_namespace.oid AND relkind=
'r'
986 AND tgrelid=pg_class.oid
987 AND nspname=%s AND relname=%s AND tgname=%s
989 foreach ( $this->getCoreSchemas() as $schema ) {
993 $this->addQuotes( $schema ),
994 $this->addQuotes( $table ),
995 $this->addQuotes( $trigger )
998 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
1009 $exists = $this->selectField(
'pg_rules',
'rulename',
1011 'rulename' => $rule,
1012 'tablename' => $table,
1013 'schemaname' => $this->getCoreSchemas()
1018 return $exists === $rule;
1022 foreach ( $this->getCoreSchemas() as $schema ) {
1023 $sql = sprintf(
"SELECT 1 FROM information_schema.table_constraints " .
1024 "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s",
1025 $this->addQuotes( $schema ),
1026 $this->addQuotes( $table ),
1027 $this->addQuotes( $constraint )
1029 $res = $this->query(
1032 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
1047 if ( !strlen( $schema ??
'' ) ) {
1051 $res = $this->query(
1052 "SELECT 1 FROM pg_catalog.pg_namespace " .
1053 "WHERE nspname = " . $this->addQuotes( $schema ) .
" LIMIT 1",
1055 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
1058 return (
$res->numRows() > 0 );
1067 $res = $this->query(
1068 "SELECT 1 FROM pg_catalog.pg_roles " .
1069 "WHERE rolname = " . $this->addQuotes( $roleName ) .
" LIMIT 1",
1071 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
1074 return (
$res->numRows() > 0 );
1083 return PostgresField::fromText( $this, $table, $field );
1087 $conn = $this->getBindingHandle();
1089 return new PostgresBlob( pg_escape_bytea( $conn, $b ) );
1095 } elseif ( $b instanceof
Blob ) {
1099 return pg_unescape_bytea( $b );
1104 return pg_escape_string( $this->getBindingHandle(), (
string)$s );
1108 $conn = $this->getBindingHandle();
1110 if ( $s ===
null ) {
1112 } elseif ( is_bool( $s ) ) {
1113 return (
string)intval( $s );
1114 } elseif ( is_int( $s ) ) {
1116 } elseif ( $s instanceof
Blob ) {
1120 $s = pg_escape_bytea( $conn, $s->fetch() );
1127 return "'" . pg_escape_string( $conn, (
string)$s ) .
"'";
1131 # Allow dollar quoting for function declarations
1132 if ( substr( $newLine, 0, 4 ) ==
'$mw$' ) {
1133 if ( $this->delimiter ) {
1134 $this->delimiter =
false;
1136 $this->delimiter =
';';
1140 return parent::streamStatementEnd( $sql, $newLine );
1144 $res = $this->query(
1145 $this->platform->lockIsFreeSQLText( $lockName ),
1147 self::QUERY_CHANGE_LOCKS
1149 $row =
$res->fetchObject();
1151 return ( $row->unlocked ===
't' );
1154 public function doLock(
string $lockName,
string $method,
int $timeout ) {
1155 $sql = $this->platform->lockSQLText( $lockName, $timeout );
1158 $loop =
new WaitConditionLoop(
1159 function () use ( $sql, $method, &$acquired ) {
1160 $res = $this->query(
1163 self::QUERY_CHANGE_LOCKS
1165 $row =
$res->fetchObject();
1167 if ( $row->acquired !==
null ) {
1168 $acquired = (float)$row->acquired;
1170 return WaitConditionLoop::CONDITION_REACHED;
1173 return WaitConditionLoop::CONDITION_CONTINUE;
1182 public function doUnlock(
string $lockName,
string $method ) {
1183 $result = $this->query(
1184 $this->platform->unlockSQLText( $lockName ),
1186 self::QUERY_CHANGE_LOCKS
1188 $row = $result->fetchObject();
1190 return ( $row->released ===
't' );
1194 $flags = self::QUERY_CHANGE_LOCKS | self::QUERY_NO_RETRY;
1197 $sql =
"SELECT pg_advisory_unlock_all()";
1198 $qs = $this->executeQuery( $sql, __METHOD__, $flags, $sql );
1199 if ( $qs->res ===
false ) {
1200 $this->reportQueryError( $qs->message, $qs->code, $sql, $fname,
true );
1205 $res = $this->query(
1206 "SHOW default_transaction_read_only",
1208 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
1210 $row =
$res->fetchObject();
1212 return $row ? ( strtolower( $row->default_transaction_read_only ) ===
'on' ) :
false;
1216 return [ self::ATTR_SCHEMAS_AS_TABLE_GROUPS =>
true ];
1223class_alias( DatabasePostgres::class,
'DatabasePostgres' );
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
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)
insertId()
Get the inserted value of an auto-increment row.
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 ...
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.stringto 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)
currentSequenceValue( $seqName)
Return the current value of a sequence.
doMultiStatementQuery(array $sqls)
Execute a batch of query statements, aborting remaining statements if one fails.
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()
wasLockTimeout()
Determines if the last failure was due to a lock timeout.Note that during a lock wait timeout,...
isConnectionError( $errno)
Do not use this method outside of Database/DBError classes.
triggerExists( $table, $trigger)
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.
ruleExists( $table, $rule)
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 the DB server is marked as read-only server-side query} 1.28to override