Module: ActiveRecord::ConnectionAdapters::Rdb::Quoting
- Included in:
- ActiveRecord::ConnectionAdapters::RdbAdapter
- Defined in:
- lib/active_record/connection_adapters/rdb/quoting.rb
Overview
:nodoc:
Constant Summary collapse
- QUOTED_FALSE =
"'false'".freeze
- QUOTED_TRUE =
"'true'".freeze
- QUOTED_POSITION =
'"POSITION"'.freeze
- QUOTED_VALUE =
'"VALUE"'.freeze
Instance Method Summary collapse
-
#lookup_cast_type_from_column(column) ⇒ Object
:nodoc:.
-
#quote_column_name(column_name) ⇒ Object
:nodoc:.
-
#quote_string(string) ⇒ Object
:nodoc:.
- #quote_table_name_for_assignment(_table, attr) ⇒ Object
- #quoted_date(time) ⇒ Object
-
#quoted_false ⇒ Object
:nodoc:.
-
#quoted_true ⇒ Object
:nodoc:.
-
#type_cast_from_column(column, value) ⇒ Object
:nodoc:.
-
#type_casted_binds(binds) ⇒ Object
:nodoc:.
- #unquoted_false ⇒ Object
- #unquoted_true ⇒ Object
Instance Method Details
#lookup_cast_type_from_column(column) ⇒ Object
:nodoc:
65 66 67 68 |
# File 'lib/active_record/connection_adapters/rdb/quoting.rb', line 65 def lookup_cast_type_from_column(column) # :nodoc: type = column.try(:sql_type) || column.try(:type) lookup_cast_type(type) end |
#quote_column_name(column_name) ⇒ Object
:nodoc:
23 24 25 26 27 28 29 30 |
# File 'lib/active_record/connection_adapters/rdb/quoting.rb', line 23 def quote_column_name(column_name) # :nodoc: column = column_name.dup.to_s column.gsub!(/(?<=[^"\w]|^)position(?=[^"\w]|$)/i, QUOTED_POSITION) column.gsub!(/(?<=[^"\w]|^)value(?=[^"\w]|$)/i, QUOTED_VALUE) column.delete!('"') column.upcase! @connection.dialect == 1 ? column.to_s : %("#{column}") end |
#quote_string(string) ⇒ Object
:nodoc:
11 12 13 |
# File 'lib/active_record/connection_adapters/rdb/quoting.rb', line 11 def quote_string(string) # :nodoc: string.gsub(/'/, "''") end |
#quote_table_name_for_assignment(_table, attr) ⇒ Object
32 33 34 |
# File 'lib/active_record/connection_adapters/rdb/quoting.rb', line 32 def quote_table_name_for_assignment(_table, attr) quote_column_name(attr) end |
#quoted_date(time) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/active_record/connection_adapters/rdb/quoting.rb', line 15 def quoted_date(time) if time.is_a?(Time) || time.is_a?(DateTime) time.localtime.strftime('%d.%m.%Y %H:%M:%S') else time.strftime('%d.%m.%Y') end end |
#quoted_false ⇒ Object
:nodoc:
48 49 50 |
# File 'lib/active_record/connection_adapters/rdb/quoting.rb', line 48 def quoted_false # :nodoc: QUOTED_FALSE end |
#quoted_true ⇒ Object
:nodoc:
40 41 42 |
# File 'lib/active_record/connection_adapters/rdb/quoting.rb', line 40 def quoted_true # :nodoc: QUOTED_TRUE end |
#type_cast_from_column(column, value) ⇒ Object
:nodoc:
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/active_record/connection_adapters/rdb/quoting.rb', line 52 def type_cast_from_column(column, value) # :nodoc: if column type = column.type || lookup_cast_type_from_column(column) if type.is_a?(ActiveRecord::Type::Serialized) value else type.serialize(value) end else value end end |
#type_casted_binds(binds) ⇒ Object
:nodoc:
70 71 72 73 74 75 76 |
# File 'lib/active_record/connection_adapters/rdb/quoting.rb', line 70 def type_casted_binds(binds) # :nodoc: if binds.first.is_a?(Array) binds.map { |column, value| type_cast(value, column) } else binds.map { |attr| type_cast(attr.value_for_database, attr) } end end |
#unquoted_false ⇒ Object
44 45 46 |
# File 'lib/active_record/connection_adapters/rdb/quoting.rb', line 44 def unquoted_false false end |
#unquoted_true ⇒ Object
36 37 38 |
# File 'lib/active_record/connection_adapters/rdb/quoting.rb', line 36 def unquoted_true true end |