Browse files

r3429@asus: jeremy | 2005-12-09 16:55:16 -0800

 Apply [3270] SQLServer rollup to stable.


git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/stable@3271 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 596fe49 commit 2018b2a8d2162689e5ecafd3408dca0edccc8696 @jeremy jeremy committed Dec 10, 2005
Showing with 18 additions and 4 deletions.
  1. +10 −0 activerecord/CHANGELOG
  2. +8 −4 activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
View
10 activerecord/CHANGELOG
@@ -2,6 +2,16 @@
* MySQL, PostgreSQL: reconnect! also reconfigures the connection. Otherwise, the connection 'loses' its settings if it times out and is reconnected. #2978 [Shugo Maeda]
+* SQLServer: fix obscure optimistic locking bug. #3068 [kajism@yahoo.com]
+
+* SQLServer: support uniqueidentifier columns. #2930 [keithm@infused.org]
+
+* SQLServer: cope with tables names qualified by owner. #3067 [jeff@ministrycentered.com]
+
+* SQLServer: cope with columns with "desc" in the name. #1950 [Ron Lusk, Ryan Tomayko]
+
+* SQLServer: cope with primary keys with "select" in the name. #3057 [rdifrango@captechventures.com]
+
* Oracle: active? performs a select instead of a commit. #3133 [Michael Schoen]
View
12 activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb
@@ -68,6 +68,7 @@ def simplified_type(field_type)
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 @@ def select_one(sql, name = nil)
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 @@ def quote_column_name(name)
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 @@ def query_contains_identity_column(sql, col)
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

0 comments on commit 2018b2a

Please sign in to comment.