所以我在这里使用了漂亮的joda-mapper助手:https://github.com/tototoshi/slick-joda-mapper当使用joda DateTime比较运行查询时,出现错误。
val today = new DateTime().withTimeAtStartOfDay() val yesterday = today.minusDays(1) val yesterdaysRun = ReportRuns.forReport(report).filter {run => run.runDate >= yesterday && run.runDate < today }.sortBy(_.runDate.desc).firstOption
如果省略过滤器,此代码运行良好,但是使用过滤器,我得到以下错误:
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (unrecognized token: "{") at org.sqlite.DB.newSQLException(DB.java:383) at org.sqlite.DB.newSQLException(DB.java:387) at org.sqlite.DB.throwex(DB.java:374) at org.sqlite.NativeDB.prepare(Native Method) at org.sqlite.DB.prepare(DB.java:123) at org.sqlite.PrepStmt.<init>(PrepStmt.java:42) at org.sqlite.Conn.prepareStatement(Conn.java:404) at org.sqlite.Conn.prepareStatement(Conn.java:399) at com.mchange.v2.c3p0.impl.NewProxyConnection.prepareStatement(NewProxyConnection.java:275) at scala.slick.jdbc.JdbcBackend$SessionDef$class.prepareStatement(JdbcBackend.scala:123) at scala.slick.jdbc.JdbcBackend$BaseSession.prepareStatement(JdbcBackend.scala:297) at scala.slick.jdbc.StatementInvoker.results(StatementInvoker.scala:28) at scala.slick.jdbc.StatementInvoker.iteratorTo(StatementInvoker.scala:16) at scala.slick.jdbc.Invoker$class.foreach(Invoker.scala:97) at scala.slick.jdbc.StatementInvoker.foreach(StatementInvoker.scala:9) at scala.slick.jdbc.Invoker$class.firstOption(Invoker.scala:44) at scala.slick.jdbc.StatementInvoker.firstOption(StatementInvoker.scala:9) at scala.slick.jdbc.UnitInvoker$class.firstOption(Invoker.scala:155) at scala.slick.driver.JdbcInvokerComponent$UnitQueryInvoker.firstOption(JdbcInvokerComponent.scala:50) at service.QueryRunnerService$$anonfun$scheduleReports$1$$anonfun$apply$1.apply(QueryRunnerService.scala:57) ...
想知道是否有人可以为我指出正确的解决方案,这是否可能是joda映射器中的SQL转义错误?还是其他?
下面是此生成的SQL查询(加上格式):
SELECT x2."id",
x2."reportid",
x2."query",
x2."run_date",
x2."status",
x2."start_time",
x2."end_time",
x2."error_message",
x2."error_details",
x2."created_at",
x2."updated_at"
FROM "report_runs" x2
WHERE ( x2."reportid" = 1 )
AND ( ( x2."run_date" >= {ts '2014-03-28 00:00:00.0'} )
AND ( x2."run_date" < {ts '2014-03-29 00:00:00.0'} ) )
ORDER BY x2."run_date" DESC
因此,我从这里使用光滑的joda-mapper帮助器:https://github.com/tototoshi/slick-joda-mapper,并且在运行具有joda DateTime比较的查询时,出现错误。今天的val =新的DateTime(...
这是Joda Mapper(https://github.com/tototoshi/slick-joda-mapper)中的错误。