Module: ActiveRecord::ConnectionAdapters::OracleEnhanced::Quoting
- Includes:
- JDBCQuoting, OCIQuoting
- 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
- 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
- .mixed_case?(name) ⇒ Boolean
-
.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.
Instance Method Summary collapse
- #column_name_matcher ⇒ Object
- #column_name_with_order_matcher ⇒ Object
-
#quote(value) ⇒ Object
:nodoc:.
-
#quote_column_name(name) ⇒ Object
QUOTING ==================================================.
-
#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).
-
#quote_string(s) ⇒ Object
:nodoc:.
-
#quote_table_name(name) ⇒ Object
:nodoc:.
-
#quoted_false ⇒ Object
:nodoc:.
-
#quoted_true ⇒ Object
:nodoc:.
- #type_cast(value) ⇒ Object
-
#unquoted_false ⇒ Object
:nodoc:.
-
#unquoted_true ⇒ Object
:nodoc:.
Class Method Details
.mixed_case?(name) ⇒ Boolean
63 64 65 66 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 63 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
58 59 60 61 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 58 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_matcher ⇒ Object
132 133 134 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 132 def column_name_matcher COLUMN_NAME end |
#column_name_with_order_matcher ⇒ Object
136 137 138 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 136 def column_name_with_order_matcher COLUMN_NAME_WITH_ORDER end |
#quote(value) ⇒ Object
:nodoc:
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 77 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
QUOTING ==================================================
see: abstract/quoting.rb
11 12 13 14 15 16 17 18 19 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 11 def quote_column_name(name) # :nodoc: name = name.to_s self.class.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)
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 23 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:
73 74 75 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 73 def quote_string(s) # :nodoc: s.gsub(/'/, "''") end |
#quote_table_name(name) ⇒ Object
:nodoc:
68 69 70 71 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 68 def quote_table_name(name) # :nodoc: name, _link = name.to_s.split("@") self.class.quoted_table_names[name] ||= [name.split(".").map { |n| quote_column_name(n) }].join(".") end |
#quoted_false ⇒ Object
:nodoc:
104 105 106 107 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 104 def quoted_false # :nodoc: return "'N'" if emulate_booleans_from_strings "0" end |
#quoted_true ⇒ Object
:nodoc:
94 95 96 97 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 94 def quoted_true # :nodoc: return "'Y'" if emulate_booleans_from_strings "1" end |
#type_cast(value) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 114 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_false ⇒ Object
:nodoc:
109 110 111 112 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 109 def unquoted_false # :nodoc: return "N" if emulate_booleans_from_strings "0" end |
#unquoted_true ⇒ Object
:nodoc:
99 100 101 102 |
# File 'lib/active_record/connection_adapters/oracle_enhanced/quoting.rb', line 99 def unquoted_true # :nodoc: return "Y" if emulate_booleans_from_strings "1" end |