@@ -41,12 +41,13 @@ def table_exists?(table_name)
4141 def indexes ( table_name , name = nil )
4242 unquoted_table_name = unqualify_table_name ( table_name )
4343 select ( "EXEC sp_helpindex #{ quote_table_name ( unquoted_table_name ) } " , name ) . inject ( [ ] ) do |indexes , index |
44- if index [ 'index_description' ] =~ /primary key/
44+ index = index . with_indifferent_access
45+ if index [ :index_description ] =~ /primary key/
4546 indexes
4647 else
47- name = index [ ' index_name' ]
48- unique = index [ ' index_description' ] =~ /unique/
49- columns = index [ ' index_keys' ] . split ( ',' ) . map do |column |
48+ name = index [ : index_name]
49+ unique = index [ : index_description] =~ /unique/
50+ columns = index [ : index_keys] . split ( ',' ) . map do |column |
5051 column . strip!
5152 column . gsub! '(-)' , '' if column . ends_with? ( '(-)' )
5253 column
@@ -60,8 +61,8 @@ def columns(table_name, name = nil)
6061 return [ ] if table_name . blank?
6162 cache_key = unqualify_table_name ( table_name )
6263 @sqlserver_columns_cache [ cache_key ] ||= column_definitions ( table_name ) . collect do |ci |
63- sqlserver_options = ci . except ( ' name' , ' default_value' , ' type' , ' null' ) . merge ( ' database_year' => database_year )
64- SQLServerColumn . new ci [ ' name' ] , ci [ ' default_value' ] , ci [ ' type' ] , ci [ ' null' ] , sqlserver_options
64+ sqlserver_options = ci . except ( : name, : default_value, : type, : null) . merge ( : database_year=> database_year )
65+ SQLServerColumn . new ci [ : name] , ci [ : default_value] , ci [ : type] , ci [ : null] , sqlserver_options
6566 end
6667 end
6768
@@ -196,30 +197,31 @@ def column_definitions(table_name)
196197 } . gsub ( /[ \t \r \n ]+/ , ' ' )
197198 results = info_schema_query { select ( sql , nil ) }
198199 results . collect do |ci |
199- ci [ 'type' ] = case ci [ 'type' ]
200+ ci = ci . symbolize_keys
201+ ci [ :type ] = case ci [ :type ]
200202 when /^bit|image|text|ntext|datetime$/
201- ci [ ' type' ]
203+ ci [ : type]
202204 when /^numeric|decimal$/i
203- "#{ ci [ ' type' ] } (#{ ci [ ' numeric_precision' ] } ,#{ ci [ ' numeric_scale' ] } )"
205+ "#{ ci [ : type] } (#{ ci [ : numeric_precision] } ,#{ ci [ : numeric_scale] } )"
204206 when /^char|nchar|varchar|nvarchar|varbinary|bigint|int|smallint$/
205- ci [ ' length' ] . to_i == -1 ? "#{ ci [ ' type' ] } (max)" : "#{ ci [ ' type' ] } (#{ ci [ ' length' ] } )"
207+ ci [ : length] . to_i == -1 ? "#{ ci [ : type] } (max)" : "#{ ci [ : type] } (#{ ci [ : length] } )"
206208 else
207- ci [ ' type' ]
209+ ci [ : type]
208210 end
209- if ci [ ' default_value' ] . nil? && views . include? ( table_name )
211+ if ci [ : default_value] . nil? && views . include? ( table_name )
210212 real_table_name = table_name_or_views_table_name ( table_name )
211- real_column_name = views_real_column_name ( table_name , ci [ ' name' ] )
213+ real_column_name = views_real_column_name ( table_name , ci [ : name] )
212214 col_default_sql = "SELECT c.COLUMN_DEFAULT FROM #{ db_name_with_period } INFORMATION_SCHEMA.COLUMNS c WHERE c.TABLE_NAME = '#{ real_table_name } ' AND c.COLUMN_NAME = '#{ real_column_name } '"
213- ci [ ' default_value' ] = info_schema_query { select_value ( col_default_sql ) }
215+ ci [ : default_value] = info_schema_query { select_value ( col_default_sql ) }
214216 end
215- ci [ ' default_value' ] = case ci [ ' default_value' ]
217+ ci [ : default_value] = case ci [ : default_value]
216218 when nil , '(null)' , '(NULL)'
217219 nil
218220 else
219- match_data = ci [ ' default_value' ] . match ( /\A \( +N?'?(.*?)'?\) +\Z /m )
221+ match_data = ci [ : default_value] . match ( /\A \( +N?'?(.*?)'?\) +\Z /m )
220222 match_data ? match_data [ 1 ] : nil
221223 end
222- ci [ ' null' ] = ci [ ' is_nullable' ] . to_i == 1 ; ci . delete ( ' is_nullable' )
224+ ci [ : null] = ci [ : is_nullable] . to_i == 1 ; ci . delete ( : is_nullable)
223225 ci
224226 end
225227 end
@@ -293,8 +295,9 @@ def view_information(table_name)
293295 @sqlserver_view_information_cache [ table_name ] ||= begin
294296 view_info = info_schema_query { select_one ( "SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = '#{ table_name } '" ) }
295297 if view_info
296- if view_info [ 'VIEW_DEFINITION' ] . blank? || view_info [ 'VIEW_DEFINITION' ] . length == 4000
297- view_info [ 'VIEW_DEFINITION' ] = info_schema_query { select_values ( "EXEC sp_helptext #{ table_name } " ) . join }
298+ view_info = view_info . with_indifferent_access
299+ if view_info [ :VIEW_DEFINITION ] . blank? || view_info [ :VIEW_DEFINITION ] . length == 4000
300+ view_info [ :VIEW_DEFINITION ] = info_schema_query { select_values ( "EXEC sp_helptext #{ table_name } " ) . join }
298301 end
299302 end
300303 view_info
@@ -307,7 +310,7 @@ def table_name_or_views_table_name(table_name)
307310 end
308311
309312 def views_real_column_name ( table_name , column_name )
310- view_definition = view_information ( table_name ) [ ' VIEW_DEFINITION' ]
313+ view_definition = view_information ( table_name ) [ : VIEW_DEFINITION]
311314 match_data = view_definition . match ( /([\w -]*)\s +as\s +#{ column_name } /im )
312315 match_data ? match_data [ 1 ] : column_name
313316 end
0 commit comments