将 HSQLDB 嵌入 Rails 应用程序时 SQL 无效
我正在致力于将 Rails 应用程序移植到 JRuby 和 HSQLDB。我的目标是将数据库和站点嵌入到单个 JAR 文件中,以便在客户站点上进行部署。我的网站在 JAR 中运行得很好,但有一些值得注意的问题。
当我使用相当普通的 ActiveRecord 模型执行以下操作时:
@total = SessionLog.count(:id)
我收到以下异常:
ActiveRecord::StatementInvalid (ActiveRecord::ActiveRecordError: Not 在聚合函数或 group by 子句中:org.hsqldb.Expression@7be117eb 在语句 [SELECT count(session_logs.id) AS count_id FROM session_logs WHERE (created_at >= '2010-02-06' ANDcreated_at <= '2010-03-09' AND session_type = 'tunnel_client') ORDER BY id DESC ]:
从 session_logs WHERE 中选择 count(session_logs.id) AS count_id (创建时间 >= '2010-02-06' 且创建时间 <= '2010-03-09' 且 session_type = 'tunnel_client') ORDER BY id DESC )
我似乎很清楚 COUNT 语句在 HSQLDB 中造成了麻烦,但我不确定解决此问题的解决方案是什么。 SQLite3 和 MySQL 都可以毫无问题地处理此 SQL 语句。
我愿意使用 HSQLDB 以外的其他数据库,但它需要可嵌入到 JVM 上的应用程序中。这就是HSQLDB的吸引力。
I am working on porting a Rails app to JRuby and HSQLDB. My goal is to embed a database and the site within a single JAR file for deployment at customer sites. I have the site working quite well from the JAR, with a few notable problems.
When I do the following with a pretty mundane ActiveRecord model:
@total = SessionLog.count(:id)
I get the following exception:
ActiveRecord::StatementInvalid (ActiveRecord::ActiveRecordError: Not
in aggregate function or group by clause: org.hsqldb.Expression@7be117eb
in statement [SELECT count(session_logs.id) AS count_id
FROM session_logs WHERE (created_at >= '2010-02-06' AND created_at <=
'2010-03-09' AND session_type = 'tunnel_client') ORDER BY id DESC ]:SELECT count(session_logs.id) AS count_id FROM session_logs WHERE
(created_at >= '2010-02-06' AND created_at <= '2010-03-09' AND
session_type = 'tunnel_client') ORDER BY id DESC )
It seems clear to me that the COUNT statement is causing the trouble in HSQLDB, but I'm not sure what the solution is to fix this. SQLite3 and MySQL both process this SQL statement without issue.
I'm open to using a different database other than HSQLDB, but it needs to be embeddable into our application on the JVM. That is the appeal of HSQLDB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能在 ActiveRecord 适配器中发现了一个错误 - 我认为是
activerecord-jdbchsqldb-adapter
。您可以尝试在某些非 ruby SQL 会话中直接运行 SQL 吗?然后也许您可以看到哪里出了问题并提交错误或(更好)提交补丁。
You've probably found a bug in the ActiveRecord adapter -
activerecord-jdbchsqldb-adapter
I assume.Can you try run the SQL directly in some non-ruby SQL session? Then maybe you can see where it's going wrong and submit a bug or (better), submit a patch.
您可以尝试H2数据库,连接它喜欢 所以。来自 维基百科:
You can try H2 Database, wire it like so. From wikipedia: