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,71 +0,0 @@
|
|
1
|
-
require 'rake_test_support'
|
2
|
-
require 'db/sqlite3'
|
3
|
-
|
4
|
-
class SQLite3RakeTest < Test::Unit::TestCase
|
5
|
-
include RakeTestSupport
|
6
|
-
|
7
|
-
def db_name; 'rake_test.sqlite3'; end
|
8
|
-
|
9
|
-
def do_setup
|
10
|
-
File.delete('rake_test.sqlite3') if File.exists?('rake_test.sqlite3')
|
11
|
-
end
|
12
|
-
|
13
|
-
def do_teardown
|
14
|
-
File.delete('rake_test.sqlite3') if File.exists?('rake_test.sqlite3')
|
15
|
-
end
|
16
|
-
|
17
|
-
test 'rake db:create (and db:drop)' do
|
18
|
-
Rake::Task["db:create"].invoke
|
19
|
-
assert_true File.exists?('rake_test.sqlite3')
|
20
|
-
|
21
|
-
Rake::Task["db:drop"].invoke
|
22
|
-
assert_false File.exists?('rake_test.sqlite3')
|
23
|
-
end
|
24
|
-
|
25
|
-
test 'rake db:test:purge' do
|
26
|
-
# Rake::Task["db:create"].invoke
|
27
|
-
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
28
|
-
ActiveRecord::Base.connection.create_table('users') { |t| t.string :name }
|
29
|
-
ActiveRecord::Base.connection.disconnect!
|
30
|
-
|
31
|
-
Rake::Task["db:test:purge"].invoke
|
32
|
-
|
33
|
-
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
34
|
-
assert_false ActiveRecord::Base.connection.table_exists?('users')
|
35
|
-
ActiveRecord::Base.connection.disconnect!
|
36
|
-
end
|
37
|
-
|
38
|
-
test 'rake db:structure:dump (and db:structure:load)' do
|
39
|
-
omit('sqlite3 not available') unless self.class.find_executable?('sqlite3')
|
40
|
-
create_rake_test_database do |connection|
|
41
|
-
create_schema_migrations_table(connection)
|
42
|
-
connection.create_table('users') { |t| t.string :name; t.timestamps }
|
43
|
-
end
|
44
|
-
|
45
|
-
structure_sql = File.join('db', structure_sql_filename)
|
46
|
-
begin
|
47
|
-
Dir.mkdir 'db' # db/structure.sql
|
48
|
-
Rake::Task["db:structure:dump"].invoke
|
49
|
-
|
50
|
-
assert File.exists?(structure_sql)
|
51
|
-
assert_match /CREATE TABLE .*?users/, File.read(structure_sql)
|
52
|
-
|
53
|
-
# db:structure:load
|
54
|
-
File.delete('rake_test.sqlite3')
|
55
|
-
Rake::Task["db:structure:load"].invoke
|
56
|
-
|
57
|
-
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
58
|
-
assert ActiveRecord::Base.connection.table_exists?('users')
|
59
|
-
ActiveRecord::Base.connection.disconnect!
|
60
|
-
ensure
|
61
|
-
File.delete(structure_sql) if File.exists?(structure_sql)
|
62
|
-
Dir.rmdir 'db'
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
test 'rake db:charset' do
|
67
|
-
expect_rake_output('UTF-8')
|
68
|
-
Rake::Task["db:charset"].invoke
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
@@ -1,268 +0,0 @@
|
|
1
|
-
require 'db/sqlite3'
|
2
|
-
require 'models/data_types'
|
3
|
-
require 'models/validates_uniqueness_of_string'
|
4
|
-
require 'simple'
|
5
|
-
require 'jdbc_common'
|
6
|
-
|
7
|
-
class SQLite3SimpleTest < Test::Unit::TestCase
|
8
|
-
include SimpleTestMethods
|
9
|
-
include ActiveRecord3TestMethods
|
10
|
-
include ColumnNameQuotingTests
|
11
|
-
include DirtyAttributeTests
|
12
|
-
include XmlColumnTests
|
13
|
-
include ExplainSupportTestMethods if ar_version("3.1")
|
14
|
-
include CustomSelectTestMethods
|
15
|
-
|
16
|
-
def test_recreate_database
|
17
|
-
assert connection.tables.include?(Entry.table_name)
|
18
|
-
db = connection.database_name
|
19
|
-
connection.recreate_database(db)
|
20
|
-
assert ! connection.tables.include?(Entry.table_name)
|
21
|
-
self.setup # avoid teardown complaining
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_execute_insert
|
25
|
-
user = User.create! :login => 'user1'
|
26
|
-
Entry.create! :title => 'E1', :user_id => user.id
|
27
|
-
|
28
|
-
assert_equal 1, Entry.count
|
29
|
-
id = connection.execute "INSERT INTO entries (title, content) VALUES ('Execute Insert', 'This now works with SQLite3')"
|
30
|
-
assert_equal Entry.last.id, id
|
31
|
-
assert_equal 2, Entry.count
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_execute_update
|
35
|
-
user = User.create! :login => 'user1'
|
36
|
-
Entry.create! :title => 'E1', :user_id => user.id
|
37
|
-
|
38
|
-
affected_rows = connection.execute "UPDATE entries SET title = 'Execute Update' WHERE id = #{Entry.first.id}"
|
39
|
-
assert_equal 1, affected_rows
|
40
|
-
assert_equal 'Execute Update', Entry.first.title
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_columns
|
44
|
-
cols = ActiveRecord::Base.connection.columns("entries")
|
45
|
-
assert cols.find {|col| col.name == "title"}
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_remove_column
|
49
|
-
assert_nothing_raised do
|
50
|
-
ActiveRecord::Schema.define do
|
51
|
-
add_column "entries", "test_remove_column", :string
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
cols = ActiveRecord::Base.connection.columns("entries")
|
56
|
-
assert cols.find {|col| col.name == "test_remove_column"}
|
57
|
-
|
58
|
-
#assert_nothing_raised do
|
59
|
-
ActiveRecord::Schema.define do
|
60
|
-
remove_column "entries", "test_remove_column"
|
61
|
-
end
|
62
|
-
#end
|
63
|
-
|
64
|
-
cols = ActiveRecord::Base.connection.columns("entries")
|
65
|
-
assert_nil cols.find {|col| col.name == "test_remove_column"}
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_rename_column
|
69
|
-
#assert_nothing_raised do
|
70
|
-
ActiveRecord::Schema.define do
|
71
|
-
rename_column "entries", "title", "name"
|
72
|
-
end
|
73
|
-
#end
|
74
|
-
|
75
|
-
cols = ActiveRecord::Base.connection.columns("entries")
|
76
|
-
assert_not_nil cols.find {|col| col.name == "name"}
|
77
|
-
assert_nil cols.find {|col| col.name == "title"}
|
78
|
-
|
79
|
-
assert_nothing_raised do
|
80
|
-
ActiveRecord::Schema.define do
|
81
|
-
rename_column "entries", "name", "title"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
cols = ActiveRecord::Base.connection.columns("entries")
|
86
|
-
assert_not_nil cols.find {|col| col.name == "title"}
|
87
|
-
assert_nil cols.find {|col| col.name == "name"}
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_rename_column_preserves_content
|
91
|
-
title = "First post!"
|
92
|
-
content = "Hello from JRuby on Rails!"
|
93
|
-
rating = 205.76
|
94
|
-
user = User.create! :login => "something"
|
95
|
-
entry = Entry.create! :title => title, :content => content, :rating => rating, :user => user
|
96
|
-
|
97
|
-
entry.reload
|
98
|
-
#assert_equal title, entry.title
|
99
|
-
#assert_equal content, entry.content
|
100
|
-
#assert_equal rating, entry.rating
|
101
|
-
|
102
|
-
ActiveRecord::Schema.define do
|
103
|
-
rename_column "entries", "title", "name"
|
104
|
-
rename_column "entries", "rating", "popularity"
|
105
|
-
end
|
106
|
-
|
107
|
-
entry = Entry.find(entry.id)
|
108
|
-
assert_equal title, entry.name
|
109
|
-
assert_equal content, entry.content
|
110
|
-
assert_equal rating, entry.popularity
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_rename_column_preserves_index
|
114
|
-
assert_equal(0, connection.indexes(:entries).size)
|
115
|
-
|
116
|
-
index_name = "entries_index"
|
117
|
-
|
118
|
-
ActiveRecord::Schema.define do
|
119
|
-
add_index "entries", "title", :name => index_name
|
120
|
-
end
|
121
|
-
|
122
|
-
indexes = connection.indexes(:entries)
|
123
|
-
assert_equal(1, indexes.size)
|
124
|
-
assert_equal "entries", indexes.first.table.to_s
|
125
|
-
assert_equal index_name, indexes.first.name
|
126
|
-
assert ! indexes.first.unique
|
127
|
-
assert_equal ["title"], indexes.first.columns
|
128
|
-
|
129
|
-
ActiveRecord::Schema.define do
|
130
|
-
rename_column "entries", "title", "name"
|
131
|
-
end
|
132
|
-
|
133
|
-
indexes = connection.indexes(:entries)
|
134
|
-
assert_equal(1, indexes.size)
|
135
|
-
assert_equal "entries", indexes.first.table.to_s
|
136
|
-
assert_equal index_name, indexes.first.name
|
137
|
-
assert ! indexes.first.unique
|
138
|
-
assert_equal ["name"], indexes.first.columns
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_column_default
|
142
|
-
assert_nothing_raised do
|
143
|
-
ActiveRecord::Schema.define do
|
144
|
-
add_column "entries", "test_column_default", :string
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
columns = ActiveRecord::Base.connection.columns("entries")
|
149
|
-
assert column = columns.find{ |c| c.name == "test_column_default" }
|
150
|
-
assert_equal column.default, nil
|
151
|
-
end
|
152
|
-
|
153
|
-
def test_change_column_default
|
154
|
-
assert_nothing_raised do
|
155
|
-
ActiveRecord::Schema.define do
|
156
|
-
add_column "entries", "test_change_column_default", :string, :default => "unchanged"
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
columns = ActiveRecord::Base.connection.columns("entries")
|
161
|
-
assert column = columns.find{ |c| c.name == "test_change_column_default" }
|
162
|
-
assert_equal column.default, 'unchanged'
|
163
|
-
|
164
|
-
assert_nothing_raised do
|
165
|
-
ActiveRecord::Schema.define do
|
166
|
-
change_column_default "entries", "test_change_column_default", "changed"
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
columns = ActiveRecord::Base.connection.columns("entries")
|
171
|
-
assert column = columns.find{ |c| c.name == "test_change_column_default" }
|
172
|
-
assert_equal column.default, 'changed'
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_change_column
|
176
|
-
assert_nothing_raised do
|
177
|
-
ActiveRecord::Schema.define do
|
178
|
-
add_column "entries", "test_change_column", :string
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
columns = ActiveRecord::Base.connection.columns("entries")
|
183
|
-
assert column = columns.find{ |c| c.name == "test_change_column" }
|
184
|
-
assert_equal column.type, :string
|
185
|
-
|
186
|
-
assert_nothing_raised do
|
187
|
-
ActiveRecord::Schema.define do
|
188
|
-
change_column "entries", "test_change_column", :integer
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
columns = ActiveRecord::Base.connection.columns("entries")
|
193
|
-
assert column = columns.find{ |c| c.name == "test_change_column" }
|
194
|
-
assert_equal column.type, :integer
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_change_column_with_new_precision_and_scale
|
198
|
-
Entry.delete_all
|
199
|
-
Entry.
|
200
|
-
connection.
|
201
|
-
change_column "entries", "rating", :decimal, :precision => 9, :scale => 7
|
202
|
-
Entry.reset_column_information
|
203
|
-
change_column = Entry.columns_hash["rating"]
|
204
|
-
assert_equal 9, change_column.precision
|
205
|
-
assert_equal 7, change_column.scale
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_change_column_preserve_other_column_precision_and_scale
|
209
|
-
Entry.delete_all
|
210
|
-
Entry.
|
211
|
-
connection.
|
212
|
-
change_column "entries", "rating", :decimal, :precision => 9, :scale => 7
|
213
|
-
Entry.reset_column_information
|
214
|
-
|
215
|
-
rating_column = Entry.columns_hash["rating"]
|
216
|
-
assert_equal 9, rating_column.precision
|
217
|
-
assert_equal 7, rating_column.scale
|
218
|
-
|
219
|
-
Entry.
|
220
|
-
connection.
|
221
|
-
change_column "entries", "title", :string, :null => false
|
222
|
-
Entry.reset_column_information
|
223
|
-
|
224
|
-
rating_column = Entry.columns_hash["rating"]
|
225
|
-
assert_equal 9, rating_column.precision
|
226
|
-
assert_equal 7, rating_column.scale
|
227
|
-
end
|
228
|
-
|
229
|
-
def test_delete_sql
|
230
|
-
ActiveRecord::Base.connection.send :delete_sql, "DELETE FROM entries"
|
231
|
-
assert Entry.all.empty?
|
232
|
-
end
|
233
|
-
|
234
|
-
# @override
|
235
|
-
def test_big_decimal
|
236
|
-
test_value = 1234567890.0 # FINE just like native adapter
|
237
|
-
db_type = DbType.create!(:big_decimal => test_value)
|
238
|
-
db_type = DbType.find(db_type.id)
|
239
|
-
assert_equal test_value, db_type.big_decimal
|
240
|
-
|
241
|
-
test_value = 1234567890_123456 # FINE just like native adapter
|
242
|
-
db_type = DbType.create!(:big_decimal => test_value)
|
243
|
-
db_type = DbType.find(db_type.id)
|
244
|
-
assert_equal test_value, db_type.big_decimal
|
245
|
-
|
246
|
-
# NOTE: this is getting f*cked up in the native adapter as well although
|
247
|
-
# differently and only when inserted manually - works with PSs (3.1+) :
|
248
|
-
test_value = 1234567890_1234567890.0
|
249
|
-
db_type = DbType.create!(:big_decimal => test_value)
|
250
|
-
db_type = DbType.find(db_type.id)
|
251
|
-
# TODO native gets us 12345678901234567000.0 JDBC gets us 1
|
252
|
-
#assert_equal test_value, db_type.big_decimal
|
253
|
-
#super
|
254
|
-
end
|
255
|
-
|
256
|
-
# @override SQLite3 returns FLOAT (JDBC type) for DECIMAL columns
|
257
|
-
def test_custom_select_decimal
|
258
|
-
model = DbType.create! :sample_small_decimal => ( decimal = BigDecimal.new('5.45') )
|
259
|
-
if ActiveRecord::VERSION::MAJOR >= 3
|
260
|
-
model = DbType.where("id = #{model.id}").select('sample_small_decimal AS custom_decimal').first
|
261
|
-
else
|
262
|
-
model = DbType.find(:first, :conditions => "id = #{model.id}", :select => 'sample_small_decimal AS custom_decimal')
|
263
|
-
end
|
264
|
-
assert_equal decimal, model.custom_decimal
|
265
|
-
#assert_instance_of BigDecimal, model.custom_decimal
|
266
|
-
end
|
267
|
-
|
268
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'db/sqlite3'
|
2
|
-
require 'transaction'
|
3
|
-
|
4
|
-
class SQLite3TransactionTest < Test::Unit::TestCase
|
5
|
-
include TransactionTestMethods
|
6
|
-
|
7
|
-
def test_supports_transaction_isolation
|
8
|
-
assert ActiveRecord::Base.connection.supports_transaction_isolation?
|
9
|
-
# NOTE: adapter tell us it supports but JDBC meta-data API returns false ?!
|
10
|
-
#assert ActiveRecord::Base.connection.supports_transaction_isolation?(:read_uncommitted)
|
11
|
-
assert ActiveRecord::Base.connection.supports_transaction_isolation?(:serializable)
|
12
|
-
end
|
13
|
-
|
14
|
-
# supports only TRANSACTION_SERIALIZABLE and TRANSACTION_READ_UNCOMMITTED
|
15
|
-
|
16
|
-
def test_transaction_isolation_read_committed
|
17
|
-
assert ! ActiveRecord::Base.connection.supports_transaction_isolation?(:read_committed)
|
18
|
-
|
19
|
-
assert_raise ActiveRecord::TransactionIsolationError do
|
20
|
-
super
|
21
|
-
end
|
22
|
-
end if Test::Unit::TestCase.ar_version('4.0')
|
23
|
-
|
24
|
-
def test_transaction_isolation_repeatable_read
|
25
|
-
assert ! ActiveRecord::Base.connection.supports_transaction_isolation?(:repeatable_read)
|
26
|
-
|
27
|
-
assert_raise ActiveRecord::TransactionIsolationError do
|
28
|
-
super
|
29
|
-
end
|
30
|
-
end if Test::Unit::TestCase.ar_version('4.0')
|
31
|
-
|
32
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'jdbc_common'
|
3
|
-
require 'db/sqlite3'
|
4
|
-
|
5
|
-
class SQLite3TypeConversionTest < Test::Unit::TestCase
|
6
|
-
|
7
|
-
if defined?(JRUBY_VERSION)
|
8
|
-
JInteger = java.lang.Integer
|
9
|
-
else
|
10
|
-
JInteger = Fixnum
|
11
|
-
class Fixnum
|
12
|
-
MAX_VALUE = 1024 * 1024 # arbitrary value ... we could pick
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.startup; DbTypeMigration.up; end
|
17
|
-
def self.shutdown; DbTypeMigration.down; end
|
18
|
-
|
19
|
-
TEST_BINARY = "Some random binary data % \0 and then some"
|
20
|
-
|
21
|
-
@@time_zone = Time.zone
|
22
|
-
|
23
|
-
setup do
|
24
|
-
Time.zone = ActiveSupport::TimeZone['UTC']
|
25
|
-
DbType.delete_all
|
26
|
-
some_time = Time.now
|
27
|
-
DbType.create!(
|
28
|
-
:sample_timestamp => some_time,
|
29
|
-
:sample_datetime => some_time.to_datetime,
|
30
|
-
:sample_time => some_time.to_time,
|
31
|
-
:sample_date => some_time.to_date,
|
32
|
-
:sample_decimal => JInteger::MAX_VALUE + 1,
|
33
|
-
:sample_small_decimal => 3.14,
|
34
|
-
:sample_binary => TEST_BINARY)
|
35
|
-
DbType.create!(
|
36
|
-
:sample_timestamp => some_time,
|
37
|
-
:sample_datetime => some_time.to_datetime,
|
38
|
-
:sample_time => some_time.to_time,
|
39
|
-
:sample_date => some_time.to_date,
|
40
|
-
:sample_decimal => JInteger::MAX_VALUE + 1,
|
41
|
-
:sample_small_decimal => 1.0,
|
42
|
-
:sample_binary => TEST_BINARY)
|
43
|
-
end
|
44
|
-
|
45
|
-
teardown { Time.zone = @@time_zone; DbType.delete_all }
|
46
|
-
|
47
|
-
def test_decimal
|
48
|
-
types = DbType.first
|
49
|
-
assert_equal((JInteger::MAX_VALUE + 1), types.sample_decimal)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_decimal_scale
|
53
|
-
assert_equal(2, DbType.columns_hash["sample_small_decimal"].scale)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_decimal_precision
|
57
|
-
assert_equal(3, DbType.columns_hash["sample_small_decimal"].precision)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_small_decimal
|
61
|
-
types = DbType.all :order => "sample_small_decimal DESC"
|
62
|
-
assert_equal(3.14, types[0].sample_small_decimal)
|
63
|
-
assert_equal(1.0, types[1].sample_small_decimal)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_small_decimal_with_ordering
|
67
|
-
types = DbType.all :order => "sample_small_decimal ASC"
|
68
|
-
types[1].sample_small_decimal
|
69
|
-
assert_equal(1.0, types[0].sample_small_decimal)
|
70
|
-
assert_equal(3.14, types[1].sample_small_decimal)
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_binary
|
74
|
-
types = DbType.first
|
75
|
-
assert_equal(TEST_BINARY, types.sample_binary)
|
76
|
-
end
|
77
|
-
|
78
|
-
class DualEncoding < ActiveRecord::Base
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_quote_binary_column_escapes_it
|
82
|
-
DualEncoding.connection.execute(<<-eosql)
|
83
|
-
CREATE TABLE dual_encodings (
|
84
|
-
id integer PRIMARY KEY AUTOINCREMENT,
|
85
|
-
name string,
|
86
|
-
data binary
|
87
|
-
)
|
88
|
-
eosql
|
89
|
-
str = "01 \x80"
|
90
|
-
str.force_encoding('ASCII-8BIT') if str.respond_to?(:force_encoding)
|
91
|
-
binary = DualEncoding.new :name => '12ščťžýáííéúäô', :data => str
|
92
|
-
binary.save!
|
93
|
-
assert_equal str, binary.data
|
94
|
-
binary.reload
|
95
|
-
if str.respond_to?(:force_encoding)
|
96
|
-
assert_equal '12ščťžýáííéúäô'.force_encoding('UTF-8'), binary.name
|
97
|
-
assert_equal "01 \x80".force_encoding('ASCII-8BIT'), binary.data
|
98
|
-
else
|
99
|
-
assert_equal '12ščťžýáííéúäô', binary.name
|
100
|
-
assert_equal "01 \x80", binary.data
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|