如何使用JRuby,ActiveRecord的,和JDBC访问MS SqlServer时,设置模式和处理情况的属性名 [英] How to set schema and handle case of attribute names when using JRuby, ActiveRecord, and JDBC to access MS SQLserver

查看:185
本文介绍了如何使用JRuby,ActiveRecord的,和JDBC访问MS SqlServer时,设置模式和处理情况的属性名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个问题来访问SQL Server数据库:

I had two problems to access SQL server database:

  • 如何设置模式

我需要访问该表是在模式'将军',而不是'DBO。除非我用set_table_name,我会像'无效的对象

The table I need to access is under schema 'general' instead of 'dbo'. Unless I use set_table_name, I will get errors like 'Invalid object'

class Role < ActiveRecord::Base
  set_table_name "general.Role"
end

有另一种方式在JDBC URL的属性设置模式。我查了MS JDBC驱动程序和JTDS驱动程序,但无法找到这样的属性。

Is there another way to set schema in the properties of jdbc url. I checked MS jdbc driver and jtds driver, but cannot find such a property.

  • 如何处理属性名称

在访问DB2,所有的属性名称是小写。但对于mssql的,属性名作为在数据库中定义,例如,RoleID保持为相同的情况下。我不知道是否只有DB2驱动力属性的名称为小写。

When accessing db2, all attributes names are lower case. But for mssql, the attribute names are kept as the same case as defined in the database, for example, "RoleID". I'm wondering if only db2 driver forces attribute names to lower case.

推荐答案

在T-SQL中,完全合格的对象名称&LT;数据库&GT;&LT;老板&GT;&LT;对象名&GT; 。请注意,你的询问是的所有者的不是架构(我猜你是从甲骨文的土地来的?)。

IN T-SQL, a fully qualified object name is <database>.<owner>.<objectname>. Note that what your asking about is the owner not the schema (I guess you are coming from Oracle land?).

由于它的对象所有者,而不是架构你连接到(如甲骨文范式),我不认为是有意义的连接到老板,这真的是你再询问。

Given that it's the object owner, not the "schema you're connected to" (as in the Oracle paradigm), I don't think it makes sense to "connect to an owner", which is really what you're asking.

使用 set_table_name 你所描述的方法是非常有效的这种情况。即使你的角色表由dbo所拥有,你仍然必须使用set_table_name,因为默认情况下的ActiveRecord会寻找角色(这是区分大小写)。

Using the set_table_name method you've described is perfectly valid for this case. Even if your Role table was owned by dbo, you would still have to use set_table_name, as by default ActiveRecord will look for "role" (and it's case sensitive).

这篇关于如何使用JRuby,ActiveRecord的,和JDBC访问MS SqlServer时,设置模式和处理情况的属性名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆