本文介绍了Rails3会谈到SQL Server 2000 -----的ActiveRecord :: JDBCError:“ROW_NUMBER'不是可以识别的函数名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的Rails 3应用程序试图使用的ActiveRecord-JDBC适配器交谈到SQL Server 2000。我试过了Microsoft JDBC驱动程序和JTDS驱动程序。似乎连接到数据库确定。

A simple Rails 3 application tries to talk to SQL Server 2000 using activerecord-jdbc-adapter. I tried both microsoft jdbc driver and jtds driver. seems to connect to database OK.

当它是时间来证明数据我得到这个错误:

when it is time to SHOW data I get this error:

的ActiveRecord :: StatementInvalid在PencilsController#秀

ActiveRecord::StatementInvalid in PencilsController#show

的ActiveRecord :: JDBCError:'RO​​W_NUMBER'不是可以识别的函数名.:选择T * FROM(SELECT ROW_NUMBER()OVER(ORDER BY [铅笔] .ID)AS _row_num,[笔] * FROM [铅笔],其中[铅笔]。[ID] = 1)T其中t._row_num介于1和1

ActiveRecord::JDBCError: 'ROW_NUMBER' is not a recognized function name.: SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY [pencils].id) AS _row_num, [pencils].* FROM [pencils] WHERE [pencils].[id] = 1) AS t WHERE t._row_num BETWEEN 1 AND 1

推荐答案

真正的问题在这里是数据库不支持适当的LIMIT和OFFSET函数。导轨2将有同样的问题。

The real problem here is the DB do not support proper LIMIT and OFFSET functions. Rails 2 would have the same problem.

有关我的老项目之一,我不得不使用Sybase15,这非常类似于旧的SQL Server。为了限制,并与数据库我不得不写我自己的适配器抵消工作:

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

它使用可滚动游标可模拟抵消。你可以尝试使用它,因为它是与SQL Server 2000或随意复制并修改您的特定需求。

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.

更新:ROW_NUMBER函数被调用的https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/mssql/limit_helpers.rb线82(SqlServerReplaceLimitOffset)

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)

对于没有更换此功能。有许多实现OFFSET的其他方式,但没有直接的之一。

There is no replacement for this function. There are other ways of implementing OFFSET but there is no straight forward one.

这篇关于Rails3会谈到SQL Server 2000 -----的ActiveRecord :: JDBCError:“ROW_NUMBER'不是可以识别的函数名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 15:47