SimpleTest: Database prefix added twice when cleaning database
beginner - December 10, 2008 - 08:26
| Project: | SimpleTest |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
When clicking the "clean environment" button, I get:
user warning: Unknown table 'dev_dev_simpletest' query: DROP TABLE dev_dev_simpletest in drupal-6/includes/database.mysql-common.inc on line 261.
user warning: Unknown table 'dev_dev_simpletest_test_id' query: DROP TABLE dev_dev_simpletest_test_id in drupal-6/includes/database.mysql-common.inc on line 261.<?php
/**
* Removed prefixed talbes from the database that are left over from crashed tests.
*/
function simpletest_clean_database() {
$tables = simpletest_get_like_tables(); // --> This returns the tables already prefixed.
$ret = array();
foreach ($tables as $table) {
db_drop_table($ret, $table); // --> the function expects un-prefixed table names!
}
?>
#1
Also, i don't know if it's related, but my database has accumulated 300+ simpletest_* tables that have not been properly cleaned.
#2
I am actually surprised that simpletest actually tries to drop {simpletest} and {simpletest_test_id}.
Is that the intended behavior?
#3
I am not sure what's the intended behavior.
I fixed the issue for myself with the attached patch:
the tables {simpletest} and {simpletest_test_id} are kept, but the countless simpletest* tables have been removed.
I removed the $prefix from the SELECT query, and I don't use db_drop_table() which will add the unwanted prefix.
#4
This is an issue with SimpleTest 7.x and should be fixed in core then backported.
#5
1) The get like tables needs to return either non-prefixed tables, 2) the prefixes need to be removed from the table names before running drop command, or 3) the $db_prefix could be set to '' just before running drops.
#6
subscribing (for 6.x-2.x branch)
http://drupal.org/files/issues/table_prefix_simpletest.patch fixes this bug for me too.
#7
Core is not affected.
#8
I'm not following the problem here....can you give me detailed instructions on how to re-create.
simpletest_get_like_tables() should be looking for tables that were created with random prefix (ie. simpletest438928095)
and should return them as such.
#9
See the comments in the php code in comment #0 above.
#10
Yes, and from reading that and patch I wasn't sure...as I think they are inconsistent.
Changing the drop to a manual query if it auto adds prefix makes sense...otherwise we could do
<?php$db_prefix = '';
db_drop..()
$db_prefix = $original;
?>
But I don't get why the get query would change.
$result = db_query("SELECT $select FROM information_schema.tables WHERE table_schema = '$database' AND table_name LIKE '$base_table%'");
That would seem to fry simpletest tables ONLY if the $db_prefix = ''; ?
#11
This no longer happens for me in simpletest 6.x-2.8, and the patch no longer applies, since the underlying code changed, so I am assuming that it is fixed.
#12
Automatically closed -- issue fixed for 2 weeks with no activity.