Module: ActiveRecord::ConnectionAdapters::Sqlserver::Quoting

Included in:
ActiveRecord::ConnectionAdapters::SQLServerAdapter
Defined in:
lib/active_record/connection_adapters/sqlserver/quoting.rb

Instance Method Summary collapse

Instance Method Details

#quote(value, column = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 8

def quote(value, column = nil)
  case value
  when String, ActiveSupport::Multibyte::Chars
    if column && column.type == :binary
      column.class.string_to_binary(value)
    elsif value.is_utf8? || (column && column.type == :string)
      "N'#{quote_string(value)}'"
    else
      super
    end
  else
    super
  end
end

#quote_column_name(name) ⇒ Object



27
28
29
30
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 27

def quote_column_name(name)
  @sqlserver_quoted_column_and_table_names[name] ||= 
    name.to_s.split('.').map{ |n| n =~ /^\[.*\]$/ ? n : "[#{n}]" }.join('.')
end

#quote_string(string) ⇒ Object



23
24
25
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 23

def quote_string(string)
  string.to_s.gsub(/\'/, "''")
end

#quote_table_name(name) ⇒ Object



32
33
34
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 32

def quote_table_name(name)
  quote_column_name(name)
end

#quoted_date(value) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 44

def quoted_date(value)
  if value.acts_like?(:time) && value.respond_to?(:usec)
    "#{super}.#{sprintf("%03d",value.usec/1000)}"
  else
    super
  end
end

#quoted_falseObject



40
41
42
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 40

def quoted_false
  QUOTED_FALSE
end

#quoted_trueObject



36
37
38
# File 'lib/active_record/connection_adapters/sqlserver/quoting.rb', line 36

def quoted_true
  QUOTED_TRUE
end