Module: ODBCAdapter::Quoting
- Included in:
- ActiveRecord::ConnectionAdapters::ODBCAdapter
- Defined in:
- lib/odbc_adapter/quoting.rb
Instance Method Summary collapse
-
#quote_column_name(name) ⇒ Object
Returns a quoted form of the column name.
-
#quote_string(string) ⇒ Object
Quotes a string, escaping any ‘ (single quote) characters.
-
#quoted_date(value) ⇒ Object
Ideally, we’d return an ODBC date or timestamp literal escape sequence, but not all ODBC drivers support them.
Instance Method Details
#quote_column_name(name) ⇒ Object
Returns a quoted form of the column name.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/odbc_adapter/quoting.rb', line 9 def quote_column_name(name) name = name.to_s quote_char = dbms.field_for(ODBC::SQL_IDENTIFIER_QUOTE_CHAR).to_s.strip return name if quote_char.length.zero? quote_char = quote_char[0] # Avoid quoting any already quoted name return name if name[0] == quote_char && name[-1] == quote_char # If DBMS's SQL_IDENTIFIER_CASE = SQL_IC_UPPER, only quote mixed # case names. if dbms.field_for(ODBC::SQL_IDENTIFIER_CASE) == ODBC::SQL_IC_UPPER return name unless (name =~ /([A-Z]+[a-z])|([a-z]+[A-Z])/) end "#{quote_char.chr}#{name}#{quote_char.chr}" end |
#quote_string(string) ⇒ Object
Quotes a string, escaping any ‘ (single quote) characters.
4 5 6 |
# File 'lib/odbc_adapter/quoting.rb', line 4 def quote_string(string) string.gsub(/\'/, "''") end |
#quoted_date(value) ⇒ Object
Ideally, we’d return an ODBC date or timestamp literal escape sequence, but not all ODBC drivers support them.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/odbc_adapter/quoting.rb', line 30 def quoted_date(value) if value.acts_like?(:time) zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal if value.respond_to?(zone_conversion_method) value = value.send(zone_conversion_method) end value.strftime("%Y-%m-%d %H:%M:%S") # Time, DateTime else value.strftime("%Y-%m-%d") # Date end end |