aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-02 01:15:41 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-02 01:15:41 +0000
commit6a3f4c932a50eff696f4e8cb646249afaf8f47a1 (patch)
treeb6da4fa60a5aa9530198acf4714ead02f513b30d /activerecord
parent8fdb4bc8f61391be185c1e65e37e83535f680a8c (diff)
downloadrails-6a3f4c932a50eff696f4e8cb646249afaf8f47a1.tar.gz
rails-6a3f4c932a50eff696f4e8cb646249afaf8f47a1.tar.bz2
rails-6a3f4c932a50eff696f4e8cb646249afaf8f47a1.zip
Added Sybase database adapter that relies on the Sybase Open Client bindings (see http://raa.ruby-lang.org/project/sybase-ctlib) (closes #3765) [John Sheets]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3734 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG7
-rwxr-xr-xactiverecord/Rakefile2
-rwxr-xr-xactiverecord/lib/active_record.rb2
-rwxr-xr-xactiverecord/test/abstract_unit.rb2
-rwxr-xr-xactiverecord/test/base_test.rb18
-rw-r--r--activerecord/test/connections/native_sybase/connection.rb24
-rw-r--r--activerecord/test/fixtures/db_definitions/sybase.drop.sql31
-rw-r--r--activerecord/test/fixtures/db_definitions/sybase.sql204
-rw-r--r--activerecord/test/fixtures/db_definitions/sybase2.drop.sql4
-rw-r--r--activerecord/test/fixtures/db_definitions/sybase2.sql5
-rw-r--r--activerecord/test/fixtures/mixin.rb2
-rwxr-xr-xactiverecord/test/inheritance_test.rb4
-rw-r--r--activerecord/test/mixin_nested_set_test.rb2
13 files changed, 295 insertions, 12 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index a5e581b878..0a27f18262 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,12 @@
*SVN*
+* Added Sybase database adapter that relies on the Sybase Open Client bindings (see http://raa.ruby-lang.org/project/sybase-ctlib) #3765 [John Sheets]. It's almost completely Active Record compliant, but has the following caveats:
+
+ * Does not support DATE SQL column types; use DATETIME instead.
+ * Date columns on HABTM join tables are returned as String, not Time.
+ * Insertions are potentially broken for :polymorphic join tables
+ * BLOB column access not yet fully supported
+
* Clear stale, cached connections left behind by defunct threads. [Jeremy Kemper]
* CHANGED DEFAULT: set ActiveRecord::Base.allow_concurrency to false. Most AR usage is in single-threaded applications. [Jeremy Kemper]
diff --git a/activerecord/Rakefile b/activerecord/Rakefile
index e2d24472e9..e07ebd445c 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 oracle )
+for adapter in %w( mysql postgresql sqlite sqlite3 firebird sqlserver sqlserver_odbc db2 oracle sybase )
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 6acdbd968a..c0c81b335d 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 oracle)
+ RAILS_CONNECTION_ADAPTERS = %w(mysql postgresql sqlite firebird sqlserver db2 oracle sybase)
end
RAILS_CONNECTION_ADAPTERS.each do |adapter|
diff --git a/activerecord/test/abstract_unit.rb b/activerecord/test/abstract_unit.rb
index 498f19b32f..1bd2f6baaf 100755
--- a/activerecord/test/abstract_unit.rb
+++ b/activerecord/test/abstract_unit.rb
@@ -23,7 +23,7 @@ class Test::Unit::TestCase #:nodoc:
# SQL Server doesn't have a separate column type just for dates,
# so the time is in the string and incorrectly formatted
- if current_adapter?(:SQLServerAdapter)
+ if current_adapter?(:SQLServerAdapter) || current_adapter?(:SybaseAdapter)
assert_equal expected.strftime("%Y/%m/%d 00:00:00"), actual.strftime("%Y/%m/%d 00:00:00")
else
assert_equal expected.to_s, actual.to_s, message
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 114e3cbd9e..a84e0ed5e8 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -284,10 +284,18 @@ class BasicsTest < Test::Unit::TestCase
# SQL Server doesn't have a separate column type just for dates, so all are returned as time
return true if current_adapter?(:SQLServerAdapter)
- assert_kind_of(
- Date, Topic.find(1).last_read,
- "The last_read attribute should be of the Date class"
- )
+ if current_adapter?(:SybaseAdapter)
+ # Sybase ctlib does not (yet?) support the date type; use datetime instead.
+ assert_kind_of(
+ Time, Topic.find(1).last_read,
+ "The last_read attribute should be of the Time class"
+ )
+ else
+ assert_kind_of(
+ Date, Topic.find(1).last_read,
+ "The last_read attribute should be of the Date class"
+ )
+ end
end
def test_preserving_time_objects
@@ -445,7 +453,7 @@ class BasicsTest < Test::Unit::TestCase
assert_equal 2, Topic.update_all("content = 'bulk updated!'")
assert_equal "bulk updated!", Topic.find(1).content
assert_equal "bulk updated!", Topic.find(2).content
- assert_equal 2, Topic.update_all(['content = ?', 'bulk updated again!']);
+ assert_equal 2, Topic.update_all(['content = ?', 'bulk updated again!'])
assert_equal "bulk updated again!", Topic.find(1).content
assert_equal "bulk updated again!", Topic.find(2).content
end
diff --git a/activerecord/test/connections/native_sybase/connection.rb b/activerecord/test/connections/native_sybase/connection.rb
new file mode 100644
index 0000000000..a3ecf85326
--- /dev/null
+++ b/activerecord/test/connections/native_sybase/connection.rb
@@ -0,0 +1,24 @@
+print "Using native Sybase Open Client\n"
+require_dependency 'fixtures/course'
+require 'logger'
+
+ActiveRecord::Base.logger = Logger.new("debug.log")
+
+db1 = 'activerecord_unittest'
+db2 = 'activerecord_unittest2'
+
+ActiveRecord::Base.establish_connection(
+ :adapter => "sybase",
+ :host => "database_ASE",
+ :username => "sa",
+ :password => "",
+ :database => db1
+)
+
+Course.establish_connection(
+ :adapter => "sybase",
+ :host => "database_ASE",
+ :username => "sa",
+ :password => "",
+ :database => db2
+)
diff --git a/activerecord/test/fixtures/db_definitions/sybase.drop.sql b/activerecord/test/fixtures/db_definitions/sybase.drop.sql
new file mode 100644
index 0000000000..f843a80f7a
--- /dev/null
+++ b/activerecord/test/fixtures/db_definitions/sybase.drop.sql
@@ -0,0 +1,31 @@
+DROP TABLE accounts
+DROP TABLE funny_jokes
+DROP TABLE companies
+DROP TABLE topics
+DROP TABLE developers
+DROP TABLE projects
+DROP TABLE developers_projects
+DROP TABLE customers
+DROP TABLE orders
+DROP TABLE movies
+DROP TABLE subscribers
+DROP TABLE booleantests
+DROP TABLE auto_id_tests
+DROP TABLE entrants
+DROP TABLE colnametests
+DROP TABLE mixins
+DROP TABLE people
+DROP TABLE readers
+DROP TABLE binaries
+DROP TABLE computers
+DROP TABLE tasks
+DROP TABLE posts
+DROP TABLE comments
+DROP TABLE authors
+DROP TABLE categories
+DROP TABLE categories_posts
+DROP TABLE fk_test_has_fk
+DROP TABLE fk_test_has_pk
+DROP TABLE keyboards
+DROP TABLE legacy_things
+go
diff --git a/activerecord/test/fixtures/db_definitions/sybase.sql b/activerecord/test/fixtures/db_definitions/sybase.sql
new file mode 100644
index 0000000000..28164d8a14
--- /dev/null
+++ b/activerecord/test/fixtures/db_definitions/sybase.sql
@@ -0,0 +1,204 @@
+CREATE TABLE accounts (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ firm_id int NULL,
+ credit_limit int NULL
+)
+
+CREATE TABLE funny_jokes (
+id numeric(9,0) IDENTITY PRIMARY KEY,
+ name varchar(50) NULL
+)
+
+CREATE TABLE companies (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ type varchar(50) NULL,
+ ruby_type varchar(50) NULL,
+ firm_id int NULL,
+ name varchar(50) NULL,
+ client_of int NULL,
+ rating int default 1
+)
+
+
+CREATE TABLE topics (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ title varchar(255) NULL,
+ author_name varchar(255) NULL,
+ author_email_address varchar(255) NULL,
+ written_on datetime NULL,
+ bonus_time time NULL,
+ last_read datetime NULL,
+ content varchar(255) NULL,
+ approved tinyint default 1 NULL,
+ replies_count int default 0 NULL,
+ parent_id int NULL,
+ type varchar(50) NULL
+)
+
+CREATE TABLE developers (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ name varchar(100) NULL,
+ salary int default 70000,
+ created_at datetime NULL,
+ updated_at datetime NULL
+)
+
+CREATE TABLE projects (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ name varchar(100) NULL,
+ type VARCHAR(255) NULL
+)
+
+CREATE TABLE developers_projects (
+ developer_id int NOT NULL,
+ project_id int NOT NULL,
+ joined_on datetime NULL,
+ access_level smallint default 1
+)
+
+CREATE TABLE orders (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ name varchar(100) NULL,
+ billing_customer_id int NULL,
+ shipping_customer_id int NULL
+)
+
+CREATE TABLE customers (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ name varchar(100) NULL,
+ balance int default 0,
+ address_street varchar(100) NULL,
+ address_city varchar(100) NULL,
+ address_country varchar(100) NULL,
+ gps_location varchar(100) NULL
+)
+
+CREATE TABLE movies (
+ movieid numeric(9,0) IDENTITY PRIMARY KEY,
+ name varchar(100) NULL
+)
+
+CREATE TABLE subscribers (
+ nick varchar(100) PRIMARY KEY,
+ name varchar(100) NULL
+)
+
+CREATE TABLE booleantests (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ value integer NULL
+)
+
+CREATE TABLE auto_id_tests (
+ auto_id numeric(9,0) IDENTITY PRIMARY KEY,
+ value integer NULL
+)
+
+CREATE TABLE entrants (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ name VARCHAR(255) NOT NULL,
+ course_id INTEGER NOT NULL
+)
+
+CREATE TABLE colnametests (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ [references] int NOT NULL
+)
+
+CREATE TABLE mixins (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ parent_id int NULL,
+ pos int NULL,
+ created_at datetime NULL,
+ updated_at datetime NULL,
+ lft int NULL,
+ rgt int NULL,
+ root_id int NULL,
+ type varchar(40) NULL
+)
+
+CREATE TABLE people (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ first_name VARCHAR(40) NOT NULL,
+ lock_version INTEGER DEFAULT 0
+)
+
+CREATE TABLE readers (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ post_id int NOT NULL,
+ person_id int NOT NULL
+)
+
+CREATE TABLE binaries (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ data image NULL
+)
+
+CREATE TABLE computers (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ developer INTEGER NOT NULL,
+ extendedWarranty INTEGER NOT NULL
+)
+
+CREATE TABLE posts (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ author_id INTEGER NULL,
+ title VARCHAR(255) NOT NULL,
+ body VARCHAR(2048) NOT NULL,
+ type VARCHAR(255) NOT NULL
+)
+
+CREATE TABLE comments (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ post_id INTEGER NOT NULL,
+ body VARCHAR(2048) NOT NULL,
+ type VARCHAR(255) NOT NULL
+)
+
+CREATE TABLE authors (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ name VARCHAR(255) NOT NULL
+)
+
+CREATE TABLE tasks (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ starting datetime NULL,
+ ending datetime NULL
+)
+
+CREATE TABLE categories (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ name VARCHAR(255) NOT NULL,
+ type VARCHAR(255) NOT NULL
+)
+
+CREATE TABLE categories_posts (
+ category_id int NOT NULL,
+ post_id int NOT NULL
+)
+
+CREATE TABLE fk_test_has_pk (
+ id numeric(9,0) IDENTITY PRIMARY KEY
+)
+
+CREATE TABLE fk_test_has_fk (
+ id numeric(9,0) PRIMARY KEY,
+ fk_id numeric(9,0) NOT NULL,
+
+ FOREIGN KEY (fk_id) REFERENCES fk_test_has_pk(id)
+)
+
+
+CREATE TABLE keyboards (
+ key_number numeric(9,0) IDENTITY PRIMARY KEY,
+ name varchar(50) NULL
+)
+
+--This table has an altered lock_version column name.
+CREATE TABLE legacy_things (
+ id numeric(9,0) IDENTITY PRIMARY KEY,
+ tps_report_number int default NULL,
+ version int default 0,
+)
+
+go
+
diff --git a/activerecord/test/fixtures/db_definitions/sybase2.drop.sql b/activerecord/test/fixtures/db_definitions/sybase2.drop.sql
new file mode 100644
index 0000000000..f4ce96fec0
--- /dev/null
+++ b/activerecord/test/fixtures/db_definitions/sybase2.drop.sql
@@ -0,0 +1,4 @@
+DROP TABLE courses
+go
+
+
diff --git a/activerecord/test/fixtures/db_definitions/sybase2.sql b/activerecord/test/fixtures/db_definitions/sybase2.sql
new file mode 100644
index 0000000000..88f9d329a3
--- /dev/null
+++ b/activerecord/test/fixtures/db_definitions/sybase2.sql
@@ -0,0 +1,5 @@
+CREATE TABLE courses (
+ id int NOT NULL PRIMARY KEY,
+ name varchar(255) NOT NULL
+)
+go
diff --git a/activerecord/test/fixtures/mixin.rb b/activerecord/test/fixtures/mixin.rb
index 0411c0d87e..78cdbef9b3 100644
--- a/activerecord/test/fixtures/mixin.rb
+++ b/activerecord/test/fixtures/mixin.rb
@@ -30,7 +30,7 @@ class ListWithStringScopeMixin < ActiveRecord::Base
end
class NestedSet < Mixin
- acts_as_nested_set :scope => "ROOT_ID IS NULL"
+ acts_as_nested_set :scope => "root_id IS NULL"
def self.table_name() "mixins" end
end
diff --git a/activerecord/test/inheritance_test.rb b/activerecord/test/inheritance_test.rb
index d726583126..211f739752 100755
--- a/activerecord/test/inheritance_test.rb
+++ b/activerecord/test/inheritance_test.rb
@@ -8,13 +8,13 @@ class InheritanceTest < Test::Unit::TestCase
def test_a_bad_type_column
#SQLServer need to turn Identity Insert On before manually inserting into the Identity column
- if current_adapter?(:SQLServerAdapter)
+ if current_adapter?(:SQLServerAdapter) || current_adapter?(:SybaseAdapter)
Company.connection.execute "SET IDENTITY_INSERT companies ON"
end
Company.connection.insert "INSERT INTO companies (id, #{QUOTED_TYPE}, name) VALUES(100, 'bad_class!', 'Not happening')"
#We then need to turn it back Off before continuing.
- if current_adapter?(:SQLServerAdapter)
+ if current_adapter?(:SQLServerAdapter) || current_adapter?(:SybaseAdapter)
Company.connection.execute "SET IDENTITY_INSERT companies OFF"
end
assert_raises(ActiveRecord::SubclassNotFound) { Company.find(100) }
diff --git a/activerecord/test/mixin_nested_set_test.rb b/activerecord/test/mixin_nested_set_test.rb
index c52dabd6b9..8764a6ac49 100644
--- a/activerecord/test/mixin_nested_set_test.rb
+++ b/activerecord/test/mixin_nested_set_test.rb
@@ -9,7 +9,7 @@ class MixinNestedSetTest < Test::Unit::TestCase
def test_mixing_in_methods
ns = NestedSet.new
assert( ns.respond_to?( :all_children ) )
- assert_equal( ns.scope_condition, "ROOT_ID IS NULL" )
+ assert_equal( ns.scope_condition, "root_id IS NULL" )
check_method_mixins ns
end