Module: ActiveRecord::ConnectionAdapters::Trino::Quoting
- Extended by:
- ActiveSupport::Concern
- Included in:
- ActiveRecord::ConnectionAdapters::TrinoAdapter
- Defined in:
- lib/active_record/connection_adapters/trino/quoting.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- QUOTED_TRUE =
"true"- QUOTED_FALSE =
"false"- QUOTED_NULL =
"NULL"- TIMESTAMP_FORMAT =
"%Y-%m-%d %H:%M:%S.%3N"- DATE_FORMAT =
"%Y-%m-%d"- NUL_BYTE =
/\x00/
Instance Method Summary collapse
-
#quote(value) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Lint/DuplicateBranch.
- #quote_column_name(name) ⇒ Object
-
#quote_string(string) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity, Lint/DuplicateBranch.
- #quote_table_name(name) ⇒ Object
- #quoted_date(value) ⇒ Object
- #quoted_false ⇒ Object
- #quoted_true ⇒ Object
Instance Method Details
#quote(value) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Lint/DuplicateBranch
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 34 def quote(value) case value when nil then QUOTED_NULL when true then QUOTED_TRUE when false then QUOTED_FALSE when BigDecimal then value.to_s("F") when Numeric then value.to_s when ::Date then "DATE '#{value.strftime(DATE_FORMAT)}'" when ::Time, ::DateTime then quote_time(value) when Symbol, String then quote_string_literal(value.to_s) else quote_string_literal(value.to_s) end end |
#quote_column_name(name) ⇒ Object
58 59 60 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 58 def quote_column_name(name) self.class.quote_column_name(name) end |
#quote_string(string) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity, Lint/DuplicateBranch
49 50 51 52 53 54 55 56 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 49 def quote_string(string) str = string.to_s if str.match?(NUL_BYTE) raise ActiveRecord::Trino::Error, "activerecord-trino-adapter: NUL byte detected in literal; refusing to quote" end str.gsub("'", "''") end |
#quote_table_name(name) ⇒ Object
62 63 64 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 62 def quote_table_name(name) self.class.quote_table_name(name) end |
#quoted_date(value) ⇒ Object
74 75 76 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 74 def quoted_date(value) value.strftime(DATE_FORMAT) end |
#quoted_false ⇒ Object
70 71 72 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 70 def quoted_false QUOTED_FALSE end |
#quoted_true ⇒ Object
66 67 68 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 66 def quoted_true QUOTED_TRUE end |