0
votes

SimpleTesting-PDOException: SQLSTATE[42S02] View Edit Revisions Posted by ichionid on December 15, 2011 at 10:56am Hi all,

I am in the processes of developing a module. I am trying to incorporate SimpleTest module in order to have a separate place that contains my code tests.

However, when I try to run a query against the tables in the database, which are build by me, I get: PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'playground.simpletest311135TABLENAME

It tries to find a table simpletest311135TABLENAME while it should look for TABLENAME. It always adds simpletest and some random number.

When I run queries against drupal default tables, like users and sessions, everything works perfect. Any workaround?

Giannis


The actual function is

function dlm_job_finished($jobId,$urls,$messageFromFS){
    $query    =  db_select('users','u');
    $query    -> fields('u',array('uid'));
    $d_alias  =  $query->innerJoin('dlm_user_auth_entities','d','%alias.uid = u.uid');
    $query    -> condition("{$d_alias}.jid",$jobId);
    $result   =  $query->execute();
    $message = variable_get('dlm_settings_email_message').'<br />';
    foreach ($result as $record) {
      foreach ($urls as $file_url_to_download){
        $message.= '<a href="'.$file_url_to_download.'">'.$file_url_to_download.'</a> <br /> ';
      }
      $message.=$messageFromFS.'<br />';      
      dlm_mail_notifier($record->uid,$message);
    }
  }

the test function is :

class DlmTestCase extends DrupalWebTestCase{

  public function setUp(){
    parent::setUp('dlm');
  }

    public function testDlmJobFinished(){
        $info = module_invoke(
                  'dlm',
                  'job_finished',
                  'awsedrfvcxzsdfrtawsedrfvcxzsdfrt',
                  array(
                    'http://media.holkeydonkey.com/download/frehvf64fdsffdf.zip',
                    'http://media.marioBos.com/download/12.zip',
                  ),
                  "additional message!"
                );
      }
}

Inside the test class the only functions that I made work is the ones that query the default drupal database tables. Also, the function above is working, I invoked in a different way and it worked, the problem is that I cannot get it working with Drupal's simpletesting module.

1
Can you post the specific lines of code that are causing this error? - Clive
please see the edited version above! - Potney Switters

1 Answers

0
votes

Apologies if I've misunderstood but I think you're trying to run a query with a simple inner join? If so your syntax is wrong, it should look like this:

$query = db_select('users','u')
  ->fields('u',array('uid'))
  ->condition('d.jid', $jobId);

$query->innerJoin('dlm_user_auth_entities', 'd', 'd.uid = u.uid');

$results = $query->execute();

The problem is with your condition:

`$query -> condition("{$d_alias}.jid",$jobId);`

The variable assigned to $d_alias (which you are using as your alias name in the above condition) is returned from $query->innerJoin() which doesn't return a string representation of the alias, it returns an object. The table name you're getting in your query might be the string representation of that object (simpletest311135).

When you use the second argument of innerJoin() that becomes the alias that the joined table will be known by in the rest of your query. So you can just use ->condition('d.jid', $jobId) as in the example above.

Hope that helps