简体   繁体   English

简单亚音速示例的SQL错误

[英]Sql error for simple subsonic example

I'm testing out SubSonic, but I'm stuck on my first simple example. 我正在测试SubSonic,但我只停留在第一个简单示例上。 I have a news table that I'm trying to fetch the 10 latest results: 我有一个新闻表,试图获取10个最新结果:

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

This results in this error: 这导致此错误:

[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]

The SQL generated: 生成的SQL:

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

It's easy to fix the sql manually, but I don't have a clue on how to make SubSonic add a correct LIMIT to the query automatically. 手动修复SQL很容易,但是我不知道如何让SubSonic自动向查询添加正确的LIMIT。 Any pointers? 有指针吗?

The limit should be a positive integer starting from 0. -10 ,10 is not 该限制应为从0开始的正整数。 -10 10,10不是

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

-The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT子句可用于约束SELECT语句返回的行数。 LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants (except when using prepared statements). LIMIT接受一个或两个数字参数,这两个参数都必须是非负整数常量(使用预处理语句时除外)。

The SQL generated should have been 生成的SQL应该已经

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

I think for Subsonic you need this 我认为Subsonic需要这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM