activerecord-jdbc-adapter-onsite 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +22 -0
- data/.travis.yml +14 -0
- data/Appraisals +16 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +45 -0
- data/History.txt +488 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +214 -0
- data/Rakefile +62 -0
- data/activerecord-jdbc-adapter.gemspec +23 -0
- data/bench/bench_attributes.rb +13 -0
- data/bench/bench_attributes_new.rb +14 -0
- data/bench/bench_create.rb +12 -0
- data/bench/bench_find_all.rb +12 -0
- data/bench/bench_find_all_mt.rb +25 -0
- data/bench/bench_model.rb +85 -0
- data/bench/bench_new.rb +12 -0
- data/bench/bench_new_valid.rb +12 -0
- data/bench/bench_valid.rb +13 -0
- data/gemfiles/rails23.gemfile +10 -0
- data/gemfiles/rails23.gemfile.lock +38 -0
- data/gemfiles/rails30.gemfile +9 -0
- data/gemfiles/rails30.gemfile.lock +33 -0
- data/gemfiles/rails31.gemfile +9 -0
- data/gemfiles/rails31.gemfile.lock +35 -0
- data/gemfiles/rails32.gemfile +9 -0
- data/gemfiles/rails32.gemfile.lock +35 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +8 -0
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
- data/lib/arel/visitors/compat.rb +13 -0
- data/lib/arel/visitors/db2.rb +17 -0
- data/lib/arel/visitors/derby.rb +32 -0
- data/lib/arel/visitors/firebird.rb +24 -0
- data/lib/arel/visitors/hsqldb.rb +26 -0
- data/lib/arel/visitors/sql_server.rb +46 -0
- data/lib/arjdbc.rb +24 -0
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/arjdbc/db2/adapter.rb +541 -0
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/arjdbc/derby/adapter.rb +358 -0
- data/lib/arjdbc/derby/connection_methods.rb +19 -0
- data/lib/arjdbc/discover.rb +92 -0
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/arjdbc/firebird/adapter.rb +140 -0
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/arjdbc/h2/adapter.rb +54 -0
- data/lib/arjdbc/h2/connection_methods.rb +13 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/arjdbc/hsqldb/adapter.rb +184 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +15 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/arjdbc/informix/adapter.rb +142 -0
- data/lib/arjdbc/informix/connection_methods.rb +11 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/arjdbc/jdbc/adapter.rb +356 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/base_ext.rb +15 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +47 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +134 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
- data/lib/arjdbc/jdbc/core_ext.rb +24 -0
- data/lib/arjdbc/jdbc/discover.rb +18 -0
- data/lib/arjdbc/jdbc/driver.rb +35 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/arjdbc/jdbc/jdbc.rake +131 -0
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +88 -0
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/arjdbc/jdbc/railtie.rb +9 -0
- data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
- data/lib/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +126 -0
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/arjdbc/mimer/adapter.rb +142 -0
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/arjdbc/mssql/adapter.rb +477 -0
- data/lib/arjdbc/mssql/connection_methods.rb +31 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +101 -0
- data/lib/arjdbc/mssql/lock_helpers.rb +72 -0
- data/lib/arjdbc/mssql/tsql_helper.rb +61 -0
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +505 -0
- data/lib/arjdbc/mysql/connection_methods.rb +28 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/arjdbc/oracle/adapter.rb +432 -0
- data/lib/arjdbc/oracle/connection_methods.rb +12 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/arjdbc/postgresql/adapter.rb +861 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +23 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/arjdbc/sqlite3/adapter.rb +389 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +35 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +46 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/USAGE +10 -0
- data/lib/generators/jdbc/jdbc_generator.rb +9 -0
- data/lib/jdbc_adapter.rb +2 -0
- data/lib/jdbc_adapter/rake_tasks.rb +3 -0
- data/lib/jdbc_adapter/version.rb +3 -0
- data/lib/pg.rb +26 -0
- data/pom.xml +57 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/compile.rake +23 -0
- data/rakelib/db.rake +39 -0
- data/rakelib/rails.rake +41 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +69 -0
- data/src/java/arjdbc/derby/DerbyModule.java +324 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +74 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +68 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +36 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1346 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +134 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +161 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +82 -0
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +126 -0
- data/test/abstract_db_create.rb +135 -0
- data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
- data/test/activerecord/jall.sh +7 -0
- data/test/activerecord/jtest.sh +3 -0
- data/test/db/db2.rb +11 -0
- data/test/db/derby.rb +12 -0
- data/test/db/h2.rb +11 -0
- data/test/db/hsqldb.rb +13 -0
- data/test/db/informix.rb +11 -0
- data/test/db/jdbc.rb +12 -0
- data/test/db/jndi_config.rb +40 -0
- data/test/db/logger.rb +3 -0
- data/test/db/mssql.rb +9 -0
- data/test/db/mysql.rb +10 -0
- data/test/db/oracle.rb +34 -0
- data/test/db/postgres.rb +18 -0
- data/test/db/sqlite3.rb +11 -0
- data/test/db2_reset_column_information_test.rb +8 -0
- data/test/db2_simple_test.rb +66 -0
- data/test/derby_migration_test.rb +68 -0
- data/test/derby_multibyte_test.rb +12 -0
- data/test/derby_reset_column_information_test.rb +8 -0
- data/test/derby_row_locking_test.rb +9 -0
- data/test/derby_simple_test.rb +139 -0
- data/test/generic_jdbc_connection_test.rb +29 -0
- data/test/h2_change_column_test.rb +68 -0
- data/test/h2_simple_test.rb +41 -0
- data/test/has_many_through.rb +79 -0
- data/test/helper.rb +108 -0
- data/test/hsqldb_simple_test.rb +6 -0
- data/test/informix_simple_test.rb +48 -0
- data/test/jdbc_common.rb +28 -0
- data/test/jndi_callbacks_test.rb +36 -0
- data/test/jndi_test.rb +25 -0
- data/test/manualTestDatabase.rb +191 -0
- data/test/models/add_not_null_column_to_table.rb +9 -0
- data/test/models/auto_id.rb +15 -0
- data/test/models/custom_pk_name.rb +14 -0
- data/test/models/data_types.rb +30 -0
- data/test/models/entry.rb +40 -0
- data/test/models/mixed_case.rb +22 -0
- data/test/models/reserved_word.rb +15 -0
- data/test/models/string_id.rb +17 -0
- data/test/models/thing.rb +16 -0
- data/test/models/validates_uniqueness_of_string.rb +19 -0
- data/test/mssql_db_create_test.rb +26 -0
- data/test/mssql_identity_insert_test.rb +19 -0
- data/test/mssql_ignore_system_views_test.rb +27 -0
- data/test/mssql_legacy_types_test.rb +58 -0
- data/test/mssql_limit_offset_test.rb +136 -0
- data/test/mssql_multibyte_test.rb +18 -0
- data/test/mssql_null_test.rb +14 -0
- data/test/mssql_reset_column_information_test.rb +8 -0
- data/test/mssql_row_locking_sql_test.rb +159 -0
- data/test/mssql_row_locking_test.rb +9 -0
- data/test/mssql_simple_test.rb +55 -0
- data/test/mysql_db_create_test.rb +27 -0
- data/test/mysql_index_length_test.rb +58 -0
- data/test/mysql_info_test.rb +123 -0
- data/test/mysql_multibyte_test.rb +10 -0
- data/test/mysql_nonstandard_primary_key_test.rb +42 -0
- data/test/mysql_reset_column_information_test.rb +8 -0
- data/test/mysql_simple_test.rb +125 -0
- data/test/oracle_reset_column_information_test.rb +8 -0
- data/test/oracle_simple_test.rb +18 -0
- data/test/oracle_specific_test.rb +83 -0
- data/test/postgres_db_create_test.rb +32 -0
- data/test/postgres_drop_db_test.rb +16 -0
- data/test/postgres_information_schema_leak_test.rb +29 -0
- data/test/postgres_mixed_case_test.rb +29 -0
- data/test/postgres_native_type_mapping_test.rb +93 -0
- data/test/postgres_nonseq_pkey_test.rb +38 -0
- data/test/postgres_reserved_test.rb +22 -0
- data/test/postgres_reset_column_information_test.rb +8 -0
- data/test/postgres_schema_search_path_test.rb +48 -0
- data/test/postgres_simple_test.rb +168 -0
- data/test/postgres_table_alias_length_test.rb +15 -0
- data/test/postgres_type_conversion_test.rb +34 -0
- data/test/row_locking.rb +90 -0
- data/test/simple.rb +731 -0
- data/test/sqlite3_reset_column_information_test.rb +8 -0
- data/test/sqlite3_simple_test.rb +316 -0
- data/test/sybase_jtds_simple_test.rb +28 -0
- data/test/sybase_reset_column_information_test.rb +8 -0
- metadata +288 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/mssql'
|
|
3
|
+
|
|
4
|
+
class MsSQLIdentityInsertTest < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
include MigrationSetup
|
|
7
|
+
|
|
8
|
+
def test_enable_identity_insert_when_necessary
|
|
9
|
+
Entry.connection.execute("INSERT INTO entries([id], [title]) VALUES (333, 'Title')")
|
|
10
|
+
Entry.connection.execute("INSERT INTO entries([title], [id]) VALUES ('Title', 344)")
|
|
11
|
+
Entry.connection.execute("INSERT INTO entries(id, title) VALUES (666, 'Title')")
|
|
12
|
+
Entry.connection.execute("INSERT INTO entries(id, title) (SELECT id+123, title FROM entries)")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_dont_enable_identity_insert_when_unnecessary
|
|
16
|
+
Entry.connection.execute("INSERT INTO entries([title]) VALUES ('[id]')")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#! /usr/bin/env jruby
|
|
2
|
+
|
|
3
|
+
require 'jdbc_common'
|
|
4
|
+
require 'db/mssql'
|
|
5
|
+
|
|
6
|
+
class IgnoreSystemViewsTest < Test::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
include MigrationSetup
|
|
9
|
+
|
|
10
|
+
def test_system_views_ignored
|
|
11
|
+
assert_equal true, table_exists?("sys.views"), %{table_exists?("sys.views")}
|
|
12
|
+
assert_equal true, table_exists?("information_schema.views"), %{table_exists?("information_schema.views")}
|
|
13
|
+
assert_equal false, table_exists?("dbo.views"), %{table_exists?("dbo.views")}
|
|
14
|
+
assert_equal false, table_exists?(:views), %{table_exists?(:views)}
|
|
15
|
+
ActiveRecord::Schema.define { suppress_messages { create_table :views } }
|
|
16
|
+
assert_equal true, table_exists?(:views), %{table_exists?(:views)}
|
|
17
|
+
ActiveRecord::Schema.define { suppress_messages { drop_table :views } }
|
|
18
|
+
assert_equal false, table_exists?(:views), %{table_exists?(:views)}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def table_exists?(*args)
|
|
24
|
+
!!ActiveRecord::Base.connection.table_exists?(*args)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/mssql'
|
|
3
|
+
|
|
4
|
+
ActiveRecord::Schema.verbose = false
|
|
5
|
+
|
|
6
|
+
class CreateArticles < ActiveRecord::Migration
|
|
7
|
+
|
|
8
|
+
def self.up
|
|
9
|
+
execute <<-SQL
|
|
10
|
+
CREATE TABLE articles (
|
|
11
|
+
[id] int NOT NULL IDENTITY(1, 1) PRIMARY KEY,
|
|
12
|
+
[title] VARCHAR(100),
|
|
13
|
+
[author] VARCHAR(60) DEFAULT 'anonymous',
|
|
14
|
+
[body] TEXT
|
|
15
|
+
)
|
|
16
|
+
SQL
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.down
|
|
20
|
+
drop_table "articles"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class Article < ActiveRecord::Base
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class MsSQLLegacyTypesTest < Test::Unit::TestCase
|
|
29
|
+
|
|
30
|
+
def setup
|
|
31
|
+
CreateArticles.up
|
|
32
|
+
@connection = ActiveRecord::Base.connection
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def teardown
|
|
36
|
+
CreateArticles.down
|
|
37
|
+
ActiveRecord::Base.clear_active_connections!
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_varchar_column
|
|
41
|
+
Article.create!(:title => "Blah blah")
|
|
42
|
+
article = Article.first
|
|
43
|
+
assert_equal("Blah blah", article.title)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
SAMPLE_TEXT = "Lorem ipsum dolor sit amet ..."
|
|
47
|
+
|
|
48
|
+
def test_text_column
|
|
49
|
+
Article.create!(:body => SAMPLE_TEXT)
|
|
50
|
+
article = Article.first
|
|
51
|
+
assert_equal(SAMPLE_TEXT, article.body)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def test_varchar_default_value
|
|
55
|
+
assert_equal("anonymous", Article.new.author)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/mssql'
|
|
3
|
+
|
|
4
|
+
ActiveRecord::Schema.verbose = false
|
|
5
|
+
|
|
6
|
+
class CreateLongShips < ActiveRecord::Migration
|
|
7
|
+
|
|
8
|
+
def self.up
|
|
9
|
+
create_table "long_ships", :force => true do |t|
|
|
10
|
+
t.string "name", :limit => 50, :null => false
|
|
11
|
+
t.integer "width", :default => 123
|
|
12
|
+
t.integer "length", :default => 456
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.down
|
|
17
|
+
drop_table "long_ships"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class LongShip < ActiveRecord::Base
|
|
23
|
+
has_many :vikings
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class CreateVikings < ActiveRecord::Migration
|
|
27
|
+
|
|
28
|
+
def self.up
|
|
29
|
+
create_table "vikings", :force => true do |t|
|
|
30
|
+
t.integer "long_ship_id", :null => false
|
|
31
|
+
t.string "name", :limit => 50, :default => "Sven"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.down
|
|
36
|
+
drop_table "vikings"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class Viking < ActiveRecord::Base
|
|
42
|
+
belongs_to :long_ship
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class CreateNoIdVikings < ActiveRecord::Migration
|
|
47
|
+
def self.up
|
|
48
|
+
create_table "no_id_vikings", :force => true do |t|
|
|
49
|
+
t.string "name", :limit => 50, :default => "Sven"
|
|
50
|
+
end
|
|
51
|
+
remove_column "no_id_vikings", "id"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.down
|
|
55
|
+
drop_table "no_id_vikings"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
class NoIdViking < ActiveRecord::Base
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class MsSQLLimitOffsetTest < Test::Unit::TestCase
|
|
65
|
+
|
|
66
|
+
def setup
|
|
67
|
+
CreateLongShips.up
|
|
68
|
+
CreateVikings.up
|
|
69
|
+
CreateNoIdVikings.up
|
|
70
|
+
@connection = ActiveRecord::Base.connection
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def teardown
|
|
74
|
+
CreateVikings.down
|
|
75
|
+
CreateLongShips.down
|
|
76
|
+
CreateNoIdVikings.down
|
|
77
|
+
ActiveRecord::Base.clear_active_connections!
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_limit_with_no_id_column_available
|
|
81
|
+
NoIdViking.create!(:name => 'Erik')
|
|
82
|
+
assert_nothing_raised(ActiveRecord::StatementInvalid) do
|
|
83
|
+
NoIdViking.find(:first)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_limit_and_offset
|
|
88
|
+
%w(one two three four five six seven eight).each do |name|
|
|
89
|
+
LongShip.create!(:name => name)
|
|
90
|
+
end
|
|
91
|
+
ship_names = LongShip.find(:all, :offset => 2, :limit => 3).map(&:name)
|
|
92
|
+
assert_equal(%w(three four five), ship_names)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def test_limit_and_offset_with_order
|
|
96
|
+
%w(one two three four five six seven eight).each do |name|
|
|
97
|
+
LongShip.create!(:name => name)
|
|
98
|
+
end
|
|
99
|
+
ship_names = LongShip.find(:all, :order => "name", :offset => 4, :limit => 2).map(&:name)
|
|
100
|
+
assert_equal(%w(seven six), ship_names)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# TODO: work out how to fix DISTINCT support without breaking :include
|
|
104
|
+
# def test_limit_and_offset_with_distinct
|
|
105
|
+
# %w(c a b a b a c d c d).each do |name|
|
|
106
|
+
# LongShip.create!(:name => name)
|
|
107
|
+
# end
|
|
108
|
+
# ship_names = LongShip.find(:all, :select => "DISTINCT name", :order => "name", :offset => 1, :limit => 2).map(&:name)
|
|
109
|
+
# assert_equal(%w(b c), ship_names)
|
|
110
|
+
# end
|
|
111
|
+
|
|
112
|
+
def test_limit_and_offset_with_include
|
|
113
|
+
skei = LongShip.create!(:name => "Skei")
|
|
114
|
+
skei.vikings.create!(:name => "Bob")
|
|
115
|
+
skei.vikings.create!(:name => "Ben")
|
|
116
|
+
skei.vikings.create!(:name => "Basil")
|
|
117
|
+
ships = Viking.find(:all, :include => :long_ship, :offset => 1, :limit => 2)
|
|
118
|
+
assert_equal(2, ships.size)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_limit_and_offset_with_include_and_order
|
|
122
|
+
|
|
123
|
+
boat1 = LongShip.create!(:name => "1-Skei")
|
|
124
|
+
boat2 = LongShip.create!(:name => "2-Skei")
|
|
125
|
+
|
|
126
|
+
boat1.vikings.create!(:name => "Adam")
|
|
127
|
+
boat2.vikings.create!(:name => "Ben")
|
|
128
|
+
boat1.vikings.create!(:name => "Carl")
|
|
129
|
+
boat2.vikings.create!(:name => "Donald")
|
|
130
|
+
|
|
131
|
+
vikings = Viking.find(:all, :include => :long_ship, :order => "long_ships.name, vikings.name", :offset => 0, :limit => 3)
|
|
132
|
+
assert_equal(["Adam", "Carl", "Ben"], vikings.map(&:name))
|
|
133
|
+
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#! /usr/bin/env jruby
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
require 'jdbc_common'
|
|
4
|
+
require 'db/mssql'
|
|
5
|
+
|
|
6
|
+
class MsSQLMultibyteTest < Test::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
include MultibyteTestMethods
|
|
9
|
+
|
|
10
|
+
def test_select_multibyte_string
|
|
11
|
+
Entry.create!(:title => 'テスト', :content => '本文')
|
|
12
|
+
entry = Entry.find(:last)
|
|
13
|
+
assert_equal "テスト", entry.title
|
|
14
|
+
assert_equal "本文", entry.content
|
|
15
|
+
assert_equal entry, Entry.find_by_title("テスト")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/mssql'
|
|
3
|
+
|
|
4
|
+
class MsSQLNullTest < Test::Unit::TestCase
|
|
5
|
+
include MigrationSetup
|
|
6
|
+
|
|
7
|
+
[nil, "NULL", "null", "(null)", "(NULL)"].each_with_index do |v, i|
|
|
8
|
+
define_method "test_null_#{i}" do
|
|
9
|
+
entry = Entry.create!(:title => v, :content => v)
|
|
10
|
+
entry = Entry.find(entry.id)
|
|
11
|
+
assert_equal [v, v], [entry.title, entry.content], "writing #{v.inspect} should read back as #{v.inspect} for both string and text columns"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#! /usr/bin/env jruby
|
|
2
|
+
|
|
3
|
+
require 'arjdbc/mssql/adapter'
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
|
|
6
|
+
# This tests ArJdbc::MsSQL#add_lock! without actually connecting to the database.
|
|
7
|
+
class MssqlRowLockingSqlTest < Test::Unit::TestCase
|
|
8
|
+
|
|
9
|
+
def test_find_all
|
|
10
|
+
add_lock_test "Appointment.find(:all)",
|
|
11
|
+
%q{SELECT * FROM appointments},
|
|
12
|
+
%q{SELECT * FROM appointments WITH(ROWLOCK,UPDLOCK)}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_find_first
|
|
16
|
+
add_lock_test "Appointment.find(:first)",
|
|
17
|
+
%q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num, appointments.* FROM appointments) AS t WHERE t._row_num BETWEEN 1 AND 1},
|
|
18
|
+
%q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num, appointments.* FROM appointments WITH(ROWLOCK,UPDLOCK) ) AS t WHERE t._row_num BETWEEN 1 AND 1}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_find_all_where
|
|
22
|
+
add_lock_test "AppointmentDetail.find(:all, :conditions => {:name => 'foo', :value => 'bar'})",
|
|
23
|
+
%q{SELECT * FROM appointment_details WHERE (appointment_details.[name] = N'foo' AND appointment_details.[value] = N'bar')},
|
|
24
|
+
%q{SELECT * FROM appointment_details WITH(ROWLOCK,UPDLOCK) WHERE (appointment_details.[name] = N'foo' AND appointment_details.[value] = N'bar')}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_find_first_where
|
|
28
|
+
add_lock_test "AppointmentDetail.find(:first, :conditions => {:name => 'foo', :value => 'bar'})",
|
|
29
|
+
%q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointment_details.id) AS _row_num, appointment_details.* FROM appointment_details WHERE (appointment_details.[name] = N'foo' AND appointment_details.[value] = N'bar')) AS t WHERE t._row_num BETWEEN 1 AND 1},
|
|
30
|
+
%q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointment_details.id) AS _row_num, appointment_details.* FROM appointment_details WITH(ROWLOCK,UPDLOCK) WHERE (appointment_details.[name] = N'foo' AND appointment_details.[value] = N'bar')) AS t WHERE t._row_num BETWEEN 1 AND 1}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_find_all_where_array
|
|
34
|
+
add_lock_test "AppointmentDetail.find(:all, :conditions => ['name = ?', 'foo'])",
|
|
35
|
+
%q{SELECT * FROM appointment_details WHERE (name = N'foo')},
|
|
36
|
+
%q{SELECT * FROM appointment_details WITH(ROWLOCK,UPDLOCK) WHERE (name = N'foo')}
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_find_first_where_array
|
|
40
|
+
add_lock_test "AppointmentDetail.find(:first, :conditions => ['name = ?', 'foo'])",
|
|
41
|
+
%q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointment_details.id) AS _row_num, appointment_details.* FROM appointment_details WHERE (name = N'foo')) AS t WHERE t._row_num BETWEEN 1 AND 1},
|
|
42
|
+
%q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointment_details.id) AS _row_num, appointment_details.* FROM appointment_details WITH(ROWLOCK,UPDLOCK) WHERE (name = N'foo')) AS t WHERE t._row_num BETWEEN 1 AND 1}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_find_all_joins
|
|
46
|
+
add_lock_test "AppointmentDetail.find(:all, :joins => :appointment)",
|
|
47
|
+
%q{SELECT appointment_details.* FROM appointment_details INNER JOIN appointments ON appointments.id = appointment_details.appointment_id},
|
|
48
|
+
%q{SELECT appointment_details.* FROM appointment_details WITH(ROWLOCK,UPDLOCK) INNER JOIN appointments WITH(ROWLOCK,UPDLOCK) ON appointments.id = appointment_details.appointment_id}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_find_first_joins
|
|
52
|
+
add_lock_test "AppointmentDetail.find(:first, :joins => :appointment)",
|
|
53
|
+
%q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointment_details.id) AS _row_num, appointment_details.* FROM appointment_details INNER JOIN appointments ON appointments.id = appointment_details.appointment_id) AS t WHERE t._row_num BETWEEN 1 AND 1},
|
|
54
|
+
%q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointment_details.id) AS _row_num, appointment_details.* FROM appointment_details WITH(ROWLOCK,UPDLOCK) INNER JOIN appointments WITH(ROWLOCK,UPDLOCK) ON appointments.id = appointment_details.appointment_id) AS t WHERE t._row_num BETWEEN 1 AND 1}
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_find_all_2joins
|
|
58
|
+
add_lock_test "Appointment.find(:all, :joins => [:appointment_details, :appointment_hl7s])",
|
|
59
|
+
%q{SELECT appointments.* FROM appointments INNER JOIN appointment_details ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s ON appointment_hl7s.appointment_id = appointments.id},
|
|
60
|
+
%q{SELECT appointments.* FROM appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN appointment_details WITH(ROWLOCK,UPDLOCK) ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s WITH(ROWLOCK,UPDLOCK) ON appointment_hl7s.appointment_id = appointments.id}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_find_first_2joins
|
|
64
|
+
add_lock_test "Appointment.find(:first, :joins => [:appointment_details, :appointment_hl7s])",
|
|
65
|
+
%q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num, appointments.* FROM appointments INNER JOIN appointment_details ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s ON appointment_hl7s.appointment_id = appointments.id) AS t WHERE t._row_num BETWEEN 1 AND 1},
|
|
66
|
+
%q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num, appointments.* FROM appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN appointment_details WITH(ROWLOCK,UPDLOCK) ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s WITH(ROWLOCK,UPDLOCK) ON appointment_hl7s.appointment_id = appointments.id) AS t WHERE t._row_num BETWEEN 1 AND 1}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_find_all_2joins_where
|
|
70
|
+
add_lock_test "Appointment.find(:all, :joins => [:appointment_details, :appointment_hl7s], :conditions => {'appointment_details.name' => 'foo'})",
|
|
71
|
+
%q{SELECT appointments.* FROM appointments INNER JOIN appointment_details ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s ON appointment_hl7s.appointment_id = appointments.id WHERE (appointment_details.[name] = N'foo')},
|
|
72
|
+
%q{SELECT appointments.* FROM appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN appointment_details WITH(ROWLOCK,UPDLOCK) ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s WITH(ROWLOCK,UPDLOCK) ON appointment_hl7s.appointment_id = appointments.id WHERE (appointment_details.[name] = N'foo')}
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_find_first_2joins_where
|
|
76
|
+
add_lock_test "Appointment.find(:first, :joins => [:appointment_details, :appointment_hl7s], :conditions => {'appointment_details.name' => 'foo'})",
|
|
77
|
+
%q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num, appointments.* FROM appointments INNER JOIN appointment_details ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s ON appointment_hl7s.appointment_id = appointments.id WHERE (appointment_details.[name] = N'foo')) AS t WHERE t._row_num BETWEEN 1 AND 1},
|
|
78
|
+
%q{SELECT t.* FROM (SELECT ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num, appointments.* FROM appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN appointment_details WITH(ROWLOCK,UPDLOCK) ON appointment_details.appointment_id = appointments.id INNER JOIN appointment_hl7s WITH(ROWLOCK,UPDLOCK) ON appointment_hl7s.appointment_id = appointments.id WHERE (appointment_details.[name] = N'foo')) AS t WHERE t._row_num BETWEEN 1 AND 1}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_custom_join_ar097
|
|
82
|
+
add_lock_test "custom join (arjdbc 0.9.7)",
|
|
83
|
+
%q{
|
|
84
|
+
SELECT t.* FROM (
|
|
85
|
+
SELECT
|
|
86
|
+
ROW_NUMBER() OVER(ORDER BY appointments.id) AS row_num,
|
|
87
|
+
appointments.*
|
|
88
|
+
FROM
|
|
89
|
+
appointments INNER JOIN
|
|
90
|
+
appointment_details AS d1 ON appointments.[id] = d1.[appointment_id]
|
|
91
|
+
WHERE (d1.[name] = N'appointment_identifier' AND d1.[value] = N'279955^MQ')
|
|
92
|
+
) AS t WHERE t.row_num BETWEEN 1 AND 1
|
|
93
|
+
}, %q{
|
|
94
|
+
SELECT t.* FROM (
|
|
95
|
+
SELECT
|
|
96
|
+
ROW_NUMBER() OVER(ORDER BY appointments.id) AS row_num,
|
|
97
|
+
appointments.*
|
|
98
|
+
FROM
|
|
99
|
+
appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN
|
|
100
|
+
appointment_details AS d1 WITH(ROWLOCK,UPDLOCK) ON appointments.[id] = d1.[appointment_id]
|
|
101
|
+
WHERE (d1.[name] = N'appointment_identifier' AND d1.[value] = N'279955^MQ')
|
|
102
|
+
) AS t WHERE t.row_num BETWEEN 1 AND 1
|
|
103
|
+
}
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_custom_join_ar111
|
|
107
|
+
add_lock_test "custom join (arjdbc 1.1.1)",
|
|
108
|
+
%q{
|
|
109
|
+
SELECT t.*
|
|
110
|
+
FROM
|
|
111
|
+
(
|
|
112
|
+
SELECT
|
|
113
|
+
ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num,
|
|
114
|
+
appointments.*
|
|
115
|
+
FROM
|
|
116
|
+
appointments INNER JOIN
|
|
117
|
+
appointment_details AS d1 ON appointments.[id] = d1.[appointment_id]
|
|
118
|
+
WHERE
|
|
119
|
+
(d1.[name] = N'appointment_identifier' AND d1.[value] = N'389727^MQ')
|
|
120
|
+
) AS t
|
|
121
|
+
WHERE
|
|
122
|
+
t._row_num BETWEEN 1 AND 1
|
|
123
|
+
}, %q{
|
|
124
|
+
SELECT t.*
|
|
125
|
+
FROM
|
|
126
|
+
(
|
|
127
|
+
SELECT
|
|
128
|
+
ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num,
|
|
129
|
+
appointments.*
|
|
130
|
+
FROM
|
|
131
|
+
appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN
|
|
132
|
+
appointment_details AS d1 WITH(ROWLOCK,UPDLOCK) ON appointments.[id] = d1.[appointment_id]
|
|
133
|
+
WHERE
|
|
134
|
+
(d1.[name] = N'appointment_identifier' AND d1.[value] = N'389727^MQ')
|
|
135
|
+
) AS t
|
|
136
|
+
WHERE
|
|
137
|
+
t._row_num BETWEEN 1 AND 1
|
|
138
|
+
}
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
private
|
|
143
|
+
|
|
144
|
+
class Dummy
|
|
145
|
+
include ::ArJdbc::MsSQL::LockHelpers::SqlServerAddLock
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def add_lock!(sql, options={})
|
|
149
|
+
result = sql.dup
|
|
150
|
+
Dummy.new.add_lock!(result, {:lock=>true}.merge(options))
|
|
151
|
+
result
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def add_lock_test(message, before, after, options={})
|
|
155
|
+
before = before.gsub(/\s*\n\s*/m, " ").strip
|
|
156
|
+
after = after.gsub(/\s*\n\s*/m, " ").strip
|
|
157
|
+
assert_equal after, add_lock!(before, options).strip, message
|
|
158
|
+
end
|
|
159
|
+
end
|