Problem using SQL Server adapter with ActiveScaffold (with patch)

0 views
Skip to first unread message

Eric Kramer

unread,
Jan 12, 2010, 4:24:46 PM1/12/10
to Rails SQLServer Adapter
Hi. I was getting strange "double-bracketed" field names when I
swapped out SQL Server for MySQL on my Rails app. I use the
ActiveScaffold (AS) plugin and for whatever reason when AS used the
standard ActiveRecord #find methods, I was getting SQL exceptions
indicating that the underlying SQL was getting double-brackets on
field names (e.g., "some_table.[[id]]").

I'm not sure whose end the problem (opportunity?) is... Perhaps AS
isn't pulling column names/metadata in a kosher way... Or perhaps it's
a SQL Server adapter issue (no offense! *smile*). Regardless, a
slight adjustment within the adapter made the problem go away:

--- Inside "sqlserveradapter.rb" ---

BEFORE:
def quote_column_name(column_name)
column_name.to_s.split('.').map{ |name| "[#{name}]" }.join('.')
end

AFTER:
def quote_column_name(column_name)
column_name.to_s.split('.').map{ |name| name =~ /[\[\]]/ ? name : "[#
{name}]" }.join('.')
end

---

Reply all
Reply to author
Forward
0 new messages