aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-12-10 00:52:41 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-12-10 00:52:41 +0000
commit42576fffe23a86712548e6235890b8606f97c1d3 (patch)
tree2e114a98217d1878cb47cde5f31f0ba6d20b193e /activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
parent6b7e51df511ccda550856435029ac7dc232b9d7a (diff)
downloadrails-42576fffe23a86712548e6235890b8606f97c1d3.tar.gz
rails-42576fffe23a86712548e6235890b8606f97c1d3.tar.bz2
rails-42576fffe23a86712548e6235890b8606f97c1d3.zip
SQLServer: fix obscure optimistic locking bug, support uniqueidentifier columns, cope with tables names qualified by owner, cope with columns with desc in the name, cope with primary keys with select in the name. Closes #3068, #2930, #3067, #1950, #3057, #3162.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3270 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
index c3fdebfd72..9d7174007c 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
@@ -68,6 +68,7 @@ module ActiveRecord
when /binary|image|varbinary/i then :binary
when /char|nchar|nvarchar|string|varchar/i then :string
when /bit/i then :boolean
+ when /uniqueidentifier/i then :string
end
end
@@ -233,6 +234,9 @@ module ActiveRecord
end
def columns(table_name, name = nil)
+ return [] if table_name.blank?
+ table_name = table_name.to_s if table_name.is_a?(Symbol)
+ table_name = table_name.split('.')[-1] unless table_name.nil?
sql = "SELECT COLUMN_NAME as ColName, COLUMN_DEFAULT as DefaultValue, DATA_TYPE as ColType, COL_LENGTH('#{table_name}', COLUMN_NAME) as Length, COLUMNPROPERTY(OBJECT_ID('#{table_name}'), COLUMN_NAME, 'IsIdentity') as IsIdentity, NUMERIC_SCALE as Scale FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '#{table_name}'"
# Comment out if you want to have the Columns select statment logged.
# Personnally, I think it adds unneccessary bloat to the log.
@@ -347,7 +351,7 @@ module ActiveRecord
def add_limit_offset!(sql, options)
if options[:limit] and options[:offset]
- total_rows = @connection.select_all("SELECT count(*) as TotalRows from (#{sql.gsub(/SELECT/i, "SELECT TOP 1000000000")}) tally")[0][:TotalRows].to_i
+ total_rows = @connection.select_all("SELECT count(*) as TotalRows from (#{sql.gsub(/\bSELECT\b/i, "SELECT TOP 1000000000")}) tally")[0][:TotalRows].to_i
if (options[:limit] + options[:offset]) >= total_rows
options[:limit] = (total_rows - options[:offset] >= 0) ? (total_rows - options[:offset]) : 0
end
@@ -509,9 +513,9 @@ module ActiveRecord
def change_order_direction(order)
case order
- when /DESC/i then order.gsub(/DESC/i, "ASC")
- when /ASC/i then order.gsub(/ASC/i, "DESC")
- else String.new(order).split(',').join(' DESC,') + ' DESC'
+ when /\bDESC\b/i then order.gsub(/\bDESC\b/i, "ASC")
+ when /\bASC\b/i then order.gsub(/\bASC\b/i, "DESC")
+ else String.new(order).split(',').join(' DESC,') + ' DESC'
end
end