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

Extended by:
ActiveSupport::Concern
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

Defined Under Namespace

Modules: ClassMethods

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)


104
105
106
107
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 104

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)


99
100
101
102
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 99

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

#quote(value) ⇒ Object

:nodoc:



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 113

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_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)



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 64

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:



109
110
111
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 109

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

#quoted_falseObject

:nodoc:



140
141
142
143
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 140

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

#quoted_trueObject

:nodoc:



130
131
132
133
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 130

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

#type_cast(value) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 150

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:



145
146
147
148
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 145

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

#unquoted_trueObject

:nodoc:



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

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