24use Wikimedia\WaitConditionLoop;
37 private $keywordTableMap;
39 private $numericVersion;
42 private $lastResultHandle;
55 $this->port = intval( $params[
'port'] ??
null );
57 if ( isset( $params[
'keywordTableMap'] ) ) {
59 'DatabasePostgres::__construct() is deprecated',
'1.37'
62 $this->keywordTableMap = $params[
'keywordTableMap'];
65 parent::__construct( $params );
68 $params[
'queryLogger'],
79 if ( !function_exists(
'pg_connect' ) ) {
81 "Postgres functions missing, have you compiled PHP with the --with-pgsql\n" .
82 "option? (Note: if you recently installed PHP, you may need to restart your\n" .
83 "webserver and database)"
87 $this->
close( __METHOD__ );
92 'dbname' => ( $db !==
null && $db !==
'' ) ? $db :
'postgres',
99 if ( $this->port > 0 ) {
100 $connectVars[
'port'] = $this->port;
103 $connectVars[
'sslmode'] =
'require';
105 $connectString = $this->makeConnectionString( $connectVars );
109 $this->conn = pg_connect( $connectString, PGSQL_CONNECT_FORCE_NEW ) ?:
null;
110 }
catch ( RuntimeException $e ) {
116 if ( !$this->conn ) {
125 'client_encoding' =>
'UTF8',
126 'datestyle' =>
'ISO, YMD',
128 'standard_conforming_strings' =>
'on',
129 'bytea_output' =>
'escape',
130 'client_min_messages' =>
'ERROR'
132 foreach ( $variables as $var => $val ) {
134 'SET ' . $this->platform->addIdentifierQuotes( $var ) .
' = ' . $this->addQuotes( $val ),
136 self::QUERY_NO_RETRY | self::QUERY_CHANGE_TRX
140 $this->currentDomain =
new DatabaseDomain( $db, $schema, $tablePrefix );
141 $this->platform->setCurrentDomain( $this->currentDomain );
142 }
catch ( RuntimeException $e ) {
156 $this->connectionParams[self::CONN_HOST],
157 $this->connectionParams[self::CONN_USER],
158 $this->connectionParams[self::CONN_PASSWORD],
164 $this->currentDomain = $domain;
165 $this->platform->setCurrentDomain( $this->currentDomain );
175 private function makeConnectionString( $vars ) {
177 foreach ( $vars as $name => $value ) {
178 $s .=
"$name='" . str_replace( [
"\\",
"'" ], [
"\\\\",
"\\'" ], $value ) .
"' ";
185 return $this->conn ? pg_close( $this->conn ) :
true;
191 $sql = mb_convert_encoding( $sql,
'UTF-8' );
193 while ( $priorRes = pg_get_result(
$conn ) ) {
194 pg_free_result( $priorRes );
197 if ( pg_send_query(
$conn, $sql ) ===
false ) {
198 throw new DBUnexpectedError( $this,
"Unable to post new query to PostgreSQL\n" );
203 $pgRes = pg_get_result(
$conn );
204 $this->lastResultHandle = $pgRes;
205 $res = pg_result_error( $pgRes ) ? false : $pgRes;
207 return new QueryStatus(
216 $qsByStatementId = [];
218 $conn = $this->getBindingHandle();
220 while ( $pgResultSet = pg_get_result( $conn ) ) {
221 pg_free_result( $pgResultSet );
224 $combinedSql = mb_convert_encoding( implode(
";\n", $sqls ),
'UTF-8' );
225 pg_send_query( $conn, $combinedSql );
228 while ( ( $pgResultSet = pg_get_result( $conn ) ) !==
false ) {
229 $this->lastResultHandle = $pgResultSet;
231 $statementId = key( $sqls );
232 if ( $statementId !==
null ) {
233 if ( pg_result_error( $pgResultSet ) ) {
236 $res =
new PostgresResultWrapper( $this, $conn, $pgResultSet );
238 $qsByStatementId[$statementId] =
new QueryStatus(
240 pg_affected_rows( $pgResultSet ),
241 (
string)pg_result_error( $pgResultSet ),
242 pg_result_error_field( $pgResultSet, PGSQL_DIAG_SQLSTATE )
248 while ( ( $statementId = key( $sqls ) ) !==
null ) {
249 $qsByStatementId[$statementId] =
new QueryStatus(
false, 0,
'Query aborted', 0 );
253 return $qsByStatementId;
260 PGSQL_DIAG_MESSAGE_PRIMARY,
261 PGSQL_DIAG_MESSAGE_DETAIL,
262 PGSQL_DIAG_MESSAGE_HINT,
263 PGSQL_DIAG_STATEMENT_POSITION,
264 PGSQL_DIAG_INTERNAL_POSITION,
265 PGSQL_DIAG_INTERNAL_QUERY,
267 PGSQL_DIAG_SOURCE_FILE,
268 PGSQL_DIAG_SOURCE_LINE,
269 PGSQL_DIAG_SOURCE_FUNCTION
271 foreach ( $diags as $d ) {
272 $this->queryLogger->debug( sprintf(
"PgSQL ERROR(%d): %s",
273 $d, pg_result_error_field( $this->lastResultHandle, $d ) ) );
281 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
283 $row =
$res->fetchRow();
286 return $row[0] ===
null ? null : (int)$row[0];
291 if ( $this->lastResultHandle ) {
292 return pg_result_error( $this->lastResultHandle );
294 return pg_last_error();
298 return $this->getLastPHPError() ?:
'No database connection';
302 if ( $this->lastResultHandle ) {
303 $lastErrno = pg_result_error_field( $this->lastResultHandle, PGSQL_DIAG_SQLSTATE );
304 if ( $lastErrno !==
false ) {
313 if ( !$this->lastResultHandle ) {
317 return pg_affected_rows( $this->lastResultHandle );
336 $fname = __METHOD__, $options = [], $join_conds = []
338 $conds = $this->platform->normalizeConditions( $conds, $fname );
339 $column = $this->platform->extractSingleFieldFromList( $var );
340 if ( is_string( $column ) && !in_array( $column, [
'*',
'1' ] ) ) {
341 $conds[] =
"$column IS NOT NULL";
344 $options[
'EXPLAIN'] =
true;
345 $res = $this->select( $table, $var, $conds, $fname, $options, $join_conds );
348 $row =
$res->fetchRow();
350 if ( preg_match(
'/rows=(\d+)/', $row[0], $count ) ) {
351 $rows = (int)$count[1];
358 public function indexInfo( $table, $index, $fname = __METHOD__ ) {
360 "SELECT indexname FROM pg_indexes WHERE tablename='$table'",
362 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
367 foreach (
$res as $row ) {
368 if ( $row->indexname == $this->indexName( $index ) ) {
377 if ( $schema ===
false ) {
378 $schemas = $this->getCoreSchemas();
380 $schemas = [ $schema ];
383 $eindex = $this->addQuotes( $index );
385 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
386 foreach ( $schemas as $schema ) {
387 $eschema = $this->addQuotes( $schema );
392 $sql = <<<__INDEXATTR__
396 i.indoption[s.g] as option,
399 (SELECT generate_series(array_lower(isub.indkey,1), array_upper(isub.indkey,1)) AS g
403 ON cis.oid=isub.indexrelid
405 ON cis.relnamespace = ns.oid
406 WHERE cis.relname=$eindex AND ns.nspname=$eschema) AS s,
412 ON ci.oid=i.indexrelid
414 ON ct.oid = i.indrelid
416 ON ci.relnamespace =
n.oid
418 ci.relname=$eindex AND
n.nspname=$eschema
419 AND attrelid = ct.oid
420 AND i.indkey[s.g] = attnum
421 AND i.indclass[s.g] = opcls.oid
422 AND pg_am.oid = opcls.opcmethod
424 $res = $this->query( $sql, __METHOD__, $flags );
427 foreach (
$res as $row ) {
440 public function indexUnique( $table, $index, $fname = __METHOD__ ) {
441 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
442 $sql =
"SELECT indexname FROM pg_indexes WHERE tablename='{$table}'" .
443 " AND indexdef LIKE 'CREATE UNIQUE%(" .
444 $this->strencode( $this->indexName( $index ) ) .
446 $res = $this->query( $sql, $fname, $flags );
451 return $res->numRows() > 0;
478 array $insertOptions,
479 array $selectOptions,
482 if ( in_array(
'IGNORE', $insertOptions ) ) {
484 $destTable = $this->tableName( $destTable );
486 $selectSql = $this->selectSQLText(
488 array_values( $varMap ),
495 $sql =
"INSERT INTO $destTable (" . implode(
',', array_keys( $varMap ) ) .
') ' .
496 $selectSql .
' ON CONFLICT DO NOTHING';
498 $this->query( $sql, $fname, self::QUERY_CHANGE_ROWS );
500 parent::doInsertSelectNative( $destTable, $srcTable, $varMap, $conds, $fname,
501 $insertOptions, $selectOptions, $selectJoinConds );
513 return $this->keywordTableMap[$name] ?? $name;
522 return parent::tableName( $name, $format );
537 "SELECT currval('" . str_replace(
"'",
"''", $seqName ) .
"')",
539 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
541 $row =
$res->fetchRow();
548 $flags = self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE;
549 $encTable = $this->tableName( $table );
550 $sql =
"SELECT t.typname as ftype,a.atttypmod as size
551 FROM pg_class c, pg_attribute a, pg_type t
552 WHERE relname='$encTable' AND a.attrelid=c.oid AND
553 a.atttypid=t.oid and a.attname='$field'";
554 $res = $this->query( $sql, __METHOD__, $flags );
555 $row =
$res->fetchObject();
556 if ( $row->ftype ==
'varchar' ) {
557 $size = $row->size - 4;
567 return $this->lastErrno() ===
'40P01';
572 return $this->lastErrno() ===
'55P03';
577 static $codes = [
'08000',
'08003',
'08006',
'08001',
'08004',
'57P01',
'57P03',
'53300' ];
579 return in_array( $errno, $codes,
true );
584 return ( $errno ===
'57014' );
592 $oldName, $newName, $temporary =
false, $fname = __METHOD__
594 $newNameE = $this->platform->addIdentifierQuotes( $newName );
595 $oldNameE = $this->platform->addIdentifierQuotes( $oldName );
597 $temporary = $temporary ?
'TEMPORARY' :
'';
600 "CREATE $temporary TABLE $newNameE " .
601 "(LIKE $oldNameE INCLUDING DEFAULTS INCLUDING INDEXES)",
603 self::QUERY_PSEUDO_PERMANENT | self::QUERY_CHANGE_SCHEMA
610 'SELECT attname FROM pg_class c'
611 .
' JOIN pg_namespace n ON (n.oid = c.relnamespace)'
612 .
' JOIN pg_attribute a ON (a.attrelid = c.oid)'
613 .
' JOIN pg_attrdef d ON (c.oid=d.adrelid and a.attnum=d.adnum)'
614 .
' WHERE relkind = \'r\''
615 .
' AND nspname = ' . $this->addQuotes( $this->getCoreSchema() )
616 .
' AND relname = ' . $this->addQuotes( $oldName )
617 .
' AND pg_get_expr(adbin, adrelid) LIKE \'nextval(%\'',
619 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
621 $row =
$res->fetchObject();
623 $field = $row->attname;
624 $newSeq =
"{$newName}_{$field}_seq";
625 $fieldE = $this->platform->addIdentifierQuotes( $field );
626 $newSeqE = $this->platform->addIdentifierQuotes( $newSeq );
627 $newSeqQ = $this->addQuotes( $newSeq );
629 "CREATE $temporary SEQUENCE $newSeqE OWNED BY $newNameE.$fieldE",
631 self::QUERY_CHANGE_SCHEMA
634 "ALTER TABLE $newNameE ALTER COLUMN $fieldE SET DEFAULT nextval({$newSeqQ}::regclass)",
636 self::QUERY_CHANGE_SCHEMA
644 $encTables = $this->tableNamesN( ...$tables );
645 $sql =
"TRUNCATE TABLE " . implode(
',', $encTables ) .
" RESTART IDENTITY";
646 $this->query( $sql, $fname, self::QUERY_CHANGE_SCHEMA );
655 public function listTables( $prefix =
'', $fname = __METHOD__ ) {
656 $eschemas = implode(
',', array_map( [ $this,
'addQuotes' ], $this->getCoreSchemas() ) );
657 $result = $this->query(
658 "SELECT DISTINCT tablename FROM pg_tables WHERE schemaname IN ($eschemas)",
660 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
664 foreach ( $result as $table ) {
665 $vars = get_object_vars( $table );
666 $table = array_pop( $vars );
667 if ( $prefix ==
'' || strpos( $table, $prefix ) === 0 ) {
668 $endArray[] = $table;
693 private function pg_array_parse( $text, &$output, $limit =
false, $offset = 1 ) {
694 if ( $limit ===
false ) {
695 $limit = strlen( $text ) - 1;
698 if ( $text ==
'{}' ) {
702 if ( $text[$offset] !=
'{' ) {
703 preg_match(
"/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/",
704 $text, $match, 0, $offset );
705 $offset += strlen( $match[0] );
706 $output[] = ( $match[1][0] !=
'"'
708 : stripcslashes( substr( $match[1], 1, -1 ) ) );
709 if ( $match[3] ==
'},' ) {
713 $offset = $this->pg_array_parse( $text, $output, $limit, $offset + 1 );
715 }
while ( $limit > $offset );
721 return '[{{int:version-db-postgres-url}} PostgreSQL]';
733 "SELECT current_schema()",
735 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
737 $row =
$res->fetchRow();
754 "SELECT current_schemas(false)",
756 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
758 $row =
$res->fetchRow();
763 return $this->pg_array_parse( $row[0], $schemas );
779 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
781 $row =
$res->fetchRow();
785 return explode(
",", $row[0] );
795 private function setSearchPath( $search_path ) {
797 "SET search_path = " . implode(
", ", $search_path ),
799 self::QUERY_CHANGE_TRX
818 if ( $this->trxLevel() ) {
823 __METHOD__ .
": a transaction is currently active"
827 if ( $this->schemaExists( $desiredSchema ) ) {
828 if ( in_array( $desiredSchema, $this->getSchemas() ) ) {
829 $this->platform->setCoreSchema( $desiredSchema );
830 $this->queryLogger->debug(
831 "Schema \"" . $desiredSchema .
"\" already in the search path\n" );
834 $search_path = $this->getSearchPath();
835 array_unshift( $search_path, $this->platform->addIdentifierQuotes( $desiredSchema ) );
836 $this->setSearchPath( $search_path );
837 $this->platform->setCoreSchema( $desiredSchema );
838 $this->queryLogger->debug(
839 "Schema \"" . $desiredSchema .
"\" added to the search path\n" );
842 $this->platform->setCoreSchema( $this->getCurrentSchema() );
843 $this->queryLogger->debug(
844 "Schema \"" . $desiredSchema .
"\" not found, using current \"" .
845 $this->getCoreSchema() .
"\"\n" );
856 return $this->platform->getCoreSchema();
866 if ( $this->tempSchema ) {
867 return [ $this->tempSchema, $this->getCoreSchema() ];
871 "SELECT nspname FROM pg_catalog.pg_namespace n WHERE n.oid = pg_my_temp_schema()",
873 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
875 $row =
$res->fetchObject();
877 $this->tempSchema = $row->nspname;
878 return [ $this->tempSchema, $this->getCoreSchema() ];
881 return [ $this->getCoreSchema() ];
885 if ( !isset( $this->numericVersion ) ) {
886 $conn = $this->getBindingHandle();
887 $versionInfo = pg_version( $conn );
888 if ( version_compare( $versionInfo[
'client'],
'7.4.0',
'lt' ) ) {
890 $this->numericVersion =
'7.3 or earlier';
891 } elseif ( isset( $versionInfo[
'server'] ) ) {
893 $this->numericVersion = $versionInfo[
'server'];
896 $this->numericVersion = pg_parameter_status( $conn,
'server_version' );
900 return $this->numericVersion;
911 private function relationExists( $table, $types, $schema =
false ) {
912 if ( !is_array( $types ) ) {
915 if ( $schema ===
false ) {
916 $schemas = $this->getCoreSchemas();
918 $schemas = [ $schema ];
920 $table = $this->realTableName( $table,
'raw' );
921 $etable = $this->addQuotes( $table );
922 foreach ( $schemas as $schema ) {
923 $eschema = $this->addQuotes( $schema );
924 $sql =
"SELECT 1 FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n "
925 .
"WHERE c.relnamespace = n.oid AND c.relname = $etable AND n.nspname = $eschema "
926 .
"AND c.relkind IN ('" . implode(
"','", $types ) .
"')";
930 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
947 public function tableExists( $table, $fname = __METHOD__, $schema =
false ) {
948 return $this->relationExists( $table, [
'r',
'v' ], $schema );
952 return $this->relationExists( $sequence,
'S', $schema );
957 SELECT 1 FROM pg_class, pg_namespace, pg_trigger
958 WHERE relnamespace=pg_namespace.oid AND relkind=
'r'
959 AND tgrelid=pg_class.oid
960 AND nspname=%s AND relname=%s AND tgname=%s
962 foreach ( $this->getCoreSchemas() as $schema ) {
966 $this->addQuotes( $schema ),
967 $this->addQuotes( $table ),
968 $this->addQuotes( $trigger )
971 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
982 $exists = $this->selectField(
'pg_rules',
'rulename',
985 'tablename' => $table,
986 'schemaname' => $this->getCoreSchemas()
991 return $exists === $rule;
995 foreach ( $this->getCoreSchemas() as $schema ) {
996 $sql = sprintf(
"SELECT 1 FROM information_schema.table_constraints " .
997 "WHERE constraint_schema = %s AND table_name = %s AND constraint_name = %s",
998 $this->addQuotes( $schema ),
999 $this->addQuotes( $table ),
1000 $this->addQuotes( $constraint )
1002 $res = $this->query(
1005 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
1020 if ( !strlen( $schema ??
'' ) ) {
1024 $res = $this->query(
1025 "SELECT 1 FROM pg_catalog.pg_namespace " .
1026 "WHERE nspname = " . $this->addQuotes( $schema ) .
" LIMIT 1",
1028 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
1031 return (
$res->numRows() > 0 );
1040 $res = $this->query(
1041 "SELECT 1 FROM pg_catalog.pg_roles " .
1042 "WHERE rolname = " . $this->addQuotes( $roleName ) .
" LIMIT 1",
1044 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
1047 return (
$res->numRows() > 0 );
1056 return PostgresField::fromText( $this, $table, $field );
1060 $conn = $this->getBindingHandle();
1062 return new PostgresBlob( pg_escape_bytea( $conn, $b ) );
1068 } elseif ( $b instanceof
Blob ) {
1072 return pg_unescape_bytea( $b );
1077 return pg_escape_string( $this->getBindingHandle(), (
string)
$s );
1081 $conn = $this->getBindingHandle();
1083 if (
$s ===
null ) {
1085 } elseif ( is_bool(
$s ) ) {
1086 return (
string)intval(
$s );
1087 } elseif ( is_int(
$s ) ) {
1089 } elseif (
$s instanceof
Blob ) {
1093 $s = pg_escape_bytea( $conn,
$s->fetch() );
1100 return "'" . pg_escape_string( $conn, (
string)
$s ) .
"'";
1104 # Allow dollar quoting for function declarations
1105 if ( substr( $newLine, 0, 4 ) ==
'$mw$' ) {
1106 if ( $this->delimiter ) {
1107 $this->delimiter =
false;
1109 $this->delimiter =
';';
1113 return parent::streamStatementEnd( $sql, $newLine );
1117 $res = $this->query(
1118 $this->platform->lockIsFreeSQLText( $lockName ),
1120 self::QUERY_CHANGE_LOCKS
1122 $row =
$res->fetchObject();
1124 return ( $row->unlocked ===
't' );
1127 public function doLock(
string $lockName,
string $method,
int $timeout ) {
1128 $sql = $this->platform->lockSQLText( $lockName, $timeout );
1131 $loop =
new WaitConditionLoop(
1132 function () use ( $lockName, $sql, $timeout, $method, &$acquired ) {
1133 $res = $this->query(
1136 self::QUERY_CHANGE_LOCKS
1138 $row =
$res->fetchObject();
1140 if ( $row->acquired !==
null ) {
1141 $acquired = (float)$row->acquired;
1143 return WaitConditionLoop::CONDITION_REACHED;
1146 return WaitConditionLoop::CONDITION_CONTINUE;
1155 public function doUnlock(
string $lockName,
string $method ) {
1156 $result = $this->query(
1157 $this->platform->unlockSQLText( $lockName ),
1159 self::QUERY_CHANGE_LOCKS
1161 $row = $result->fetchObject();
1163 return ( $row->released ===
't' );
1167 $flags = self::QUERY_CHANGE_LOCKS | self::QUERY_NO_RETRY;
1170 $sql =
"SELECT pg_advisory_unlock_all()";
1171 $qs = $this->executeQuery( $sql, __METHOD__, $flags, $sql );
1172 if ( $qs->res ===
false ) {
1173 $this->reportQueryError( $qs->message, $qs->code, $sql, $fname,
true );
1178 $res = $this->query(
1179 "SHOW default_transaction_read_only",
1181 self::QUERY_IGNORE_DBO_TRX | self::QUERY_CHANGE_NONE
1183 $row =
$res->fetchObject();
1185 return $row ? ( strtolower( $row->default_transaction_read_only ) ===
'on' ) :
false;
1189 return [ self::ATTR_SCHEMAS_AS_TABLE_GROUPS =>
true ];
1196class_alias( DatabasePostgres::class,
'DatabasePostgres' );
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
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 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 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)
remappedTableName( $name)
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.
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 is marked as read-only server-side query} 1.28to override
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s