aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/connection_adapters/oracle_adapter.rb72
-rw-r--r--activerecord/test/adapter_test.rb2
-rw-r--r--activerecord/test/connections/native_oracle/connection.rb2
-rw-r--r--activerecord/test/migration_test.rb14
4 files changed, 48 insertions, 42 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
index 421573d130..f12b02fca3 100644
--- a/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
@@ -210,15 +210,17 @@ begin
end
def quote(value, column = nil) #:nodoc:
- if column && column.type == :binary then %Q{empty_#{ column.sql_type }()}
- else case value
- when String then %Q{'#{quote_string(value)}'}
- when NilClass then 'null'
- when TrueClass then '1'
- when FalseClass then '0'
- when Numeric then value.to_s
- when Date, Time then %Q{'#{value.strftime("%Y-%m-%d %H:%M:%S")}'}
- else %Q{'#{quote_string(value.to_yaml)}'}
+ if column && column.type == :binary
+ %Q{empty_#{ column.sql_type rescue 'blob' }()}
+ else
+ case value
+ when String : %Q{'#{quote_string(value)}'}
+ when NilClass : 'null'
+ when TrueClass : '1'
+ when FalseClass : '0'
+ when Numeric : value.to_s
+ when Date, Time : %Q{'#{value.strftime("%Y-%m-%d %H:%M:%S")}'}
+ else %Q{'#{quote_string(value.to_yaml)}'}
end
end
end
@@ -356,7 +358,7 @@ begin
end
def columns(table_name, name = nil) #:nodoc:
- table_info = @connection.object_info(table_name)
+ (owner, table_name) = @connection.describe(table_name)
table_cols = %Q{
select column_name, data_type, data_default, nullable,
@@ -365,13 +367,16 @@ begin
null) as length,
decode(data_type, 'NUMBER', data_scale, null) as scale
from all_tab_columns
- where owner = '#{table_info.schema}'
- and table_name = '#{table_info.name}'
+ where owner = '#{owner}'
+ and table_name = '#{table_name}'
order by column_id
}
select_all(table_cols, name).map do |row|
- row['data_default'].sub!(/^'(.*)'\s*$/, '\1') if row['data_default']
+ if row['data_default']
+ row['data_default'].sub!(/^(.*?)\s*$/, '\1')
+ row['data_default'].sub!(/^'(.*)'$/, '\1')
+ end
OracleColumn.new(
oracle_downcase(row['column_name']),
row['data_default'],
@@ -385,7 +390,7 @@ begin
def create_table(name, options = {}) #:nodoc:
super(name, options)
- execute "CREATE SEQUENCE #{name}_seq" unless options[:id] == false
+ execute "CREATE SEQUENCE #{name}_seq START WITH 10000" unless options[:id] == false
end
def rename_table(name, new_name) #:nodoc:
@@ -465,7 +470,7 @@ begin
private
def select(sql, name = nil)
- cursor = log(sql, name) { @connection.exec sql }
+ cursor = execute(sql, name)
cols = cursor.get_col_names.map { |x| oracle_downcase(x) }
rows = []
@@ -531,30 +536,27 @@ begin
# missing constant from oci8 < 0.1.14
OCI_PTYPE_UNK = 0 unless defined?(OCI_PTYPE_UNK)
- def object_info(name)
- OraObject.new describe(name.to_s, OCI_PTYPE_UNK)
- end
-
- def describe(name, type)
+ # Uses the describeAny OCI call to find the target owner and table_name
+ # indicated by +name+, parsing through synonynms as necessary. Returns
+ # an array of [owner, table_name].
+ def describe(name)
@desc ||= @@env.alloc(OCIDescribe)
@desc.attrSet(OCI_ATTR_DESC_PUBLIC, -1) if VERSION >= '0.1.14'
- @desc.describeAny(@svc, name, type)
- @desc.attrGet(OCI_ATTR_PARAM)
- end
-
- class OraObject #:nodoc:
- attr_reader :schema, :name
- def initialize(info)
- case info.attrGet(OCI_ATTR_PTYPE)
- when OCI_PTYPE_TABLE, OCI_PTYPE_VIEW
- @schema = info.attrGet(OCI_ATTR_OBJ_SCHEMA)
- @name = info.attrGet(OCI_ATTR_OBJ_NAME)
- when OCI_PTYPE_SYN
- @schema = info.attrGet(OCI_ATTR_SCHEMA_NAME)
- @name = info.attrGet(OCI_ATTR_NAME)
- end
+ @desc.describeAny(@svc, name.to_s, OCI_PTYPE_UNK)
+ info = @desc.attrGet(OCI_ATTR_PARAM)
+
+ case info.attrGet(OCI_ATTR_PTYPE)
+ when OCI_PTYPE_TABLE, OCI_PTYPE_VIEW
+ owner = info.attrGet(OCI_ATTR_OBJ_SCHEMA)
+ table_name = info.attrGet(OCI_ATTR_OBJ_NAME)
+ [owner, table_name]
+ when OCI_PTYPE_SYN
+ schema = info.attrGet(OCI_ATTR_SCHEMA_NAME)
+ name = info.attrGet(OCI_ATTR_NAME)
+ describe(schema + '.' + name)
end
end
+
end
diff --git a/activerecord/test/adapter_test.rb b/activerecord/test/adapter_test.rb
index 772dd0e5a8..c4027b31cb 100644
--- a/activerecord/test/adapter_test.rb
+++ b/activerecord/test/adapter_test.rb
@@ -42,7 +42,7 @@ class AdapterTest < Test::Unit::TestCase
def test_current_database
if @connection.respond_to?(:current_database)
- assert_equal "activerecord_unittest", @connection.current_database
+ assert_equal ENV['ARUNIT_DB_NAME'] || "activerecord_unittest", @connection.current_database
end
end
diff --git a/activerecord/test/connections/native_oracle/connection.rb b/activerecord/test/connections/native_oracle/connection.rb
index 095fe9d5ee..b0d9696a70 100644
--- a/activerecord/test/connections/native_oracle/connection.rb
+++ b/activerecord/test/connections/native_oracle/connection.rb
@@ -6,7 +6,7 @@ ActiveRecord::Base.logger = Logger.new STDOUT
ActiveRecord::Base.logger.level = Logger::WARN
# Set these to your database connection strings
-db = 'activerecord_unit_tests'
+db = ENV['ARUNIT_DB'] || 'activerecord_unittest'
ActiveRecord::Base.establish_connection(
:adapter => 'oracle',
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb
index cbcc29fdec..7c19b07447 100644
--- a/activerecord/test/migration_test.rb
+++ b/activerecord/test/migration_test.rb
@@ -257,8 +257,8 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_nothing_raised do
if current_adapter?(:OracleAdapter)
- # Oracle requires the explicit sequence for the pk
- ActiveRecord::Base.connection.execute "INSERT INTO octopi (id, url) VALUES (octopi_seq.nextval, 'http://www.foreverflying.com/octopus-black7.jpg')"
+ # Oracle requires the explicit sequence value for the pk
+ ActiveRecord::Base.connection.execute "INSERT INTO octopi (id, url) VALUES (1, 'http://www.foreverflying.com/octopus-black7.jpg')"
else
ActiveRecord::Base.connection.execute "INSERT INTO octopi (url) VALUES ('http://www.foreverflying.com/octopus-black7.jpg')"
end
@@ -466,9 +466,13 @@ if ActiveRecord::Base.connection.supports_migrations?
columns = Person.connection.columns(:binary_testings)
data_column = columns.detect { |c| c.name == "data" }
-
- assert_equal "", data_column.default
-
+
+ if current_adapter?(:OracleAdapter)
+ assert_equal "empty_blob()", data_column.default
+ else
+ assert_equal "", data_column.default
+ end
+
Person.connection.drop_table :binary_testings rescue nil
end