Namespace

Class/Module Index [+]

Quicksearch

JdbcSpec::Oracle

Public Class Methods

adapter_matcher(name, *) click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 34
def self.adapter_matcher(name, *)
  name =~ /oracle/ ? self : false
end
column_selector() click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 38
def self.column_selector
  [/oracle/, lambda {|cfg,col| col.extend(::JdbcSpec::Oracle::Column)}]
end
extended(mod) click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 12
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 |c|
          value = self[c.name]
          value = value.to_yaml if unserializable_attribute?(c.name, c)
          next if value.nil?  || (value == '')

          connection.write_large_object(c.type == :binary, c.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
  mod.class_eval do
    alias_chained_method :insert, :query_dirty, :jdbc_oracle_insert
  end
end

Public Instance Methods

_execute(sql, name = nil) click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 160
def _execute(sql, name = nil)
  case sql.strip
    when /\A\(?\s*(select|show)/ then
      @connection.execute_query(sql)
    else
      @connection.execute_update(sql)
    end
end
adapter_name() click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 103
def adapter_name
  'oracle'
end
add_order_by_for_association_limiting!(sql, options) click to toggle source

ORDER BY clause for the passed order option.

Uses column aliases as defined by distinct.

# File lib/jdbc_adapter/jdbc_oracle.rb, line 294
def add_order_by_for_association_limiting!(sql, options)
  return sql if options[:order].blank?

  order = options[:order].split(',').collect { |s| s.strip }.reject(&:blank?)
  order.map! {|s| $1 if s =~ / (.*)/}
  order = order.zip((0...order.size).to_a).map { |s,i| "alias_#{i}__ #{s}" }.join(', ')

  sql << "ORDER BY #{order}"
end
after_save_with_oracle_lob() click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 15
def after_save_with_oracle_lob
  self.class.columns.select { |c| c.sql_type =~ /LOB\(|LOB$/ }.each do |c|
    value = self[c.name]
    value = value.to_yaml if unserializable_attribute?(c.name, c)
    next if value.nil?  || (value == '')

    connection.write_large_object(c.type == :binary, c.name, self.class.table_name, self.class.primary_key, quote_value(id), value)
  end
end
columns(table_name, name=nil) click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 308
def columns(table_name, name=nil)
  @connection.columns_internal(table_name, name, oracle_schema)
end
distinct(columns, order_by) click to toggle source

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/jdbc_adapter/jdbc_oracle.rb, line 278
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 = order_by.split(',').map { |s| s.strip }.reject(&:blank?)
  order_columns = order_columns.zip((0...order_columns.size).to_a).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
drop_database(name) click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 137
def drop_database(name)
  recreate_database(name)
end
indexes(table, name = nil) click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 156
def indexes(table, name = nil)
  @connection.indexes(table, name, @connection.connection.meta_data.user_name)
end
modify_types(tp) click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 169
def modify_types(tp)
  tp[:primary_key] = "NUMBER(38) NOT NULL PRIMARY KEY"
  tp[:integer] = { :name => "NUMBER", :limit => 38 }
  tp[:datetime] = { :name => "DATE" }
  tp[:timestamp] = { :name => "DATE" }
  tp[:time] = { :name => "DATE" }
  tp[:date] = { :name => "DATE" }
  tp
end
quoted_date(value) click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 349
def quoted_date(value)
  %{TIMESTAMP'#{value.strftime("%Y-%m-%d %H:%M:%S")}'}
end
recreate_database(name) click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 133
def recreate_database(name)
  tables.each{ |table| drop_table(table) }
end
table_alias_length() click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 107
def table_alias_length
  30
end
tables() click to toggle source
# File lib/jdbc_adapter/jdbc_oracle.rb, line 304
def tables
  @connection.tables(nil, oracle_schema)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.