diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-06-30 16:55:49 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-06-30 16:55:49 +0000 |
commit | 9085e3ab226115cfcf65aec5ea05a33b15f549ff (patch) | |
tree | 5d99222cfe2cd3c9a96f2438cb9043c509c5628a /includes/database/mysql | |
parent | 9e0af44f621fb015d5913a629513e5b60aaa06c2 (diff) | |
download | brdo-9085e3ab226115cfcf65aec5ea05a33b15f549ff.tar.gz brdo-9085e3ab226115cfcf65aec5ea05a33b15f549ff.tar.bz2 |
#840182 by chx, Berdir: Fixed Testing is broken due to wrong prefix being used.
Diffstat (limited to 'includes/database/mysql')
-rw-r--r-- | includes/database/mysql/database.inc | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/includes/database/mysql/database.inc b/includes/database/mysql/database.inc index d2575b32b..552d95b8d 100644 --- a/includes/database/mysql/database.inc +++ b/includes/database/mysql/database.inc @@ -96,7 +96,9 @@ class DatabaseConnection_mysql extends DatabaseConnection { $new_id = $this->query('INSERT INTO {sequences} () VALUES ()', array(), array('return' => Database::RETURN_INSERT_ID)); } if (!$this->shutdownRegistered) { - drupal_register_shutdown_function(array($this, 'nextIdDelete')); + // Use register_shutdown_function() here to keep the database system + // independent of Drupal. + register_shutdown_function(array($this, 'nextIdDelete')); $shutdownRegistered = TRUE; } return $new_id; @@ -111,9 +113,19 @@ class DatabaseConnection_mysql extends DatabaseConnection { // table based solely on values from the table so deleting all values would // be a problem in this case. Also, TRUNCATE resets the auto increment // counter. - $max_id = $this->query('SELECT MAX(value) FROM {sequences}')->fetchField(); - // We know we are using MySQL here, so need for the slower db_delete(). - $this->query('DELETE FROM {sequences} WHERE value < :value', array(':value' => $max_id)); + try { + $max_id = $this->query('SELECT MAX(value) FROM {sequences}')->fetchField(); + // We know we are using MySQL here, no need for the slower db_delete(). + $this->query('DELETE FROM {sequences} WHERE value < :value', array(':value' => $max_id)); + } + // During testing, this function is called from shutdown with the + // simpletest prefix stored in $this->connection, and those tables are gone + // by the time shutdown is called so we need to ignore the database + // errors. There is no problem with completely ignoring errors here: if + // these queries fail, the sequence will work just fine, just use a bit + // more database storage and memory. + catch (PDOException $e) { + } } } |