Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Get the green light for Oracle AR unit tests (closes #4573) [Michael …

…Schoen]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4152 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 949bf2937a7e8808d2329b1e5bd5b8e2017f8181 1 parent 4cee09e
@dhh dhh authored
View
72 activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
@@ -210,15 +210,17 @@ def quote_string(string) #:nodoc:
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 @@ def indexes(table_name, name = nil) #:nodoc:
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 @@ def columns(table_name, name = nil) #:nodoc:
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 @@ def columns(table_name, name = nil) #:nodoc:
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 @@ def structure_drop #:nodoc:
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 @@ def define_a_column(i)
# 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
View
2  activerecord/test/adapter_test.rb
@@ -42,7 +42,7 @@ def test_indexes
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
View
2  activerecord/test/connections/native_oracle/connection.rb
@@ -6,7 +6,7 @@
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',
View
14 activerecord/test/migration_test.rb
@@ -257,8 +257,8 @@ def test_rename_table
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 @@ def test_create_table_with_binary_column
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
Please sign in to comment.
Something went wrong with that request. Please try again.