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.
一个简单的Rails 3应用程序尝试使用activerecord-jdbc-adapter与SQL Server 2000通信。我尝试了microsoft jdbc驱动程序和jtds驱动程序。好像连接数据库好了。
when it is time to SHOW data I get this error:
什么时候显示数据我得到这个错误:
ActiveRecord::StatementInvalid in PencilsController#show
PencilsController#show中的ActiveRecord :: StatementInvalid
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
ActiveRecord的:: JDBCError: 'ROW_NUMBER' 不是可以识别的函数名.:选择T * FROM(SELECT ROW_NUMBER)OVER(ORDER BY [铅笔](.ID)AS _row_num,[笔] * FROM [铅笔],其中[。铅笔]。[id] = 1)AS t WHERE t._row_num在1和1之间
2 个解决方案
#1
1
The real problem here is the DB do not support proper LIMIT and OFFSET functions. Rails 2 would have the same problem.
这里真正的问题是DB不支持正确的LIMIT和OFFSET功能。 Rails 2会遇到同样的问题。
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:
对于我的一个旧项目,我不得不使用Sybase15,它与旧的SQL Server非常相似。要使限制和偏移量与该DB一起工作,我必须编写自己的适配器:
https://github.com/arkadiyk/ar-sybase-jdbc-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.
它使用可滚动游标来模拟偏移。您可以尝试使用它与SQL SERVER 2000一样,也可以随意克隆它并根据您的特定需求进行修改。
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)
更新:ROW_NUMBER函数在https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/mssql/limit_helpers.rb第82行调用(SqlServerReplaceLimitOffset)
There is no replacement for this function. There are other ways of implementing OFFSET but there is no straight forward one.
这个功能没有替代品。还有其他实现OFFSET的方法,但没有直接的方法。
#2
0
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
这有点旧,但如果有人在这里经过,我把另一个使用activerecord-sqlserver-adapter的解决方案放在一起,可用于将rails 3.2 app连接到sqlserver 2000
https://bitbucket.org/jose_schmidt/rails-sqlserver-adapter-sql-server-2000-friendly
https://bitbucket.org/jose_schmidt/rails-sqlserver-adapter-sql-server-2000-friendly
#1
1
The real problem here is the DB do not support proper LIMIT and OFFSET functions. Rails 2 would have the same problem.
这里真正的问题是DB不支持正确的LIMIT和OFFSET功能。 Rails 2会遇到同样的问题。
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:
对于我的一个旧项目,我不得不使用Sybase15,它与旧的SQL Server非常相似。要使限制和偏移量与该DB一起工作,我必须编写自己的适配器:
https://github.com/arkadiyk/ar-sybase-jdbc-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.
它使用可滚动游标来模拟偏移。您可以尝试使用它与SQL SERVER 2000一样,也可以随意克隆它并根据您的特定需求进行修改。
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)
更新:ROW_NUMBER函数在https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/mssql/limit_helpers.rb第82行调用(SqlServerReplaceLimitOffset)
There is no replacement for this function. There are other ways of implementing OFFSET but there is no straight forward one.
这个功能没有替代品。还有其他实现OFFSET的方法,但没有直接的方法。
#2
0
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
这有点旧,但如果有人在这里经过,我把另一个使用activerecord-sqlserver-adapter的解决方案放在一起,可用于将rails 3.2 app连接到sqlserver 2000
https://bitbucket.org/jose_schmidt/rails-sqlserver-adapter-sql-server-2000-friendly
https://bitbucket.org/jose_schmidt/rails-sqlserver-adapter-sql-server-2000-friendly