Module: DataTaster::SqlLiteral

Defined in:
lib/data_taster/sql_literal.rb

Overview

Necessary to format Ruby values (the non sanitized values) for use as MySQL INSERT literal fragments

Constant Summary collapse

BINARY_COLUMN_TYPE =
/\A(?:tiny|medium|long)?blob|varbinary|binary|bit|geometry/i
TEXT_COLUMN_TYPE =
/\Ajson|(?:var)?char|(?:tiny|medium|long)?text|enum|set/i

Class Method Summary collapse

Class Method Details

.format(client, value, column_type: nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/data_taster/sql_literal.rb', line 12

def self.format(client, value, column_type: nil)
  case value
  when String
    format_string_value(client, value, column_type: column_type)
  when nil, true, false, Integer, Float, BigDecimal
    format_scalar(value)
  when Time, DateTime, Date
    format_temporal(client, value)
  else
    "'#{client.escape(value.to_s)}'"
  end
end