开发者

How to set schema and handle case of attribute names when using JRuby, ActiveRecord, and JDBC to access MS SQLserver

I had two problems to access SQL server database:

  • how to set schema

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

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.

  • how to handle attribute names

When accessing db2, all attributes names are lower case. But for mssql, the attribute names are kept as the same case as defin开发者_StackOverflow中文版ed in the database, for example, "RoleID". I'm wondering if only db2 driver forces attribute names to lower case.


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.

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜