aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-01 16:01:53 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-01 16:01:53 +0000
commit631181ca18d2a21c3e72039b0c7f6c5a0b2fc05a (patch)
tree616eff996cee75f95695580660e31291038dca0d /activerecord
parent7056fc6782cba6dacccbba86cb231b58d8f5b4c8 (diff)
downloadrails-631181ca18d2a21c3e72039b0c7f6c5a0b2fc05a.tar.gz
rails-631181ca18d2a21c3e72039b0c7f6c5a0b2fc05a.tar.bz2
rails-631181ca18d2a21c3e72039b0c7f6c5a0b2fc05a.zip
Renamed the "oci" adapter to "oracle", but kept the old name as an alias (closes #4017) [schoenm@earthlink.net]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3718 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/Rakefile2
-rwxr-xr-xactiverecord/lib/active_record.rb2
-rw-r--r--activerecord/lib/active_record/connection_adapters/oracle_adapter.rb (renamed from activerecord/lib/active_record/connection_adapters/oci_adapter.rb)90
-rwxr-xr-xactiverecord/test/base_test.rb10
-rw-r--r--activerecord/test/binary_test.rb2
-rw-r--r--activerecord/test/column_alias_test.rb2
-rw-r--r--activerecord/test/connections/native_oracle/connection.rb (renamed from activerecord/test/connections/native_oci/connection.rb)16
-rw-r--r--activerecord/test/fixtures/db_definitions/create_oracle_db.sh0
-rw-r--r--activerecord/test/fixtures/db_definitions/oracle.drop.sql (renamed from activerecord/test/fixtures/db_definitions/oci.drop.sql)0
-rw-r--r--activerecord/test/fixtures/db_definitions/oracle.sql (renamed from activerecord/test/fixtures/db_definitions/oci.sql)4
-rw-r--r--activerecord/test/fixtures/db_definitions/oracle2.drop.sql (renamed from activerecord/test/fixtures/db_definitions/oci2.drop.sql)0
-rw-r--r--activerecord/test/fixtures/db_definitions/oracle2.sql (renamed from activerecord/test/fixtures/db_definitions/oci2.sql)0
-rwxr-xr-xactiverecord/test/fixtures_test.rb10
-rw-r--r--activerecord/test/migration_test.rb6
-rwxr-xr-xactiverecord/test/readonly_test.rb2
-rw-r--r--activerecord/test/synonym_test_oracle.rb (renamed from activerecord/test/synonym_test_oci.rb)0
17 files changed, 83 insertions, 65 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index ecad62c038..e24268ccb9 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Renamed the "oci" adapter to "oracle", but kept the old name as an alias #4017 [schoenm@earthlink.net]
+
* Fixed that Base.save should always return false if the save didn't succeed, including if it has halted by before_save's #1861, #2477 [DHH]
* Speed up class -> connection caching and stale connection verification. #3979 [Stefan Kaes]
diff --git a/activerecord/Rakefile b/activerecord/Rakefile
index f45c506539..e2d24472e9 100755
--- a/activerecord/Rakefile
+++ b/activerecord/Rakefile
@@ -27,7 +27,7 @@ task :default => [ :test_mysql, :test_sqlite, :test_postgresql ]
# Run the unit tests
-for adapter in %w( mysql postgresql sqlite sqlite3 firebird sqlserver sqlserver_odbc db2 oci )
+for adapter in %w( mysql postgresql sqlite sqlite3 firebird sqlserver sqlserver_odbc db2 oracle )
Rake::TestTask.new("test_#{adapter}") { |t|
t.libs << "test" << "test/connections/native_#{adapter}"
t.pattern = "test/*_test{,_#{adapter}}.rb"
diff --git a/activerecord/lib/active_record.rb b/activerecord/lib/active_record.rb
index ba306c0dfc..6acdbd968a 100755
--- a/activerecord/lib/active_record.rb
+++ b/activerecord/lib/active_record.rb
@@ -68,7 +68,7 @@ ActiveRecord::Base.class_eval do
end
unless defined?(RAILS_CONNECTION_ADAPTERS)
- RAILS_CONNECTION_ADAPTERS = %w(mysql postgresql sqlite firebird sqlserver db2 oci)
+ RAILS_CONNECTION_ADAPTERS = %w(mysql postgresql sqlite firebird sqlserver db2 oracle)
end
RAILS_CONNECTION_ADAPTERS.each do |adapter|
diff --git a/activerecord/lib/active_record/connection_adapters/oci_adapter.rb b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
index f0b2d0778a..7489fac327 100644
--- a/activerecord/lib/active_record/connection_adapters/oci_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb
@@ -1,4 +1,4 @@
-# oci_adapter.rb -- ActiveRecord adapter for Oracle 8i, 9i, 10g
+# oracle_adapter.rb -- ActiveRecord adapter for Oracle 8i, 9i, 10g
#
# Original author: Graham Jenkins
#
@@ -30,18 +30,24 @@ begin
module ActiveRecord
class Base
- def self.oci_connection(config) #:nodoc:
+ def self.oracle_connection(config) #:nodoc:
# Use OCI8AutoRecover instead of normal OCI8 driver.
- ConnectionAdapters::OCIAdapter.new OCI8AutoRecover.new(config), logger
+ ConnectionAdapters::OracleAdapter.new OCI8AutoRecover.new(config), logger
+ end
+
+ # for backwards-compatibility
+ def self.oci_connection(config) #:nodoc:
+ config[:database] = config[:host]
+ self.oracle_connection(config)
end
# Enable the id column to be bound into the sql later, by the adapter's insert method.
# This is preferable to inserting the hard-coded value here, because the insert method
# needs to know the id value explicitly.
- alias :attributes_with_quotes_pre_oci :attributes_with_quotes #:nodoc:
+ alias :attributes_with_quotes_pre_oracle :attributes_with_quotes #:nodoc:
def attributes_with_quotes(creating = true) #:nodoc:
- aq = attributes_with_quotes_pre_oci creating
- if connection.class == ConnectionAdapters::OCIAdapter
+ aq = attributes_with_quotes_pre_oracle creating
+ if connection.class == ConnectionAdapters::OracleAdapter
aq[self.class.primary_key] = ":id" if creating && aq[self.class.primary_key].nil?
end
aq
@@ -51,7 +57,7 @@ begin
# and write back the data.
after_save :write_lobs
def write_lobs() #:nodoc:
- if connection.is_a?(ConnectionAdapters::OCIAdapter)
+ if connection.is_a?(ConnectionAdapters::OracleAdapter)
self.class.columns.select { |c| c.type == :binary }.each { |c|
value = self[c.name]
next if value.nil? || (value == '')
@@ -68,7 +74,7 @@ begin
module ConnectionAdapters #:nodoc:
- class OCIColumn < Column #:nodoc:
+ class OracleColumn < Column #:nodoc:
attr_reader :sql_type
# overridden to add the concept of scale, required to differentiate
@@ -153,15 +159,15 @@ begin
# is supported in Oracle9i and later. You will need to use #finder_sql for
# has_and_belongs_to_many associations to run against Oracle8.
#
- # Options:
+ # Required parameters:
#
- # * <tt>:username</tt> -- Defaults to root
- # * <tt>:password</tt> -- Defaults to nothing
- # * <tt>:host</tt> -- Defaults to localhost
- class OCIAdapter < AbstractAdapter
+ # * <tt>:username</tt>
+ # * <tt>:password</tt>
+ # * <tt>:database</tt>
+ class OracleAdapter < AbstractAdapter
def adapter_name #:nodoc:
- 'OCI'
+ 'Oracle'
end
def supports_migrations? #:nodoc:
@@ -172,7 +178,7 @@ begin
{
:primary_key => "NUMBER(38) NOT NULL PRIMARY KEY",
:string => { :name => "VARCHAR2", :limit => 255 },
- :text => { :name => "LONG" },
+ :text => { :name => "BLOB" },
:integer => { :name => "NUMBER", :limit => 38 },
:float => { :name => "NUMBER" },
:datetime => { :name => "DATE" },
@@ -214,7 +220,8 @@ begin
end
- # CONNECTION MANAGEMENT ====================================#
+ # CONNECTION MANAGEMENT ====================================
+ #
# Returns true if the connection is active.
def active?
@@ -223,17 +230,23 @@ begin
# last known state, which isn't good enough if the connection has
# gone stale since the last use.
@connection.ping
- rescue OCIError
+ rescue OCIException
false
end
# Reconnects to the database.
def reconnect!
@connection.reset!
- rescue OCIError => e
+ rescue OCIException => e
@logger.warn "#{adapter_name} automatic reconnection failed: #{e.message}"
end
+ # Disconnects from the database.
+ def disconnect!
+ @connection.logoff rescue nil
+ @connection.active = false
+ end
+
# DATABASE STATEMENTS ======================================
#
@@ -346,16 +359,17 @@ begin
from all_tab_columns
where owner = '#{table_info.schema}'
and table_name = '#{table_info.name}'
+ order by column_id
}
select_all(table_cols, name).map do |row|
row['data_default'].sub!(/^'(.*)'\s*$/, '\1') if row['data_default']
- OCIColumn.new(
- oci_downcase(row['column_name']),
+ OracleColumn.new(
+ oracle_downcase(row['column_name']),
row['data_default'],
row['data_type'],
- row['length'],
- row['scale'],
+ row['length'].to_i,
+ row['scale'].to_i,
row['nullable'] == 'Y'
)
end
@@ -444,7 +458,7 @@ begin
def select(sql, name = nil)
cursor = log(sql, name) { @connection.exec sql }
- cols = cursor.get_col_names.map { |x| oci_downcase(x) }
+ cols = cursor.get_col_names.map { |x| oracle_downcase(x) }
rows = []
while row = cursor.fetch
@@ -476,7 +490,7 @@ begin
# I don't know anybody who does this, but we'll handle the theoretical case of a
# camelCase column name. I imagine other dbs handle this different, since there's a
# unit test that's currently failing test_oci.
- def oci_downcase(column_name)
+ def oracle_downcase(column_name)
column_name =~ /[a-z]/ ? column_name : column_name.downcase
end
@@ -500,8 +514,8 @@ begin
end
end
- # missing constant from oci8
- OCI_PTYPE_UNK = 0
+ # 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)
@@ -529,11 +543,11 @@ begin
end
- # The OCIConnectionFactory factors out the code necessary to connect and
- # configure an OCI connection.
- class OCIConnectionFactory #:nodoc:
- def new_connection(username, password, host)
- conn = OCI8.new username, password, host
+ # The OracleConnectionFactory factors out the code necessary to connect and
+ # configure an Oracle/OCI connection.
+ class OracleConnectionFactory #:nodoc:
+ def new_connection(username, password, database)
+ conn = OCI8.new username, password, database
conn.exec %q{alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS'}
conn.exec %q{alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS'} rescue nil
conn.autocommit = true
@@ -559,11 +573,11 @@ begin
end
@@auto_retry = false
- def initialize(config, factory = OCIConnectionFactory.new)
+ def initialize(config, factory = OracleConnectionFactory.new)
@active = true
- @username, @password, @host = config[:username], config[:password], config[:host]
+ @username, @password, @database = config[:username], config[:password], config[:database]
@factory = factory
- @connection = @factory.new_connection @username, @password, @host
+ @connection = @factory.new_connection @username, @password, @database
super @connection
end
@@ -582,7 +596,7 @@ begin
def reset!
logoff rescue nil
begin
- @connection = @factory.new_connection @username, @password, @host
+ @connection = @factory.new_connection @username, @password, @database
__setobj__ @connection
@active = true
rescue
@@ -605,7 +619,7 @@ begin
begin
@connection.exec(sql, *bindvars)
- rescue OCIError => e
+ rescue OCIException => e
raise unless LOST_CONNECTION_ERROR_CODES.include?(e.code)
@active = false
raise unless should_retry
@@ -621,6 +635,10 @@ rescue LoadError
# OCI8 driver is unavailable.
module ActiveRecord # :nodoc:
class Base
+ def self.oracle_connection(config) # :nodoc:
+ # Set up a reasonable error message
+ raise LoadError, "Oracle/OCI libraries could not be loaded."
+ end
def self.oci_connection(config) # :nodoc:
# Set up a reasonable error message
raise LoadError, "Oracle/OCI libraries could not be loaded."
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 4cdf24c03d..114e3cbd9e 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -17,7 +17,7 @@ class MasterCreditCard < ActiveRecord::Base; end
class Post < ActiveRecord::Base; end
class Computer < ActiveRecord::Base; end
class NonExistentTable < ActiveRecord::Base; end
-class TestOCIDefault < ActiveRecord::Base; end
+class TestOracleDefault < ActiveRecord::Base; end
class LoosePerson < ActiveRecord::Base
attr_protected :credit_rating, :administrator
@@ -526,8 +526,8 @@ class BasicsTest < Test::Unit::TestCase
# Oracle has some funky default handling, so it requires a bit of
# extra testing. See ticket #2788.
- if current_adapter?(:OCIAdapter)
- test = TestOCIDefault.new
+ if current_adapter?(:OracleAdapter)
+ test = TestOracleDefault.new
assert_equal "X", test.test_char
assert_equal "hello", test.test_string
assert_equal 3, test.test_int
@@ -536,7 +536,7 @@ class BasicsTest < Test::Unit::TestCase
def test_utc_as_time_zone
# Oracle and SQLServer do not have a TIME datatype.
- return true if current_adapter?(:SQLServerAdapter) || current_adapter?(:OCIAdapter)
+ return true if current_adapter?(:SQLServerAdapter) || current_adapter?(:OracleAdapter)
Topic.default_timezone = :utc
attributes = { "bonus_time" => "5:42:00AM" }
@@ -704,7 +704,7 @@ class BasicsTest < Test::Unit::TestCase
def test_attributes_on_dummy_time
# Oracle and SQL Server do not have a TIME datatype.
- return true if current_adapter?(:SQLServerAdapter) || current_adapter?(:OCIAdapter)
+ return true if current_adapter?(:SQLServerAdapter) || current_adapter?(:OracleAdapter)
attributes = {
"bonus_time" => "5:42:00AM"
diff --git a/activerecord/test/binary_test.rb b/activerecord/test/binary_test.rb
index 8ba758a892..e7a87a4833 100644
--- a/activerecord/test/binary_test.rb
+++ b/activerecord/test/binary_test.rb
@@ -20,7 +20,7 @@ class BinaryTest < Test::Unit::TestCase
# Without using prepared statements, it makes no sense to test
# BLOB data with DB2 or Firebird, because the length of a statement
# is limited to 32KB.
- unless %w(SQLServer DB2 OCI Firebird).include? ActiveRecord::Base.connection.adapter_name
+ unless %w(SQLServer DB2 Oracle Firebird).include? ActiveRecord::Base.connection.adapter_name
def test_load_save
bin = Binary.new
bin.data = @data
diff --git a/activerecord/test/column_alias_test.rb b/activerecord/test/column_alias_test.rb
index 729a252eef..19526cf9b3 100644
--- a/activerecord/test/column_alias_test.rb
+++ b/activerecord/test/column_alias_test.rb
@@ -4,7 +4,7 @@ require 'fixtures/topic'
class TestColumnAlias < Test::Unit::TestCase
fixtures :topics
- QUERY = if 'OCI' == ActiveRecord::Base.connection.adapter_name
+ QUERY = if 'Oracle' == ActiveRecord::Base.connection.adapter_name
'SELECT id AS pk FROM topics WHERE ROWNUM < 2'
else
'SELECT id AS pk FROM topics'
diff --git a/activerecord/test/connections/native_oci/connection.rb b/activerecord/test/connections/native_oracle/connection.rb
index 0b1babb898..095fe9d5ee 100644
--- a/activerecord/test/connections/native_oci/connection.rb
+++ b/activerecord/test/connections/native_oracle/connection.rb
@@ -1,25 +1,23 @@
-print "Using OCI Oracle\n"
+print "Using Oracle\n"
require_dependency 'fixtures/course'
require 'logger'
ActiveRecord::Base.logger = Logger.new STDOUT
ActiveRecord::Base.logger.level = Logger::WARN
-db1 = 'activerecord_unittest'
-db2 = 'activerecord_unittest2'
+# Set these to your database connection strings
+db = 'activerecord_unit_tests'
ActiveRecord::Base.establish_connection(
- :adapter => 'oci',
- :host => '', # can use an oracle SID
+ :adapter => 'oracle',
:username => 'arunit',
:password => 'arunit',
- :database => db1
+ :database => db
)
Course.establish_connection(
- :adapter => 'oci',
- :host => '', # can use an oracle SID
+ :adapter => 'oracle',
:username => 'arunit2',
:password => 'arunit2',
- :database => db2
+ :database => db
)
diff --git a/activerecord/test/fixtures/db_definitions/create_oracle_db.sh b/activerecord/test/fixtures/db_definitions/create_oracle_db.sh
deleted file mode 100644
index e69de29bb2..0000000000
--- a/activerecord/test/fixtures/db_definitions/create_oracle_db.sh
+++ /dev/null
diff --git a/activerecord/test/fixtures/db_definitions/oci.drop.sql b/activerecord/test/fixtures/db_definitions/oracle.drop.sql
index 4d4ddb835d..4d4ddb835d 100644
--- a/activerecord/test/fixtures/db_definitions/oci.drop.sql
+++ b/activerecord/test/fixtures/db_definitions/oracle.drop.sql
diff --git a/activerecord/test/fixtures/db_definitions/oci.sql b/activerecord/test/fixtures/db_definitions/oracle.sql
index 7ecbea29b0..39099b1747 100644
--- a/activerecord/test/fixtures/db_definitions/oci.sql
+++ b/activerecord/test/fixtures/db_definitions/oracle.sql
@@ -275,13 +275,13 @@ create table keyboards (
);
create sequence keyboards_seq minvalue 10000;
-create table test_oci_defaults (
+create table test_oracle_defaults (
id integer not null primary key,
test_char char(1) default 'X' not null,
test_string varchar2(20) default 'hello' not null,
test_int integer default 3 not null
);
-create sequence test_oci_defaults_seq minvalue 10000;
+create sequence test_oracle_defaults_seq minvalue 10000;
--This table has an altered lock_version column name.
create table legacy_things (
diff --git a/activerecord/test/fixtures/db_definitions/oci2.drop.sql b/activerecord/test/fixtures/db_definitions/oracle2.drop.sql
index abe7e55c31..abe7e55c31 100644
--- a/activerecord/test/fixtures/db_definitions/oci2.drop.sql
+++ b/activerecord/test/fixtures/db_definitions/oracle2.drop.sql
diff --git a/activerecord/test/fixtures/db_definitions/oci2.sql b/activerecord/test/fixtures/db_definitions/oracle2.sql
index 3c171f4f14..3c171f4f14 100644
--- a/activerecord/test/fixtures/db_definitions/oci2.sql
+++ b/activerecord/test/fixtures/db_definitions/oracle2.sql
diff --git a/activerecord/test/fixtures_test.rb b/activerecord/test/fixtures_test.rb
index a57232e315..51f7109645 100755
--- a/activerecord/test/fixtures_test.rb
+++ b/activerecord/test/fixtures_test.rb
@@ -61,7 +61,7 @@ class FixturesTest < Test::Unit::TestCase
t.column :written_on, :datetime
t.column :bonus_time, :time
t.column :last_read, :date
- t.column :content, :text
+ t.column :content, :string
t.column :approved, :boolean, :default => true
t.column :replies_count, :integer, :default => 0
t.column :parent_id, :integer
@@ -78,16 +78,16 @@ class FixturesTest < Test::Unit::TestCase
topics = create_fixtures("topics")
- # Restore prefix/suffix to its previous values
- ActiveRecord::Base.table_name_prefix = old_prefix
- ActiveRecord::Base.table_name_suffix = old_suffix
-
firstRow = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'David'")
assert_equal("The First Topic", firstRow["title"])
secondRow = ActiveRecord::Base.connection.select_one("SELECT * FROM prefix_topics_suffix WHERE author_name = 'Mary'")
assert_nil(secondRow["author_email_address"])
ensure
+ # Restore prefix/suffix to its previous values
+ ActiveRecord::Base.table_name_prefix = old_prefix
+ ActiveRecord::Base.table_name_suffix = old_suffix
+
ActiveRecord::Base.connection.drop_table :prefix_topics_suffix rescue nil
end
end
diff --git a/activerecord/test/migration_test.rb b/activerecord/test/migration_test.rb
index 8d8deb8026..4fec71d39f 100644
--- a/activerecord/test/migration_test.rb
+++ b/activerecord/test/migration_test.rb
@@ -84,7 +84,7 @@ if ActiveRecord::Base.connection.supports_migrations?
four = columns.detect { |c| c.name == "four" }
assert_equal "hello", one.default
- if current_adapter?(:OCIAdapter)
+ if current_adapter?(:OracleAdapter)
# Oracle doesn't support native booleans
assert_equal true, two.default == 1
assert_equal false, three.default != 0
@@ -153,7 +153,7 @@ if ActiveRecord::Base.connection.supports_migrations?
assert_equal Fixnum, bob.age.class
assert_equal Time, bob.birthday.class
- if current_adapter?(:SQLServerAdapter) or current_adapter?(:OCIAdapter)
+ if current_adapter?(:SQLServerAdapter) or current_adapter?(:OracleAdapter)
# SQL Server and Oracle don't differentiate between date/time
assert_equal Time, bob.favorite_day.class
else
@@ -241,7 +241,7 @@ if ActiveRecord::Base.connection.supports_migrations?
ActiveRecord::Base.connection.rename_table :octopuses, :octopi
assert_nothing_raised do
- if current_adapter?(:OCIAdapter)
+ 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')"
else
diff --git a/activerecord/test/readonly_test.rb b/activerecord/test/readonly_test.rb
index bd9b8ef1b7..55f5cbe4ca 100755
--- a/activerecord/test/readonly_test.rb
+++ b/activerecord/test/readonly_test.rb
@@ -79,7 +79,7 @@ class ReadOnlyTest < Test::Unit::TestCase
# Oracle barfs on this because the join includes unqualified and
# conflicting column names
- unless current_adapter?(:OCIAdapter)
+ unless current_adapter?(:OracleAdapter)
Post.with_scope(:find => { :joins => ', developers' }) do
assert Post.find(1).readonly?
assert Post.find(1, :readonly => true).readonly?
diff --git a/activerecord/test/synonym_test_oci.rb b/activerecord/test/synonym_test_oracle.rb
index fcfb2f3bd1..fcfb2f3bd1 100644
--- a/activerecord/test/synonym_test_oci.rb
+++ b/activerecord/test/synonym_test_oracle.rb