Commit cef10893 authored by Dries's avatar Dries

- Patch #570900 by Crell | asimmonds: Changed Destroy remnants of update_sql().

parent 0a0b067c
......@@ -911,7 +911,7 @@ function _drupal_decode_exception($exception) {
// The first element in the stack is the call, the second element gives us the caller.
// We skip calls that occurred in one of the classes of the database layer
// or in one of its global functions.
$db_functions = array('db_query', 'db_query_range', 'update_sql');
$db_functions = array('db_query', 'db_query_range');
while (!empty($backtrace[1]) && ($caller = $backtrace[1]) &&
((isset($caller['class']) && (strpos($caller['class'], 'Query') !== FALSE || strpos($caller['class'], 'Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE)) ||
in_array($caller['function'], $db_functions))) {
......@@ -4790,11 +4790,9 @@ function drupal_install_schema($module) {
$schema = drupal_get_schema_unprocessed($module);
_drupal_schema_initialize($module, $schema);
$ret = array();
foreach ($schema as $name => $table) {
db_create_table($ret, $name, $table);
db_create_table($name, $table);
}
return $ret;
}
/**
......@@ -4815,13 +4813,11 @@ function drupal_uninstall_schema($module) {
$schema = drupal_get_schema_unprocessed($module);
_drupal_schema_initialize($module, $schema);
$ret = array();
foreach ($schema as $table) {
if (db_table_exists($table['name'])) {
db_drop_table($ret, $table['name']);
db_drop_table($table['name']);
}
}
return $ret;
}
/**
......
......@@ -2041,22 +2041,6 @@ function db_escape_table($table) {
return Database::getConnection()->escapeTable($table);
}
/**
* Perform an SQL query and return success or failure.
*
* @param $sql
* A string containing a complete SQL query. %-substitution
* parameters are not supported.
* @return
* An array containing the keys:
* success: a boolean indicating whether the query succeeded
* query: the SQL query executed, passed through check_plain()
*/
function update_sql($sql) {
$result = Database::getConnection()->query($sql);
return array('success' => $result !== FALSE, 'query' => check_plain($sql));
}
/**
* Retrieve the name of the currently active database driver, such as
* "mysql" or "pgsql".
......@@ -2095,16 +2079,14 @@ function db_close(array $options = array()) {
/**
* Create a new table from a Drupal table definition.
*
* @param $ret
* Array to which query results will be added.
* @param $name
* The name of the table to create.
* @param $table
* A Schema API table definition array.
*/
function db_create_table(&$ret, $name, $table) {
function db_create_table($name, $table) {
if (!db_table_exists($name)) {
return Database::getConnection()->schema()->createTable($ret, $name, $table);
return Database::getConnection()->schema()->createTable($name, $table);
}
}
......@@ -2165,34 +2147,28 @@ function db_type_map() {
/**
* Rename a table.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be renamed.
* @param $new_name
* The new name for the table.
*/
function db_rename_table(&$ret, $table, $new_name) {
return Database::getConnection()->schema()->renameTable($ret, $table, $new_name);
function db_rename_table($table, $new_name) {
return Database::getConnection()->schema()->renameTable($table, $new_name);
}
/**
* Drop a table.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be dropped.
*/
function db_drop_table(&$ret, $table) {
return Database::getConnection()->schema()->dropTable($ret, $table);
function db_drop_table($table) {
return Database::getConnection()->schema()->dropTable($table);
}
/**
* Add a new field to a table.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* Name of the table to be altered.
* @param $field
......@@ -2212,29 +2188,25 @@ function db_drop_table(&$ret, $table) {
* explanation why.
* @see db_change_field()
*/
function db_add_field(&$ret, $table, $field, $spec, $keys_new = array()) {
return Database::getConnection()->schema()->addField($ret, $table, $field, $spec, $keys_new);
function db_add_field($table, $field, $spec, $keys_new = array()) {
return Database::getConnection()->schema()->addField($table, $field, $spec, $keys_new);
}
/**
* Drop a field.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $field
* The field to be dropped.
*/
function db_drop_field(&$ret, $table, $field) {
return Database::getConnection()->schema()->dropField($ret, $table, $field);
function db_drop_field($table, $field) {
return Database::getConnection()->schema()->dropField($table, $field);
}
/**
* Set the default value for a field.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $field
......@@ -2242,55 +2214,47 @@ function db_drop_field(&$ret, $table, $field) {
* @param $default
* Default value to be set. NULL for 'default NULL'.
*/
function db_field_set_default(&$ret, $table, $field, $default) {
return Database::getConnection()->schema()->fieldSetDefault($ret, $table, $field, $default);
function db_field_set_default($table, $field, $default) {
return Database::getConnection()->schema()->fieldSetDefault($table, $field, $default);
}
/**
* Set a field to have no default value.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $field
* The field to be altered.
*/
function db_field_set_no_default(&$ret, $table, $field) {
return Database::getConnection()->schema()->fieldSetNoDefault($ret, $table, $field);
function db_field_set_no_default($table, $field) {
return Database::getConnection()->schema()->fieldSetNoDefault($table, $field);
}
/**
* Add a primary key.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $fields
* Fields for the primary key.
*/
function db_add_primary_key(&$ret, $table, $fields) {
return Database::getConnection()->schema()->addPrimaryKey($ret, $table, $fields);
function db_add_primary_key($table, $fields) {
return Database::getConnection()->schema()->addPrimaryKey($table, $fields);
}
/**
* Drop the primary key.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
*/
function db_drop_primary_key(&$ret, $table) {
return Database::getConnection()->schema()->dropPrimaryKey($ret, $table);
function db_drop_primary_key($table) {
return Database::getConnection()->schema()->dropPrimaryKey($table);
}
/**
* Add a unique key.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $name
......@@ -2298,29 +2262,25 @@ function db_drop_primary_key(&$ret, $table) {
* @param $fields
* An array of field names.
*/
function db_add_unique_key(&$ret, $table, $name, $fields) {
return Database::getConnection()->schema()->addUniqueKey($ret, $table, $name, $fields);
function db_add_unique_key($table, $name, $fields) {
return Database::getConnection()->schema()->addUniqueKey($table, $name, $fields);
}
/**
* Drop a unique key.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $name
* The name of the key.
*/
function db_drop_unique_key(&$ret, $table, $name) {
return Database::getConnection()->schema()->dropUniqueKey($ret, $table, $name);
function db_drop_unique_key($table, $name) {
return Database::getConnection()->schema()->dropUniqueKey($table, $name);
}
/**
* Add an index.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $name
......@@ -2328,22 +2288,20 @@ function db_drop_unique_key(&$ret, $table, $name) {
* @param $fields
* An array of field names.
*/
function db_add_index(&$ret, $table, $name, $fields) {
return Database::getConnection()->schema()->addIndex($ret, $table, $name, $fields);
function db_add_index($table, $name, $fields) {
return Database::getConnection()->schema()->addIndex($table, $name, $fields);
}
/**
* Drop an index.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $name
* The name of the index.
*/
function db_drop_index(&$ret, $table, $name) {
return Database::getConnection()->schema()->dropIndex($ret, $table, $name);
function db_drop_index($table, $name) {
return Database::getConnection()->schema()->dropIndex($table, $name);
}
/**
......@@ -2369,8 +2327,8 @@ function db_drop_index(&$ret, $table, $name) {
* and you want to change foo.bar to be type serial, leaving it as the
* primary key. The correct sequence is:
* @code
* db_drop_primary_key($ret, 'foo');
* db_change_field($ret, 'foo', 'bar', 'bar',
* db_drop_primary_key('foo');
* db_change_field('foo', 'bar', 'bar',
* array('type' => 'serial', 'not null' => TRUE),
* array('primary key' => array('bar')));
* @endcode
......@@ -2393,8 +2351,6 @@ function db_drop_index(&$ret, $table, $name) {
* unless you are converting a field to be type serial. You can use
* the $keys_new argument in all cases.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* Name of the table.
* @param $field
......@@ -2408,9 +2364,8 @@ function db_drop_index(&$ret, $table, $name) {
* table along with changing the field. The format is the same as a
* table specification but without the 'fields' element.
*/
function db_change_field(&$ret, $table, $field, $field_new, $spec, $keys_new = array()) {
return Database::getConnection()->schema()->changeField($ret, $table, $field, $field_new, $spec, $keys_new);
function db_change_field($table, $field, $field_new, $spec, $keys_new = array()) {
return Database::getConnection()->schema()->changeField($table, $field, $field_new, $spec, $keys_new);
}
/**
......
......@@ -243,40 +243,40 @@ protected function createKeysSql($spec) {
}
protected function createKeySql($fields) {
$ret = array();
$return = array();
foreach ($fields as $field) {
if (is_array($field)) {
$ret[] = '`' . $field[0] . '`(' . $field[1] . ')';
$return[] = '`' . $field[0] . '`(' . $field[1] . ')';
}
else {
$ret[] = '`' . $field . '`';
$return[] = '`' . $field . '`';
}
}
return implode(', ', $ret);
return implode(', ', $return);
}
protected function createKeysSqlHelper($fields) {
$ret = array();
$return = array();
foreach ($fields as $field) {
if (is_array($field)) {
$ret[] = '`' . $field[0] . '`(' . $field[1] . ')';
$return[] = '`' . $field[0] . '`(' . $field[1] . ')';
}
else {
$ret[] = '`' . $field . '`';
$return[] = '`' . $field . '`';
}
}
return implode(', ', $ret);
return implode(', ', $return);
}
public function renameTable(&$ret, $table, $new_name) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
public function renameTable($table, $new_name) {
$this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
}
public function dropTable(&$ret, $table) {
$ret[] = update_sql('DROP TABLE {' . $table . '}');
public function dropTable($table) {
$this->connection->query('DROP TABLE {' . $table . '}');
}
public function addField(&$ret, $table, $field, $spec, $keys_new = array()) {
public function addField($table, $field, $spec, $keys_new = array()) {
$fixnull = FALSE;
if (!empty($spec['not null']) && !isset($spec['default'])) {
$fixnull = TRUE;
......@@ -287,24 +287,23 @@ public function addField(&$ret, $table, $field, $spec, $keys_new = array()) {
if (count($keys_new)) {
$query .= ', ADD ' . implode(', ADD ', $this->createKeysSql($keys_new));
}
$ret[] = update_sql($query);
$this->connection->query($query);
if (isset($spec['initial'])) {
// All this because update_sql does not support %-placeholders.
$sql = 'UPDATE {' . $table . '} SET ' . $field . ' = :value';
$result = db_query($sql, array(':value' => $spec['initial']));
$ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql . ' (' . $spec['initial'] . ')'));
$this->connection->update($table)
->fields(array($field, $spec['initial']))
->execute();
}
if ($fixnull) {
$spec['not null'] = TRUE;
$this->changeField($ret, $table, $field, $field, $spec);
$this->changeField($table, $field, $field, $spec);
}
}
public function dropField(&$ret, $table, $field) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} DROP `' . $field . '`');
public function dropField($table, $field) {
$this->connection->query('ALTER TABLE {' . $table . '} DROP `' . $field . '`');
}
public function fieldSetDefault(&$ret, $table, $field, $default) {
public function fieldSetDefault($table, $field, $default) {
if (is_null($default)) {
$default = 'NULL';
}
......@@ -312,44 +311,43 @@ public function fieldSetDefault(&$ret, $table, $field, $default) {
$default = is_string($default) ? "'$default'" : $default;
}
$ret[] = update_sql('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` SET DEFAULT ' . $default);
$this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` SET DEFAULT ' . $default);
}
public function fieldSetNoDefault(&$ret, $table, $field) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` DROP DEFAULT');
public function fieldSetNoDefault($table, $field) {
$this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` DROP DEFAULT');
}
public function addPrimaryKey(&$ret, $table, $fields) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . $this->createKeySql($fields) . ')');
public function addPrimaryKey($table, $fields) {
$this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . $this->createKeySql($fields) . ')');
}
public function dropPrimaryKey(&$ret, $table) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} DROP PRIMARY KEY');
public function dropPrimaryKey($table) {
$this->connection->query('ALTER TABLE {' . $table . '} DROP PRIMARY KEY');
}
public function addUniqueKey(&$ret, $table, $name, $fields) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} ADD UNIQUE KEY `' . $name . '` (' . $this->createKeySql($fields) . ')');
public function addUniqueKey($table, $name, $fields) {
$this->connection->query('ALTER TABLE {' . $table . '} ADD UNIQUE KEY `' . $name . '` (' . $this->createKeySql($fields) . ')');
}
public function dropUniqueKey(&$ret, $table, $name) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} DROP KEY `' . $name . '`');
public function dropUniqueKey($table, $name) {
$this->connection->query('ALTER TABLE {' . $table . '} DROP KEY `' . $name . '`');
}
public function addIndex(&$ret, $table, $name, $fields) {
$query = 'ALTER TABLE {' . $table . '} ADD INDEX `' . $name . '` (' . $this->createKeySql($fields) . ')';
$ret[] = update_sql($query);
public function addIndex($table, $name, $fields) {
$this->connection->query('ALTER TABLE {' . $table . '} ADD INDEX `' . $name . '` (' . $this->createKeySql($fields) . ')');
}
public function dropIndex(&$ret, $table, $name) {
$ret[] = update_sql('ALTER TABLE {' . $table . '} DROP INDEX `' . $name . '`');
public function dropIndex($table, $name) {
$this->connection->query('ALTER TABLE {' . $table . '} DROP INDEX `' . $name . '`');
}
public function changeField(&$ret, $table, $field, $field_new, $spec, $keys_new = array()) {
public function changeField($table, $field, $field_new, $spec, $keys_new = array()) {
$sql = 'ALTER TABLE {' . $table . '} CHANGE `' . $field . '` ' . $this->createFieldSql($field_new, $this->processField($spec));
if (count($keys_new)) {
$sql .= ', ADD ' . implode(', ADD ', $this->createKeysSql($keys_new));
}
$ret[] = update_sql($sql);
$this->connection->query($sql);
}
public function prepareComment($comment, $length = NULL) {
......@@ -374,11 +372,11 @@ public function getComment($table, $column = NULL) {
$condition->condition('column_name', $column);
$condition->compile($this->connection, $this);
// Don't use {} around information_schema.columns table.
return db_query("SELECT column_comment FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchField();
return $this->connection->query("SELECT column_comment FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchField();
}
$condition->compile($this->connection, $this);
// Don't use {} around information_schema.tables table.
$comment = db_query("SELECT table_comment FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchField();
$comment = $this->connection->query("SELECT table_comment FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchField();
// Work-around for MySQL 5.0 bug http://bugs.mysql.com/bug.php?id=11379
return preg_replace('/; InnoDB free:.*$/', '', $comment);
}
......
This diff is collapsed.
......@@ -267,30 +267,24 @@ public function columnExists($table, $column) {
/**
* Rename a table.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be renamed.
* @param $new_name
* The new name for the table.
*/
abstract public function renameTable(&$ret, $table, $new_name);
abstract public function renameTable($table, $new_name);
/**
* Drop a table.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be dropped.
*/
abstract public function dropTable(&$ret, $table);
abstract public function dropTable($table);
/**
* Add a new field to a table.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* Name of the table to be altered.
* @param $field
......@@ -309,25 +303,21 @@ public function columnExists($table, $column) {
* or index including it in this array. @see db_change_field for more
* explanation why.
*/
abstract public function addField(&$ret, $table, $field, $spec, $keys_new = array());
abstract public function addField($table, $field, $spec, $keys_new = array());
/**
* Drop a field.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $field
* The field to be dropped.
*/
abstract public function dropField(&$ret, $table, $field);
abstract public function dropField($table, $field);
/**
* Set the default value for a field.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $field
......@@ -335,47 +325,39 @@ public function columnExists($table, $column) {
* @param $default
* Default value to be set. NULL for 'default NULL'.
*/
abstract public function fieldSetDefault(&$ret, $table, $field, $default);
abstract public function fieldSetDefault($table, $field, $default);
/**
* Set a field to have no default value.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $field
* The field to be altered.
*/
abstract public function fieldSetNoDefault(&$ret, $table, $field);
abstract public function fieldSetNoDefault($table, $field);
/**
* Add a primary key.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $fields
* Fields for the primary key.
*/
abstract public function addPrimaryKey(&$ret, $table, $fields);
abstract public function addPrimaryKey($table, $fields);
/**
* Drop the primary key.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
*/
abstract public function dropPrimaryKey(&$ret, $table);
abstract public function dropPrimaryKey($table);
/**
* Add a unique key.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $name
......@@ -383,25 +365,21 @@ public function columnExists($table, $column) {
* @param $fields
* An array of field names.
*/
abstract public function addUniqueKey(&$ret, $table, $name, $fields);
abstract public function addUniqueKey($table, $name, $fields);
/**
* Drop a unique key.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $name
* The name of the key.
*/
abstract public function dropUniqueKey(&$ret, $table, $name);
abstract public function dropUniqueKey($table, $name);
/**
* Add an index.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $name
......@@ -409,20 +387,17 @@ public function columnExists($table, $column) {
* @param $fields
* An array of field names.
*/
abstract public function addIndex(&$ret, $table, $name, $fields);
abstract public function addIndex($table, $name, $fields);
/**
* Drop an index.
*
* @param $ret
* Array to which query results will be added.
* @param $table
* The table to be altered.
* @param $name
</