[development] Simpletest question

Jennifer Hodgdon yahgrp at poplarware.com
Tue Jan 26 15:50:10 UTC 2010


The table aliasing with {} should definitely work just fine in 
SimpleTest, or else nothing in Drupal would work. You probably have 
some other error. Do your queries work in PHPMyAdmin or in the MySQL 
command line, in the regular database where you know the table names??

That said, there's a global $db_prefix that gives you the database 
prefix (see settings.php and the db_prefix_tables function in 
includes/database.inc).

    --Jennifer

David Thibault wrote:
> Is there a way to figure out the table prefix that Simpletest generates at runtime?  I am trying to run a test that does a bunch of inserts, then I need to figure out how many rows were created in the table.  However, I can't query the table because simpletest changes the name of it every time.  Also, I tried {table_name} instead of table_name in the query but it didn't work (line numbers inserted below to help with reading the error message later):
> 
> 21 public function test_sync () {
> 22    require_once(drupal_get_path('module','compoundmanagement').'/compoundmanagement.inc');
> 23    $result = db_query('select count(objdid) as count from {cpd_compounds}');
> 24    $row = $result->db_fetch_object($result);
> 25    $this->pass('There are '.$row->count.' compounds in cpd_compounds');
> 26    $this->drupalGet('sync_cpds',array('absolute' => TRUE));
> 27    $result = db_query('select count(objdid) as count from {cpd_compounds}');
> 28    $row = $result->db_fetch_object($result);
> 29    $this->pass('There are now '.$row->count.' compounds in cpd_compounds');
> 30    $this->assertEqual($row->count,1313,"CPD_COMPOUNDS should have 1313 rows.");
> 31 }
> 
> The test above threw this error:
> 
> An error occurred.
> /batch?id=18&op=do
> <br />
> <b>Fatal error</b>: Call to a member function db_fetch_object() on a non-object in <b>C:\wamp\www\drupal\sites\all\modules\compoundmanagement\compoundmanagement.test</b> on line <b>24</b><br />

-- 
Jennifer Hodgdon * Poplar ProductivityWare
www.poplarware.com
Drupal, WordPress, and custom Web programming



More information about the development mailing list