@@ -68,15 +68,15 @@ def columns(table_name)
68
68
return [ ] if table_name . blank?
69
69
70
70
column_definitions ( table_name ) . map do |ci |
71
- sqlserver_options = ci . slice :ordinal_position , :is_primary , :is_identity , :table_name
72
- sql_type_metadata = fetch_type_metadata ci [ : type] , sqlserver_options
71
+ sqlserver_options = ci . slice ( :ordinal_position , :is_primary , :is_identity , :table_name )
72
+ sql_type_metadata = fetch_type_metadata ( ci [ ' type' ] , sqlserver_options )
73
73
new_column (
74
- ci [ : name] ,
75
- ci [ : default_value] ,
74
+ ci [ ' name' ] ,
75
+ ci [ ' default_value' ] ,
76
76
sql_type_metadata ,
77
- ci [ : null] ,
78
- ci [ : default_function] ,
79
- ci [ : collation] ,
77
+ ci [ ' null' ] ,
78
+ ci [ ' default_function' ] ,
79
+ ci [ ' collation' ] ,
80
80
nil ,
81
81
sqlserver_options
82
82
)
@@ -480,16 +480,16 @@ def initialize_native_database_types
480
480
end
481
481
482
482
def column_definitions ( table_name )
483
- identifier = database_prefix_identifier ( table_name )
484
- database = identifier . fully_qualified_database_quoted
483
+ identifier = database_prefix_identifier ( table_name )
484
+ database = identifier . fully_qualified_database_quoted
485
485
view_exists = view_exists? ( table_name )
486
- view_tblnm = view_table_name ( table_name ) if view_exists
486
+ view_table_name = view_table_name ( table_name ) if view_exists
487
487
488
488
if view_exists
489
489
sql = <<~SQL
490
490
SELECT LOWER(c.COLUMN_NAME) AS [name], c.COLUMN_DEFAULT AS [default]
491
491
FROM #{ database } .INFORMATION_SCHEMA.COLUMNS c
492
- WHERE c.TABLE_NAME = #{ quote ( view_tblnm ) }
492
+ WHERE c.TABLE_NAME = #{ quote ( view_table_name ) }
493
493
SQL
494
494
results = internal_exec_query ( sql , "SCHEMA" )
495
495
default_functions = results . each . with_object ( { } ) { |row , out | out [ row [ "name" ] ] = row [ "default" ] } . compact
@@ -504,30 +504,29 @@ def column_definitions(table_name)
504
504
results = internal_exec_query ( sql , "SCHEMA" , binds )
505
505
506
506
columns = results . map do |ci |
507
- ci = ci . to_h . symbolize_keys
508
- ci [ :_type ] = ci [ :type ]
509
- ci [ :table_name ] = view_tblnm || table_name
510
- ci [ :type ] = case ci [ :type ]
507
+ ci [ '_type' ] = ci [ 'type' ]
508
+ ci [ 'table_name' ] = view_table_name || table_name
509
+ ci [ 'type' ] = case ci [ 'type' ]
511
510
when /^bit|image|text|ntext|datetime$/
512
- ci [ : type]
511
+ ci [ ' type' ]
513
512
when /^datetime2|datetimeoffset$/i
514
- "#{ ci [ : type] } (#{ ci [ : datetime_precision] } )"
513
+ "#{ ci [ ' type' ] } (#{ ci [ ' datetime_precision' ] } )"
515
514
when /^time$/i
516
- "#{ ci [ : type] } (#{ ci [ : datetime_precision] } )"
515
+ "#{ ci [ ' type' ] } (#{ ci [ ' datetime_precision' ] } )"
517
516
when /^numeric|decimal$/i
518
- "#{ ci [ : type] } (#{ ci [ : numeric_precision] } ,#{ ci [ : numeric_scale] } )"
517
+ "#{ ci [ ' type' ] } (#{ ci [ ' numeric_precision' ] } ,#{ ci [ ' numeric_scale' ] } )"
519
518
when /^float|real$/i
520
- "#{ ci [ : type] } "
519
+ "#{ ci [ ' type' ] } "
521
520
when /^char|nchar|varchar|nvarchar|binary|varbinary|bigint|int|smallint$/
522
- ci [ : length] . to_i == -1 ? "#{ ci [ : type] } (max)" : "#{ ci [ : type] } (#{ ci [ : length] } )"
521
+ ci [ ' length' ] . to_i == -1 ? "#{ ci [ ' type' ] } (max)" : "#{ ci [ ' type' ] } (#{ ci [ ' length' ] } )"
523
522
else
524
- ci [ : type]
523
+ ci [ ' type' ]
525
524
end
526
- ci [ : default_value] ,
527
- ci [ : default_function] = begin
528
- default = ci [ : default_value]
525
+ ci [ ' default_value' ] ,
526
+ ci [ ' default_function' ] = begin
527
+ default = ci [ ' default_value' ]
529
528
if default . nil? && view_exists
530
- view_column = views_real_column_name ( table_name , ci [ : name] ) . downcase
529
+ view_column = views_real_column_name ( table_name , ci [ ' name' ] ) . downcase
531
530
default = default_functions [ view_column ] if view_column . present?
532
531
end
533
532
case default
@@ -542,19 +541,19 @@ def column_definitions(table_name)
542
541
when /CREATE DEFAULT/mi
543
542
[ nil , nil ]
544
543
else
545
- type = case ci [ : type]
546
- when /smallint|int|bigint/ then ci [ : _type]
547
- else ci [ : type]
544
+ type = case ci [ ' type' ]
545
+ when /smallint|int|bigint/ then ci [ ' _type' ]
546
+ else ci [ ' type' ]
548
547
end
549
548
value = default . match ( /\A \( (.*)\) \Z /m ) [ 1 ]
550
549
value = select_value ( "SELECT CAST(#{ value } AS #{ type } ) AS value" , "SCHEMA" )
551
550
[ value , nil ]
552
551
end
553
552
end
554
- ci [ : null] = ci [ : is_nullable] . to_i == 1
553
+ ci [ ' null' ] = ci [ ' is_nullable' ] . to_i == 1
555
554
ci . delete ( :is_nullable )
556
- ci [ : is_primary] = ci [ : is_primary] . to_i == 1
557
- ci [ : is_identity] = ci [ : is_identity] . to_i == 1 unless [ TrueClass , FalseClass ] . include? ( ci [ : is_identity] . class )
555
+ ci [ ' is_primary' ] = ci [ ' is_primary' ] . to_i == 1
556
+ ci [ ' is_identity' ] = ci [ ' is_identity' ] . to_i == 1 unless [ TrueClass , FalseClass ] . include? ( ci [ ' is_identity' ] . class )
558
557
ci
559
558
end
560
559
@@ -706,21 +705,20 @@ def view_table_name(table_name)
706
705
707
706
def view_information ( table_name )
708
707
@view_information ||= { }
708
+
709
709
@view_information [ table_name ] ||= begin
710
710
identifier = SQLServer ::Utils . extract_identifiers ( table_name )
711
711
information_query_table = identifier . database . present? ? "[#{ identifier . database } ].[INFORMATION_SCHEMA].[VIEWS]" : "[INFORMATION_SCHEMA].[VIEWS]"
712
- view_info = select_one "SELECT * FROM #{ information_query_table } WITH (NOLOCK) WHERE TABLE_NAME = #{ quote ( identifier . object ) } " , "SCHEMA"
713
-
714
- if view_info
715
- view_info = view_info . to_h . with_indifferent_access
716
- if view_info [ :VIEW_DEFINITION ] . blank? || view_info [ :VIEW_DEFINITION ] . length == 4000
717
- view_info [ :VIEW_DEFINITION ] = begin
718
- select_values ( "EXEC sp_helptext #{ identifier . object_quoted } " , "SCHEMA" ) . join
719
- rescue
720
- warn "No view definition found, possible permissions problem.\n Please run GRANT VIEW DEFINITION TO your_user;"
721
- nil
722
- end
723
- end
712
+
713
+ view_info = select_one ( "SELECT * FROM #{ information_query_table } WITH (NOLOCK) WHERE TABLE_NAME = #{ quote ( identifier . object ) } " , "SCHEMA" )
714
+
715
+ if view_info && view_info [ 'VIEW_DEFINITION' ] . blank? || view_info [ 'VIEW_DEFINITION' ] . length == 4000
716
+ view_info [ 'VIEW_DEFINITION' ] = begin
717
+ select_values ( "EXEC sp_helptext #{ identifier . object_quoted } " , "SCHEMA" ) . join
718
+ rescue
719
+ warn "No view definition found, possible permissions problem.\n Please run GRANT VIEW DEFINITION TO your_user;"
720
+ nil
721
+ end
724
722
end
725
723
726
724
view_info
0 commit comments