Chris@0: query($query, $args, $options); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::query() Chris@0: * @see \Drupal\Core\Database\Connection::defaultOptions() Chris@0: */ Chris@0: function db_query($query, array $args = [], array $options = []) { Chris@0: if (empty($options['target'])) { Chris@0: $options['target'] = 'default'; Chris@0: } Chris@0: Chris@0: return Database::getConnection($options['target'])->query($query, $args, $options); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Executes a query against the active database, restricted to a range. Chris@0: * Chris@0: * @param string $query Chris@0: * The prepared statement query to run. Although it will accept both named and Chris@0: * unnamed placeholders, named placeholders are strongly preferred as they are Chris@0: * more self-documenting. Chris@0: * @param $from Chris@0: * The first record from the result set to return. Chris@0: * @param $count Chris@0: * The number of records to return from the result set. Chris@0: * @param array $args Chris@0: * An array of values to substitute into the query. If the query uses named Chris@0: * placeholders, this is an associative array in any order. If the query uses Chris@0: * unnamed placeholders (?), this is an indexed array and the order must match Chris@0: * the order of placeholders in the query string. Chris@0: * @param array $options Chris@0: * An array of options to control how the query operates. Chris@0: * Chris@0: * @return \Drupal\Core\Database\StatementInterface Chris@0: * A prepared statement object, already executed. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call queryRange() on it. For example, Chris@0: * $injected_database->queryRange($query, $from, $count, $args, $options); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::queryRange() Chris@0: * @see \Drupal\Core\Database\Connection::defaultOptions() Chris@0: */ Chris@0: function db_query_range($query, $from, $count, array $args = [], array $options = []) { Chris@18: @trigger_error('db_query_range() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call queryRange() on it. For example, $injected_database->queryRange($query, $from, $count, $args, $options). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: if (empty($options['target'])) { Chris@0: $options['target'] = 'default'; Chris@0: } Chris@0: Chris@0: return Database::getConnection($options['target'])->queryRange($query, $from, $count, $args, $options); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Executes a SELECT query string and saves the result set to a temporary table. Chris@0: * Chris@0: * The execution of the query string happens against the active database. Chris@0: * Chris@0: * @param string $query Chris@0: * The prepared SELECT statement query to run. Although it will accept both Chris@0: * named and unnamed placeholders, named placeholders are strongly preferred Chris@0: * as they are more self-documenting. Chris@0: * @param array $args Chris@0: * An array of values to substitute into the query. If the query uses named Chris@0: * placeholders, this is an associative array in any order. If the query uses Chris@0: * unnamed placeholders (?), this is an indexed array and the order must match Chris@0: * the order of placeholders in the query string. Chris@0: * @param array $options Chris@0: * An array of options to control how the query operates. Chris@0: * Chris@18: * @return string Chris@0: * The name of the temporary table. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call queryTemporary() on it. For example, Chris@0: * $injected_database->queryTemporary($query, $args, $options); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::queryTemporary() Chris@0: * @see \Drupal\Core\Database\Connection::defaultOptions() Chris@0: */ Chris@0: function db_query_temporary($query, array $args = [], array $options = []) { Chris@18: @trigger_error('db_query_temporary() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call queryTemporary() on it. For example, $injected_database->queryTemporary($query, $args, $options). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: if (empty($options['target'])) { Chris@0: $options['target'] = 'default'; Chris@0: } Chris@0: Chris@0: return Database::getConnection($options['target'])->queryTemporary($query, $args, $options); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a new InsertQuery object for the active database. Chris@0: * Chris@0: * @param string $table Chris@0: * The table into which to insert. Chris@0: * @param array $options Chris@0: * An array of options to control how the query operates. Chris@0: * Chris@0: * @return \Drupal\Core\Database\Query\Insert Chris@0: * A new Insert object for this connection. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call insert() on it. For example, Chris@0: * $injected_database->insert($table, $options); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::insert() Chris@0: * @see \Drupal\Core\Database\Connection::defaultOptions() Chris@0: */ Chris@0: function db_insert($table, array $options = []) { Chris@18: @trigger_error('db_insert() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call insert() on it. For example, $injected_database->insert($table, $options); See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: if (empty($options['target']) || $options['target'] == 'replica') { Chris@0: $options['target'] = 'default'; Chris@0: } Chris@0: return Database::getConnection($options['target'])->insert($table, $options); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a new MergeQuery object for the active database. Chris@0: * Chris@0: * @param string $table Chris@0: * Name of the table to associate with this query. Chris@0: * @param array $options Chris@0: * An array of options to control how the query operates. Chris@0: * Chris@0: * @return \Drupal\Core\Database\Query\Merge Chris@0: * A new Merge object for this connection. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call merge() on it. For example, Chris@0: * $injected_database->merge($table, $options); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::merge() Chris@0: * @see \Drupal\Core\Database\Connection::defaultOptions() Chris@0: */ Chris@0: function db_merge($table, array $options = []) { Chris@18: @trigger_error('db_merge() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call merge() on it. For example, $injected_database->merge($table, $options). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@18: // @todo Move away from here setting default target connection, Chris@18: // https://www.drupal.org/node/2947775 Chris@0: if (empty($options['target']) || $options['target'] == 'replica') { Chris@0: $options['target'] = 'default'; Chris@0: } Chris@0: return Database::getConnection($options['target'])->merge($table, $options); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a new UpdateQuery object for the active database. Chris@0: * Chris@0: * @param string $table Chris@0: * The table to update. Chris@0: * @param array $options Chris@0: * An array of options to control how the query operates. Chris@0: * Chris@0: * @return \Drupal\Core\Database\Query\Update Chris@0: * A new Update object for this connection. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call update() on it. For example, Chris@0: * $injected_database->update($table, $options); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::update() Chris@0: * @see \Drupal\Core\Database\Connection::defaultOptions() Chris@0: */ Chris@0: function db_update($table, array $options = []) { Chris@18: @trigger_error('db_update() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call call update() on it. For example, $injected_database->update($table, $options); See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: if (empty($options['target']) || $options['target'] == 'replica') { Chris@0: $options['target'] = 'default'; Chris@0: } Chris@0: return Database::getConnection($options['target'])->update($table, $options); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a new DeleteQuery object for the active database. Chris@0: * Chris@0: * @param string $table Chris@0: * The table from which to delete. Chris@0: * @param array $options Chris@0: * An array of options to control how the query operates. Chris@0: * Chris@0: * @return \Drupal\Core\Database\Query\Delete Chris@0: * A new Delete object for this connection. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call delete() on it. For example, Chris@0: * $injected_database->delete($table, $options); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::delete() Chris@0: * @see \Drupal\Core\Database\Connection::defaultOptions() Chris@0: */ Chris@0: function db_delete($table, array $options = []) { Chris@18: @trigger_error('db_delete is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call delete() on it. For example, $injected_database->delete($table, $options). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@18: // @todo Move away from here setting default target connection, Chris@18: // https://www.drupal.org/node/2947775 Chris@0: if (empty($options['target']) || $options['target'] == 'replica') { Chris@0: $options['target'] = 'default'; Chris@0: } Chris@0: return Database::getConnection($options['target'])->delete($table, $options); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a new TruncateQuery object for the active database. Chris@0: * Chris@0: * @param string $table Chris@0: * The table from which to truncate. Chris@0: * @param array $options Chris@0: * An array of options to control how the query operates. Chris@0: * Chris@0: * @return \Drupal\Core\Database\Query\Truncate Chris@0: * A new Truncate object for this connection. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call truncate() on it. For example, Chris@0: * $injected_database->truncate($table, $options); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::truncate() Chris@0: * @see \Drupal\Core\Database\Connection::defaultOptions() Chris@0: */ Chris@0: function db_truncate($table, array $options = []) { Chris@18: @trigger_error('db_truncate() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call truncate() on it. For example, $injected_database->truncate($table, $options). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: if (empty($options['target']) || $options['target'] == 'replica') { Chris@0: $options['target'] = 'default'; Chris@0: } Chris@0: return Database::getConnection($options['target'])->truncate($table, $options); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a new SelectQuery object for the active database. Chris@0: * Chris@0: * @param string|\Drupal\Core\Database\Query\SelectInterface $table Chris@0: * The base table for this query. May be a string or another SelectInterface Chris@0: * object. If a SelectInterface object is passed, it will be used as a Chris@0: * subselect. Chris@0: * @param string $alias Chris@0: * (optional) The alias for the base table of this query. Chris@0: * @param array $options Chris@0: * (optional) An array of options to control how the query operates. Chris@0: * Chris@0: * @return \Drupal\Core\Database\Query\Select Chris@0: * A new Select object for this connection. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call select() on it. For example, Chris@0: * $injected_database->select($table, $alias, $options); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::select() Chris@0: * @see \Drupal\Core\Database\Connection::defaultOptions() Chris@0: */ Chris@0: function db_select($table, $alias = NULL, array $options = []) { Chris@18: @trigger_error('db_select() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call call select() on it. For example, $injected_database->db_select($table, $alias, $options); See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: if (empty($options['target'])) { Chris@0: $options['target'] = 'default'; Chris@0: } Chris@0: return Database::getConnection($options['target'])->select($table, $alias, $options); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a new transaction object for the active database. Chris@0: * Chris@0: * @param string $name Chris@0: * Optional name of the transaction. Chris@0: * @param array $options Chris@0: * An array of options to control how the transaction operates: Chris@0: * - target: The database target name. Chris@0: * Chris@0: * @return \Drupal\Core\Database\Transaction Chris@0: * A new Transaction object for this connection. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call startTransaction() on it. For example, Chris@0: * $injected_database->startTransaction($name); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::startTransaction() Chris@0: * @see \Drupal\Core\Database\Connection::defaultOptions() Chris@0: */ Chris@0: function db_transaction($name = NULL, array $options = []) { Chris@18: @trigger_error('db_transaction is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call startTransaction() on it. For example, $injected_database->startTransaction($name). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@18: // @todo Move away from here setting default target connection, Chris@18: // https://www.drupal.org/node/2947775 Chris@0: if (empty($options['target'])) { Chris@0: $options['target'] = 'default'; Chris@0: } Chris@0: return Database::getConnection($options['target'])->startTransaction($name); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets a new active database. Chris@0: * Chris@0: * @param $key Chris@0: * The key in the $databases array to set as the default database. Chris@0: * Chris@0: * @return string|null Chris@0: * The key of the formerly active database. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Use Chris@0: * \Drupal\Core\Database\Database::setActiveConnection(). Chris@0: */ Chris@0: function db_set_active($key = 'default') { Chris@17: @trigger_error('db_set_active() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::setActiveConnection() instead. See https://www.drupal.org/node/2944084.', E_USER_DEPRECATED); Chris@0: return Database::setActiveConnection($key); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Restricts a dynamic table name to safe characters. Chris@0: * Chris@0: * Only keeps alphanumeric and underscores. Chris@0: * Chris@0: * @param $table Chris@0: * The table name to escape. Chris@0: * Chris@0: * @return string Chris@0: * The escaped table name as a string. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call escapeTable() on it. For example, Chris@0: * $injected_database->escapeTable($table); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::escapeTable() Chris@0: */ Chris@0: function db_escape_table($table) { Chris@18: @trigger_error('db_escape_table() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call escapeTable() on it. For example, $injected_database->escapeTable($table). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->escapeTable($table); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Restricts a dynamic column or constraint name to safe characters. Chris@0: * Chris@0: * Only keeps alphanumeric and underscores. Chris@0: * Chris@0: * @param string $field Chris@0: * The field name to escape. Chris@0: * Chris@0: * @return string Chris@0: * The escaped field name as a string. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@18: * call escapeField() on it. For example, Chris@18: * $injected_database->escapeField($field); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::escapeField() Chris@0: */ Chris@0: function db_escape_field($field) { Chris@18: @trigger_error('db_escape_field() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call escapeField() on it. For example, $injected_database->escapeField($field). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->escapeField($field); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Escapes characters that work as wildcard characters in a LIKE pattern. Chris@0: * Chris@0: * The wildcard characters "%" and "_" as well as backslash are prefixed with Chris@0: * a backslash. Use this to do a search for a verbatim string without any Chris@0: * wildcard behavior. Chris@0: * Chris@0: * You must use a query builder like db_select() in order to use db_like() on Chris@0: * all supported database systems. Using db_like() with db_query() or Chris@0: * db_query_range() is not supported. Chris@0: * Chris@0: * For example, the following does a case-insensitive query for all rows whose Chris@0: * name starts with $prefix: Chris@0: * @code Chris@0: * $result = db_select('person', 'p') Chris@0: * ->fields('p') Chris@0: * ->condition('name', db_like($prefix) . '%', 'LIKE') Chris@0: * ->execute() Chris@0: * ->fetchAll(); Chris@0: * @endcode Chris@0: * Chris@0: * Backslash is defined as escape character for LIKE patterns in Chris@0: * DatabaseCondition::mapConditionOperator(). Chris@0: * Chris@0: * @param string $string Chris@0: * The string to escape. Chris@0: * Chris@0: * @return string Chris@0: * The escaped string. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call escapeLike() on it. For example, Chris@0: * $injected_database->escapeLike($string); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::escapeLike() Chris@0: */ Chris@0: function db_like($string) { Chris@18: @trigger_error('db_like() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call escapeLike() on it. For example, $injected_database->escapeLike($string). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->escapeLike($string); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves the name of the currently active database driver. Chris@0: * Chris@0: * @return string Chris@0: * The name of the currently active database driver. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call driver() on it. For example, $injected_database->driver($string); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::driver() Chris@0: */ Chris@0: function db_driver() { Chris@18: @trigger_error('db_driver() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call driver() on it. For example, $injected_database->driver($string). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->driver(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Closes the active database connection. Chris@0: * Chris@0: * @param array $options Chris@0: * An array of options to control which connection is closed. Only the target Chris@0: * key has any meaning in this case. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Use Chris@0: * \Drupal\Core\Database\Database::closeConnection($target). Chris@0: * Chris@0: * @see \Drupal\Core\Database\Database::closeConnection() Chris@0: */ Chris@0: function db_close(array $options = []) { Chris@18: @trigger_error('db_close() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::closeConnection() instead. See https://www.drupal.org/node/2993033.', E_USER_DEPRECATED); Chris@0: if (empty($options['target'])) { Chris@0: $options['target'] = NULL; Chris@0: } Chris@0: Database::closeConnection($options['target']); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves a unique id. Chris@0: * Chris@0: * Use this function if for some reason you can't use a serial field. Using a Chris@0: * serial field is preferred, and InsertQuery::execute() returns the value of Chris@0: * the last ID inserted. Chris@0: * Chris@0: * @param int $existing_id Chris@0: * After a database import, it might be that the sequences table is behind, so Chris@0: * by passing in a minimum ID, it can be assured that we never issue the same Chris@0: * ID. Chris@0: * Chris@0: * @return int Chris@0: * An integer number larger than any number returned before for this sequence. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container and Chris@0: * call nextId() on it. For example, $injected_database->nextId($existing_id); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Connection::nextId() Chris@0: */ Chris@0: function db_next_id($existing_id = 0) { Chris@18: @trigger_error('db_next_id() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container and call nextId() on it. For example, $injected_database->nextId($existing_id). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->nextId($existing_id); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a new DatabaseCondition, set to "OR" all conditions together. Chris@0: * Chris@0: * @return \Drupal\Core\Database\Query\Condition Chris@0: * A new Condition object, set to "OR" all conditions together. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Create Chris@0: * a \Drupal\Core\Database\Query\Condition object, specifying an OR Chris@0: * conjunction: new Condition('OR'); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Query\Condition Chris@0: */ Chris@0: function db_or() { Chris@18: @trigger_error('db_or() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Create a \Drupal\Core\Database\Query\Condition object, specifying an OR conjunction: new Condition(\'OR\'), instead. See https://www.drupal.org/node/2993033.', E_USER_DEPRECATED); Chris@0: return new Condition('OR'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a new DatabaseCondition, set to "AND" all conditions together. Chris@0: * Chris@0: * @return \Drupal\Core\Database\Query\Condition Chris@0: * A new Condition object, set to "AND" all conditions together. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Create Chris@0: * a \Drupal\Core\Database\Query\Condition object, specifying an AND Chris@0: * conjunction: new Condition('AND'); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Query\Condition Chris@0: */ Chris@0: function db_and() { Chris@18: @trigger_error('db_and() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Create a \Drupal\Core\Database\Query\Condition object, specifying an AND conjunction: new Condition(\'AND\'), instead. See https://www.drupal.org/node/2993033.', E_USER_DEPRECATED); Chris@0: return new Condition('AND'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a new DatabaseCondition, set to "XOR" all conditions together. Chris@0: * Chris@0: * @return \Drupal\Core\Database\Query\Condition Chris@0: * A new Condition object, set to "XOR" all conditions together. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Create Chris@18: * a \Drupal\Core\Database\Query\Condition object, specifying a XOR Chris@0: * conjunction: new Condition('XOR'); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Query\Condition Chris@0: */ Chris@0: function db_xor() { Chris@18: @trigger_error('db_xor() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Create a \Drupal\Core\Database\Query\Condition object, specifying a XOR conjunction: new Condition(\'XOR\'), instead. See https://www.drupal.org/node/2993033.', E_USER_DEPRECATED); Chris@0: return new Condition('XOR'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a new DatabaseCondition, set to the specified conjunction. Chris@0: * Chris@18: * Internal API function call. Creating a Chris@18: * \Drupal\Core\Database\Query\Condition object, specifying the desired Chris@18: * conjunction ('AND', 'OR' or 'XOR'), is preferred. Chris@0: * Chris@0: * @param string $conjunction Chris@0: * The conjunction to use for query conditions (AND, OR or XOR). Chris@0: * Chris@0: * @return \Drupal\Core\Database\Query\Condition Chris@0: * A new Condition object, set to the specified conjunction. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Create Chris@0: * a \Drupal\Core\Database\Query\Condition object, specifying the desired Chris@18: * conjunction: new Condition($conjunction); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Query\Condition Chris@0: */ Chris@0: function db_condition($conjunction) { Chris@18: @trigger_error('db_condition() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Create a \Drupal\Core\Database\Query\Condition object, specifying the desired conjunction: new Condition($conjunction), instead. See https://www.drupal.org/node/2993033.', E_USER_DEPRECATED); Chris@0: return new Condition($conjunction); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @} End of "addtogroup database". Chris@0: */ Chris@0: Chris@0: Chris@0: /** Chris@0: * @addtogroup schemaapi Chris@0: * @{ Chris@0: */ Chris@0: Chris@0: /** Chris@0: * Creates a new table from a Drupal table definition. Chris@0: * Chris@0: * @param string $name Chris@0: * The name of the table to create. Chris@0: * @param array $table Chris@0: * A Schema API table definition array. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call createTable() on it. For example, Chris@0: * $injected_database->schema()->createTable($name, $table); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::createTable() Chris@0: */ Chris@0: function db_create_table($name, $table) { Chris@18: @trigger_error('db_create_table() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call createTable() on it. For example, $injected_database->schema()->createTable($name, $table). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->createTable($name, $table); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns an array of field names from an array of key/index column specifiers. Chris@0: * Chris@0: * This is usually an identity function but if a key/index uses a column prefix Chris@0: * specification, this function extracts just the name. Chris@0: * Chris@0: * @param array $fields Chris@0: * An array of key/index column specifiers. Chris@0: * Chris@0: * @return array Chris@0: * An array of field names. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call fieldNames() on it. For example, Chris@0: * $injected_database->schema()->fieldNames($fields); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::fieldNames() Chris@0: */ Chris@0: function db_field_names($fields) { Chris@18: @trigger_error('db_field_names() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call fieldNames() on it. For example, $injected_database->schema()->fieldNames($fields). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->fieldNames($fields); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks if an index exists in the given table. Chris@0: * Chris@0: * @param string $table Chris@0: * The name of the table in drupal (no prefixing). Chris@0: * @param string $name Chris@0: * The name of the index in drupal (no prefixing). Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the given index exists, otherwise FALSE. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call indexExists() on it. For example, Chris@0: * $injected_database->schema()->indexExists($table, $name); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::indexExists() Chris@0: */ Chris@0: function db_index_exists($table, $name) { Chris@18: @trigger_error('db_index_exists() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call indexExists() on it. For example, $injected_database->schema()->indexExists($table, $name). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->indexExists($table, $name); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks if a table exists. Chris@0: * Chris@0: * @param string $table Chris@0: * The name of the table in drupal (no prefixing). Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the given table exists, otherwise FALSE. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call tableExists() on it. For example, Chris@0: * $injected_database->schema()->tableExists($table); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::tableExists() Chris@0: */ Chris@0: function db_table_exists($table) { Chris@17: @trigger_error( Chris@17: 'db_table_exists() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use $injected_database->schema()->tableExists($table) instead. See https://www.drupal.org/node/2947929.', Chris@17: E_USER_DEPRECATED Chris@17: ); Chris@17: Chris@0: return Database::getConnection()->schema()->tableExists($table); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Checks if a column exists in the given table. Chris@0: * Chris@0: * @param $table Chris@0: * The name of the table in drupal (no prefixing). Chris@0: * @param $field Chris@0: * The name of the field. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the given column exists, otherwise FALSE. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call fieldExists() on it. For example, Chris@0: * $injected_database->schema()->fieldExists($table, $field); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::fieldExists() Chris@0: */ Chris@0: function db_field_exists($table, $field) { Chris@18: @trigger_error('db_field_exists() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call fieldExists() on it. For example, $injected_database->schema()->fieldExists($table, $field). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->fieldExists($table, $field); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Finds all tables that are like the specified base table name. Chris@0: * Chris@0: * @param string $table_expression Chris@0: * An SQL expression, for example "simpletest%" (without the quotes). Chris@0: * Chris@0: * @return array Chris@0: * Array, both the keys and the values are the matching tables. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call findTables() on it. For example, Chris@0: * $injected_database->schema()->findTables($table_expression); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::findTables() Chris@0: */ Chris@0: function db_find_tables($table_expression) { Chris@18: @trigger_error( Chris@18: 'db_find_tables() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use $injected_database->schema()->findTables($table_expression) instead. See https://www.drupal.org/node/2993033', Chris@18: E_USER_DEPRECATED Chris@18: ); Chris@0: return Database::getConnection()->schema()->findTables($table_expression); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Renames a table. Chris@0: * Chris@0: * @param $table Chris@0: * The current name of the table to be renamed. Chris@0: * @param $new_name Chris@0: * The new name for the table. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call renameTable() on it. For example, Chris@0: * $injected_database->schema()->renameTable($table, $new_name); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::renameTable() Chris@0: */ Chris@0: function db_rename_table($table, $new_name) { Chris@18: @trigger_error('db_rename_table() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call renameTable() on it. For example, $injected_database->schema()->renameTable($table, $new_name). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->renameTable($table, $new_name); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Drops a table. Chris@0: * Chris@0: * @param $table Chris@0: * The table to be dropped. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call dropTable() on it. For example, Chris@0: * $injected_database->schema()->dropTable($table); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::dropTable() Chris@0: */ Chris@0: function db_drop_table($table) { Chris@17: @trigger_error('db_drop_table() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\Database::getConnection()->schema()->dropTable() instead. See https://www.drupal.org/node/2987737', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->dropTable($table); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a new field to a table. Chris@0: * Chris@0: * @param $table Chris@0: * Name of the table to be altered. Chris@0: * @param $field Chris@0: * Name of the field to be added. Chris@0: * @param array $spec Chris@0: * The field specification array, as taken from a schema definition. The Chris@0: * specification may also contain the key 'initial'; the newly-created field Chris@0: * will be set to the value of the key in all rows. This is most useful for Chris@0: * creating NOT NULL columns with no default value in existing tables. Chris@0: * @param array $keys_new Chris@0: * (optional) Keys and indexes specification to be created on the table along Chris@0: * with adding the field. The format is the same as a table specification, but Chris@0: * without the 'fields' element. If you are adding a type 'serial' field, you Chris@0: * MUST specify at least one key or index including it in this array. See Chris@18: * \Drupal\Core\Database\Schema::changeField() for more explanation why. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call addField() on it. For example, Chris@0: * $injected_database->schema()->addField($table, $field, $spec, $keys_new); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::addField() Chris@18: * @see \Drupal\Core\Database\Schema::changeField() Chris@0: */ Chris@0: function db_add_field($table, $field, $spec, $keys_new = []) { Chris@18: @trigger_error('db_add_field() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addField() on it. For example, $injected_database->schema()->addField($table, $field, $spec, $keys_new). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->addField($table, $field, $spec, $keys_new); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Drops a field. Chris@0: * Chris@0: * @param $table Chris@0: * The table to be altered. Chris@0: * @param $field Chris@0: * The field to be dropped. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the field was successfully dropped, FALSE if there was no field by Chris@0: * that name to begin with. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call dropField() on it. For example, Chris@0: * $injected_database->schema()->dropField($table, $field); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::dropField() Chris@0: */ Chris@0: function db_drop_field($table, $field) { Chris@18: @trigger_error('db_drop_field() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropField() on it. For example, $injected_database->schema()->dropField($table, $field). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->dropField($table, $field); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets the default value for a field. Chris@0: * Chris@0: * @param $table Chris@0: * The table to be altered. Chris@0: * @param $field Chris@0: * The field to be altered. Chris@0: * @param $default Chris@0: * Default value to be set. NULL for 'default NULL'. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@18: * its schema driver, and call changeField() on it, passing a full field Chris@18: * specification. For example, Chris@18: * $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new); Chris@0: * Chris@18: * @see \Drupal\Core\Database\Schema::changeField() Chris@0: */ Chris@0: function db_field_set_default($table, $field, $default) { Chris@18: @trigger_error('db_field_set_default() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it, passing a full field specification. For example, $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->fieldSetDefault($table, $field, $default); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets a field to have no default value. Chris@0: * Chris@0: * @param $table Chris@0: * The table to be altered. Chris@0: * @param $field Chris@0: * The field to be altered. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@18: * its schema driver, and call changeField() on it, passing a full field Chris@18: * specification. For example, Chris@18: * $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new); Chris@0: * Chris@18: * @see \Drupal\Core\Database\Schema::changeField() Chris@0: */ Chris@0: function db_field_set_no_default($table, $field) { Chris@18: @trigger_error('db_field_set_no_default() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it, passing a full field specification. For example, $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->fieldSetNoDefault($table, $field); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a primary key to a database table. Chris@0: * Chris@0: * @param $table Chris@0: * Name of the table to be altered. Chris@0: * @param $fields Chris@0: * Array of fields for the primary key. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call addPrimaryKey() on it. For example, Chris@0: * $injected_database->schema()->addPrimaryKey($table, $fields); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::addPrimaryKey() Chris@0: */ Chris@0: function db_add_primary_key($table, $fields) { Chris@18: @trigger_error('db_add_primary_key() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addPrimaryKey() on it. For example, $injected_database->schema()->addPrimaryKey($table, $fields). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->addPrimaryKey($table, $fields); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Drops the primary key of a database table. Chris@0: * Chris@0: * @param $table Chris@0: * Name of the table to be altered. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the primary key was successfully dropped, FALSE if there was no Chris@0: * primary key on this table to begin with. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call dropPrimaryKey() on it. For example, Chris@0: * $injected_database->schema()->dropPrimaryKey($table); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::dropPrimaryKey() Chris@0: */ Chris@0: function db_drop_primary_key($table) { Chris@18: @trigger_error('db_drop_primary_key() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropPrimaryKey() on it. For example, $injected_database->schema()->dropPrimaryKey($table). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->dropPrimaryKey($table); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds a unique key. Chris@0: * Chris@0: * @param $table Chris@0: * The table to be altered. Chris@0: * @param $name Chris@0: * The name of the key. Chris@0: * @param array $fields Chris@0: * An array of field names. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call addUniqueKey() on it. For example, Chris@0: * $injected_database->schema()->addUniqueKey($table, $name, $fields); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::addUniqueKey() Chris@0: */ Chris@0: function db_add_unique_key($table, $name, $fields) { Chris@18: @trigger_error('db_add_unique_key() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addUniqueKey() on it. For example, $injected_database->schema()->addUniqueKey($table, $name, $fields). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->addUniqueKey($table, $name, $fields); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Drops a unique key. Chris@0: * Chris@0: * @param $table Chris@0: * The table to be altered. Chris@0: * @param $name Chris@0: * The name of the key. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the key was successfully dropped, FALSE if there was no key by Chris@0: * that name to begin with. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call dropUniqueKey() on it. For example, Chris@0: * $injected_database->schema()->dropUniqueKey($table, $name); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::dropUniqueKey() Chris@0: */ Chris@0: function db_drop_unique_key($table, $name) { Chris@18: @trigger_error('db_drop_unique_key() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropUniqueKey() on it. For example, $injected_database->schema()->dropUniqueKey($table, $name). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->dropUniqueKey($table, $name); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Adds an index. Chris@0: * Chris@0: * @param $table Chris@0: * The table to be altered. Chris@0: * @param $name Chris@0: * The name of the index. Chris@0: * @param array $fields Chris@0: * An array of field names. Chris@0: * @param array $spec Chris@0: * The table specification of the table to be altered, as taken from a schema Chris@0: * definition. See \Drupal\Core\Database\Schema::addIndex() for how to obtain Chris@0: * this specification. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call addIndex() on it. For example, Chris@0: * $injected_database->schema()->addIndex($table, $name, $fields, $spec); Chris@0: * Chris@0: * @see hook_schema() Chris@0: * @see schemaapi Chris@0: * @see \Drupal\Core\Database\Schema::addIndex() Chris@0: */ Chris@0: function db_add_index($table, $name, $fields, array $spec) { Chris@18: @trigger_error('db_add_index() is deprecated in Drupal 8.0.x and will be removed in Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call addIndex() on it. For example, $injected_database->schema()->addIndex($table, $name, $fields, $spec). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@18: Database::getConnection()->schema()->addIndex($table, $name, $fields, $spec); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Drops an index. Chris@0: * Chris@0: * @param $table Chris@0: * The table to be altered. Chris@0: * @param $name Chris@0: * The name of the index. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the index was successfully dropped, FALSE if there was no index Chris@0: * by that name to begin with. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call dropIndex() on it. For example, Chris@0: * $injected_database->schema()->dropIndex($table, $name); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::dropIndex() Chris@0: */ Chris@0: function db_drop_index($table, $name) { Chris@18: @trigger_error('db_drop_index() is deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call dropIndex() on it. For example, $injected_database->schema()->dropIndex($table, $name). See https://www.drupal.org/node/2993033', E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->dropIndex($table, $name); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Changes a field definition. Chris@0: * Chris@0: * IMPORTANT NOTE: To maintain database portability, you have to explicitly Chris@0: * recreate all indices and primary keys that are using the changed field. Chris@0: * Chris@0: * That means that you have to drop all affected keys and indexes with Chris@18: * db_drop_{primary_key,unique_key,index}() before calling Chris@18: * \Drupal\Core\Database\Schema::changeField(). Chris@0: * To recreate the keys and indices, pass the key definitions as the optional Chris@18: * $keys_new argument directly to \Drupal\Core\Database\Schema::changeField(). Chris@0: * Chris@0: * For example, suppose you have: Chris@0: * @code Chris@0: * $schema['foo'] = array( Chris@0: * 'fields' => array( Chris@0: * 'bar' => array('type' => 'int', 'not null' => TRUE) Chris@0: * ), Chris@0: * 'primary key' => array('bar') Chris@0: * ); Chris@0: * @endcode Chris@0: * and you want to change foo.bar to be type serial, leaving it as the primary Chris@0: * key. The correct sequence is: Chris@0: * @code Chris@18: * $schema = \Drupal::database()->schema(); Chris@18: * $schema->dropPrimaryKey('foo'); Chris@18: * $schema->changeField('foo', 'bar', 'bar', Chris@0: * array('type' => 'serial', 'not null' => TRUE), Chris@0: * array('primary key' => array('bar'))); Chris@0: * @endcode Chris@0: * Chris@0: * The reasons for this are due to the different database engines: Chris@0: * Chris@0: * On PostgreSQL, changing a field definition involves adding a new field and Chris@0: * dropping an old one which causes any indices, primary keys and sequences Chris@0: * (from serial-type fields) that use the changed field to be dropped. Chris@0: * Chris@0: * On MySQL, all type 'serial' fields must be part of at least one key or index Chris@0: * as soon as they are created. You cannot use Chris@0: * db_add_{primary_key,unique_key,index}() for this purpose because the ALTER Chris@0: * TABLE command will fail to add the column without a key or index Chris@0: * specification. The solution is to use the optional $keys_new argument to Chris@0: * create the key or index at the same time as field. Chris@0: * Chris@0: * You could use db_add_{primary_key,unique_key,index}() in all cases unless you Chris@0: * are converting a field to be type serial. You can use the $keys_new argument Chris@0: * in all cases. Chris@0: * Chris@0: * @param $table Chris@0: * Name of the table. Chris@0: * @param $field Chris@0: * Name of the field to change. Chris@0: * @param $field_new Chris@0: * New name for the field (set to the same as $field if you don't want to Chris@0: * change the name). Chris@0: * @param $spec Chris@0: * The field specification for the new field. Chris@0: * @param array $keys_new Chris@0: * (optional) Keys and indexes specification to be created on the table along Chris@0: * with changing the field. The format is the same as a table specification Chris@0: * but without the 'fields' element. Chris@0: * Chris@0: * @deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get Chris@0: * a database connection injected into your service from the container, get Chris@0: * its schema driver, and call changeField() on it. For example, Chris@0: * $injected_database->schema()->changeField($table, $field, $field_new, $spec, $keys_new); Chris@0: * Chris@0: * @see \Drupal\Core\Database\Schema::changeField() Chris@0: */ Chris@0: function db_change_field($table, $field, $field_new, $spec, $keys_new = []) { Chris@18: @trigger_error("Deprecated as of Drupal 8.0.x, will be removed in Drupal 9.0.0. Instead, get a database connection injected into your service from the container, get its schema driver, and call changeField() on it. For example, \$injected_database->schema()->changeField(\$table, \$field, \$field_new, \$spec, \$keys_new). See https://www.drupal.org/node/2993033", E_USER_DEPRECATED); Chris@0: return Database::getConnection()->schema()->changeField($table, $field, $field_new, $spec, $keys_new); Chris@0: } Chris@0: Chris@0: /** Chris@0: * @} End of "addtogroup schemaapi". Chris@0: */ Chris@0: Chris@0: /** Chris@0: * Sets a session variable specifying the lag time for ignoring a replica Chris@0: * server (A replica server is traditionally referred to as Chris@0: * a "slave" in database server documentation). Chris@18: * Chris@18: * @deprecated as of Drupal 8.7.x, will be removed in Drupal 9.0.0. Use Chris@18: * \Drupal::service('database.replica_kill_switch')->trigger() instead. Chris@18: * Chris@18: * @see https://www.drupal.org/node/2997500 Chris@0: * @see https://www.drupal.org/node/2275877 Chris@0: */ Chris@0: function db_ignore_replica() { Chris@18: @trigger_error('db_ignore_replica() is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use \Drupal\Core\Database\ReplicaKillSwitch::trigger() instead. See https://www.drupal.org/node/2997500', E_USER_DEPRECATED); Chris@18: \Drupal::service('database.replica_kill_switch')->trigger(); Chris@0: }