activerecord-jdbc-adapter 1.3.0.beta2 → 1.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -8
- data/.travis.yml +40 -31
- data/.yardopts +4 -0
- data/Appraisals +2 -5
- data/CONTRIBUTING.md +46 -0
- data/Gemfile +21 -4
- data/Gemfile.lock +42 -17
- data/{History.txt → History.md} +142 -75
- data/README.md +102 -104
- data/RUNNING_TESTS.md +76 -0
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +35 -18
- data/gemfiles/rails23.gemfile +4 -3
- data/gemfiles/rails23.gemfile.lock +9 -6
- data/gemfiles/rails30.gemfile +4 -3
- data/gemfiles/rails30.gemfile.lock +9 -6
- data/gemfiles/rails31.gemfile +4 -3
- data/gemfiles/rails31.gemfile.lock +9 -6
- data/gemfiles/rails32.gemfile +4 -3
- data/gemfiles/rails32.gemfile.lock +17 -14
- data/gemfiles/rails40.gemfile +5 -5
- data/gemfiles/rails40.gemfile.lock +17 -69
- data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/arel/visitors/compat.rb +22 -3
- data/lib/arel/visitors/db2.rb +8 -4
- data/lib/arel/visitors/derby.rb +14 -13
- data/lib/arel/visitors/firebird.rb +5 -4
- data/lib/arel/visitors/hsqldb.rb +11 -9
- data/lib/arel/visitors/sql_server.rb +89 -61
- data/lib/arjdbc.rb +1 -1
- data/lib/arjdbc/db2/adapter.rb +181 -212
- data/lib/arjdbc/db2/as400.rb +31 -18
- data/lib/arjdbc/db2/column.rb +167 -0
- data/lib/arjdbc/db2/connection_methods.rb +2 -0
- data/lib/arjdbc/derby/adapter.rb +206 -107
- data/lib/arjdbc/derby/connection_methods.rb +4 -9
- data/lib/arjdbc/firebird.rb +1 -0
- data/lib/arjdbc/firebird/adapter.rb +202 -64
- data/lib/arjdbc/firebird/connection_methods.rb +20 -0
- data/lib/arjdbc/h2/adapter.rb +56 -36
- data/lib/arjdbc/hsqldb/adapter.rb +99 -68
- data/lib/arjdbc/jdbc/adapter.rb +474 -265
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +8 -7
- data/lib/arjdbc/jdbc/arel_support.rb +132 -0
- data/lib/arjdbc/jdbc/base_ext.rb +8 -7
- data/lib/arjdbc/jdbc/callbacks.rb +16 -10
- data/lib/arjdbc/jdbc/column.rb +25 -3
- data/lib/arjdbc/jdbc/connection.rb +28 -55
- data/lib/arjdbc/jdbc/extension.rb +14 -14
- data/lib/arjdbc/jdbc/java.rb +6 -3
- data/lib/arjdbc/jdbc/jdbc.rake +1 -1
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +2 -2
- data/lib/arjdbc/jdbc/rake_tasks.rb +1 -1
- data/lib/arjdbc/jdbc/type_converter.rb +5 -2
- data/lib/arjdbc/mssql/adapter.rb +160 -280
- data/lib/arjdbc/mssql/column.rb +182 -0
- data/lib/arjdbc/mssql/connection_methods.rb +37 -4
- data/lib/arjdbc/mssql/explain_support.rb +13 -21
- data/lib/arjdbc/mssql/limit_helpers.rb +79 -42
- data/lib/arjdbc/mssql/lock_methods.rb +77 -0
- data/lib/arjdbc/mssql/utils.rb +11 -11
- data/lib/arjdbc/mysql/adapter.rb +165 -247
- data/lib/arjdbc/mysql/column.rb +123 -0
- data/lib/arjdbc/mysql/connection_methods.rb +3 -6
- data/lib/arjdbc/oracle/adapter.rb +282 -288
- data/lib/arjdbc/oracle/column.rb +122 -0
- data/lib/arjdbc/oracle/connection_methods.rb +3 -0
- data/lib/arjdbc/postgresql/adapter.rb +336 -574
- data/lib/arjdbc/postgresql/column.rb +458 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +1 -2
- data/lib/arjdbc/postgresql/schema_creation.rb +38 -0
- data/lib/arjdbc/sqlite3/adapter.rb +189 -145
- data/lib/arjdbc/sqlite3/explain_support.rb +1 -1
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +8 -8
- data/lib/arjdbc/util/quoted_cache.rb +60 -0
- data/lib/arjdbc/util/table_copier.rb +110 -0
- data/lib/arjdbc/version.rb +6 -7
- data/pom.xml +56 -2
- data/rakelib/02-test.rake +72 -83
- data/rakelib/db.rake +29 -17
- data/src/java/arjdbc/ArJdbcModule.java +21 -18
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +84 -12
- data/src/java/arjdbc/derby/DerbyModule.java +140 -143
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +58 -7
- data/src/java/arjdbc/h2/H2Module.java +43 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +7 -6
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1223 -648
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +24 -23
- data/src/java/arjdbc/mysql/MySQLModule.java +33 -32
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +147 -30
- data/src/java/arjdbc/oracle/OracleModule.java +13 -13
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +114 -6
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +166 -36
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +101 -19
- data/src/java/arjdbc/util/QuotingUtils.java +19 -19
- metadata +240 -394
- data/bench/bench_attributes.rb +0 -13
- data/bench/bench_attributes_new.rb +0 -14
- data/bench/bench_create.rb +0 -12
- data/bench/bench_find_all.rb +0 -12
- data/bench/bench_find_all_mt.rb +0 -25
- data/bench/bench_model.rb +0 -85
- data/bench/bench_new.rb +0 -12
- data/bench/bench_new_valid.rb +0 -12
- data/bench/bench_valid.rb +0 -13
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +0 -9
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +0 -15
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +0 -46
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +0 -98
- data/lib/arjdbc/mssql/lock_helpers.rb +0 -76
- data/lib/arjdbc/mssql/tsql_methods.rb +0 -58
- data/lib/arjdbc/postgresql/column_cast.rb +0 -134
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +0 -25
- data/test/activerecord/jall.sh +0 -7
- data/test/activerecord/jtest.sh +0 -3
- data/test/assets/flowers.jpg +0 -0
- data/test/binary.rb +0 -67
- data/test/db/db2.rb +0 -43
- data/test/db/db2/binary_test.rb +0 -6
- data/test/db/db2/has_many_through_test.rb +0 -6
- data/test/db/db2/rake_test.rb +0 -82
- data/test/db/db2/rake_test_data.sql +0 -35
- data/test/db/db2/reset_column_information_test.rb +0 -5
- data/test/db/db2/serialize_test.rb +0 -6
- data/test/db/db2/simple_test.rb +0 -81
- data/test/db/db2/test_helper.rb +0 -6
- data/test/db/db2/unit_test.rb +0 -73
- data/test/db/derby.rb +0 -12
- data/test/db/derby/binary_test.rb +0 -6
- data/test/db/derby/migration_test.rb +0 -74
- data/test/db/derby/rake_test.rb +0 -96
- data/test/db/derby/reset_column_information_test.rb +0 -6
- data/test/db/derby/row_locking_test.rb +0 -20
- data/test/db/derby/schema_dump_test.rb +0 -5
- data/test/db/derby/serialize_test.rb +0 -6
- data/test/db/derby/simple_test.rb +0 -173
- data/test/db/derby/test_helper.rb +0 -6
- data/test/db/derby/unit_test.rb +0 -32
- data/test/db/derby/xml_column_test.rb +0 -17
- data/test/db/h2.rb +0 -11
- data/test/db/h2/binary_test.rb +0 -6
- data/test/db/h2/change_column_test.rb +0 -68
- data/test/db/h2/identity_column_test.rb +0 -35
- data/test/db/h2/offset_test.rb +0 -49
- data/test/db/h2/rake_test.rb +0 -98
- data/test/db/h2/schema_dump_test.rb +0 -29
- data/test/db/h2/serialize_test.rb +0 -6
- data/test/db/h2/simple_test.rb +0 -56
- data/test/db/hsqldb.rb +0 -11
- data/test/db/hsqldb/binary_test.rb +0 -6
- data/test/db/hsqldb/rake_test.rb +0 -101
- data/test/db/hsqldb/schema_dump_test.rb +0 -19
- data/test/db/hsqldb/serialize_test.rb +0 -6
- data/test/db/hsqldb/simple_test.rb +0 -17
- data/test/db/informix.rb +0 -13
- data/test/db/jdbc.rb +0 -16
- data/test/db/jdbc_derby.rb +0 -14
- data/test/db/jdbc_h2.rb +0 -17
- data/test/db/jdbc_mysql.rb +0 -13
- data/test/db/jdbc_postgres.rb +0 -23
- data/test/db/jndi_config.rb +0 -32
- data/test/db/jndi_pooled_config.rb +0 -32
- data/test/db/mssql.rb +0 -11
- data/test/db/mssql/binary_test.rb +0 -6
- data/test/db/mssql/exec_proc_test.rb +0 -46
- data/test/db/mssql/identity_insert_test.rb +0 -18
- data/test/db/mssql/ignore_system_views_test.rb +0 -40
- data/test/db/mssql/limit_offset_test.rb +0 -190
- data/test/db/mssql/multibyte_test.rb +0 -16
- data/test/db/mssql/multiple_connections_test.rb +0 -71
- data/test/db/mssql/rake_test.rb +0 -143
- data/test/db/mssql/reset_column_information_test.rb +0 -6
- data/test/db/mssql/row_locking_test.rb +0 -7
- data/test/db/mssql/serialize_test.rb +0 -6
- data/test/db/mssql/simple_test.rb +0 -140
- data/test/db/mssql/transaction_test.rb +0 -6
- data/test/db/mssql/types_test.rb +0 -205
- data/test/db/mssql/unit_test.rb +0 -249
- data/test/db/mysql.rb +0 -4
- data/test/db/mysql/_rails_test_mysql.32.out +0 -6585
- data/test/db/mysql/binary_test.rb +0 -6
- data/test/db/mysql/connection_test.rb +0 -51
- data/test/db/mysql/index_length_test.rb +0 -58
- data/test/db/mysql/multibyte_test.rb +0 -10
- data/test/db/mysql/nonstandard_primary_key_test.rb +0 -39
- data/test/db/mysql/rake_test.rb +0 -97
- data/test/db/mysql/reset_column_information_test.rb +0 -6
- data/test/db/mysql/schema_dump_test.rb +0 -228
- data/test/db/mysql/serialize_test.rb +0 -6
- data/test/db/mysql/simple_test.rb +0 -187
- data/test/db/mysql/statement_escaping_test.rb +0 -46
- data/test/db/mysql/transaction_test.rb +0 -6
- data/test/db/mysql/types_test.rb +0 -30
- data/test/db/mysql/unit_test.rb +0 -93
- data/test/db/mysql_config.rb +0 -7
- data/test/db/oracle.rb +0 -27
- data/test/db/oracle/binary_test.rb +0 -6
- data/test/db/oracle/limit_test.rb +0 -24
- data/test/db/oracle/multibyte_test.rb +0 -22
- data/test/db/oracle/rake_test.rb +0 -100
- data/test/db/oracle/reset_column_information_test.rb +0 -6
- data/test/db/oracle/serialize_test.rb +0 -6
- data/test/db/oracle/simple_test.rb +0 -140
- data/test/db/oracle/specific_test.rb +0 -180
- data/test/db/oracle/transaction_test.rb +0 -31
- data/test/db/oracle/unit_test.rb +0 -31
- data/test/db/postgres.rb +0 -11
- data/test/db/postgres/_rails_test_postgres.32.out +0 -6405
- data/test/db/postgres/a_custom_primary_key_test.rb +0 -50
- data/test/db/postgres/active_schema_unit_test.rb +0 -68
- data/test/db/postgres/array_type_test.rb +0 -101
- data/test/db/postgres/binary_test.rb +0 -6
- data/test/db/postgres/connection_test.rb +0 -63
- data/test/db/postgres/data_types_test.rb +0 -703
- data/test/db/postgres/hstore_test.rb +0 -200
- data/test/db/postgres/information_schema_leak_test.rb +0 -30
- data/test/db/postgres/json_test.rb +0 -86
- data/test/db/postgres/ltree_test.rb +0 -51
- data/test/db/postgres/mixed_case_test.rb +0 -29
- data/test/db/postgres/native_types_test.rb +0 -124
- data/test/db/postgres/rake_test.rb +0 -117
- data/test/db/postgres/reserved_test.rb +0 -22
- data/test/db/postgres/reset_column_information_test.rb +0 -6
- data/test/db/postgres/row_locking_test.rb +0 -21
- data/test/db/postgres/schema_dump_test.rb +0 -95
- data/test/db/postgres/schema_test.rb +0 -115
- data/test/db/postgres/simple_test.rb +0 -260
- data/test/db/postgres/table_alias_length_test.rb +0 -16
- data/test/db/postgres/transaction_test.rb +0 -6
- data/test/db/postgres/unit_test.rb +0 -31
- data/test/db/postgres_config.rb +0 -10
- data/test/db/sqlite3.rb +0 -6
- data/test/db/sqlite3/_rails_test_sqlite3.32.out +0 -6274
- data/test/db/sqlite3/has_many_though_test.rb +0 -6
- data/test/db/sqlite3/rake_test.rb +0 -71
- data/test/db/sqlite3/reset_column_information_test.rb +0 -6
- data/test/db/sqlite3/schema_dump_test.rb +0 -6
- data/test/db/sqlite3/serialize_test.rb +0 -6
- data/test/db/sqlite3/simple_test.rb +0 -268
- data/test/db/sqlite3/transaction_test.rb +0 -32
- data/test/db/sqlite3/type_conversion_test.rb +0 -104
- data/test/has_many_through.rb +0 -61
- data/test/informix_simple_test.rb +0 -48
- data/test/jdbc/db2.rb +0 -36
- data/test/jdbc/oracle.rb +0 -34
- data/test/jdbc_column_test.rb +0 -23
- data/test/jdbc_common.rb +0 -16
- data/test/jdbc_connection_test.rb +0 -196
- data/test/jndi_callbacks_test.rb +0 -33
- data/test/jndi_test.rb +0 -55
- data/test/manualTestDatabase.rb +0 -191
- data/test/models/add_not_null_column_to_table.rb +0 -9
- data/test/models/auto_id.rb +0 -15
- data/test/models/binary.rb +0 -18
- data/test/models/custom_pk_name.rb +0 -15
- data/test/models/data_types.rb +0 -40
- data/test/models/entry.rb +0 -41
- data/test/models/mixed_case.rb +0 -22
- data/test/models/reserved_word.rb +0 -15
- data/test/models/rights_and_roles.rb +0 -57
- data/test/models/string_id.rb +0 -17
- data/test/models/thing.rb +0 -17
- data/test/models/topic.rb +0 -32
- data/test/models/validates_uniqueness_of_string.rb +0 -19
- data/test/rails/mysql.rb +0 -13
- data/test/rails/sqlite3/version.rb +0 -6
- data/test/rails_stub.rb +0 -31
- data/test/rake_test_support.rb +0 -298
- data/test/row_locking.rb +0 -102
- data/test/schema_dump.rb +0 -182
- data/test/serialize.rb +0 -275
- data/test/shared_helper.rb +0 -35
- data/test/simple.rb +0 -1317
- data/test/sybase_jtds_simple_test.rb +0 -28
- data/test/sybase_reset_column_information_test.rb +0 -6
- data/test/test_helper.rb +0 -304
- data/test/transaction.rb +0 -109
@@ -1,140 +0,0 @@
|
|
1
|
-
require 'jdbc_common'
|
2
|
-
require 'db/mssql'
|
3
|
-
|
4
|
-
class MSSQLSimpleTest < Test::Unit::TestCase
|
5
|
-
include SimpleTestMethods
|
6
|
-
include ActiveRecord3TestMethods
|
7
|
-
include DirtyAttributeTests
|
8
|
-
|
9
|
-
include ExplainSupportTestMethods if ar_version("3.1")
|
10
|
-
|
11
|
-
# MS SQL 2005 doesn't have a DATE class, only TIMESTAMP
|
12
|
-
|
13
|
-
# String comparisons are insensitive by default
|
14
|
-
undef_method :test_validates_uniqueness_of_strings_case_sensitive
|
15
|
-
|
16
|
-
def test_does_not_munge_quoted_strings
|
17
|
-
example_quoted_values = [%{'quoted'}, %{D\'oh!}]
|
18
|
-
example_quoted_values.each do |value|
|
19
|
-
entry = Entry.create!(:title => value)
|
20
|
-
entry.reload
|
21
|
-
assert_equal(value, entry.title)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_change_column_default
|
26
|
-
Entry.connection.change_column "entries", "title", :string, :default => "new default"
|
27
|
-
Entry.reset_column_information
|
28
|
-
assert_equal("new default", Entry.new.title)
|
29
|
-
|
30
|
-
Entry.connection.change_column "entries", "title", :string, :default => nil
|
31
|
-
Entry.reset_column_information
|
32
|
-
assert_equal(nil, Entry.new.title)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_change_column_nullability
|
36
|
-
Entry.connection.change_column "entries", "title", :string, :null => true
|
37
|
-
Entry.reset_column_information
|
38
|
-
title_column = Entry.columns.find { |c| c.name == "title" }
|
39
|
-
assert(title_column.null)
|
40
|
-
|
41
|
-
Entry.connection.change_column "entries", "title", :string, :null => false
|
42
|
-
Entry.reset_column_information
|
43
|
-
title_column = Entry.columns.find { |c| c.name == "title" }
|
44
|
-
assert(!title_column.null)
|
45
|
-
end
|
46
|
-
|
47
|
-
[nil, "NULL", "null", "(null)", "(NULL)"].each_with_index do |v, i|
|
48
|
-
define_method "test_null_#{i}" do
|
49
|
-
entry = Entry.create!(:title => v, :content => v)
|
50
|
-
entry = Entry.find(entry.id)
|
51
|
-
assert_equal [v, v], [entry.title, entry.content], "writing #{v.inspect} " +
|
52
|
-
"should read back as #{v.inspect} for both string and text columns"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# ACTIVERECORD_JDBC-124
|
57
|
-
def test_model_does_not_have_row_num_column
|
58
|
-
User.create! :login => 'row_num'
|
59
|
-
model = User.first
|
60
|
-
assert_false model.attributes.keys.include?("_row_num")
|
61
|
-
assert_false model.respond_to?(:_row_num)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_returns_charset
|
65
|
-
assert_not_nil ActiveRecord::Base.connection.charset
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_rename_table
|
69
|
-
user = User.create! :login => 'luser'
|
70
|
-
begin
|
71
|
-
ActiveRecord::Base.connection.rename_table 'users', 'lusers'
|
72
|
-
lusers = Class.new(ActiveRecord::Base)
|
73
|
-
lusers.table_name = 'lusers'
|
74
|
-
assert_kind_of ActiveRecord::Base, lusers.find(user.id)
|
75
|
-
ensure
|
76
|
-
CreateUsers.up rescue nil
|
77
|
-
ActiveRecord::Base.connection.execute("DROP TABLE lusers") rescue nil
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_remove_column_with_index
|
82
|
-
ActiveRecord::Schema.define do
|
83
|
-
add_column :entries, 'another_column', :string
|
84
|
-
add_index :entries, 'another_column'
|
85
|
-
end
|
86
|
-
|
87
|
-
columns = ActiveRecord::Base.connection.columns("entries")
|
88
|
-
assert columns.find { |col| col.name == 'another_column' }
|
89
|
-
|
90
|
-
ActiveRecord::Schema.define do
|
91
|
-
remove_column "entries", 'another_column'
|
92
|
-
end
|
93
|
-
|
94
|
-
columns = ActiveRecord::Base.connection.columns("entries")
|
95
|
-
assert ! columns.find { |col| col.name == 'another_column' }
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_find_by_sql_WITH_statement
|
99
|
-
user = User.create! :login => 'ferko'
|
100
|
-
Entry.create! :title => 'aaa', :user_id => user.id
|
101
|
-
entries = Entry.find_by_sql '' +
|
102
|
-
'WITH EntryAndUser (title, login, updated_on) AS ' +
|
103
|
-
'(' +
|
104
|
-
' SELECT e.title, u.login, e.updated_on ' +
|
105
|
-
' FROM entries e INNER JOIN users u ON e.user_id = u.id ' +
|
106
|
-
')' +
|
107
|
-
' ' +
|
108
|
-
'SELECT * FROM EntryAndUser ORDER BY title ASC'
|
109
|
-
assert entries.first
|
110
|
-
assert entries.first.title
|
111
|
-
assert entries.first.login
|
112
|
-
end
|
113
|
-
|
114
|
-
def test_exec
|
115
|
-
ActiveRecord::Base.connection.execute "CREATE PROCEDURE usp_allentries AS SELECT * FROM entries"
|
116
|
-
|
117
|
-
assert ActiveRecord::Base.connection.exec_query(" EXEC usp_allentries ")
|
118
|
-
|
119
|
-
# exec_sql = "EXEC sp_msforeachdb 'SELECT count(*) FROM sys.objects'"
|
120
|
-
# NOTE: our _execute logic assumes all EXEC statements to do an update :
|
121
|
-
# assert_not_empty ActiveRecord::Base.connection.execute(exec_sql) # [ { '' => 42 }]
|
122
|
-
ensure
|
123
|
-
ActiveRecord::Base.connection.execute "DROP PROCEDURE usp_allentries" rescue nil
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_current_user
|
127
|
-
# skip if ActiveRecord::Base.connection.send(:sqlserver_2000?)
|
128
|
-
assert_equal 'dbo', ActiveRecord::Base.connection.current_user
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_default_schema
|
132
|
-
# skip if ActiveRecord::Base.connection.send(:sqlserver_2000?)
|
133
|
-
assert_equal 'dbo', ActiveRecord::Base.connection.default_schema
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
class MSSQLHasManyThroughTest < Test::Unit::TestCase
|
139
|
-
include HasManyThroughMethods
|
140
|
-
end
|
data/test/db/mssql/types_test.rb
DELETED
@@ -1,205 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'db/mssql'
|
3
|
-
|
4
|
-
class MSSQLDateTimeTypesTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
TABLE_DEFINITION = <<-SQL
|
7
|
-
CREATE TABLE date_and_times (
|
8
|
-
[id] int NOT NULL IDENTITY(1, 1) PRIMARY KEY,
|
9
|
-
[datetime] DATETIME
|
10
|
-
)
|
11
|
-
SQL
|
12
|
-
|
13
|
-
@@default_timezone = ActiveRecord::Base.default_timezone
|
14
|
-
|
15
|
-
def self.startup
|
16
|
-
ActiveRecord::Base.default_timezone = :local
|
17
|
-
ActiveRecord::Base.connection.execute TABLE_DEFINITION
|
18
|
-
# ActiveRecord::Base.logger.level = Logger::DEBUG
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.shutdown
|
22
|
-
# ActiveRecord::Base.logger.level = Logger::WARN
|
23
|
-
ActiveRecord::Base.connection.execute "DROP TABLE date_and_times"
|
24
|
-
ActiveRecord::Base.default_timezone = @@default_timezone
|
25
|
-
end
|
26
|
-
|
27
|
-
class DateAndTime < ActiveRecord::Base; end
|
28
|
-
|
29
|
-
def test_datetime
|
30
|
-
# January 1, 1753, through December 31, 9999 + 00:00:00 through 23:59:59.997
|
31
|
-
datetime = DateTime.parse('2012-12-21T21:11:01')
|
32
|
-
model = DateAndTime.create! :datetime => datetime
|
33
|
-
assert_datetime_equal datetime, model.reload.datetime
|
34
|
-
end if ar_version('3.0')
|
35
|
-
|
36
|
-
if ActiveRecord::Base.connection.sqlserver_version >= '2008'
|
37
|
-
|
38
|
-
# 2008 Date and Time: http://msdn.microsoft.com/en-us/library/ff848733.aspx
|
39
|
-
|
40
|
-
TABLE_DEFINITION.replace <<-SQL
|
41
|
-
CREATE TABLE date_and_times (
|
42
|
-
[id] int NOT NULL IDENTITY(1, 1),
|
43
|
-
[datetime] DATETIME,
|
44
|
-
[date] DATE,
|
45
|
-
[datetime2] DATETIME2,
|
46
|
-
[datetime25] DATETIME2(5),
|
47
|
-
[smalldatetime] SMALLDATETIME,
|
48
|
-
[time] TIME
|
49
|
-
PRIMARY KEY CLUSTERED ( [id] ASC ) WITH (
|
50
|
-
PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
|
51
|
-
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON
|
52
|
-
) ON [PRIMARY]
|
53
|
-
)
|
54
|
-
SQL
|
55
|
-
|
56
|
-
def test_date
|
57
|
-
# 0001-01-01 through 9999-12-31
|
58
|
-
date = DateTime.parse('2012-12-31')
|
59
|
-
model = DateAndTime.create! :date => date
|
60
|
-
assert_instance_of Date, model.reload.date
|
61
|
-
assert_date_equal date.to_date, model.date
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_datetime2
|
65
|
-
# date range + 00:00:00 through 23:59:59.9999999
|
66
|
-
datetime = DateTime.parse('2012-12-21T21:11:01')
|
67
|
-
model = DateAndTime.create! :datetime2 => datetime
|
68
|
-
assert_not_nil model.datetime2
|
69
|
-
assert_datetime_equal datetime, model.reload.datetime2
|
70
|
-
end if ar_version('3.0')
|
71
|
-
|
72
|
-
def test_datetime25
|
73
|
-
# id = DateAndTime.connection.insert 'INSERT INTO date_and_times ([datetime25])' +
|
74
|
-
# " VALUES ('1982-07-13 02:24:56.12345')"
|
75
|
-
# model = DateAndTime.find(id)
|
76
|
-
# assert_not_nil model.datetime25
|
77
|
-
# datetime = Time.local(1982, 7, 13, 02, 24, 56, 123450)
|
78
|
-
# assert_equal datetime, model.datetime25
|
79
|
-
|
80
|
-
datetime = Time.local(1982, 7, 13, 02, 24, 56, 123000)
|
81
|
-
model = DateAndTime.create! :datetime25 => datetime
|
82
|
-
assert_not_nil model.datetime25
|
83
|
-
assert_datetime_equal datetime, model.reload.datetime25
|
84
|
-
assert_equal datetime.usec, model.datetime25.usec if ar_version('3.2')
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_smalldatetime
|
88
|
-
# 1900-01-01 through 2079-06-06 + 00:00:00 through 23:59:59
|
89
|
-
# with seconds always zero - rounded to the nearest minute
|
90
|
-
datetime = DateTime.parse('1999-12-31T23:59:21')
|
91
|
-
model = DateAndTime.create! :smalldatetime => datetime
|
92
|
-
datetime = DateTime.parse('1999-12-31T23:59:00')
|
93
|
-
assert_datetime_equal datetime, model.reload.smalldatetime
|
94
|
-
|
95
|
-
datetime = DateTime.parse('1999-12-31T22:59:31')
|
96
|
-
model = DateAndTime.create! :smalldatetime => datetime
|
97
|
-
datetime = DateTime.parse('1999-12-31T23:00:00')
|
98
|
-
assert_datetime_equal datetime, model.reload.smalldatetime
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_time
|
102
|
-
# 00:00:00.0000000 through 23:59:59.9999999
|
103
|
-
time = Time.local(0000, 1, 01, 23, 59, 58, 987000)
|
104
|
-
model = DateAndTime.create! :time => time
|
105
|
-
assert_not_nil model.time
|
106
|
-
assert_time_equal time, model.reload.time
|
107
|
-
assert_equal 987000, model.time.usec
|
108
|
-
|
109
|
-
id = DateAndTime.connection.insert 'INSERT INTO date_and_times ([time])' +
|
110
|
-
" VALUES ('22:05:59.123456')"
|
111
|
-
model = DateAndTime.find(id)
|
112
|
-
assert_not_nil model.time
|
113
|
-
time = Time.local(2000, 1, 01, 22, 05, 59, 123456)
|
114
|
-
assert_time_equal time, model.time
|
115
|
-
assert_equal time.usec, model.time.usec
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
class MSSQLLegacyTypesTest < Test::Unit::TestCase
|
123
|
-
|
124
|
-
class CreateArticles < ActiveRecord::Migration
|
125
|
-
|
126
|
-
def self.up
|
127
|
-
execute <<-SQL
|
128
|
-
CREATE TABLE articles (
|
129
|
-
[id] int NOT NULL IDENTITY(1, 1) PRIMARY KEY,
|
130
|
-
[title] VARCHAR(100),
|
131
|
-
[author] VARCHAR(60) DEFAULT 'anonymous',
|
132
|
-
[text] TEXT,
|
133
|
-
[ntext] NTEXT,
|
134
|
-
[image] IMAGE
|
135
|
-
)
|
136
|
-
SQL
|
137
|
-
end
|
138
|
-
|
139
|
-
def self.down
|
140
|
-
drop_table "articles"
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
class Article < ActiveRecord::Base; end
|
146
|
-
|
147
|
-
def self.startup; CreateArticles.up; end
|
148
|
-
|
149
|
-
def self.shutdown; CreateArticles.down; end
|
150
|
-
|
151
|
-
def teardown
|
152
|
-
ActiveRecord::Base.clear_active_connections!
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_varchar_column
|
156
|
-
article = Article.create! :title => "Blah blah"
|
157
|
-
assert_equal("Blah blah", article.reload.title)
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_varchar_default_value
|
161
|
-
assert_equal("anonymous", Article.new.author)
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_text_column
|
165
|
-
sample_text = "Lorem ipsum dolor sit amet ..."
|
166
|
-
article = Article.create! :text => sample_text.dup
|
167
|
-
assert_equal(sample_text, article.reload.text)
|
168
|
-
end
|
169
|
-
|
170
|
-
def test_ntext_column
|
171
|
-
sample_text = "Lorem ipsum dolor sit amet ..."
|
172
|
-
article = Article.create! :ntext => sample_text.dup
|
173
|
-
assert_equal(sample_text, article.reload.ntext)
|
174
|
-
end
|
175
|
-
|
176
|
-
test "text, ntext and image are treated as special" do
|
177
|
-
assert_not_empty columns = Article.columns
|
178
|
-
assert_true columns.find { |column| column.name == 'text' }.special
|
179
|
-
assert_true columns.find { |column| column.name == 'ntext' }.special
|
180
|
-
assert_true columns.find { |column| column.name == 'image' }.special
|
181
|
-
assert ! Article.columns.find { |column| column.name == 'id' }.special
|
182
|
-
assert ! Article.columns.find { |column| column.name == 'title' }.special
|
183
|
-
assert ! Article.columns.find { |column| column.name == 'author' }.special
|
184
|
-
|
185
|
-
special_column_names = Article.connection.send(:special_column_names, 'articles')
|
186
|
-
assert_equal ['text', 'ntext', 'image'], special_column_names
|
187
|
-
special_column_names = Article.connection.send(:special_column_names, '[articles]')
|
188
|
-
assert_equal ['text', 'ntext', 'image'], special_column_names
|
189
|
-
end
|
190
|
-
|
191
|
-
test "repairs select equlity comparison for special columns" do
|
192
|
-
sql = "SELECT * FROM articles WHERE text = '1' ORDER BY text"
|
193
|
-
r_sql = Article.connection.send(:repair_special_columns, sql)
|
194
|
-
assert_equal "SELECT * FROM articles WHERE [text] LIKE '1' ", r_sql
|
195
|
-
|
196
|
-
sql = "SELECT * FROM [articles] WHERE [text]='1' AND [ntext]= '2' ORDER BY [ntext]"
|
197
|
-
r_sql = Article.connection.send(:repair_special_columns, sql)
|
198
|
-
assert_equal "SELECT * FROM [articles] WHERE [text] LIKE '1' AND [ntext] LIKE '2' ", r_sql
|
199
|
-
|
200
|
-
sql = "SELECT * FROM [articles] WHERE [text] = 'text' AND [title] = 't' ORDER BY title"
|
201
|
-
r_sql = Article.connection.send(:repair_special_columns, sql)
|
202
|
-
assert_equal "SELECT * FROM [articles] WHERE [text] LIKE 'text' AND [title] = 't' ORDER BY title", r_sql
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
data/test/db/mssql/unit_test.rb
DELETED
@@ -1,249 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'arjdbc/mssql'
|
3
|
-
|
4
|
-
class MSSQLUnitTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
# NOTE: lot of tests kindly borrowed from __activerecord-sqlserver-adapter__
|
7
|
-
|
8
|
-
test "get table name" do
|
9
|
-
insert_sql = "INSERT INTO [funny_jokes] ([name]) VALUES('Knock knock')"
|
10
|
-
update_sql = "UPDATE [customers] SET [address_street] = NULL WHERE [id] = 2"
|
11
|
-
select_sql = "SELECT * FROM [customers] WHERE ([customers].[id] = 1)"
|
12
|
-
|
13
|
-
connection = new_adapter_stub
|
14
|
-
assert_equal 'funny_jokes', connection.send(:get_table_name, insert_sql)
|
15
|
-
assert_equal 'customers', connection.send(:get_table_name, update_sql)
|
16
|
-
assert_equal 'customers', connection.send(:get_table_name, select_sql)
|
17
|
-
|
18
|
-
assert_equal '[funny_jokes]', connection.send(:get_table_name, insert_sql, true)
|
19
|
-
assert_equal '[customers]', connection.send(:get_table_name, update_sql, true)
|
20
|
-
assert_equal '[customers]', connection.send(:get_table_name, select_sql, true)
|
21
|
-
|
22
|
-
select_sql = " SELECT * FROM customers WHERE ( customers.id = 1 ) "
|
23
|
-
assert_equal 'customers', connection.send(:get_table_name, select_sql)
|
24
|
-
assert_equal 'customers', connection.send(:get_table_name, select_sql, true)
|
25
|
-
|
26
|
-
assert_nil connection.send(:get_table_name, 'SELECT 1')
|
27
|
-
# NOTE: this has been failing even before refactoring - not sure if it's needed :
|
28
|
-
#assert_nil connection.send(:get_table_name, 'SELECT * FROM someFunction()')
|
29
|
-
#assert_nil connection.send(:get_table_name, 'SELECT * FROM someFunction() WHERE 1 > 2')
|
30
|
-
end
|
31
|
-
|
32
|
-
context "Utils" do
|
33
|
-
|
34
|
-
setup do
|
35
|
-
@expected_table_name = 'baz'
|
36
|
-
@expected_db_name = 'foo'
|
37
|
-
@first_second_table_names = ['[baz]','baz','[bar].[baz]','bar.baz']
|
38
|
-
@third_table_names = ['[foo].[bar].[baz]','foo.bar.baz']
|
39
|
-
@qualifed_table_names = @first_second_table_names + @third_table_names
|
40
|
-
end
|
41
|
-
|
42
|
-
test 'return clean table_name from Utils.unqualify_table_name' do
|
43
|
-
@qualifed_table_names.each do |qtn|
|
44
|
-
assert_equal @expected_table_name,
|
45
|
-
ArJdbc::MSSQL::Utils.send(:unqualify_table_name, qtn),
|
46
|
-
"This qualifed_table_name #{qtn} did not unqualify correctly."
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
test 'return nil from Utils.unqualify_db_name when table_name is less than 2 qualified' do
|
51
|
-
@first_second_table_names.each do |qtn|
|
52
|
-
assert_equal nil, ArJdbc::MSSQL::Utils.send(:unqualify_db_name, qtn),
|
53
|
-
"This qualifed_table_name #{qtn} did not return nil."
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
test 'return clean db_name from Utils.unqualify_db_name when table is thrid level qualified' do
|
58
|
-
@third_table_names.each do |qtn|
|
59
|
-
assert_equal @expected_db_name,
|
60
|
-
ArJdbc::MSSQL::Utils.send(:unqualify_db_name, qtn),
|
61
|
-
"This qualifed_table_name #{qtn} did not unqualify the db_name correctly."
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
test "quote column name" do
|
68
|
-
connection = new_adapter_stub
|
69
|
-
assert_equal "[foo]", connection.quote_column_name("foo")
|
70
|
-
assert_equal "[bar]", connection.quote_column_name("[bar]")
|
71
|
-
assert_equal "[foo]]bar]", connection.quote_column_name("foo]bar")
|
72
|
-
|
73
|
-
assert_equal "[dbo].[foo]", connection.quote_column_name("dbo.foo")
|
74
|
-
assert_equal "[dbo].[bar]", connection.quote_column_name("[dbo].[bar]")
|
75
|
-
assert_equal "[foo].[bar]", connection.quote_column_name("[foo].bar")
|
76
|
-
assert_equal "[foo].[bar]", connection.quote_column_name("foo.[bar]")
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
80
|
-
|
81
|
-
def new_adapter_stub(config = {})
|
82
|
-
config = config.merge({
|
83
|
-
:adapter => 'jdbc',
|
84
|
-
:adapter_spec => ArJdbc::MSSQL,
|
85
|
-
:sqlserver_version => 2008
|
86
|
-
})
|
87
|
-
connection = stub('connection'); logger = nil
|
88
|
-
connection.stub_everything
|
89
|
-
adapter = ActiveRecord::ConnectionAdapters::JdbcAdapter.new connection, logger, config
|
90
|
-
yield(adapter) if block_given?
|
91
|
-
adapter
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
# This tests ArJdbc::MSSQL#add_lock! without actually connecting to the database.
|
97
|
-
class MSSQLRowLockingUnitTest < Test::Unit::TestCase
|
98
|
-
|
99
|
-
def test_find_all
|
100
|
-
add_lock_test "Appointment.find(:all)",
|
101
|
-
%q{SELECT * FROM appointments},
|
102
|
-
%q{SELECT * FROM appointments WITH(ROWLOCK,UPDLOCK)}
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_find_first
|
106
|
-
add_lock_test "Appointment.find(:first)",
|
107
|
-
%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},
|
108
|
-
%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}
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_find_all_where
|
112
|
-
add_lock_test "AppointmentDetail.find(:all, :conditions => {:name => 'foo', :value => 'bar'})",
|
113
|
-
%q{SELECT * FROM appointment_details WHERE (appointment_details.[name] = N'foo' AND appointment_details.[value] = N'bar')},
|
114
|
-
%q{SELECT * FROM appointment_details WITH(ROWLOCK,UPDLOCK) WHERE (appointment_details.[name] = N'foo' AND appointment_details.[value] = N'bar')}
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_find_first_where
|
118
|
-
add_lock_test "AppointmentDetail.find(:first, :conditions => {:name => 'foo', :value => 'bar'})",
|
119
|
-
%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},
|
120
|
-
%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}
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_find_all_where_array
|
124
|
-
add_lock_test "AppointmentDetail.find(:all, :conditions => ['name = ?', 'foo'])",
|
125
|
-
%q{SELECT * FROM appointment_details WHERE (name = N'foo')},
|
126
|
-
%q{SELECT * FROM appointment_details WITH(ROWLOCK,UPDLOCK) WHERE (name = N'foo')}
|
127
|
-
end
|
128
|
-
|
129
|
-
def test_find_first_where_array
|
130
|
-
add_lock_test "AppointmentDetail.find(:first, :conditions => ['name = ?', 'foo'])",
|
131
|
-
%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},
|
132
|
-
%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}
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_find_all_joins
|
136
|
-
add_lock_test "AppointmentDetail.find(:all, :joins => :appointment)",
|
137
|
-
%q{SELECT appointment_details.* FROM appointment_details INNER JOIN appointments ON appointments.id = appointment_details.appointment_id},
|
138
|
-
%q{SELECT appointment_details.* FROM appointment_details WITH(ROWLOCK,UPDLOCK) INNER JOIN appointments WITH(ROWLOCK,UPDLOCK) ON appointments.id = appointment_details.appointment_id}
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_find_first_joins
|
142
|
-
add_lock_test "AppointmentDetail.find(:first, :joins => :appointment)",
|
143
|
-
%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},
|
144
|
-
%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}
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_find_all_2joins
|
148
|
-
add_lock_test "Appointment.find(:all, :joins => [:appointment_details, :appointment_hl7s])",
|
149
|
-
%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},
|
150
|
-
%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}
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_find_first_2joins
|
154
|
-
add_lock_test "Appointment.find(:first, :joins => [:appointment_details, :appointment_hl7s])",
|
155
|
-
%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},
|
156
|
-
%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}
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_find_all_2joins_where
|
160
|
-
add_lock_test "Appointment.find(:all, :joins => [:appointment_details, :appointment_hl7s], :conditions => {'appointment_details.name' => 'foo'})",
|
161
|
-
%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')},
|
162
|
-
%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')}
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_find_first_2joins_where
|
166
|
-
add_lock_test "Appointment.find(:first, :joins => [:appointment_details, :appointment_hl7s], :conditions => {'appointment_details.name' => 'foo'})",
|
167
|
-
%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},
|
168
|
-
%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}
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_custom_join_ar097
|
172
|
-
add_lock_test "custom join (arjdbc 0.9.7)",
|
173
|
-
%q{
|
174
|
-
SELECT t.* FROM (
|
175
|
-
SELECT
|
176
|
-
ROW_NUMBER() OVER(ORDER BY appointments.id) AS row_num,
|
177
|
-
appointments.*
|
178
|
-
FROM
|
179
|
-
appointments INNER JOIN
|
180
|
-
appointment_details AS d1 ON appointments.[id] = d1.[appointment_id]
|
181
|
-
WHERE (d1.[name] = N'appointment_identifier' AND d1.[value] = N'279955^MQ')
|
182
|
-
) AS t WHERE t.row_num BETWEEN 1 AND 1
|
183
|
-
}, %q{
|
184
|
-
SELECT t.* FROM (
|
185
|
-
SELECT
|
186
|
-
ROW_NUMBER() OVER(ORDER BY appointments.id) AS row_num,
|
187
|
-
appointments.*
|
188
|
-
FROM
|
189
|
-
appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN
|
190
|
-
appointment_details AS d1 WITH(ROWLOCK,UPDLOCK) ON appointments.[id] = d1.[appointment_id]
|
191
|
-
WHERE (d1.[name] = N'appointment_identifier' AND d1.[value] = N'279955^MQ')
|
192
|
-
) AS t WHERE t.row_num BETWEEN 1 AND 1
|
193
|
-
}
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_custom_join_ar111
|
197
|
-
add_lock_test "custom join (arjdbc 1.1.1)",
|
198
|
-
%q{
|
199
|
-
SELECT t.*
|
200
|
-
FROM
|
201
|
-
(
|
202
|
-
SELECT
|
203
|
-
ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num,
|
204
|
-
appointments.*
|
205
|
-
FROM
|
206
|
-
appointments INNER JOIN
|
207
|
-
appointment_details AS d1 ON appointments.[id] = d1.[appointment_id]
|
208
|
-
WHERE
|
209
|
-
(d1.[name] = N'appointment_identifier' AND d1.[value] = N'389727^MQ')
|
210
|
-
) AS t
|
211
|
-
WHERE
|
212
|
-
t._row_num BETWEEN 1 AND 1
|
213
|
-
}, %q{
|
214
|
-
SELECT t.*
|
215
|
-
FROM
|
216
|
-
(
|
217
|
-
SELECT
|
218
|
-
ROW_NUMBER() OVER(ORDER BY appointments.id) AS _row_num,
|
219
|
-
appointments.*
|
220
|
-
FROM
|
221
|
-
appointments WITH(ROWLOCK,UPDLOCK) INNER JOIN
|
222
|
-
appointment_details AS d1 WITH(ROWLOCK,UPDLOCK) ON appointments.[id] = d1.[appointment_id]
|
223
|
-
WHERE
|
224
|
-
(d1.[name] = N'appointment_identifier' AND d1.[value] = N'389727^MQ')
|
225
|
-
) AS t
|
226
|
-
WHERE
|
227
|
-
t._row_num BETWEEN 1 AND 1
|
228
|
-
}
|
229
|
-
end
|
230
|
-
|
231
|
-
class Dummy
|
232
|
-
include ::ArJdbc::MSSQL::LockHelpers::SqlServerAddLock
|
233
|
-
end
|
234
|
-
|
235
|
-
private
|
236
|
-
|
237
|
-
def add_lock!(sql, options={})
|
238
|
-
result = sql.dup
|
239
|
-
Dummy.new.add_lock!(result, {:lock=>true}.merge(options))
|
240
|
-
result
|
241
|
-
end
|
242
|
-
|
243
|
-
def add_lock_test(message, before, after, options={})
|
244
|
-
before = before.gsub(/\s*\n\s*/m, " ").strip
|
245
|
-
after = after.gsub(/\s*\n\s*/m, " ").strip
|
246
|
-
assert_equal after, add_lock!(before, options).strip, message
|
247
|
-
end
|
248
|
-
|
249
|
-
end
|