Module: ActiveRecord::ConnectionAdapters::MSSQL::Quoting
- Included in:
- ActiveRecord::ConnectionAdapters::MSSQLAdapter
- Defined in:
- lib/arjdbc/mssql/quoting.rb
Constant Summary collapse
- QUOTED_TRUE =
'1'.freeze
- QUOTED_FALSE =
'0'.freeze
Instance Method Summary collapse
- #column_name_matcher ⇒ Object
- #column_name_with_order_matcher ⇒ Object
-
#quote_default_expression(value, column) ⇒ Object
Does not quote function default values for UUID columns.
-
#quote_string(s) ⇒ Object
Quotes strings for use in SQL input.
-
#quoted_date(value) ⇒ Object
Quote date/time values for use in SQL input, includes microseconds with three digits only if the value is a Time responding to usec.
- #quoted_false ⇒ Object
- #quoted_time(value) ⇒ Object
- #quoted_true ⇒ Object
Instance Method Details
#column_name_matcher ⇒ Object
69 70 71 |
# File 'lib/arjdbc/mssql/quoting.rb', line 69 def column_name_matcher COLUMN_NAME end |
#column_name_with_order_matcher ⇒ Object
73 74 75 |
# File 'lib/arjdbc/mssql/quoting.rb', line 73 def column_name_with_order_matcher COLUMN_NAME_WITH_ORDER end |
#quote_default_expression(value, column) ⇒ Object
Does not quote function default values for UUID columns
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/arjdbc/mssql/quoting.rb', line 33 def quote_default_expression(value, column) cast_type = lookup_cast_type(column.sql_type) if cast_type.type == :uuid && value =~ /\(\)/ value elsif column.type == :datetime_basic && value.is_a?(String) # let's trust the user to set a right default value for this # legacy type something like: '2017-02-28 01:59:19.789' quote(value) else super end end |
#quote_string(s) ⇒ Object
Quotes strings for use in SQL input.
28 29 30 |
# File 'lib/arjdbc/mssql/quoting.rb', line 28 def quote_string(s) s.to_s.gsub(/\'/, "''") end |
#quoted_date(value) ⇒ Object
Quote date/time values for use in SQL input, includes microseconds with three digits only if the value is a Time responding to usec. The JDBC drivers does not work with 6 digits microseconds
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/arjdbc/mssql/quoting.rb', line 13 def quoted_date(value) if value.acts_like?(:time) value = time_with_db_timezone(value) end result = value.to_s(:db) if value.respond_to?(:usec) && value.usec > 0 "#{result}.#{sprintf("%06d", value.usec)}" else result end end |
#quoted_false ⇒ Object
50 51 52 |
# File 'lib/arjdbc/mssql/quoting.rb', line 50 def quoted_false QUOTED_FALSE end |
#quoted_time(value) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/arjdbc/mssql/quoting.rb', line 55 def quoted_time(value) if value.acts_like?(:time) tz_value = time_with_db_timezone(value) usec = value.respond_to?(:usec) ? value.usec : 0 sprintf('%02d:%02d:%02d.%06d', tz_value.hour, tz_value.min, tz_value.sec, usec) else quoted_date(value) end end |
#quoted_true ⇒ Object
46 47 48 |
# File 'lib/arjdbc/mssql/quoting.rb', line 46 def quoted_true QUOTED_TRUE end |