activerecord-jdbc-adapter 1.2.9.1 → 1.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -0
- data/Appraisals +12 -4
- data/Gemfile +3 -3
- data/Gemfile.lock +19 -19
- data/History.txt +90 -16
- data/LICENSE.txt +2 -1
- data/README.md +14 -1
- data/activerecord-jdbc-adapter.gemspec +2 -2
- data/gemfiles/rails23.gemfile +5 -5
- data/gemfiles/rails23.gemfile.lock +27 -27
- data/gemfiles/rails30.gemfile +3 -3
- data/gemfiles/rails30.gemfile.lock +8 -8
- data/gemfiles/rails31.gemfile +4 -4
- data/gemfiles/rails31.gemfile.lock +18 -18
- data/gemfiles/rails32.gemfile +4 -4
- data/gemfiles/rails32.gemfile.lock +17 -17
- data/gemfiles/rails40.gemfile +17 -0
- data/gemfiles/rails40.gemfile.lock +126 -0
- data/lib/activerecord-jdbc-adapter.rb +0 -7
- data/lib/arjdbc.rb +6 -5
- data/lib/arjdbc/db2.rb +1 -1
- data/lib/arjdbc/db2/adapter.rb +52 -29
- data/lib/arjdbc/db2/connection_methods.rb +13 -14
- data/lib/arjdbc/derby.rb +1 -1
- data/lib/arjdbc/derby/adapter.rb +29 -9
- data/lib/arjdbc/derby/connection_methods.rb +17 -20
- data/lib/arjdbc/firebird.rb +1 -1
- data/lib/arjdbc/h2.rb +2 -2
- data/lib/arjdbc/h2/adapter.rb +1 -1
- data/lib/arjdbc/h2/connection_methods.rb +12 -16
- data/lib/arjdbc/hsqldb.rb +1 -1
- data/lib/arjdbc/hsqldb/connection_methods.rb +13 -16
- data/lib/arjdbc/informix.rb +1 -1
- data/lib/arjdbc/informix/connection_methods.rb +8 -10
- data/lib/arjdbc/jdbc.rb +1 -1
- data/lib/arjdbc/jdbc/adapter.rb +125 -53
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/base_ext.rb +34 -9
- data/lib/arjdbc/jdbc/column.rb +15 -2
- data/lib/arjdbc/jdbc/connection.rb +0 -2
- data/lib/arjdbc/jdbc/connection_methods.rb +10 -3
- data/lib/arjdbc/jdbc/driver.rb +2 -2
- data/lib/arjdbc/jdbc/extension.rb +35 -21
- data/lib/arjdbc/jdbc/java.rb +0 -2
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +35 -25
- data/lib/arjdbc/jdbc/railtie.rb +2 -9
- data/lib/arjdbc/mimer.rb +1 -1
- data/lib/arjdbc/mssql.rb +2 -2
- data/lib/arjdbc/mssql/adapter.rb +271 -92
- data/lib/arjdbc/mssql/connection_methods.rb +30 -32
- data/lib/arjdbc/mssql/explain_support.rb +107 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +48 -18
- data/lib/arjdbc/mysql.rb +1 -1
- data/lib/arjdbc/mysql/adapter.rb +63 -14
- data/lib/arjdbc/mysql/connection_methods.rb +22 -24
- data/lib/arjdbc/mysql/explain_support.rb +2 -5
- data/lib/arjdbc/oracle.rb +1 -1
- data/lib/arjdbc/oracle/adapter.rb +78 -38
- data/lib/arjdbc/oracle/connection_methods.rb +9 -10
- data/lib/arjdbc/postgresql.rb +1 -1
- data/lib/arjdbc/postgresql/adapter.rb +964 -380
- data/lib/arjdbc/postgresql/column_cast.rb +136 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +19 -21
- data/lib/arjdbc/postgresql/explain_support.rb +3 -6
- data/lib/arjdbc/railtie.rb +9 -0
- data/lib/arjdbc/sqlite3.rb +1 -1
- data/lib/arjdbc/sqlite3/adapter.rb +73 -26
- data/lib/arjdbc/sqlite3/connection_methods.rb +27 -28
- data/lib/arjdbc/sqlite3/explain_support.rb +2 -5
- data/lib/arjdbc/sybase.rb +1 -1
- data/lib/arjdbc/version.rb +5 -4
- data/pom.xml +8 -0
- data/rakelib/02-test.rake +57 -51
- data/rakelib/compile.rake +17 -5
- data/rakelib/rails.rake +42 -31
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +4 -3
- data/src/java/arjdbc/derby/DerbyModule.java +98 -85
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +70 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +0 -4
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +26 -15
- data/src/java/arjdbc/jdbc/Callable.java +44 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +10 -2
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1675 -834
- data/src/java/arjdbc/jdbc/SQLBlock.java +9 -3
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +73 -36
- data/src/java/arjdbc/mysql/MySQLModule.java +11 -10
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +86 -80
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +27 -7
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +214 -0
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +25 -67
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +52 -49
- data/src/java/arjdbc/util/QuotingUtils.java +6 -6
- data/test/abstract_db_create.rb +11 -11
- data/test/activerecord/connection_adapters/type_conversion_test.rb +18 -12
- data/test/db/db2.rb +1 -1
- data/test/{db2_binary_test.rb → db/db2/binary_test.rb} +0 -0
- data/test/db/db2/has_many_through_test.rb +6 -0
- data/test/{db2_reset_column_information_test.rb → db/db2/reset_column_information_test.rb} +1 -2
- data/test/{db2_serialize_test.rb → db/db2/serialize_test.rb} +0 -0
- data/test/{db2_simple_test.rb → db/db2/simple_test.rb} +1 -8
- data/test/db/db2/test_helper.rb +6 -0
- data/test/{db2_test.rb → db/db2/unit_test.rb} +1 -1
- data/test/db/derby.rb +1 -1
- data/test/{derby_binary_test.rb → db/derby/binary_test.rb} +0 -0
- data/test/{derby_migration_test.rb → db/derby/migration_test.rb} +0 -0
- data/test/{derby_reset_column_information_test.rb → db/derby/reset_column_information_test.rb} +0 -0
- data/test/{derby_row_locking_test.rb → db/derby/row_locking_test.rb} +1 -4
- data/test/db/derby/schema_dump_test.rb +5 -0
- data/test/{derby_serialize_test.rb → db/derby/serialize_test.rb} +0 -0
- data/test/{derby_simple_test.rb → db/derby/simple_test.rb} +23 -38
- data/test/db/derby/test_helper.rb +6 -0
- data/test/db/derby/unit_test.rb +32 -0
- data/test/db/derby/xml_column_test.rb +17 -0
- data/test/db/h2.rb +1 -1
- data/test/{h2_binary_test.rb → db/h2/binary_test.rb} +0 -0
- data/test/{h2_change_column_test.rb → db/h2/change_column_test.rb} +1 -0
- data/test/{h2_schema_dump_test.rb → db/h2/schema_dump_test.rb} +0 -0
- data/test/{h2_serialize_test.rb → db/h2/serialize_test.rb} +0 -0
- data/test/{h2_simple_test.rb → db/h2/simple_test.rb} +3 -1
- data/test/db/hsqldb.rb +1 -1
- data/test/{hsqldb_binary_test.rb → db/hsqldb/binary_test.rb} +0 -0
- data/test/{hsqldb_schema_dump_test.rb → db/hsqldb/schema_dump_test.rb} +0 -0
- data/test/{hsqldb_serialize_test.rb → db/hsqldb/serialize_test.rb} +0 -0
- data/test/{hsqldb_simple_test.rb → db/hsqldb/simple_test.rb} +3 -1
- data/test/db/informix.rb +1 -1
- data/test/db/jdbc.rb +3 -2
- data/test/db/jdbc_derby.rb +1 -1
- data/test/db/jdbc_h2.rb +1 -1
- data/test/db/jdbc_mysql.rb +1 -1
- data/test/db/jdbc_postgres.rb +1 -1
- data/test/db/jndi_config.rb +1 -2
- data/test/db/jndi_pooled_config.rb +2 -3
- data/test/db/mssql.rb +2 -2
- data/test/{mssql_binary_test.rb → db/mssql/binary_test.rb} +0 -0
- data/test/{mssql_db_create_test.rb → db/mssql/db_create_test.rb} +1 -1
- data/test/db/mssql/exec_proc_test.rb +46 -0
- data/test/{mssql_identity_insert_test.rb → db/mssql/identity_insert_test.rb} +0 -0
- data/test/db/mssql/ignore_system_views_test.rb +40 -0
- data/test/{mssql_limit_offset_test.rb → db/mssql/limit_offset_test.rb} +10 -1
- data/test/{mssql_multibyte_test.rb → db/mssql/multibyte_test.rb} +0 -0
- data/test/db/mssql/multiple_connections_test.rb +71 -0
- data/test/{mssql_reset_column_information_test.rb → db/mssql/reset_column_information_test.rb} +0 -0
- data/test/{mssql_row_locking_test.rb → db/mssql/row_locking_test.rb} +0 -0
- data/test/{mssql_serialize_test.rb → db/mssql/serialize_test.rb} +1 -1
- data/test/db/mssql/simple_test.rb +140 -0
- data/test/db/mssql/transaction_test.rb +6 -0
- data/test/db/mssql/types_test.rb +205 -0
- data/test/{mssql_test.rb → db/mssql/unit_test.rb} +2 -2
- data/test/db/mysql.rb +1 -2
- data/test/db/mysql/_rails_test_mysql.32.out +6768 -0
- data/test/{mysql_binary_test.rb → db/mysql/binary_test.rb} +0 -0
- data/test/db/mysql/connection_test.rb +51 -0
- data/test/{mysql_db_create_test.rb → db/mysql/db_create_test.rb} +0 -0
- data/test/{mysql_index_length_test.rb → db/mysql/index_length_test.rb} +0 -0
- data/test/{mysql_multibyte_test.rb → db/mysql/multibyte_test.rb} +0 -0
- data/test/{mysql_nonstandard_primary_key_test.rb → db/mysql/nonstandard_primary_key_test.rb} +0 -0
- data/test/{mysql_reset_column_information_test.rb → db/mysql/reset_column_information_test.rb} +0 -0
- data/test/{mysql_schema_dump_test.rb → db/mysql/schema_dump_test.rb} +9 -1
- data/test/{mysql_serialize_test.rb → db/mysql/serialize_test.rb} +0 -0
- data/test/{mysql_simple_test.rb → db/mysql/simple_test.rb} +16 -8
- data/test/db/mysql/transaction_test.rb +6 -0
- data/test/db/mysql/types_test.rb +30 -0
- data/test/{mysql_test.rb → db/mysql/unit_test.rb} +1 -1
- data/test/db/mysql_config.rb +1 -1
- data/test/db/oracle.rb +1 -1
- data/test/{oracle_binary_test.rb → db/oracle/binary_test.rb} +0 -0
- data/test/{oracle_limit_test.rb → db/oracle/limit_test.rb} +0 -0
- data/test/db/oracle/multibyte_test.rb +22 -0
- data/test/{oracle_reset_column_information_test.rb → db/oracle/reset_column_information_test.rb} +0 -0
- data/test/{oracle_serialize_test.rb → db/oracle/serialize_test.rb} +0 -0
- data/test/{oracle_simple_test.rb → db/oracle/simple_test.rb} +14 -19
- data/test/{oracle_specific_test.rb → db/oracle/specific_test.rb} +62 -16
- data/test/db/oracle/transaction_test.rb +31 -0
- data/test/db/oracle/unit_test.rb +31 -0
- data/test/db/postgres.rb +1 -1
- data/test/db/postgres/_rails_test_postgres.32.out +6777 -0
- data/test/db/postgres/a_custom_primary_key_test.rb +50 -0
- data/test/db/postgres/array_type_test.rb +101 -0
- data/test/{postgres_binary_test.rb → db/postgres/binary_test.rb} +0 -0
- data/test/db/postgres/connection_test.rb +55 -0
- data/test/db/postgres/data_types_test.rb +703 -0
- data/test/{postgres_db_create_test.rb → db/postgres/db_create_test.rb} +1 -1
- data/test/{postgres_drop_db_test.rb → db/postgres/db_drop_test.rb} +2 -0
- data/test/db/postgres/hstore_test.rb +200 -0
- data/test/db/postgres/information_schema_leak_test.rb +30 -0
- data/test/db/postgres/json_test.rb +86 -0
- data/test/db/postgres/ltree_test.rb +50 -0
- data/test/{postgres_mixed_case_test.rb → db/postgres/mixed_case_test.rb} +0 -0
- data/test/db/postgres/native_types_test.rb +128 -0
- data/test/{postgres_reserved_test.rb → db/postgres/reserved_test.rb} +0 -0
- data/test/{postgres_reset_column_information_test.rb → db/postgres/reset_column_information_test.rb} +0 -0
- data/test/{postgres_row_locking_test.rb → db/postgres/row_locking_test.rb} +0 -0
- data/test/{postgres_schema_dump_test.rb → db/postgres/schema_dump_test.rb} +4 -4
- data/test/db/postgres/schema_test.rb +113 -0
- data/test/{postgres_simple_test.rb → db/postgres/simple_test.rb} +48 -8
- data/test/{postgres_table_alias_length_test.rb → db/postgres/table_alias_length_test.rb} +2 -1
- data/test/db/postgres/transaction_test.rb +6 -0
- data/test/{postgres_test.rb → db/postgres/unit_test.rb} +3 -3
- data/test/db/sqlite3.rb +1 -1
- data/test/db/sqlite3/_rails_test_sqlite3.32.out +6502 -0
- data/test/db/sqlite3/has_many_though_test.rb +6 -0
- data/test/{sqlite3_reset_column_information_test.rb → db/sqlite3/reset_column_information_test.rb} +0 -0
- data/test/{sqlite3_schema_dump_test.rb → db/sqlite3/schema_dump_test.rb} +0 -0
- data/test/{sqlite3_serialize_test.rb → db/sqlite3/serialize_test.rb} +0 -0
- data/test/{sqlite3_simple_test.rb → db/sqlite3/simple_test.rb} +63 -63
- data/test/db/sqlite3/transaction_test.rb +32 -0
- data/test/{sqlite3_type_conversion_test.rb → db/sqlite3/type_conversion_test.rb} +0 -0
- data/test/has_many_through.rb +29 -64
- data/test/jdbc/oracle.rb +11 -0
- data/test/jndi_test.rb +16 -4
- data/test/models/auto_id.rb +1 -1
- data/test/models/rights_and_roles.rb +57 -0
- data/test/row_locking.rb +3 -0
- data/test/schema_dump.rb +24 -10
- data/test/simple.rb +359 -104
- data/test/test_helper.rb +4 -2
- data/test/transaction.rb +109 -0
- metadata +119 -86
- data/lib/arjdbc/jdbc/compatibility.rb +0 -51
- data/lib/arjdbc/jdbc/core_ext.rb +0 -24
- data/lib/arjdbc/jdbc/discover.rb +0 -18
- data/test/derby_schema_dump_test.rb +0 -9
- data/test/mssql_ignore_system_views_test.rb +0 -30
- data/test/mssql_legacy_types_test.rb +0 -58
- data/test/mssql_null_test.rb +0 -14
- data/test/mssql_simple_test.rb +0 -51
- data/test/postgres_information_schema_leak_test.rb +0 -28
- data/test/postgres_native_type_mapping_test.rb +0 -93
- data/test/postgres_nonseq_pkey_test.rb +0 -38
- data/test/postgres_schema_search_path_test.rb +0 -48
- data/test/postgres_type_conversion_test.rb +0 -33
File without changes
|
@@ -1,7 +1,9 @@
|
|
1
|
-
require 'jdbc_common'
|
2
1
|
require 'db/hsqldb'
|
2
|
+
require 'simple'
|
3
3
|
|
4
4
|
class HsqldbSimpleTest < Test::Unit::TestCase
|
5
5
|
include SimpleTestMethods
|
6
6
|
include ExplainSupportTestMethods if ar_version("3.1")
|
7
|
+
include ActiveRecord3TestMethods
|
8
|
+
include CustomSelectTestMethods
|
7
9
|
end
|
data/test/db/informix.rb
CHANGED
data/test/db/jdbc.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
require 'db/mysql_config'
|
3
3
|
|
4
4
|
require 'jdbc/mysql' # driver not loaded for plain JDBC
|
@@ -7,9 +7,10 @@ Jdbc::MySQL.load_driver
|
|
7
7
|
JDBC_CONFIG = {
|
8
8
|
:adapter => 'jdbc',
|
9
9
|
:driver => 'com.mysql.jdbc.Driver',
|
10
|
-
:url => "jdbc:mysql://#{MYSQL_CONFIG[:host]}/#{MYSQL_CONFIG[:database]}",
|
11
10
|
:username => MYSQL_CONFIG[:username],
|
12
11
|
:password => MYSQL_CONFIG[:password],
|
13
12
|
}
|
13
|
+
JDBC_CONFIG[:url] = "jdbc:mysql://" <<
|
14
|
+
"#{MYSQL_CONFIG[:host]}:#{MYSQL_CONFIG[:port] || 3306}/#{MYSQL_CONFIG[:database]}"
|
14
15
|
|
15
16
|
ActiveRecord::Base.establish_connection(JDBC_CONFIG)
|
data/test/db/jdbc_derby.rb
CHANGED
data/test/db/jdbc_h2.rb
CHANGED
data/test/db/jdbc_mysql.rb
CHANGED
data/test/db/jdbc_postgres.rb
CHANGED
data/test/db/jndi_config.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'arjdbc'
|
2
|
-
require 'jdbc_common'
|
3
1
|
|
4
2
|
JNDI_CONFIG = {
|
5
3
|
:adapter => 'jdbc', :jndi => 'jdbc/DerbyDB'
|
@@ -32,4 +30,5 @@ begin
|
|
32
30
|
init_context.create_subcontext 'jdbc'
|
33
31
|
rescue javax.naming.NameAlreadyBoundException
|
34
32
|
end
|
33
|
+
|
35
34
|
init_context.bind JNDI_CONFIG[:jndi], data_source
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'arjdbc'
|
2
|
-
require 'jdbc_common'
|
3
1
|
|
4
2
|
JNDI_POOLED_CONFIG = {
|
5
3
|
:adapter => 'jdbc', :jndi => 'jdbc/PooledDerbyDB'
|
@@ -32,4 +30,5 @@ begin
|
|
32
30
|
init_context.create_subcontext 'jdbc'
|
33
31
|
rescue javax.naming.NameAlreadyBoundException
|
34
32
|
end
|
35
|
-
|
33
|
+
|
34
|
+
init_context.bind JNDI_POOLED_CONFIG[:jndi], data_source
|
data/test/db/mssql.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
MSSQL_CONFIG = { :adapter => 'mssql' }
|
4
4
|
MSSQL_CONFIG[:database] = ENV['SQLDATABASE'] || 'weblog_development'
|
@@ -8,4 +8,4 @@ MSSQL_CONFIG[:password] = ENV['SQLPASS'] || ''
|
|
8
8
|
MSSQL_CONFIG[:host] = ENV['SQLHOST'] || 'localhost'
|
9
9
|
MSSQL_CONFIG[:port] = ENV['SQLPORT'] if ENV['SQLPORT']
|
10
10
|
|
11
|
-
ActiveRecord::Base.establish_connection(MSSQL_CONFIG)
|
11
|
+
ActiveRecord::Base.establish_connection(MSSQL_CONFIG)
|
File without changes
|
@@ -0,0 +1,46 @@
|
|
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
|
File without changes
|
@@ -0,0 +1,40 @@
|
|
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
|
+
|
@@ -108,7 +108,7 @@ class MSSQLLimitOffsetTest < Test::Unit::TestCase
|
|
108
108
|
end
|
109
109
|
ships = LegacyShip.limit(3)
|
110
110
|
assert_equal(3, ships.size)
|
111
|
-
end
|
111
|
+
end if ar_version('3.0')
|
112
112
|
|
113
113
|
def test_limit_and_offset
|
114
114
|
%w(one two three four five six seven eight).each do |name|
|
@@ -169,4 +169,13 @@ class MSSQLLimitOffsetTest < Test::Unit::TestCase
|
|
169
169
|
assert_equal("You must specify :limit with :offset.", error.message)
|
170
170
|
end
|
171
171
|
|
172
|
+
def test_limit_with_group_by
|
173
|
+
%w(one two three four five six seven eight).each do |name|
|
174
|
+
LongShip.create!(:name => name)
|
175
|
+
end
|
176
|
+
|
177
|
+
ships = LongShip.group(:name).find(:all, :limit => 2)
|
178
|
+
asset_equal(['one', 'two'], ships.map(&:name))
|
179
|
+
end if ar_version('3.0')
|
180
|
+
|
172
181
|
end
|
File without changes
|
@@ -0,0 +1,71 @@
|
|
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/{mssql_reset_column_information_test.rb → db/mssql/reset_column_information_test.rb}
RENAMED
File without changes
|
File without changes
|
@@ -0,0 +1,140 @@
|
|
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
|