* @file
* @ingroup Database
*/
+namespace Wikimedia\Rdbms;
+
use Wikimedia\ScopedCallback;
-use Wikimedia\Rdbms\Blob;
-use Wikimedia\Rdbms\LikeMatch;
-use Wikimedia\Rdbms\DBMasterPos;
-use Wikimedia\Rdbms\Field;
+use Exception;
+use RuntimeException;
+use UnexpectedValueException;
+use stdClass;
/**
* Basic database interface for live and lazy-loaded relation database handles
*/
public function pendingWriteCallers();
+ /**
+ * Get the number of affected rows from pending write queries
+ *
+ * @return integer
+ * @since 1.30
+ */
+ public function pendingWriteRowsAffected();
+
/**
* Is a connection to the database open?
* @return bool
* member variables.
* If no more rows are available, false is returned.
*
- * @param ResultWrapper|stdClass $res Object as returned from IDatabase::query(), etc.
+ * @param IResultWrapper|stdClass $res Object as returned from IDatabase::query(), etc.
* @return stdClass|bool
* @throws DBUnexpectedError Thrown if the database returns an error
*/
* form. Fields are retrieved with $row['fieldname'].
* If no more rows are available, false is returned.
*
- * @param ResultWrapper $res Result object as returned from IDatabase::query(), etc.
+ * @param IResultWrapper $res Result object as returned from IDatabase::query(), etc.
* @return array|bool
* @throws DBUnexpectedError Thrown if the database returns an error
*/
* @param bool $tempIgnore Whether to avoid throwing an exception on errors...
* maybe best to catch the exception instead?
* @throws DBError
- * @return bool|ResultWrapper True for a successful write query, ResultWrapper object
+ * @return bool|IResultWrapper True for a successful write query, IResultWrapper object
* for a successful read query, or false on failure if $tempIgnore set
*/
public function query( $sql, $fname = __METHOD__, $tempIgnore = false );
* @param string|array $cond The condition array. See IDatabase::select() for details.
* @param string $fname The function name of the caller.
* @param string|array $options The query options. See IDatabase::select() for details.
+ * @param string|array $join_conds The query join conditions. See IDatabase::select() for details.
*
* @return bool|mixed The value from the field, or false on failure.
*/
public function selectField(
- $table, $var, $cond = '', $fname = __METHOD__, $options = []
+ $table, $var, $cond = '', $fname = __METHOD__, $options = [], $join_conds = []
);
/**
* @param string|array $cond The condition array. See IDatabase::select() for details.
* @param string $fname The function name of the caller.
* @param string|array $options The query options. See IDatabase::select() for details.
+ * @param string|array $join_conds The query join conditions. See IDatabase::select() for details.
*
* @return bool|array The values from the field, or false on failure
* @since 1.25
*/
public function selectFieldValues(
- $table, $var, $cond = '', $fname = __METHOD__, $options = []
+ $table, $var, $cond = '', $fname = __METHOD__, $options = [], $join_conds = []
);
/**
*
* [ 'page' => [ 'LEFT JOIN', 'page_latest=rev_id' ] ]
*
- * @return ResultWrapper|bool If the query returned no rows, a ResultWrapper
+ * @return IResultWrapper|bool If the query returned no rows, a IResultWrapper
* with no rows in it will be returned. If there was a query error, a
* DBQueryError exception will be thrown, except if the "ignore errors"
* option was set, in which case false will be returned.
*/
public function buildStringCast( $field );
+ /**
+ * Returns true if DBs are assumed to be on potentially different servers
+ *
+ * In systems like mysql/mariadb, different databases can easily be referenced on a single
+ * connection merely by name, even in a single query via JOIN. On the other hand, Postgres
+ * treats databases as fully separate, only allowing mechanisms like postgres_fdw to
+ * effectively "mount" foreign DBs. This is true even among DBs on the same server.
+ *
+ * @return bool
+ * @since 1.29
+ */
+ public function databasesAreIndependent();
+
/**
* Change the current database
*
* @param string $db
* @return bool Success or failure
+ * @throws DBConnectionError If databasesAreIndependent() is true and an error occurs
*/
public function selectDB( $db );
* for the format. Use $conds == "*" to delete all rows
* @param string $fname Name of the calling function
* @throws DBUnexpectedError
- * @return bool|ResultWrapper
+ * @return bool|IResultWrapper
*/
public function delete( $table, $conds, $fname = __METHOD__ );
* IDatabase::insert() for details.
* @param array $selectOptions Options for the SELECT part of the query, see
* IDatabase::select() for details.
+ * @param array $selectJoinConds Join conditions for the SELECT part of the query, see
+ * IDatabase::select() for details.
*
- * @return ResultWrapper
+ * @return bool
*/
public function insertSelect( $destTable, $srcTable, $varMap, $conds,
$fname = __METHOD__,
- $insertOptions = [], $selectOptions = []
+ $insertOptions = [], $selectOptions = [], $selectJoinConds = []
);
/**
*/
public function unionQueries( $sqls, $all );
+ /**
+ * Construct a UNION query for permutations of conditions
+ *
+ * Databases sometimes have trouble with queries that have multiple values
+ * for multiple condition parameters combined with limits and ordering.
+ * This method constructs queries for the Cartesian product of the
+ * conditions and unions them all together.
+ *
+ * @see IDatabase::select()
+ * @since 1.30
+ * @param string|array $table Table name
+ * @param string|array $vars Field names
+ * @param array $permute_conds Conditions for the Cartesian product. Keys
+ * are field names, values are arrays of the possible values for that
+ * field.
+ * @param string|array $extra_conds Additional conditions to include in the
+ * query.
+ * @param string $fname Caller function name
+ * @param string|array $options Query options. In addition to the options
+ * recognized by IDatabase::select(), the following may be used:
+ * - NOTALL: Set to use UNION instead of UNION ALL.
+ * - INNER ORDER BY: If specified and supported, subqueries will use this
+ * instead of ORDER BY.
+ * @param string|array $join_conds Join conditions
+ * @return string SQL query string.
+ */
+ public function unionConditionPermutations(
+ $table, $vars, array $permute_conds, $extra_conds = '', $fname = __METHOD__,
+ $options = [], $join_conds = []
+ );
+
/**
* Returns an SQL expression for a simple conditional. This doesn't need
* to be overridden unless CASE isn't supported in your DBMS.
public function conditional( $cond, $trueVal, $falseVal );
/**
- * Returns a comand for str_replace function in SQL query.
+ * Returns a command for str_replace function in SQL query.
* Uses REPLACE() in MySQL
*
* @param string $orig Column to modify
*/
public function setTableAliases( array $aliases );
}
+
+class_alias( IDatabase::class, 'IDatabase' );