29use Wikimedia\WaitConditionLoop;
42 private $numericVersion;
45 private $lastResultHandle;
56 $this->port = intval(
$params[
'port'] ??
null );
76 protected function open( $server, $user, $password, $db, $schema, $tablePrefix ) {
77 if ( !function_exists(
'pg_connect' ) ) {
79 "Postgres functions missing, have you compiled PHP with the --with-pgsql\n" .
80 "option? (Note: if you recently installed PHP, you may need to restart your\n" .
81 "webserver and database)"
85 $this->
close( __METHOD__ );
90 'dbname' => ( $db !==
null && $db !==
'' ) ? $db :
'postgres',
92 'password' => $password
94 if ( $server !==
null && $server !==
'' ) {
95 $connectVars[
'host'] = $server;
97 if ( $this->port > 0 ) {
98 $connectVars[
'port'] = $this->port;
101 $connectVars[
'sslmode'] =
'require';
103 $connectString = $this->makeConnectionString( $connectVars );
107 $this->conn = pg_connect( $connectString, PGSQL_CONNECT_FORCE_NEW ) ?:
null;
108 }
catch ( RuntimeException $e ) {
114 if ( !$this->conn ) {
123 'client_encoding' =>
'UTF8',
124 'datestyle' =>
'ISO, YMD',
126 'standard_conforming_strings' =>
'on',
127 'bytea_output' =>
'escape',
128 'client_min_messages' =>
'ERROR'
130 foreach ( $variables as $var => $val ) {
131 $sql =
'SET ' . $this->platform->addIdentifierQuotes( $var ) .
' = ' . $this->
addQuotes( $val );
132 $query =
new Query( $sql, self::QUERY_NO_RETRY | self::QUERY_CHANGE_TRX,
'SET' );
133 $this->
query( $query, __METHOD__ );
136 $this->currentDomain =
new DatabaseDomain( $db, $schema, $tablePrefix );
137 $this->platform->setCurrentDomain( $this->currentDomain );
138 }
catch ( RuntimeException $e ) {
149 if ( $database ===
null ) {
152 $this->currentDomain->getDatabase(),
153 $domain->
getSchema() ?? $this->currentDomain->getSchema(),
156 $this->platform->setCurrentDomain( $this->currentDomain );
157 } elseif ( $this->
getDBname() !== $database ) {
161 $this->connectionParams[self::CONN_HOST],
162 $this->connectionParams[self::CONN_USER],
163 $this->connectionParams[self::CONN_PASSWORD],
169 $this->currentDomain = $domain;
170 $this->platform->setCurrentDomain( $this->currentDomain );
180 private function makeConnectionString( $vars ) {
182 foreach ( $vars as $name => $value ) {
183 $s .=
"$name='" . str_replace( [
"\\",
"'" ], [
"\\\\",
"\\'" ], $value ) .
"' ";
190 return $this->conn ? pg_close( $this->conn ) :
true;
196 $sql = mb_convert_encoding( $sql,
'UTF-8' );
198 while ( $priorRes = pg_get_result(
$conn ) ) {
199 pg_free_result( $priorRes );
202 if ( pg_send_query(
$conn, $sql ) ===
false ) {
203 throw new DBUnexpectedError( $this,
"Unable to post new query to PostgreSQL\n" );
208 $pgRes = pg_get_result(
$conn );
211 $this->lastResultHandle = $pgRes;
212 $res = pg_result_error( $pgRes ) ? false : $pgRes;
214 return new QueryStatus(
216 is_bool( $res ) ? $res : new PostgresResultWrapper( $this,
$conn, $res ),
217 $pgRes ? pg_affected_rows( $pgRes ) : 0,
227 PGSQL_DIAG_MESSAGE_PRIMARY,
228 PGSQL_DIAG_MESSAGE_DETAIL,
229 PGSQL_DIAG_MESSAGE_HINT,
230 PGSQL_DIAG_STATEMENT_POSITION,
231 PGSQL_DIAG_INTERNAL_POSITION,
232 PGSQL_DIAG_INTERNAL_QUERY,
234 PGSQL_DIAG_SOURCE_FILE,
235 PGSQL_DIAG_SOURCE_LINE,
236 PGSQL_DIAG_SOURCE_FUNCTION
238 foreach ( $diags as $d ) {
239 $this->logger->debug( sprintf(
"PgSQL ERROR(%d): %s",
241 $d, pg_result_error_field( $this->lastResultHandle, $d ) ) );
250 $qs = $this->doSingleStatementQuery(
"SELECT lastval() AS id" );
252 return $qs->res ? (int)$qs->res->fetchRow()[
'id'] : 0;
257 if ( $this->lastResultHandle ) {
259 return pg_result_error( $this->lastResultHandle );
261 return pg_last_error() ?: $this->lastConnectError;
265 return $this->getLastPHPError() ?:
'No database connection';
269 if ( $this->lastResultHandle ) {
271 $lastErrno = pg_result_error_field( $this->lastResultHandle, PGSQL_DIAG_SQLSTATE );
272 if ( $lastErrno !==
false ) {
296 $fname = __METHOD__, $options = [], $join_conds = []
298 $conds = $this->platform->normalizeConditions( $conds, $fname );
299 $column = $this->platform->extractSingleFieldFromList( $var );
300 if ( is_string( $column ) && !in_array( $column, [
'*',
'1' ] ) ) {
301 $conds[] =
"$column IS NOT NULL";
304 $options[
'EXPLAIN'] =
true;
305 $res = $this->select( $table, $var, $conds, $fname, $options, $join_conds );
308 $row = $res->fetchRow();
310 if ( preg_match(
'/rows=(\d+)/', $row[0], $count ) ) {
311 $rows = (int)$count[1];
318 public function indexInfo( $table, $index, $fname = __METHOD__ ) {
320 "SELECT indexname FROM pg_indexes WHERE tablename='$table'",
321 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
324 $res = $this->query( $query );
328 foreach ( $res as $row ) {
329 if ( $row->indexname == $this->platform->indexName( $index ) ) {
338 if ( $schema ===
false ) {
339 $schemas = $this->getCoreSchemas();
341 $schemas = [ $schema ];
344 $eindex = $this->addQuotes( $index );
346 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
347 foreach ( $schemas as $schema ) {
348 $eschema = $this->addQuotes( $schema );
353 $sql = <<<__INDEXATTR__
357 i.indoption[s.g] as option,
360 (SELECT generate_series(array_lower(isub.indkey,1), array_upper(isub.indkey,1)) AS g
364 ON cis.oid=isub.indexrelid
366 ON cis.relnamespace = ns.oid
367 WHERE cis.relname=$eindex AND ns.nspname=$eschema) AS s,
373 ON ci.oid=i.indexrelid
375 ON ct.oid = i.indrelid
377 ON ci.relnamespace = n.oid
379 ci.relname=$eindex AND n.nspname=$eschema
380 AND attrelid = ct.oid
381 AND i.indkey[s.g] = attnum
382 AND i.indclass[s.g] = opcls.oid
383 AND pg_am.oid = opcls.opcmethod
385 $query =
new Query( $sql, $flags,
'SELECT' );
386 $res = $this->query( $query, __METHOD__ );
389 foreach ( $res as $row ) {
402 public function indexUnique( $table, $index, $fname = __METHOD__ ) {
403 $sql =
"SELECT indexname FROM pg_indexes WHERE tablename='{$table}'" .
404 " AND indexdef LIKE 'CREATE UNIQUE%(" .
405 $this->strencode( $this->platform->indexName( $index ) ) .
407 $query =
new Query( $sql, self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
'SELECT' );
408 $res = $this->query( $query, $fname );
409 return $res && $res->numRows() > 0;
436 array $insertOptions,
437 array $selectOptions,
440 if ( in_array(
'IGNORE', $insertOptions ) ) {
442 $destTableEnc = $this->tableName( $destTable );
444 $selectSql = $this->selectSQLText(
446 array_values( $varMap ),
453 $sql =
"INSERT INTO $destTableEnc (" . implode(
',', array_keys( $varMap ) ) .
') ' .
454 $selectSql .
' ON CONFLICT DO NOTHING';
455 $query =
new Query( $sql, self::QUERY_CHANGE_ROWS,
'INSERT', $destTable );
456 $this->query( $query, $fname );
458 parent::doInsertSelectNative( $destTable, $srcTable, $varMap, $conds, $fname,
459 $insertOptions, $selectOptions, $selectJoinConds );
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' );
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;
496 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
497 $encTable = $this->tableName( $table );
498 $sql =
"SELECT t.typname as ftype,a.atttypmod as size
499 FROM pg_class c, pg_attribute a, pg_type t
500 WHERE relname='$encTable' AND a.attrelid=c.oid AND
501 a.atttypid=t.oid and a.attname='$field'";
502 $query =
new Query( $sql, $flags,
'SELECT' );
503 $res = $this->query( $query, __METHOD__ );
504 $row = $res->fetchObject();
505 if ( $row->ftype ==
'varchar' ) {
506 $size = $row->size - 4;
516 return $this->lastErrno() ===
'40P01';
521 static $codes = [
'08000',
'08003',
'08006',
'08001',
'08004',
'57P01',
'57P03',
'53300' ];
523 return in_array( $errno, $codes,
true );
528 return ( $errno ===
'57014' );
536 $oldName, $newName, $temporary =
false, $fname = __METHOD__
538 $newNameE = $this->platform->addIdentifierQuotes( $newName );
539 $oldNameE = $this->platform->addIdentifierQuotes( $oldName );
541 $temporary = $temporary ?
'TEMPORARY' :
'';
543 "CREATE $temporary TABLE $newNameE " .
544 "(LIKE $oldNameE INCLUDING DEFAULTS INCLUDING INDEXES)",
545 self::QUERY_PSEUDO_PERMANENT | self::QUERY_CHANGE_SCHEMA,
546 $temporary ?
'CREATE TEMPORARY' :
'CREATE',
550 $ret = $this->query( $query, $fname );
555 $sql =
'SELECT attname FROM pg_class c'
556 .
' JOIN pg_namespace n ON (n.oid = c.relnamespace)'
557 .
' JOIN pg_attribute a ON (a.attrelid = c.oid)'
558 .
' JOIN pg_attrdef d ON (c.oid=d.adrelid and a.attnum=d.adnum)'
559 .
' WHERE relkind = \'r\''
560 .
' AND nspname = ' . $this->addQuotes( $this->getCoreSchema() )
561 .
' AND relname = ' . $this->addQuotes( $oldName )
562 .
' AND pg_get_expr(adbin, adrelid) LIKE \'nextval(%\'';
565 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
569 $res = $this->query( $query, $fname );
570 $row = $res->fetchObject();
572 $field = $row->attname;
573 $newSeq =
"{$newName}_{$field}_seq";
574 $fieldE = $this->platform->addIdentifierQuotes( $field );
575 $newSeqE = $this->platform->addIdentifierQuotes( $newSeq );
576 $newSeqQ = $this->addQuotes( $newSeq );
578 "CREATE $temporary SEQUENCE $newSeqE OWNED BY $newNameE.$fieldE",
579 self::QUERY_CHANGE_SCHEMA,
584 $this->query( $query, $fname );
586 "ALTER TABLE $newNameE ALTER COLUMN $fieldE SET DEFAULT nextval({$newSeqQ}::regclass)",
587 self::QUERY_CHANGE_SCHEMA,
592 $this->query( $query, $fname );
599 $sql =
"TRUNCATE TABLE " . $this->tableName( $table ) .
" RESTART IDENTITY";
600 $query =
new Query( $sql, self::QUERY_CHANGE_SCHEMA,
'TRUNCATE', $table );
601 $this->query( $query, $fname );
610 public function listTables( $prefix =
'', $fname = __METHOD__ ) {
611 $eschemas = implode(
',', array_map( [ $this,
'addQuotes' ], $this->getCoreSchemas() ) );
613 "SELECT DISTINCT tablename FROM pg_tables WHERE schemaname IN ($eschemas)",
614 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
617 $result = $this->query( $query, $fname );
620 foreach ( $result as $table ) {
621 $vars = get_object_vars( $table );
622 $table = array_pop( $vars );
623 if ( $prefix ==
'' || strpos( $table, $prefix ) === 0 ) {
624 $endArray[] = $table;
649 private function pg_array_parse( $text, &$output, $limit =
false, $offset = 1 ) {
650 if ( $limit ===
false ) {
651 $limit = strlen( $text ) - 1;
654 if ( $text ==
'{}' ) {
658 if ( $text[$offset] !=
'{' ) {
659 preg_match(
"/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/",
660 $text, $match, 0, $offset );
661 $offset += strlen( $match[0] );
662 $output[] = ( $match[1][0] !=
'"'
664 : stripcslashes( substr( $match[1], 1, -1 ) ) );
665 if ( $match[3] ==
'},' ) {
669 $offset = $this->pg_array_parse( $text, $output, $limit, $offset + 1 );
671 }
while ( $limit > $offset );
677 return '[{{int:version-db-postgres-url}} PostgreSQL]';
689 "SELECT current_schema()",
690 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
693 $res = $this->query( $query, __METHOD__ );
694 $row = $res->fetchRow();
711 "SELECT current_schemas(false)",
712 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
715 $res = $this->query( $query, __METHOD__ );
716 $row = $res->fetchRow();
721 return $this->pg_array_parse( $row[0], $schemas );
736 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
739 $res = $this->query( $query, __METHOD__ );
740 $row = $res->fetchRow();
744 return explode(
",", $row[0] );
754 private function setSearchPath( $search_path ) {
756 "SET search_path = " . implode(
", ", $search_path ),
757 self::QUERY_CHANGE_TRX,
760 $this->query( $query, __METHOD__ );
778 if ( $this->trxLevel() ) {
783 __METHOD__ .
": a transaction is currently active"
787 if ( $this->schemaExists( $desiredSchema ) ) {
788 if ( in_array( $desiredSchema, $this->getSchemas() ) ) {
789 $this->platform->setCoreSchema( $desiredSchema );
790 $this->logger->debug(
791 "Schema \"" . $desiredSchema .
"\" already in the search path\n" );
794 $search_path = $this->getSearchPath();
795 array_unshift( $search_path, $this->platform->addIdentifierQuotes( $desiredSchema ) );
796 $this->setSearchPath( $search_path );
797 $this->platform->setCoreSchema( $desiredSchema );
798 $this->logger->debug(
799 "Schema \"" . $desiredSchema .
"\" added to the search path\n" );
802 $this->platform->setCoreSchema( $this->getCurrentSchema() );
803 $this->logger->debug(
804 "Schema \"" . $desiredSchema .
"\" not found, using current \"" .
805 $this->getCoreSchema() .
"\"\n" );
816 return $this->platform->getCoreSchema();
826 if ( $this->tempSchema ) {
827 return [ $this->tempSchema, $this->getCoreSchema() ];
830 "SELECT nspname FROM pg_catalog.pg_namespace n WHERE n.oid = pg_my_temp_schema()",
831 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
834 $res = $this->query( $query, __METHOD__ );
835 $row = $res->fetchObject();
837 $this->tempSchema = $row->nspname;
838 return [ $this->tempSchema, $this->getCoreSchema() ];
841 return [ $this->getCoreSchema() ];
845 if ( !isset( $this->numericVersion ) ) {
847 $this->numericVersion = pg_version( $this->getBindingHandle() )[
'server'];
850 return $this->numericVersion;
861 private function relationExists( $table, $types, $schema =
false ) {
862 if ( !is_array( $types ) ) {
865 if ( $schema ===
false ) {
866 $schemas = $this->getCoreSchemas();
868 $schemas = [ $schema ];
870 $table = $this->tableName( $table,
'raw' );
871 $etable = $this->addQuotes( $table );
872 foreach ( $schemas as $schema ) {
873 $eschema = $this->addQuotes( $schema );
874 $sql =
"SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
875 .
"WHERE c.relnamespace = n.oid AND c.relname = $etable AND n.nspname = $eschema "
876 .
"AND c.relkind IN ('" . implode(
"','", $types ) .
"')";
879 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
882 $res = $this->query( $query, __METHOD__ );
883 if ( $res && $res->numRows() ) {
898 public function tableExists( $table, $fname = __METHOD__, $schema =
false ) {
899 return $this->relationExists( $table, [
'r',
'v' ], $schema );
903 return $this->relationExists( $sequence,
'S', $schema );
907 foreach ( $this->getCoreSchemas() as $schema ) {
908 $sql = sprintf(
"SELECT 1 FROM information_schema.table_constraints " .
909 "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s",
910 $this->addQuotes( $schema ),
911 $this->addQuotes( $table ),
912 $this->addQuotes( $constraint )
916 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
919 $res = $this->query( $query, __METHOD__ );
920 if ( $res && $res->numRows() ) {
933 if ( !strlen( $schema ??
'' ) ) {
937 "SELECT 1 FROM pg_catalog.pg_namespace " .
938 "WHERE nspname = " . $this->addQuotes( $schema ) .
" LIMIT 1",
939 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
942 $res = $this->query( $query, __METHOD__ );
944 return ( $res->numRows() > 0 );
954 "SELECT 1 FROM pg_catalog.pg_roles " .
955 "WHERE rolname = " . $this->addQuotes( $roleName ) .
" LIMIT 1",
956 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
959 $res = $this->query( $query, __METHOD__ );
961 return ( $res->numRows() > 0 );
970 return PostgresField::fromText( $this, $table, $field );
974 $conn = $this->getBindingHandle();
976 return new PostgresBlob( pg_escape_bytea( $conn, $b ) );
982 } elseif ( $b instanceof
Blob ) {
986 return pg_unescape_bytea( $b );
991 return pg_escape_string( $this->getBindingHandle(), (
string)$s );
995 $conn = $this->getBindingHandle();
999 } elseif ( is_bool( $s ) ) {
1000 return (
string)intval( $s );
1001 } elseif ( is_int( $s ) ) {
1003 } elseif ( $s instanceof
Blob ) {
1007 $s = pg_escape_bytea( $conn, $s->fetch() );
1014 return "'" . pg_escape_string( $conn, (
string)$s ) .
"'";
1018 # Allow dollar quoting for function declarations
1019 if ( str_starts_with( $newLine,
'$mw$' ) ) {
1020 if ( $this->delimiter ) {
1021 $this->delimiter =
false;
1023 $this->delimiter =
';';
1027 return parent::streamStatementEnd( $sql, $newLine );
1032 $this->platform->lockIsFreeSQLText( $lockName ),
1033 self::QUERY_CHANGE_LOCKS,
1036 $res = $this->query( $query, $method );
1037 $row = $res->fetchObject();
1039 return (
bool)$row->unlocked;
1042 public function doLock(
string $lockName,
string $method,
int $timeout ) {
1044 $this->platform->lockSQLText( $lockName, $timeout ),
1045 self::QUERY_CHANGE_LOCKS,
1050 $loop =
new WaitConditionLoop(
1051 function () use ( $query, $method, &$acquired ) {
1052 $res = $this->query( $query, $method );
1053 $row = $res->fetchObject();
1055 if ( $row->acquired !==
null ) {
1056 $acquired = (float)$row->acquired;
1058 return WaitConditionLoop::CONDITION_REACHED;
1061 return WaitConditionLoop::CONDITION_CONTINUE;
1070 public function doUnlock(
string $lockName,
string $method ) {
1072 $this->platform->unlockSQLText( $lockName ),
1073 self::QUERY_CHANGE_LOCKS,
1076 $result = $this->query( $query, $method );
1077 $row = $result->fetchObject();
1079 return (
bool)$row->released;
1083 $flags = self::QUERY_CHANGE_LOCKS | self::QUERY_NO_RETRY;
1086 $sql =
"SELECT pg_advisory_unlock_all()";
1087 $query =
new Query( $sql, $flags,
'UNLOCK' );
1088 $qs = $this->executeQuery( $query, __METHOD__, $flags );
1089 if ( $qs->res ===
false ) {
1090 $this->reportQueryError( $qs->message, $qs->code, $sql, $fname,
true );
1096 "SHOW default_transaction_read_only",
1097 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
1100 $res = $this->query( $query, __METHOD__ );
1101 $row = $res->fetchObject();
1103 return $row && strtolower( $row->default_transaction_read_only ) ===
'on';
1109 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
1110 $encTable = $this->addQuotes( $this->tableName( $table,
'raw' ) );
1111 foreach ( $this->getCoreSchemas() as $schema ) {
1112 $encSchema = $this->addQuotes( $schema );
1114 "SELECT column_name,data_type,column_default " .
1115 "FROM information_schema.columns " .
1116 "WHERE table_name = $encTable AND table_schema = $encSchema",
1117 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE,
1120 $res = $this->query( $query, __METHOD__ );
1121 if ( $res->numRows() ) {
1122 foreach ( $res as $row ) {
1124 $row->column_default !==
null &&
1125 str_starts_with( $row->column_default,
"nextval(" ) &&
1126 in_array( $row->data_type, [
'integer',
'bigint' ],
true )
1128 $column = $row->column_name;
1139 return [ self::ATTR_SCHEMAS_AS_TABLE_GROUPS => true ];
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
array $params
The job parameters.
Class to handle database/schema/prefix specifications for IDatabase.
Postgres database abstraction layer.
truncateTable( $table, $fname=__METHOD__)
Delete all data in a table and reset any sequences owned by that table.
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.
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.
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.
sequenceExists( $sequence, $schema=false)
wasDeadlock()
Determines if the last failure was due to a deadlock.
__construct(array $params)
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.
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.
textFieldSize( $table, $field)
Returns the size of a text field, or -1 for "unlimited".
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...
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.28