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,46 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'db/mssql'
|
3
|
-
|
4
|
-
class MSSQLExecProcTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def self.startup
|
7
|
-
ActiveRecord::Base.connection.
|
8
|
-
create_table :sample_table, :force => true do |t|
|
9
|
-
t.column :sample_column, :datetime
|
10
|
-
end
|
11
|
-
# ActiveRecord::Base.logger.level = Logger::DEBUG
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.shutdown
|
15
|
-
# ActiveRecord::Base.logger.level = Logger::WARN
|
16
|
-
ActiveRecord::Base.connection.drop_table :sample_table
|
17
|
-
end
|
18
|
-
|
19
|
-
test 'execute a simple procedure' do
|
20
|
-
tables = connection.execute_procedure :sp_tables
|
21
|
-
assert_instance_of Array, tables
|
22
|
-
assert tables.first.respond_to?(:keys)
|
23
|
-
end
|
24
|
-
|
25
|
-
test 'takes parameter arguments' do
|
26
|
-
tables = connection.execute_procedure :sp_tables, 'sample_table'
|
27
|
-
table_info = tables.first
|
28
|
-
assert_equal 1, tables.size
|
29
|
-
assert_equal 'TABLE', table_info['TABLE_TYPE']
|
30
|
-
assert_equal 'sample_table', table_info['TABLE_NAME']
|
31
|
-
end
|
32
|
-
|
33
|
-
test 'takes named parameter arguments' do
|
34
|
-
tables = connection.exec_proc :sp_tables, :table_name => 'tables', :table_owner => 'sys'
|
35
|
-
table_info = tables.first
|
36
|
-
assert_equal 1, tables.size
|
37
|
-
assert_equal 'VIEW', table_info['TABLE_TYPE'], "Table Info: #{table_info.inspect}"
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def connection
|
43
|
-
ActiveRecord::Base.connection
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'jdbc_common'
|
2
|
-
require 'db/mssql'
|
3
|
-
|
4
|
-
class MSSQLIdentityInsertTest < Test::Unit::TestCase
|
5
|
-
include MigrationSetup
|
6
|
-
|
7
|
-
def test_enable_identity_insert_when_necessary
|
8
|
-
Entry.connection.execute("INSERT INTO entries([id], [title]) VALUES (333, 'Title')")
|
9
|
-
Entry.connection.execute("INSERT INTO entries([title], [id]) VALUES ('Title', 344)")
|
10
|
-
Entry.connection.execute("INSERT INTO entries(id, title) VALUES (666, 'Title')")
|
11
|
-
Entry.connection.execute("INSERT INTO entries(id, title) (SELECT id+123, title FROM entries)")
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_dont_enable_identity_insert_when_unnecessary
|
15
|
-
Entry.connection.execute("INSERT INTO entries([title]) VALUES ('[id]')")
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'jdbc_common'
|
2
|
-
require 'db/mssql'
|
3
|
-
|
4
|
-
class MSSQLIgnoreSystemViewsTest < Test::Unit::TestCase
|
5
|
-
include MigrationSetup
|
6
|
-
|
7
|
-
def test_system_views_ignored
|
8
|
-
assert_not_include tables, 'views'
|
9
|
-
if ActiveRecord::Base.connection.sqlserver_version == "2000"
|
10
|
-
assert_false table_exists?("sys.views"), %{table_exists?("sys.views")}
|
11
|
-
assert_false table_exists?("information_schema.views"), %{table_exists?("information_schema.views")}
|
12
|
-
else
|
13
|
-
assert_true table_exists?("sys.views"), %{table_exists?("sys.views")}
|
14
|
-
assert_true table_exists?("information_schema.views"), %{table_exists?("information_schema.views")}
|
15
|
-
|
16
|
-
assert_true table_exists?(:views), %{table_exists?(:views)}
|
17
|
-
end
|
18
|
-
assert_false table_exists?("dbo.views"), %{table_exists?("dbo.views")}
|
19
|
-
#assert_false table_exists?(:views), %{table_exists?(:views)}
|
20
|
-
ActiveRecord::Schema.define { suppress_messages { create_table :views } }
|
21
|
-
assert_include tables, 'views'
|
22
|
-
assert_true table_exists?(:views), %{table_exists?(:views)}
|
23
|
-
ActiveRecord::Schema.define { suppress_messages { drop_table :views } }
|
24
|
-
#assert_false table_exists?(:views), %{table_exists?(:views)}
|
25
|
-
ensure
|
26
|
-
ActiveRecord::Base.connection.drop_table(:views) rescue nil
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def tables
|
32
|
-
ActiveRecord::Base.connection.tables
|
33
|
-
end
|
34
|
-
|
35
|
-
def table_exists?(*args)
|
36
|
-
ActiveRecord::Base.connection.table_exists?(*args)
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
@@ -1,190 +0,0 @@
|
|
1
|
-
require 'jdbc_common'
|
2
|
-
require 'db/mssql'
|
3
|
-
|
4
|
-
class MSSQLLimitOffsetTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
class CreateLegacyShips < ActiveRecord::Migration
|
7
|
-
|
8
|
-
def self.up
|
9
|
-
create_table "legacy_ships",{:primary_key => :ShipKey} 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 "legacy_ships"
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
class LegacyShip < ActiveRecord::Base
|
23
|
-
self.primary_key = "ShipKey"
|
24
|
-
end
|
25
|
-
|
26
|
-
class CreateLongShips < ActiveRecord::Migration
|
27
|
-
|
28
|
-
def self.up
|
29
|
-
create_table "long_ships", :force => true do |t|
|
30
|
-
t.string "name", :limit => 50, :null => false
|
31
|
-
t.integer "width", :default => 123
|
32
|
-
t.integer "length", :default => 456
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.down
|
37
|
-
drop_table "long_ships"
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
class LongShip < ActiveRecord::Base
|
43
|
-
has_many :vikings
|
44
|
-
end
|
45
|
-
|
46
|
-
class CreateVikings < ActiveRecord::Migration
|
47
|
-
|
48
|
-
def self.up
|
49
|
-
create_table "vikings", :force => true do |t|
|
50
|
-
t.integer "long_ship_id", :null => false
|
51
|
-
t.string "name", :limit => 50, :default => "Sven"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.down
|
56
|
-
drop_table "vikings"
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
class Viking < ActiveRecord::Base
|
62
|
-
belongs_to :long_ship
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
class CreateNoIdVikings < ActiveRecord::Migration
|
67
|
-
def self.up
|
68
|
-
create_table "no_id_vikings", :force => true do |t|
|
69
|
-
t.string "name", :limit => 50, :default => "Sven"
|
70
|
-
end
|
71
|
-
remove_column "no_id_vikings", "id"
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.down
|
75
|
-
drop_table "no_id_vikings"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
class NoIdViking < ActiveRecord::Base
|
80
|
-
end
|
81
|
-
|
82
|
-
def setup
|
83
|
-
CreateLegacyShips.up
|
84
|
-
CreateLongShips.up
|
85
|
-
CreateVikings.up
|
86
|
-
CreateNoIdVikings.up
|
87
|
-
ActiveRecord::Base.connection
|
88
|
-
end
|
89
|
-
|
90
|
-
def teardown
|
91
|
-
CreateLegacyShips.down
|
92
|
-
CreateVikings.down
|
93
|
-
CreateLongShips.down
|
94
|
-
CreateNoIdVikings.down
|
95
|
-
ActiveRecord::Base.clear_active_connections!
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_limit_with_no_id_column_available
|
99
|
-
NoIdViking.create!(:name => 'Erik')
|
100
|
-
#assert_nothing_raised(ActiveRecord::StatementInvalid) do
|
101
|
-
NoIdViking.first
|
102
|
-
#end
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_limit_with_alternate_named_primary_key
|
106
|
-
%w(one two three four five six seven eight).each do |name|
|
107
|
-
LegacyShip.create!(:name => name)
|
108
|
-
end
|
109
|
-
ships = LegacyShip.limit(3)
|
110
|
-
assert_equal(3, ships.size)
|
111
|
-
end if ar_version('3.0')
|
112
|
-
|
113
|
-
def test_limit_and_offset
|
114
|
-
%w(one two three four five six seven eight).each do |name|
|
115
|
-
LongShip.create!(:name => name)
|
116
|
-
end
|
117
|
-
ship_names = LongShip.find(:all, :offset => 2, :limit => 3).map(&:name)
|
118
|
-
assert_equal(%w(three four five), ship_names)
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_limit_and_offset_with_order
|
122
|
-
%w(one two three four five six seven eight).each do |name|
|
123
|
-
LongShip.create!(:name => name)
|
124
|
-
end
|
125
|
-
ship_names = LongShip.find(:all, :order => "name", :offset => 4, :limit => 2).map(&:name)
|
126
|
-
assert_equal(%w(seven six), ship_names)
|
127
|
-
end
|
128
|
-
|
129
|
-
# TODO: work out how to fix DISTINCT support without breaking :include
|
130
|
-
# def test_limit_and_offset_with_distinct
|
131
|
-
# %w(c a b a b a c d c d).each do |name|
|
132
|
-
# LongShip.create!(:name => name)
|
133
|
-
# end
|
134
|
-
# ship_names = LongShip.find(:all, :select => "DISTINCT name", :order => "name", :offset => 1, :limit => 2).map(&:name)
|
135
|
-
# assert_equal(%w(b c), ship_names)
|
136
|
-
# end
|
137
|
-
|
138
|
-
def test_limit_and_offset_with_include
|
139
|
-
skei = LongShip.create!(:name => "Skei")
|
140
|
-
skei.vikings.create!(:name => "Bob")
|
141
|
-
skei.vikings.create!(:name => "Ben")
|
142
|
-
skei.vikings.create!(:name => "Basil")
|
143
|
-
if ar_version('4.0')
|
144
|
-
ships = Viking.includes(:long_ship).offset(1).limit(2) #.all
|
145
|
-
else
|
146
|
-
ships = Viking.find(:all, :include => :long_ship, :offset => 1, :limit => 2)
|
147
|
-
end
|
148
|
-
assert_equal(2, ships.size)
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_limit_and_offset_with_include_and_order
|
152
|
-
boat1 = LongShip.create!(:name => "1-Skei")
|
153
|
-
boat2 = LongShip.create!(:name => "2-Skei")
|
154
|
-
|
155
|
-
boat1.vikings.create!(:name => "Adam")
|
156
|
-
boat2.vikings.create!(:name => "Ben")
|
157
|
-
boat1.vikings.create!(:name => "Carl")
|
158
|
-
boat2.vikings.create!(:name => "Donald")
|
159
|
-
|
160
|
-
if ar_version('4.0')
|
161
|
-
vikings = Viking.includes(:long_ship).order('long_ships.name, vikings.name').references(:long_ship).offset(0).limit(3)
|
162
|
-
else
|
163
|
-
vikings = Viking.find(:all, :include => :long_ship, :order => "long_ships.name, vikings.name", :offset => 0, :limit => 3)
|
164
|
-
end
|
165
|
-
assert_equal ["Adam", "Carl", "Ben"], vikings.map(&:name)
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_offset_without_limit
|
169
|
-
%w( egy keto harom negy ot hat het nyolc ).each do |name|
|
170
|
-
LongShip.create!(:name => name)
|
171
|
-
end
|
172
|
-
error = assert_raise ActiveRecord::ActiveRecordError do
|
173
|
-
if ar_version('3.0')
|
174
|
-
LongShip.select(:name).offset(2).all
|
175
|
-
else
|
176
|
-
LongShip.find(:all, :select => 'name', :offset => 2)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
assert_equal "You must specify :limit with :offset.", error.message
|
180
|
-
end
|
181
|
-
|
182
|
-
def test_limit_with_group_by
|
183
|
-
%w( one two three four five six seven eight ).each do |name|
|
184
|
-
LongShip.create!(:name => name)
|
185
|
-
end
|
186
|
-
ships = LongShip.select(:name).group(:name).limit(2).all
|
187
|
-
assert_equal ['one', 'two'], ships.map(&:name)
|
188
|
-
end if ar_version('3.0')
|
189
|
-
|
190
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'jdbc_common'
|
3
|
-
require 'db/mssql'
|
4
|
-
|
5
|
-
class MSSQLMultibyteTest < Test::Unit::TestCase
|
6
|
-
include MultibyteTestMethods
|
7
|
-
|
8
|
-
def test_select_multibyte_string
|
9
|
-
Entry.create!(:title => 'テスト', :content => '本文')
|
10
|
-
entry = Entry.find(:last)
|
11
|
-
assert_equal "テスト", entry.title
|
12
|
-
assert_equal "本文", entry.content
|
13
|
-
assert_equal entry, Entry.find_by_title("テスト")
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'db/mssql'
|
3
|
-
|
4
|
-
class MSSQLMultipleConnectionsTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
MSSQL_CONFIG2 = { :adapter => 'mssql' }
|
7
|
-
MSSQL_CONFIG2[:database] = ENV['SQL2DATABASE']
|
8
|
-
MSSQL_CONFIG2[:username] = ENV['SQL2USER'] || MSSQL_CONFIG[:username]
|
9
|
-
MSSQL_CONFIG2[:password] = ENV['SQL2PASS'] || MSSQL_CONFIG[:password]
|
10
|
-
MSSQL_CONFIG2[:host] = MSSQL_CONFIG[:host]
|
11
|
-
MSSQL_CONFIG2[:port] = MSSQL_CONFIG[:port]
|
12
|
-
|
13
|
-
OLD_CONFIG = ActiveRecord::Base.configurations.dup
|
14
|
-
|
15
|
-
if MSSQL_CONFIG2[:database]
|
16
|
-
|
17
|
-
class Database1 < ActiveRecord::Base
|
18
|
-
self.abstract_class = true
|
19
|
-
#establish_connection 'db1'
|
20
|
-
end
|
21
|
-
|
22
|
-
class Model1 < Database1
|
23
|
-
end
|
24
|
-
|
25
|
-
class Database2 < ActiveRecord::Base
|
26
|
-
self.abstract_class = true
|
27
|
-
#establish_connection 'db2'
|
28
|
-
end
|
29
|
-
|
30
|
-
class Model2 < Database2
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.startup
|
34
|
-
ActiveRecord::Base.clear_active_connections!
|
35
|
-
ActiveRecord::Base.configurations.replace('db1' => MSSQL_CONFIG, 'db2' => MSSQL_CONFIG2)
|
36
|
-
|
37
|
-
Database1.establish_connection 'db1'
|
38
|
-
Database2.establish_connection 'db2'
|
39
|
-
|
40
|
-
Database1.connection.execute "CREATE TABLE [model1s] " +
|
41
|
-
"([id] int NOT NULL IDENTITY(1, 1) PRIMARY KEY, [name] NVARCHAR(10))"
|
42
|
-
Database2.connection.execute "CREATE TABLE [model2s] " +
|
43
|
-
"([id] int NOT NULL IDENTITY(1, 1) PRIMARY KEY, [name] NVARCHAR(10))"
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.shutdown
|
47
|
-
Database1.connection.execute "DROP TABLE [model1s]"
|
48
|
-
Database2.connection.execute "DROP TABLE [model2s]"
|
49
|
-
|
50
|
-
ActiveRecord::Base.clear_active_connections!
|
51
|
-
|
52
|
-
ActiveRecord::Base.configurations.replace OLD_CONFIG
|
53
|
-
ActiveRecord::Base.establish_connection MSSQL_CONFIG
|
54
|
-
end
|
55
|
-
|
56
|
-
test "create and retrieve models" do
|
57
|
-
assert_nil Model1.first
|
58
|
-
assert_nil Model2.first
|
59
|
-
|
60
|
-
Model1.create :name => 'm1'
|
61
|
-
Model2.create :name => 'm2'
|
62
|
-
|
63
|
-
assert_not_nil Model1.first
|
64
|
-
assert_not_nil Model2.first
|
65
|
-
end
|
66
|
-
|
67
|
-
else
|
68
|
-
puts "#{self.name} skipped since no second MS-SQL database configured"
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
data/test/db/mssql/rake_test.rb
DELETED
@@ -1,143 +0,0 @@
|
|
1
|
-
require 'rake_test_support'
|
2
|
-
require 'db/mssql'
|
3
|
-
|
4
|
-
class MSSQLRakeDbCreateTest < Test::Unit::TestCase
|
5
|
-
include RakeTestSupport
|
6
|
-
|
7
|
-
def db_config
|
8
|
-
MSSQL_CONFIG
|
9
|
-
end
|
10
|
-
|
11
|
-
def do_teardown
|
12
|
-
drop_rake_test_database(:silence)
|
13
|
-
end
|
14
|
-
|
15
|
-
test 'rake db:create (and db:drop)' do
|
16
|
-
begin
|
17
|
-
Rake::Task["db:create"].invoke
|
18
|
-
rescue => e
|
19
|
-
if e.message =~ /CREATE DATABASE permission denied/
|
20
|
-
puts "\nwarning: db:create test skipped; add 'dbcreator' role to user '#{db_config[:username]}' to run"
|
21
|
-
return
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
ActiveRecord::Base.establish_connection(db_config.merge(:database => "master"))
|
26
|
-
assert_include databases, db_name
|
27
|
-
|
28
|
-
Rake::Task["db:drop"].invoke
|
29
|
-
|
30
|
-
ActiveRecord::Base.establish_connection(db_config.merge(:database => "master"))
|
31
|
-
assert_not_include databases, db_name
|
32
|
-
end
|
33
|
-
|
34
|
-
test 'rake db:drop (non-existing database)' do
|
35
|
-
drop_rake_test_database(:silence)
|
36
|
-
Rake::Task["db:drop"].invoke
|
37
|
-
end
|
38
|
-
|
39
|
-
test 'rake db:test:purge' do
|
40
|
-
# Rake::Task["db:create"].invoke
|
41
|
-
create_rake_test_database do |connection|
|
42
|
-
connection.create_table('users') { |t| t.string :name }
|
43
|
-
end
|
44
|
-
|
45
|
-
Rake::Task["db:test:purge"].invoke
|
46
|
-
|
47
|
-
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
48
|
-
assert_false ActiveRecord::Base.connection.table_exists?('users')
|
49
|
-
ActiveRecord::Base.connection.disconnect!
|
50
|
-
end
|
51
|
-
|
52
|
-
test 'rake db:structure:dump (and db:structure:load)' do
|
53
|
-
omit('smoscript not available') unless self.class.find_executable?('smoscript')
|
54
|
-
# Rake::Task["db:create"].invoke
|
55
|
-
create_rake_test_database do |connection|
|
56
|
-
create_schema_migrations_table(connection)
|
57
|
-
connection.create_table('users') { |t| t.string :name; t.timestamps }
|
58
|
-
end
|
59
|
-
|
60
|
-
structure_sql = File.join('db', structure_sql_filename)
|
61
|
-
begin
|
62
|
-
Dir.mkdir 'db' # db/structure.sql
|
63
|
-
Rake::Task["db:structure:dump"].invoke
|
64
|
-
|
65
|
-
assert File.exists?(structure_sql)
|
66
|
-
# CREATE TABLE [dbo].[users]( ... )
|
67
|
-
assert_match /CREATE TABLE .*?\[users\]/i, File.read(structure_sql)
|
68
|
-
|
69
|
-
# db:structure:load
|
70
|
-
drop_rake_test_database(:silence)
|
71
|
-
create_rake_test_database
|
72
|
-
Rake::Task["db:structure:load"].invoke
|
73
|
-
|
74
|
-
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
75
|
-
assert ActiveRecord::Base.connection.table_exists?('users')
|
76
|
-
ActiveRecord::Base.connection.disconnect!
|
77
|
-
ensure
|
78
|
-
File.delete(structure_sql) if File.exists?(structure_sql)
|
79
|
-
Dir.rmdir 'db'
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
setup { rm_r 'db' if File.exist?('db') }
|
84
|
-
|
85
|
-
test 'rake db:charset' do
|
86
|
-
create_rake_test_database
|
87
|
-
# using the default character set, the character_set_name should be
|
88
|
-
# iso_1 (ISO 8859-1) for the char and varchar data types
|
89
|
-
expect_rake_output /iso_1|UCS/i
|
90
|
-
Rake::Task["db:charset"].invoke
|
91
|
-
end
|
92
|
-
|
93
|
-
test 'rake db:collation' do
|
94
|
-
create_rake_test_database
|
95
|
-
# default (for iso_1) : 'SQL_Latin1_General_CP1_CI_AS'
|
96
|
-
expect_rake_output /SQL_.*/
|
97
|
-
Rake::Task["db:collation"].invoke
|
98
|
-
end
|
99
|
-
|
100
|
-
# @override
|
101
|
-
def create_rake_test_database(db_name = self.db_name)
|
102
|
-
ActiveRecord::Base.establish_connection db_config
|
103
|
-
connection = ActiveRecord::Base.connection
|
104
|
-
unless connection.database_exists?(db_name)
|
105
|
-
# connection.use_database('master')
|
106
|
-
connection.create_database(db_name, db_config)
|
107
|
-
end
|
108
|
-
|
109
|
-
if block_given?
|
110
|
-
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
111
|
-
yield ActiveRecord::Base.connection
|
112
|
-
end
|
113
|
-
ActiveRecord::Base.connection.disconnect!
|
114
|
-
end
|
115
|
-
|
116
|
-
# @override
|
117
|
-
def drop_rake_test_database(silence = false)
|
118
|
-
ActiveRecord::Base.establish_connection db_config
|
119
|
-
connection = ActiveRecord::Base.connection
|
120
|
-
begin
|
121
|
-
#current_db_name = connection.current_database
|
122
|
-
#if current_db_name.upcase == db_name.upcase
|
123
|
-
connection.use_database('master')
|
124
|
-
#end
|
125
|
-
connection.drop_database(db_name)
|
126
|
-
rescue => e
|
127
|
-
raise e unless silence
|
128
|
-
end
|
129
|
-
ActiveRecord::Base.connection.disconnect!
|
130
|
-
end
|
131
|
-
|
132
|
-
private
|
133
|
-
|
134
|
-
def databases
|
135
|
-
if ActiveRecord::Base.connection.send(:sqlserver_2000?)
|
136
|
-
select = "SELECT name FROM master..sysdatabases ORDER BY name"
|
137
|
-
else
|
138
|
-
select = "SELECT name FROM sys.sysdatabases"
|
139
|
-
end
|
140
|
-
ActiveRecord::Base.connection.select_rows(select).flatten
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|