findSql spPager spLinker

#1 和珅

SELECT COUNT() as sp_counter FROM (select user.* from user  where project in (select project.id from project where  1=1 and category='5')) sp_tmp_table_pager1
执行错误: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') as sp_counter FROM (select advertise.* from advertise where project in (select' at line 1

这个错误是由于什么引起的?
主键和外键已经设置
请教下findSql +spPager +spLinker有没有实际的例子?
小弟不才,在教程里面没有找到,也是我对这个框架没有深入

@jake @等等


2013-11-04 10:20:36

#2 jake

没有设置主键,从提示“SELECT COUNT() ”可以看出,如果是设置了主键,那么会是SELECT COUNT(主键)

手册在此:http://www.speedphp.com/thread-3798-1-1.html

2013-11-04 10:32:52

#3 和珅

jake 发表于 2013-11-4 10:32
没有设置主键,从提示“SELECT COUNT() ”可以看出,如果是设置了主键,那么会是SELECT COUNT(主键)

手册 ...
class user extends spModel
{
  var $pk = "id"; // 每个留言唯一的标志,可以称为主键
  var $table = "user"; // 数据表的名称
  // 由spModel的变量$linker来设置表间关联
        var $linker = array(
                'project'=>array(
                        'type' => 'hasone',   // 关联类型,这里是一对一关联
                        'map' => 'base',    // 关联的标识
                        'mapkey' => 'project', // 本表与对应表关联的字段名
                        'fclass' => 'project', // 对应表的类名
                        'fkey' => 'id',    // 对应表中关联的字段名
                        'enabled' => true     // 启用关联
                )
        );
}

$sql="select user.* from advertise where user.project in (select project.id from project where ".$conditions.")";
$results=$user->spLinker()->spPager($this->spArgs('page', 1), 12)->findSql($sql);

我在user和project里面确实设置了$pk ,因此感觉困惑。

是因为我用了一句嵌套sql导致的吗?


2013-11-04 11:35:12

#4 jake

。。。既然findSql了,还要加spLinker吗? 这个不支持吧。

2013-11-04 11:54:44

#5 和珅

jake 发表于 2013-11-4 11:54
。。。既然findSql了,还要加spLinker吗? 这个不支持吧。
.......... 我之前搜索看到你回复一个人说支持三个一起用,我就用了{:soso_e127:},多谢jake。可以结贴了。

也给以后犯这种错误的人个参考。

2013-11-04 12:16:06

#6 jake

和珅 发表于 2013-11-4 12:16
.......... 我之前搜索看到你回复一个人说支持三个一起用,我就用了,多谢jake。可以结贴了 ...
嗯,主要是SQL语句需要比较简单呃,否则是没办法做到分页关联等。但是用到了findSQL,那么SQL语句肯定不会简单的。

2013-11-04 13:38:40