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

beginner - December 10, 2008 - 08:27

Also, i don't know if it's related, but my database has accumulated 300+ simpletest_* tables that have not been properly cleaned.

#2

beginner - December 10, 2008 - 08:32

I am actually surprised that simpletest actually tries to drop {simpletest} and {simpletest_test_id}.
Is that the intended behavior?

#3

beginner - December 10, 2008 - 08:56
Status:active» needs work

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.

AttachmentSize
table_prefix_simpletest.patch 1.19 KB

#4

boombatower - December 10, 2008 - 17:20
Project:SimpleTest» Drupal
Version:6.x-2.x-dev» 7.x-dev
Component:Code» simpletest.module

This is an issue with SimpleTest 7.x and should be fixed in core then backported.

#5

boombatower - December 10, 2008 - 17:22
Title:prefix added twice to tables to drop» SimpleTest: Database prefix added twice when cleaning database

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

Wesley Tanaka - January 12, 2009 - 12:51

subscribing (for 6.x-2.x branch)

http://drupal.org/files/issues/table_prefix_simpletest.patch fixes this bug for me too.

#7

Damien Tournoud - January 12, 2009 - 12:32
Project:Drupal» SimpleTest
Version:7.x-dev» 6.x-2.x-dev
Component:simpletest.module» Code

Core is not affected.

#8

boombatower - February 8, 2009 - 03:34

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

beginner - February 8, 2009 - 09:55

See the comments in the php code in comment #0 above.

#10

boombatower - February 8, 2009 - 21:26

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

Wesley Tanaka - July 1, 2009 - 04:03
Status:needs work» fixed

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

System Message - July 15, 2009 - 04:10
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.