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
This commit is contained in:
David Heinemeier Hansson 2006-03-02 01:15:41 +00:00
parent 8fdb4bc8f6
commit 6a3f4c932a
13 changed files with 295 additions and 12 deletions

View File

@ -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]

View File

@ -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"

View File

@ -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|

View File

@ -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

View File

@ -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

View File

@ -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
)

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,4 @@
DROP TABLE courses
go

View File

@ -0,0 +1,5 @@
CREATE TABLE courses (
id int NOT NULL PRIMARY KEY,
name varchar(255) NOT NULL
)
go

View File

@ -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

View File

@ -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) }

View File

@ -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