Skip to content

Commit

Permalink
updated History and RDoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rsim committed Feb 24, 2010
1 parent 0815362 commit 632808a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
2 changes: 2 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
== 1.2.4 2010-02-23

* Enhancements:
* rake db:test:purge will drop all schema objects from test schema (including views, synonyms, packages, functions, procedures) -
they should be always reloaded before tests run if necessary
* added views, synonyms, packages, functions, procedures, indexes, triggers, types, primary, unique and foreign key constraints to structure dump
* added :temporary option for create_table to create temporary tables
* added :tablespace option for add_index
Expand Down
38 changes: 23 additions & 15 deletions lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def supports_savepoints? #:nodoc:
true
end

#:stopdoc:
NATIVE_DATABASE_TYPES = {
:primary_key => "NUMBER(38) NOT NULL PRIMARY KEY",
:string => { :name => "VARCHAR2", :limit => 255 },
Expand All @@ -439,6 +440,7 @@ def supports_savepoints? #:nodoc:
NATIVE_DATABASE_TYPES_BOOLEAN_STRINGS = NATIVE_DATABASE_TYPES.dup.merge(
:boolean => { :name => "VARCHAR2", :limit => 1 }
)
#:startdoc:

def native_database_types #:nodoc:
emulate_booleans_from_strings ? NATIVE_DATABASE_TYPES_BOOLEAN_STRINGS : NATIVE_DATABASE_TYPES
Expand Down Expand Up @@ -606,7 +608,8 @@ def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #
end
protected :insert_sql

AUTOGENERATED_SEQUENCE_NAME = 'autogenerated'.freeze #:nodoc:
# use in set_sequence_name to avoid fetching primary key value from sequence
AUTOGENERATED_SEQUENCE_NAME = 'autogenerated'.freeze

# Returns the next sequence value from a sequence generator. Not generally
# called directly; used by ActiveRecord to get the next primary key value
Expand Down Expand Up @@ -736,16 +739,17 @@ def lob_order_by_expression(klass, order) #:nodoc:
#
# see: abstract/schema_statements.rb

# current database name
# Current database name
def current_database
select_value("select sys_context('userenv','db_name') from dual")
end

# current database session user
# Current database session user
def current_user
select_value("select sys_context('userenv','session_user') from dual")
end

# Default tablespace name of current user
def default_tablespace
select_value("select lower(default_tablespace) from user_users where username = sys_context('userenv','session_user')")
end
Expand Down Expand Up @@ -1205,7 +1209,7 @@ def structure_dump #:nodoc:
select_all("select table_name from all_tables where owner = sys_context('userenv','session_user') order by 1").inject(s) do |structure, table|
table_name = table['table_name']
virtual_columns = virtual_columns_for(table_name)
ddl = "create#{ ' global temporary' if temporary?(table_name)} table #{table_name} (\n "
ddl = "create#{ ' global temporary' if temporary_table?(table_name)} table #{table_name} (\n "
cols = select_all(%Q{
select column_name, data_type, data_length, char_used, char_length, data_precision, data_scale, data_default, nullable
from user_tab_columns
Expand All @@ -1226,7 +1230,7 @@ def structure_dump #:nodoc:
end
end

def structure_dump_virtual_column(column, data_default)
def structure_dump_virtual_column(column, data_default) #:nodoc:
data_default = data_default.gsub(/"/, '')
col = "#{column['column_name'].downcase} #{column['data_type'].downcase}"
if column['data_type'] =='NUMBER' and !column['data_precision'].nil?
Expand All @@ -1240,7 +1244,7 @@ def structure_dump_virtual_column(column, data_default)
col << " GENERATED ALWAYS AS (#{data_default}) VIRTUAL"
end

def structure_dump_column(column)
def structure_dump_column(column) #:nodoc:
col = "#{column['column_name'].downcase} #{column['data_type'].downcase}"
if column['data_type'] =='NUMBER' and !column['data_precision'].nil?
col << "(#{column['data_precision'].to_i}"
Expand All @@ -1255,12 +1259,12 @@ def structure_dump_column(column)
col
end

def structure_dump_constraints(table)
def structure_dump_constraints(table) #:nodoc:
out = [structure_dump_primary_key(table), structure_dump_unique_keys(table)].flatten.compact
out.length > 0 ? ",\n#{out.join(",\n")}" : ''
end

def structure_dump_primary_key(table)
def structure_dump_primary_key(table) #:nodoc:
opts = {:name => '', :cols => []}
pks = select_all(<<-SQL, "Primary Keys")
select a.constraint_name, a.column_name, a.position
Expand All @@ -1278,7 +1282,7 @@ def structure_dump_primary_key(table)
opts[:cols].length > 0 ? " CONSTRAINT #{opts[:name]} PRIMARY KEY (#{opts[:cols].join(',')})" : nil
end

def structure_dump_unique_keys(table)
def structure_dump_unique_keys(table) #:nodoc:
keys = {}
uks = select_all(<<-SQL, "Primary Keys")
select a.constraint_name, a.column_name, a.position
Expand All @@ -1298,7 +1302,7 @@ def structure_dump_unique_keys(table)
end
end

def structure_dump_fk_constraints
def structure_dump_fk_constraints #:nodoc:
fks = select_all("select table_name from all_tables where owner = sys_context('userenv','session_user') order by 1").map do |table|
if respond_to?(:foreign_keys) && (foreign_keys = foreign_keys(table["table_name"])).any?
foreign_keys.map do |fk|
Expand Down Expand Up @@ -1353,7 +1357,7 @@ def structure_dump_db_stored_code #:nodoc:
structure
end

def structure_dump_indexes(table_name)
def structure_dump_indexes(table_name) #:nodoc:
statements = indexes(table_name).map do |options|
#def add_index(table_name, column_name, options = {})
column_names = options[:columns]
Expand Down Expand Up @@ -1382,14 +1386,14 @@ def structure_drop #:nodoc:
end
end

def temp_table_drop
def temp_table_drop #:nodoc:
# changed select from user_tables to all_tables - much faster in large data dictionaries
select_all("select table_name from all_tables where owner = sys_context('userenv','session_user') and temporary = 'Y' order by 1").inject('') do |drop, table|
drop << "drop table #{table.to_a.first.last} cascade constraints;\n\n"
end
end

def full_drop(preserve_tables=false)
def full_drop(preserve_tables=false) #:nodoc:
s = preserve_tables ? [] : [structure_drop]
s << temp_table_drop if preserve_tables
s << drop_sql_for_feature("view")
Expand Down Expand Up @@ -1444,10 +1448,11 @@ def distinct(columns, order_by) #:nodoc:
sql << order_columns * ", "
end

def temporary?(table_name)
def temporary_table?(table_name) #:nodoc:
select_value("select temporary from user_tables where table_name = '#{table_name.upcase}'") == 'Y'
end

# statements separator used in structure dump
STATEMENT_TOKEN = "\n\n--@@@--\n\n"

# ORDER BY clause for the passed order option.
Expand Down Expand Up @@ -1560,7 +1565,10 @@ def drop_sql_for_object(type)
# PL/SQL in Oracle uses dbms_output for logging print statements
# These methods stick that output into the Rails log so Ruby and PL/SQL
# code can can be debugged together in a single application
DBMS_OUTPUT_BUFFER_SIZE = 10000 #can be 1-1000000

# Maximum DBMS_OUTPUT buffer size
DBMS_OUTPUT_BUFFER_SIZE = 10000 # can be 1-1000000

# Turn DBMS_Output logging on
def enable_dbms_output
set_dbms_output_plsql_connection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def set_delete_method(&block)
self.custom_delete_method = block
end

def create_method_name_before_custom_methods
def create_method_name_before_custom_methods #:nodoc:
if private_method_defined?(:create_without_timestamps) && defined?(ActiveRecord::VERSION) && ActiveRecord::VERSION::STRING.to_f >= 2.3
:create_without_timestamps
elsif private_method_defined?(:create_without_callbacks)
Expand All @@ -62,7 +62,7 @@ def create_method_name_before_custom_methods
end
end

def update_method_name_before_custom_methods
def update_method_name_before_custom_methods #:nodoc:
if private_method_defined?(:update_without_dirty)
:update_without_dirty
elsif private_method_defined?(:update_without_timestamps) && defined?(ActiveRecord::VERSION) && ActiveRecord::VERSION::STRING.to_f >= 2.3
Expand All @@ -74,7 +74,7 @@ def update_method_name_before_custom_methods
end
end

def destroy_method_name_before_custom_methods
def destroy_method_name_before_custom_methods #:nodoc:
if public_method_defined?(:destroy_without_callbacks)
:destroy_without_callbacks
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class OracleEnhancedForeignKeyDefinition < Struct.new(:from_table, :to_table, :o
class OracleEnhancedSynonymDefinition < Struct.new(:name, :table_owner, :table_name, :db_link) #:nodoc:
end

class OracleEnhancedIndexDefinition < Struct.new(:table, :name, :unique, :tablespace, :columns)
class OracleEnhancedIndexDefinition < Struct.new(:table, :name, :unique, :tablespace, :columns) #:nodoc:
end

module OracleEnhancedSchemaDefinitions #:nodoc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def oracle_enhanced_table(table, stream)
tbl.print " create_table #{table.inspect}"

# addition to make temporary option work
tbl.print ", :temporary => true" if @connection.temporary?(table)
tbl.print ", :temporary => true" if @connection.temporary_table?(table)

if columns.detect { |c| c.name == pk }
if pk != 'id'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ class ::TestPost < ActiveRecord::Base
@conn.create_table :foos, :temporary => true, :id => false do |t|
t.integer :id
end
@conn.temporary?("foos").should be_true
@conn.temporary_table?("foos").should be_true
end
end
end

0 comments on commit 632808a

Please sign in to comment.