Module: ActiveRecord::ConnectionAdapters::SQLServer::Quoting
- Extended by:
- ActiveSupport::Concern
- Included in:
- ActiveRecord::ConnectionAdapters::SQLServerAdapter
- Defined in:
- lib/active_record/connection_adapters/sqlserver/quoting.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- QUOTED_COLUMN_NAMES =
:nodoc:
Concurrent::Map.new
- QUOTED_TABLE_NAMES =
:nodoc:
Concurrent::Map.new
Instance Method Summary collapse
- #fetch_type_metadata(sql_type, sqlserver_options = {}) ⇒ Object
- #quote(value) ⇒ Object
- #quote_default_expression(value, column) ⇒ Object
- #quote_string(s) ⇒ Object
- #quote_string_single(s) ⇒ Object
- #quote_string_single_national(s) ⇒ Object
- #quoted_date(value) ⇒ Object
- #quoted_false ⇒ Object
- #quoted_true ⇒ Object
- #type_cast(value) ⇒ Object
- #unquoted_false ⇒ Object
- #unquoted_true ⇒ Object
Instance Method Details
#fetch_type_metadata(sql_type, sqlserver_options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 54 def (sql_type, = {}) cast_type = lookup_cast_type(sql_type) simple_type = SqlTypeMetadata.new( sql_type: sql_type, type: cast_type.type, limit: cast_type.limit, precision: cast_type.precision, scale: cast_type.scale ) SQLServer::TypeMetadata.new(simple_type, **) end |
#quote(value) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 115 def quote(value) case value when Type::Binary::Data "0x#{value.hex}" when ActiveRecord::Type::SQLServer::Data value.quoted when String, ActiveSupport::Multibyte::Chars "N#{super}" else super end end |
#quote_default_expression(value, column) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 80 def quote_default_expression(value, column) cast_type = lookup_cast_type(column.sql_type) if cast_type.type == :uuid && value.is_a?(String) && value.include?('()') value else super end end |
#quote_string(s) ⇒ Object
68 69 70 |
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 68 def quote_string(s) SQLServer::Utils.quote_string(s) end |
#quote_string_single(s) ⇒ Object
72 73 74 |
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 72 def quote_string_single(s) SQLServer::Utils.quote_string_single(s) end |
#quote_string_single_national(s) ⇒ Object
76 77 78 |
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 76 def quote_string_single_national(s) SQLServer::Utils.quote_string_single_national(s) end |
#quoted_date(value) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 105 def quoted_date(value) if value.acts_like?(:time) Type::DateTime.new.serialize(value) elsif value.acts_like?(:date) Type::Date.new.serialize(value) else value end end |
#quoted_false ⇒ Object
97 98 99 |
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 97 def quoted_false '0' end |
#quoted_true ⇒ Object
89 90 91 |
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 89 def quoted_true '1' end |
#type_cast(value) ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 128 def type_cast(value) case value when ActiveRecord::Type::SQLServer::Data value.to_s else super end end |
#unquoted_false ⇒ Object
101 102 103 |
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 101 def unquoted_false 0 end |
#unquoted_true ⇒ Object
93 94 95 |
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 93 def unquoted_true 1 end |