光滑下降并引发抛出错误

时间:2014-09-28 10:39:46

标签: scala playframework slick playframework-2.3

我正在学习使用Slick Play Scala并遇到问题。使用drop和take时,Slick生成的查询会抛出一个错误(没有删除就行,但我需要分页)。

val categories = TableQuery[Categories]

def list(page: Int = 0, pageSize: Int = 10, orderBy: Int = 1)(implicit s: Session): Page[Category] = {

    val offset = pageSize * page
    val totalRows = count
    /* Error here */
    val result = categories.drop(offset).take(pageSize).list
    /* This works fine */
    /* val result = categories.list */

    Page(result, page, offset, totalRows)
  }

生成的查询和错误堆栈跟踪:

[JdbcSQLException: Syntax error in SQL statement "SELECT X2.""id"", X2.""name"", X2.""description"" FROM (SELECT X3.""id"" AS ""id"", X3.""name"" AS ""name"", X3.""description"" AS ""description"" FROM ""core_category"" X3 FETCH[*] NEXT 10 ROW ONLY) X2 "; expected "RIGHT, LEFT, FULL, INNER, JOIN, CROSS, NATURAL, ,, WHERE, GROUP, HAVING, UNION, MINUS, EXCEPT, INTERSECT, ORDER, LIMIT, FOR, )"; SQL statement:
select x2."id", x2."name", x2."description" from (select x3."id" as "id", x3."name" as "name", x3."description" as "description" from "core_category" x3 fetch next 10 row only) x2 [42001-175]]

任何想法如何在不收到此错误的情况下实现分页?

1 个答案:

答案 0 :(得分:0)

我正在导入JdbcDriver而不是个性化的驱动程序(在我的情况下是H2Driver)来获取正确的方言。