# File lib/arjdbc/oracle/adapter.rb, line 139 def self.arel2_visitors(config) { 'oracle' => Arel::Visitors::Oracle } end
# File lib/arjdbc/oracle/adapter.rb, line 37 def self.column_selector [ /oracle/, lambda { |cfg, column| column.extend(::ArJdbc::Oracle::Column) } ] end
# File lib/arjdbc/oracle/adapter.rb, line 8 def self.extended(mod) unless @@_lob_callback_added ActiveRecord::Base.class_eval do def after_save_with_oracle_lob self.class.columns.select { |c| c.sql_type =~ /LOB\(|LOB$/ }.each do |column| value = ::ArJdbc::SerializedAttributesHelper.dump_column_value(self, column) next if value.nil? || (value == '') connection.write_large_object( column.type == :binary, column.name, self.class.table_name, self.class.primary_key, quote_value(id), value ) end end end ActiveRecord::Base.after_save :after_save_with_oracle_lob @@_lob_callback_added = true end unless ActiveRecord::ConnectionAdapters::AbstractAdapter. instance_methods(false).detect { |m| m.to_s == "prefetch_primary_key?" } require 'arjdbc/jdbc/quoted_primary_key' ActiveRecord::Base.extend ArJdbc::QuotedPrimaryKeyExtension end end
# File lib/arjdbc/oracle/adapter.rb, line 145 def adapter_name ADAPTER_NAME end
ORDER BY clause for the passed order option.
Uses column aliases as defined by {distinct}.
# File lib/arjdbc/oracle/adapter.rb, line 423 def add_order_by_for_association_limiting!(sql, options) return sql if options[:order].blank? order_columns = extract_order_columns(options[:order]) do |columns| columns.map! { |s| $1 if s =~ / (.*)/ }; columns end order = order_columns.map { |s, i| "alias_#{i}__ #{s}" } # @see {#distinct} sql << "ORDER BY #{order.join(', ')}" end
# File lib/arjdbc/oracle/adapter.rb, line 11 def after_save_with_oracle_lob self.class.columns.select { |c| c.sql_type =~ /LOB\(|LOB$/ }.each do |column| value = ::ArJdbc::SerializedAttributesHelper.dump_column_value(self, column) next if value.nil? || (value == '') connection.write_large_object( column.type == :binary, column.name, self.class.table_name, self.class.primary_key, quote_value(id), value ) end end
# File lib/arjdbc/oracle/adapter.rb, line 193 def column_name_length; IDENTIFIER_LENGTH; end
# File lib/arjdbc/oracle/adapter.rb, line 305 def current_schema=(schema_owner) execute("ALTER SESSION SET current_schema=#{schema_owner}") end
SELECT DISTINCT clause for a given set of columns and a given ORDER BY clause.
Oracle requires the ORDER BY columns to be in the SELECT list for DISTINCT queries. However, with those columns included in the SELECT DISTINCT list, you won't actually get a distinct list of the column you want (presuming the column has duplicates with multiple values for the ordered-by columns. So we use the FIRST_VALUE function to get a single (first) value for each column, effectively making every row the same.
distinct("posts.id", "posts.created_at desc")
# File lib/arjdbc/oracle/adapter.rb, line 408 def distinct(columns, order_by) return "DISTINCT #{columns}" if order_by.blank? # construct a valid DISTINCT clause, ie. one that includes the ORDER BY columns, using # FIRST_VALUE such that the inclusion of these columns doesn't invalidate the DISTINCT order_columns = extract_order_columns(order_by).map do |c, i| "FIRST_VALUE(#{c.split.first}) OVER (PARTITION BY #{columns} ORDER BY #{c}) AS alias_#{i}__" end sql = "DISTINCT #{columns}, " sql << order_columns * ", " end
# File lib/arjdbc/oracle/adapter.rb, line 222 def drop_database(name) recreate_database(name) end
# File lib/arjdbc/oracle/adapter.rb, line 510 def explain(arel, binds = []) sql = "EXPLAIN PLAN FOR #{to_sql(arel)}" return if sql =~ /FROM all_/ exec_query(sql, 'EXPLAIN', binds) select_values("SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY)", 'EXPLAIN').join("\n") end
# File lib/arjdbc/oracle/adapter.rb, line 192 def index_name_length; IDENTIFIER_LENGTH; end
# File lib/arjdbc/oracle/adapter.rb, line 279 def indexes(table, name = nil) @connection.indexes(table, name, @connection.connection.meta_data.user_name) end
# File lib/arjdbc/oracle/adapter.rb, line 45 def jdbc_column_class ::ActiveRecord::ConnectionAdapters::OracleColumn end
# File lib/arjdbc/oracle/adapter.rb, line 169 def modify_types(types) super(types) NATIVE_DATABASE_TYPES.each do |key, value| types[key] = value.dup end types end
# File lib/arjdbc/oracle/adapter.rb, line 165 def native_database_types super.merge(NATIVE_DATABASE_TYPES) end
# File lib/arjdbc/oracle/adapter.rb, line 250 def next_sequence_value(sequence_name) # avoid #select or #select_one so that the sequence values aren't cached execute("SELECT #{quote_table_name(sequence_name)}.nextval id FROM dual").first['id'].to_i end
# File lib/arjdbc/oracle/adapter.rb, line 177 def prefetch_primary_key?(table_name = nil) columns(table_name).detect {|c| c.primary } if table_name end
# File lib/arjdbc/oracle/adapter.rb, line 218 def recreate_database(name, options = {}) tables.each{ |table| drop_table(table) } end
# File lib/arjdbc/oracle/adapter.rb, line 517 def select(sql, name = nil, binds = []) records = execute(sql, name, binds) for column in records column.delete('raw_rnum_') end records end
# File lib/arjdbc/oracle/adapter.rb, line 255 def sql_literal?(value) defined?(::Arel::SqlLiteral) && ::Arel::SqlLiteral === value end
maximum length of Oracle identifiers is 30
# File lib/arjdbc/oracle/adapter.rb, line 190 def table_alias_length; IDENTIFIER_LENGTH; end
Generated with the Darkfish Rdoc Generator 2.