Module: ActiveRecord::ConnectionAdapters::Trino::Quoting
- Included in:
- ActiveRecord::ConnectionAdapters::TrinoAdapter
- Defined in:
- lib/active_record/connection_adapters/trino/quoting.rb
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
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 21 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
45 46 47 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 45 def quote_column_name(name) %("#{name.to_s.gsub('"', '""')}") end |
#quote_string(string) ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity, Lint/DuplicateBranch
36 37 38 39 40 41 42 43 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 36 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
49 50 51 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 49 def quote_table_name(name) name.to_s.split(".").map { |part| quote_column_name(part) }.join(".") end |
#quoted_date(value) ⇒ Object
61 62 63 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 61 def quoted_date(value) value.strftime(DATE_FORMAT) end |
#quoted_false ⇒ Object
57 58 59 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 57 def quoted_false QUOTED_FALSE end |
#quoted_true ⇒ Object
53 54 55 |
# File 'lib/active_record/connection_adapters/trino/quoting.rb', line 53 def quoted_true QUOTED_TRUE end |