SimpleTesting-PDOException:SQLSTATE[42S02]
SimpleTesting-PDOException: SQLSTATE[42S02] 查看编辑修订 ichionid 发布于 2011 年 12 月 15 日上午 10:56 大家好,
我正在开发一个模块。我正在尝试合并 SimpleTest 模块,以便有一个单独的位置来包含我的代码测试。
但是,当我尝试对数据库中由我构建的表运行查询时,我得到: PDOException: SQLSTATE[42S02]: 未找到基表或视图: 1146 Table 'playground.simpletest311135TABLENAME
它尝试查找表 simpletest311135TABLENAME,同时它应该查找 TABLENAME。它总是添加 simpletest 和一些随机数。
当我对 drupal 默认表(如用户和会话)运行查询时,一切都很完美。有什么解决办法吗?
Giannis
实际的功能是
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);
}
}
测试功能:
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!"
);
}
}
在测试类中,我唯一工作的功能是查询默认 drupal 数据库表的功能。另外,上面的函数正在工作,我以不同的方式调用并且它工作了,问题是我无法让它与 Drupal 的 simpletesting 模块一起工作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我误解了,我很抱歉,但我认为您正在尝试使用简单的内部联接来运行查询?如果是这样,您的语法错误,它应该如下所示:
问题出在您的条件上:
分配给
$d_alias
的变量(您在上述条件中用作别名)是从$query->innerJoin()
它不返回别名的字符串表示形式,而是返回一个对象。您在查询中获取的表名称可能是该对象的字符串表示形式 (simpletest311135
)。当您使用
innerJoin()
的第二个参数时,该参数将成为查询其余部分中连接表的别名。因此,您可以像上面的示例一样使用->condition('d.jid', $jobId)
。希望有帮助
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:
The problem is with your condition:
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