Rails3 与 SQL Server 2000 对话-----ActiveRecord::JDBCError: 'ROW_NUMBER'不是可识别的函数名称
一个简单的 Rails 3 应用程序尝试使用 activerecord-jdbc-adapter 与 SQL Server 2000 进行通信。我尝试了 microsoft jdbc 驱动程序和 jtds 驱动程序。似乎连接数据库正常。
当需要显示数据时,我收到此错误:
ActiveRecord::StatementInvalid in PencilsController#show
ActiveRecord::JDBCError: 'ROW_NUMBER' is not a recognized function name.: SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY) [铅笔].id) AS _row_num, [铅笔].* FROM [铅笔] WHERE [铅笔].[id] = 1) AS t WHERE t._row_num BETWEEN 1 AND 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里真正的问题是数据库不支持正确的 LIMIT 和 OFFSET 函数。 Rails 2 也会有同样的问题。
对于我的一个旧项目,我必须使用 Sybase15,它与旧的 SQL Server 非常相似。为了使限制和偏移与该数据库一起工作,我必须编写自己的适配器:
https:// github.com/arkadiyk/ar-sybase-jdbc-adapter。
它使用可滚动光标来模拟偏移。您可以尝试像在 SQL SERVER 2000 中一样使用它,也可以随意克隆它并根据您的特定需要进行修改。
更新:
ROW_NUMBER 函数在 https:/ 处调用/github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/mssql/limit_helpers.rb第82行(SqlServerReplaceLimitOffset)
此函数没有替代项。还有其他实现 OFFSET 的方法,但没有直接的方法。
The real problem here is the DB do not support proper LIMIT and OFFSET functions. Rails 2 would have the same problem.
For one of my old projects I had to use Sybase15, which is quite similar to old SQL Server. To make limit and offset work with that DB I had to write my own adapter:
https://github.com/arkadiyk/ar-sybase-jdbc-adapter .
It uses scrollable cursors to simulate offset. You can try to use it as it is with SQL SERVER 2000 or feel free to clone it and modify for your specific needs.
Update:
The ROW_NUMBER function is called at https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/mssql/limit_helpers.rb line 82 (SqlServerReplaceLimitOffset)
There is no replacement for this function. There are other ways of implementing OFFSET but there is no straight forward one.
这是一种旧的,但如果有人经过这里,我整理了另一个使用 activerecord-sqlserver-adapter 的解决方案,可用于将 Rails 3.2 应用程序连接到 sqlserver 2000
https://bitbucket.org/jose_schmidt/rails-sqlserver-adapter-sql-server-2000-Friendly
This is kind a old, but if anyone is passing through here, i put together another solution that uses activerecord-sqlserver-adapter that can be used to connect a rails 3.2 app to sqlserver 2000
https://bitbucket.org/jose_schmidt/rails-sqlserver-adapter-sql-server-2000-friendly