将 HSQLDB 嵌入 Rails 应用程序时 SQL 无效

发布于 2024-08-24 03:17:59 字数 924 浏览 10 评论 0原文

我正在致力于将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怎会甘心 2024-08-31 03:17:59

您可能在 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.

三人与歌 2024-08-31 03:17:59

您可以尝试H2数据库,连接它喜欢 所以。来自 维基百科

数据库引擎由 Thomas Mueller 编写。他还开发了 Java 数据库引擎 Hypersonic SQL [1]。 2001 年,Hysonic SQL 被停止,HSQLDB 小组成立,继续开发 Hypersonic SQL 代码。 H2 这个名称代表 Hypersonic 2,但 H2 不与 Hypersonic SQL 或 HSQLDB 共享任何代码。 H2 是从头开始构建的。

You can try H2 Database, wire it like so. From wikipedia:

The database engine is written by Thomas Mueller. He also developed the Java database engine Hypersonic SQL [1]. In 2001, the Hypersonic SQL was stopped, and the HSQLDB Group was formed to continue work on the Hypersonic SQL code. The name H2 stands for Hypersonic 2, however H2 does not share any code with Hypersonic SQL or HSQLDB. H2 is built from scratch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文