Module: ActiveRecord::ConnectionAdapters::OracleEnhanced::Quoting

Includes:
JDBCQuoting, OCIQuoting
Included in:
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
Defined in:
lib/active_record/connection_adapters/oracle_enhanced/quoting.rb,
lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb,
lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb

Constant Summary collapse

QUOTED_COLUMN_NAMES =

QUOTING ==================================================

see: abstract/quoting.rb

Concurrent::Map.new
QUOTED_TABLE_NAMES =

:nodoc:

Concurrent::Map.new
NONQUOTED_OBJECT_NAME =

Names must be from 1 to 30 bytes long with these exceptions:

  • Names of databases are limited to 8 bytes.

  • Names of database links can be as long as 128 bytes.

Nonquoted identifiers cannot be Oracle Database reserved words

Nonquoted identifiers must begin with an alphabetic character from your database character set

Nonquoted identifiers can contain only alphanumeric characters from your database character set and the underscore (_), dollar sign ($), and pound sign (#). Oracle strongly discourages you from using $ and # in nonquoted identifiers.

/[[:alpha:]][\w$#]{0,29}/
VALID_TABLE_NAME =
/\A(?:#{NONQUOTED_OBJECT_NAME}\.)?#{NONQUOTED_OBJECT_NAME}?\Z/

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.mixed_case?(name) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 65

def self.mixed_case?(name)
  object_name = name.include?(".") ? name.split(".").second : name
  !!(object_name =~ /[A-Z]/ && object_name =~ /[a-z]/)
end

.valid_table_name?(name) ⇒ Boolean

unescaped table name should start with letter and contain letters, digits, _, $ or # can be prefixed with schema name CamelCase table names should be quoted

Returns:

  • (Boolean)


60
61
62
63
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 60

def self.valid_table_name?(name) # :nodoc:
  object_name = name.to_s
  !!(object_name =~ VALID_TABLE_NAME && !mixed_case?(object_name))
end

Instance Method Details

#column_name_matcherObject



134
135
136
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 134

def column_name_matcher
  COLUMN_NAME
end

#column_name_with_order_matcherObject



138
139
140
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 138

def column_name_with_order_matcher
  COLUMN_NAME_WITH_ORDER
end

#quote(value) ⇒ Object

:nodoc:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 79

def quote(value) # :nodoc:
  case value
  when Type::OracleEnhanced::CharacterString::Data then
    "'#{quote_string(value.to_s)}'"
  when Type::OracleEnhanced::NationalCharacterString::Data then
    +"N" << "'#{quote_string(value.to_s)}'"
  when ActiveModel::Type::Binary::Data then
    "empty_blob()"
  when Type::OracleEnhanced::Text::Data then
    "empty_clob()"
  when Type::OracleEnhanced::NationalCharacterText::Data then
    "empty_nclob()"
  else
    super
  end
end

#quote_column_name(name) ⇒ Object

:nodoc:



13
14
15
16
17
18
19
20
21
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 13

def quote_column_name(name) # :nodoc:
  name = name.to_s
  QUOTED_COLUMN_NAMES[name] ||= if /\A[a-z][a-z_0-9$#]*\Z/.match?(name)
    "\"#{name.upcase}\""
  else
    # remove double quotes which cannot be used inside quoted identifier
    "\"#{name.delete('"')}\""
  end
end

#quote_column_name_or_expression(name) ⇒ Object

This method is used in add_index to identify either column name (which is quoted) or function based index (in which case function expression is not quoted)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 25

def quote_column_name_or_expression(name) # :nodoc:
  name = name.to_s
  case name
  # if only valid lowercase column characters in name
  when /^[a-z][a-z_0-9$#]*$/
    "\"#{name.upcase}\""
  when /^[a-z][a-z_0-9$#-]*$/i
    "\"#{name}\""
  # if other characters present then assume that it is expression
  # which should not be quoted
  else
    name
  end
end

#quote_string(s) ⇒ Object

:nodoc:



75
76
77
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 75

def quote_string(s) # :nodoc:
  s.gsub(/'/, "''")
end

#quote_table_name(name) ⇒ Object

:nodoc:



70
71
72
73
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 70

def quote_table_name(name) # :nodoc:
  name, _link = name.to_s.split("@")
  QUOTED_TABLE_NAMES[name] ||= [name.split(".").map { |n| quote_column_name(n) }].join(".")
end

#quoted_falseObject

:nodoc:



106
107
108
109
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 106

def quoted_false # :nodoc:
  return "'N'" if emulate_booleans_from_strings
  "0"
end

#quoted_trueObject

:nodoc:



96
97
98
99
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 96

def quoted_true # :nodoc:
  return "'Y'" if emulate_booleans_from_strings
  "1"
end

#type_cast(value) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 116

def type_cast(value)
  case value
  when Type::OracleEnhanced::TimestampTz::Data, Type::OracleEnhanced::TimestampLtz::Data
    if value.acts_like?(:time)
      zone_conversion_method = ActiveRecord.default_timezone == :utc ? :getutc : :getlocal
      value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
    else
      value
    end
  when Type::OracleEnhanced::NationalCharacterString::Data
    value.to_s
  when Type::OracleEnhanced::CharacterString::Data
    value
  else
    super
  end
end

#unquoted_falseObject

:nodoc:



111
112
113
114
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 111

def unquoted_false # :nodoc:
  return "N" if emulate_booleans_from_strings
  "0"
end

#unquoted_trueObject

:nodoc:



101
102
103
104
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 101

def unquoted_true # :nodoc:
  return "Y" if emulate_booleans_from_strings
  "1"
end