【问题标题】:Sql error for simple subsonic example简单亚音速示例的 Sql 错误
【发布时间】:2011-01-31 20:47:38
【问题描述】:

我正在测试 SubSonic,但我坚持我的第一个简单示例。我有一个新闻表,我正在尝试获取 10 个最新结果:

var newsItems = News.GetPaged("datecreated", 0, 10);

这会导致这个错误:

[MySqlException (0x80004005): 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 '-10, 10' at line 6]

生成的 SQL:

SELECT `newsid`, `datecreated`, `headline`, `body`, `link`, `picture`, `linkinfo`, `postedby`, `comments`, `category` FROM news  ORDER BY newsid DESC LIMIT -10,10

手动修复 sql 很容易,但我不知道如何让 SubSonic 自动为查询添加正确的 LIMIT。有什么指点吗?

【问题讨论】:

    标签: sql mysql subsonic3 mysql-error-1064


    【解决方案1】:

    限制应该是从0开始的正整数。-10,10不是

    http://dev.mysql.com/doc/refman/5.0/en/select.html

    -LIMIT 子句可用于限制 SELECT 语句返回的行数。 LIMIT 接受一个或两个数字参数,它们都必须是非负整数常量(使用准备好的语句时除外)。

    生成的 SQL 应该是

    SELECT `newsid`, `datecreated`, `headline`, `body`, `link`, `picture`,
        `linkinfo`, `postedby`, `comments`, `category`
    FROM news  ORDER BY newsid DESC LIMIT 10;
    

    我认为Subsonic 你需要这个

    var newsItems = News.GetPaged("datecreated", 1, 10);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-28
      • 2010-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多