Module: ActiveRecord::ConnectionAdapters::Duckdb::Quoting

Extended by:
ActiveSupport::Concern
Included in:
ActiveRecord::ConnectionAdapters::DuckdbAdapter
Defined in:
lib/active_record/connection_adapters/duckdb/quoting.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#quote(value) ⇒ String

Quotes a value for safe inclusion in SQL statements

Parameters:

  • value (Object)

    The value to quote

Returns:

  • (String)

    The appropriately quoted value for SQL



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/active_record/connection_adapters/duckdb/quoting.rb', line 36

def quote(value)
  case value
  when String
    "'#{value.gsub("'", "''")}'"
  when nil
    'NULL'
  when true
    'TRUE'
  when false
    'FALSE'
  when Numeric
    value.to_s
  when Time, DateTime
    "'#{value.utc.strftime("%Y-%m-%d %H:%M:%S")}'"
  when Date
    "'#{value.strftime("%Y-%m-%d")}'"
  else
    "'#{value.to_s.gsub("'", "''")}'"
  end
end

#quote_column_name(name) ⇒ String

Quotes a column name for use in SQL statements

Parameters:

  • name (String, Symbol)

    The column name to quote

Returns:

  • (String)

    The quoted column name wrapped in double quotes



29
30
31
# File 'lib/active_record/connection_adapters/duckdb/quoting.rb', line 29

def quote_column_name(name)
  %("#{name}")
end

#quote_table_name(name) ⇒ String

Quotes a table name for use in SQL statements

Parameters:

  • name (String, Symbol)

    The table name to quote

Returns:

  • (String)

    The quoted table name (delegates to quote_column_name)



22
23
24
# File 'lib/active_record/connection_adapters/duckdb/quoting.rb', line 22

def quote_table_name(name)
  quote_column_name(name)
end