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,173 +0,0 @@
|
|
1
|
-
# encoding: ASCII-8BIT
|
2
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
3
|
-
require 'simple'
|
4
|
-
require 'has_many_through'
|
5
|
-
|
6
|
-
class DerbySimpleTest < Test::Unit::TestCase
|
7
|
-
include SimpleTestMethods
|
8
|
-
include ActiveRecord3TestMethods
|
9
|
-
include CustomSelectTestMethods
|
10
|
-
|
11
|
-
# @override
|
12
|
-
def test_empty_insert_statement
|
13
|
-
# "INSERT INTO table VALUES ( DEFAULT ) " not supported by Derby DB
|
14
|
-
pend if ar_version('4.0')
|
15
|
-
super
|
16
|
-
end
|
17
|
-
|
18
|
-
# Check that a table-less VALUES(xxx) query (like SELECT works.
|
19
|
-
def test_values
|
20
|
-
value = nil
|
21
|
-
assert_nothing_raised do
|
22
|
-
value = ActiveRecord::Base.connection.send(:select_rows, "VALUES('ur', 'doin', 'it', 'right')")
|
23
|
-
end
|
24
|
-
assert_equal [['ur', 'doin', 'it', 'right']], value
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_find_with_include_and_order
|
28
|
-
Entry.create! :title => 'First Post!',
|
29
|
-
:content => "Hello from 'JRuby on Rails'!",
|
30
|
-
:user => (user = User.create!(:login => "someone"))
|
31
|
-
|
32
|
-
users = User.find(:all, :include=>[:entries], :order=>"entries.rating DESC", :limit => 2)
|
33
|
-
|
34
|
-
assert users.include?(user)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_text_and_string_conversions
|
38
|
-
e = DbType.create!(:sample_string => '', :sample_text => '').reload
|
39
|
-
|
40
|
-
# Derby will normally reject any non text value.
|
41
|
-
# The adapter has been patched to convert non text values to strings
|
42
|
-
['string', 45, 4.3, 18488425889503641645].each do |value|
|
43
|
-
assert_nothing_raised do
|
44
|
-
e.sample_string = value
|
45
|
-
e.sample_text = value
|
46
|
-
e.save!
|
47
|
-
e.reload
|
48
|
-
assert_equal [value.to_s]*2, [e.sample_string, e.sample_text]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
[true, false].each do |value|
|
52
|
-
assert_nothing_raised do
|
53
|
-
e.sample_string = value
|
54
|
-
e.sample_text = value
|
55
|
-
e.save!
|
56
|
-
e.reload
|
57
|
-
assert_equal [value ? "1" : "0"]*2, [e.sample_string, e.sample_text]
|
58
|
-
end
|
59
|
-
end
|
60
|
-
assert_nothing_raised do
|
61
|
-
value = Time.now
|
62
|
-
if ActiveRecord::VERSION::MAJOR >= 3
|
63
|
-
str = value.utc.to_s(:db)
|
64
|
-
else # AR 2 #quoted_date did not do TZ conversions
|
65
|
-
str = value.to_s(:db)
|
66
|
-
end
|
67
|
-
e.sample_string = value
|
68
|
-
e.sample_text = value
|
69
|
-
e.save!
|
70
|
-
e.reload
|
71
|
-
assert_equal [str]*2, [e.sample_string, e.sample_text]
|
72
|
-
end
|
73
|
-
assert_nothing_raised do
|
74
|
-
value = Date.today
|
75
|
-
e.sample_string = value
|
76
|
-
e.sample_text = value
|
77
|
-
e.save!
|
78
|
-
e.reload
|
79
|
-
assert_equal [value.to_s(:db)]*2, [e.sample_string, e.sample_text]
|
80
|
-
end
|
81
|
-
value = {'a' => 7}
|
82
|
-
assert_nothing_raised do
|
83
|
-
e.sample_string = value
|
84
|
-
e.sample_text = value
|
85
|
-
e.save!
|
86
|
-
e.reload
|
87
|
-
assert_equal [value.to_yaml]*2, [e.sample_string, e.sample_text]
|
88
|
-
end
|
89
|
-
value = BigDecimal.new("0")
|
90
|
-
assert_nothing_raised do
|
91
|
-
e.sample_string = value
|
92
|
-
e.sample_text = value
|
93
|
-
e.save!
|
94
|
-
e.reload
|
95
|
-
assert_equal ['0.0']*2, [e.sample_string, e.sample_text]
|
96
|
-
end
|
97
|
-
# An empty string is treated as a null value in Oracle: http://www.techonthenet.com/oracle/questions/empty_null.php
|
98
|
-
unless ActiveRecord::Base.connection.adapter_name =~ /oracle/i
|
99
|
-
assert_nothing_raised do
|
100
|
-
e.sample_string = nil
|
101
|
-
e.sample_text = nil
|
102
|
-
e.save!
|
103
|
-
e.reload
|
104
|
-
assert_equal [nil]*2, [e.sample_string, e.sample_text]
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_data_types
|
110
|
-
# from test/models/data_types.rb, with the modifications as noted in the comments.
|
111
|
-
expected_types = [
|
112
|
-
["id", :integer, { }],
|
113
|
-
["sample_timestamp", :datetime, { }], # :timestamp is just an alias for :datetime in Derby
|
114
|
-
["sample_datetime", :datetime, { }],
|
115
|
-
["sample_date", :date, { }],
|
116
|
-
["sample_time", :time, { }],
|
117
|
-
# NOTE: it's an :integer because the :scale is 0 (...right?) :
|
118
|
-
["sample_decimal", :integer, { :precision => 9, :scale => 0 }],
|
119
|
-
["sample_small_decimal", :decimal, { :precision => 3, :scale => 2, :default => 3.14 }],
|
120
|
-
["sample_default_decimal", :integer, { }], # decimal by default assumes :scale => 0
|
121
|
-
["sample_float", :float, { }],
|
122
|
-
["sample_binary", :binary, { }],
|
123
|
-
["sample_boolean", :boolean, { }],
|
124
|
-
["sample_string", :string, { :default => '' }],
|
125
|
-
["sample_integer", :integer, { }], # don't care about the limit
|
126
|
-
["sample_integer_with_limit_2", :integer, { }], # don't care about the limit
|
127
|
-
["sample_integer_with_limit_8", :integer, { }], # don't care about the limit
|
128
|
-
["sample_integer_no_limit", :integer, { }],
|
129
|
-
["sample_integer_neg_default", :integer, { :default => -1 }],
|
130
|
-
["sample_text", :text, { }],
|
131
|
-
["big_decimal", :integer, { :precision => 31, :scale => 0 }],
|
132
|
-
["decimal_with_scale", :decimal, { :precision => 15, :scale => 3 }],
|
133
|
-
].sort{ |a,b| a[0] <=> b[0] }
|
134
|
-
|
135
|
-
column_names = (expected_types.map{|et| et[0]} + DbType.column_names).sort.uniq
|
136
|
-
result = []
|
137
|
-
column_names.each do |column_name|
|
138
|
-
et = expected_types.detect{|t| t[0] == column_name }
|
139
|
-
col = DbType.columns_hash[column_name]
|
140
|
-
if col
|
141
|
-
attrs = et && Hash[et[2].keys.map{|k| [k, col.send(k)]}]
|
142
|
-
result << [col.name, col.type, attrs]
|
143
|
-
else
|
144
|
-
result << [column_name, nil, nil]
|
145
|
-
end
|
146
|
-
end
|
147
|
-
result.sort!{|a,b| a[0] <=> b[0]}
|
148
|
-
|
149
|
-
assert_equal expected_types, result
|
150
|
-
end
|
151
|
-
|
152
|
-
# @override Derby is made in IBM thus it needs to get complicated with 1.42
|
153
|
-
def test_custom_select_float
|
154
|
-
model = DbType.create! :sample_float => 1.42
|
155
|
-
if ActiveRecord::VERSION::MAJOR >= 3
|
156
|
-
model = DbType.where("id = #{model.id}").select('sample_float AS custom_sample_float').first
|
157
|
-
else
|
158
|
-
model = DbType.find(:first, :conditions => "id = #{model.id}", :select => 'sample_float AS custom_sample_float')
|
159
|
-
end
|
160
|
-
assert_instance_of Float, model.custom_sample_float
|
161
|
-
custom_sample_float = (model.custom_sample_float * 100).round.to_f / 100 # .round(2) 1.8.7 compatible
|
162
|
-
assert_equal 1.42, custom_sample_float # Derby otherwise returns us smt like: 1.4199999570846558
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
|
167
|
-
class DerbyMultibyteTest < Test::Unit::TestCase
|
168
|
-
include MultibyteTestMethods
|
169
|
-
end
|
170
|
-
|
171
|
-
class DerbyHasManyThroughTest < Test::Unit::TestCase
|
172
|
-
include HasManyThroughMethods
|
173
|
-
end
|
data/test/db/derby/unit_test.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# encoding: ASCII-8BIT
|
2
|
-
require 'test_helper'
|
3
|
-
|
4
|
-
class DerbyUnitTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
class DerbyImpl
|
7
|
-
include ArJdbc::Derby
|
8
|
-
def initialize; end
|
9
|
-
end
|
10
|
-
derby = DerbyImpl.new
|
11
|
-
|
12
|
-
test "quote (string) without column passed" do
|
13
|
-
s = "'"; q = "''"
|
14
|
-
assert_equal q, derby.quote_string(s)
|
15
|
-
assert_equal "'string #{q}'", derby.quote(v = "string #{s}"), "while quoting #{v.inspect}"
|
16
|
-
assert_equal "' #{q}'", derby.quote(v = " #{s}", nil), "while quoting #{v.inspect}"
|
17
|
-
assert_equal "'#{q}str'", derby.quote(v = "#{s}str", nil), "while quoting #{v.inspect}"
|
18
|
-
end
|
19
|
-
|
20
|
-
test "quote (string) keeps original" do
|
21
|
-
s = "kôň ůň löw9876qűáéőú.éáű-mehehehehehehe0 \x01 \x02"
|
22
|
-
q = "'kôň ůň löw9876qűáéőú.éáű-mehehehehehehe0 \x01 \x02'"
|
23
|
-
assert_equal q, derby.quote(s.dup)
|
24
|
-
|
25
|
-
if s.respond_to?(:force_encoding)
|
26
|
-
s.force_encoding('UTF-8')
|
27
|
-
q.force_encoding('UTF-8')
|
28
|
-
assert_equal q, derby.quote(s.dup)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
-
require 'simple'
|
3
|
-
|
4
|
-
class DerbyXmlColumnTest < Test::Unit::TestCase
|
5
|
-
include FixtureSetup
|
6
|
-
include XmlColumnTests
|
7
|
-
|
8
|
-
def xml_sql_type; 'xml'; end
|
9
|
-
|
10
|
-
# @override
|
11
|
-
def test_use_xml_column
|
12
|
-
omit("[derby] XML values are not allowed in top-level result sets;")
|
13
|
-
# we'll need to somehow magically add XMLSERIALIZE for all XML columns !
|
14
|
-
super
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
data/test/db/h2.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
config = { :adapter => 'h2', :database => 'test' } # adds .h2.db suffix
|
4
|
-
|
5
|
-
ActiveRecord::Base.establish_connection(config)
|
6
|
-
|
7
|
-
at_exit do
|
8
|
-
Dir['*test.h2.db'].each { |f| FileUtils.rm(f) }
|
9
|
-
Dir['*test.lock.db'].each { |f| FileUtils.rm(f) }
|
10
|
-
Dir['*test.trace.db'].each { |f| FileUtils.rm(f) }
|
11
|
-
end
|
data/test/db/h2/binary_test.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'db/h2'
|
2
|
-
require 'jdbc_common'
|
3
|
-
|
4
|
-
class H2ChangeColumnTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
class Person < ActiveRecord::Base; end
|
7
|
-
|
8
|
-
class CreatePeopleTable < ActiveRecord::Migration
|
9
|
-
def self.up
|
10
|
-
create_table :people do |t|
|
11
|
-
t.integer :phone
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.down
|
16
|
-
drop_table :people
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def setup
|
21
|
-
CreatePeopleTable.up
|
22
|
-
end
|
23
|
-
|
24
|
-
def teardown
|
25
|
-
CreatePeopleTable.down
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_should_change_column_type
|
29
|
-
ActiveRecord::Migration.change_column :people, :phone, :string
|
30
|
-
Person.reset_column_information
|
31
|
-
|
32
|
-
p = Person.create!(:phone => 'ABC')
|
33
|
-
assert_equal 'ABC', p.phone
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_sets_defaults_on_column
|
37
|
-
ActiveRecord::Migration.change_column :people, :phone, :string, :default => '123456'
|
38
|
-
Person.reset_column_information
|
39
|
-
|
40
|
-
p = Person.create!
|
41
|
-
assert_equal '123456', p.phone
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_should_change_column_default_value
|
45
|
-
ActiveRecord::Migration.add_column :people, :email, :string, :default => 'foo@example.com'
|
46
|
-
ActiveRecord::Migration.change_column :people, :email, :string, :default => 'bar@example.com'
|
47
|
-
Person.reset_column_information
|
48
|
-
|
49
|
-
p = Person.create!
|
50
|
-
assert_equal 'bar@example.com', p.email
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_should_set_non_null_restriction
|
54
|
-
ActiveRecord::Migration.change_column :people, :phone, :string, :null => false
|
55
|
-
Person.reset_column_information
|
56
|
-
assert_raise(ActiveRecord::StatementInvalid) { Person.create! }
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_should_set_null_restriction_with_default
|
60
|
-
p = Person.create!
|
61
|
-
ActiveRecord::Migration.change_column :people, :phone, :string, :null => true, :default => '123456'
|
62
|
-
Person.reset_column_information
|
63
|
-
|
64
|
-
assert_nil p.reload.phone
|
65
|
-
assert_equal '123456', Person.create!.phone
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'db/h2'
|
3
|
-
|
4
|
-
class H2IdentityColumnTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
class Persona < ActiveRecord::Base
|
7
|
-
end
|
8
|
-
|
9
|
-
class CreatePersonasTable < ActiveRecord::Migration
|
10
|
-
def self.up
|
11
|
-
create_table :personas do |t|
|
12
|
-
t.string :firstname
|
13
|
-
t.string :lastname
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.down
|
18
|
-
drop_table :personas
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def setup
|
23
|
-
CreatePersonasTable.up
|
24
|
-
Persona.create(:firstname => "John", :lastname => "Smith")
|
25
|
-
end
|
26
|
-
|
27
|
-
def teardown
|
28
|
-
CreatePersonasTable.down
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_auto_increment
|
32
|
-
assert_equal 1, Persona.all[0].id, "H2 auto increment initially should start at ID 1, not 0"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
data/test/db/h2/offset_test.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'db/h2'
|
3
|
-
|
4
|
-
class H2OffsetTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
class Persona < ActiveRecord::Base
|
7
|
-
end
|
8
|
-
|
9
|
-
class CreatePersonasTable < ActiveRecord::Migration
|
10
|
-
def self.up
|
11
|
-
create_table :personas do |t|
|
12
|
-
t.string :firstname
|
13
|
-
t.string :lastname
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.down
|
18
|
-
drop_table :personas
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def setup
|
23
|
-
CreatePersonasTable.up
|
24
|
-
Persona.create(:firstname => "John", :lastname => "Smith")
|
25
|
-
Persona.create(:firstname => "Jill", :lastname => "Smith")
|
26
|
-
Persona.create(:firstname => "Joan", :lastname => "Smith")
|
27
|
-
Persona.create(:firstname => "Jason", :lastname => "Smith")
|
28
|
-
Persona.create(:firstname => "Jack", :lastname => "Smith")
|
29
|
-
Persona.create(:firstname => "Jenssen", :lastname => "Smith")
|
30
|
-
Persona.create(:firstname => "Joe", :lastname => "Smith")
|
31
|
-
Persona.create(:firstname => "Johanna", :lastname => "Smith")
|
32
|
-
Persona.create(:firstname => "James", :lastname => "Smith")
|
33
|
-
Persona.create(:firstname => "Jim", :lastname => "Smith")
|
34
|
-
Persona.create(:firstname => "Jody", :lastname => "Smith")
|
35
|
-
end
|
36
|
-
|
37
|
-
def teardown
|
38
|
-
CreatePersonasTable.down
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_offset
|
42
|
-
query = Arel::Table.new(:persons).skip(3)
|
43
|
-
assert_nothing_raised do
|
44
|
-
sql = query.to_sql
|
45
|
-
assert_equal "SELECT LIMIT 3", sql[0..13], "SQL statement was not generated, properly"
|
46
|
-
end
|
47
|
-
end if ar_version('3.0')
|
48
|
-
|
49
|
-
end
|
data/test/db/h2/rake_test.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'rake_test_support'
|
2
|
-
require 'db/h2'
|
3
|
-
|
4
|
-
class H2RakeTest < Test::Unit::TestCase
|
5
|
-
include RakeTestSupport
|
6
|
-
|
7
|
-
def db_name; 'mem:rake-test'; end
|
8
|
-
|
9
|
-
def do_teardown
|
10
|
-
drop_rake_test_database(:silence)
|
11
|
-
end
|
12
|
-
|
13
|
-
test 'rake db:create (and db:drop)' do
|
14
|
-
@db_name = 'rake-create-test'
|
15
|
-
Rake::Task["db:create"].invoke
|
16
|
-
assert_true File.exists?("#{@db_name}.h2.db"), "db file: #{@db_name}.h2.db is missing"
|
17
|
-
|
18
|
-
Rake::Task["db:drop"].invoke
|
19
|
-
assert_false File.exists?("#{@db_name}.h2.db"), "db file: #{@db_name}.h2.db not deleted"
|
20
|
-
end
|
21
|
-
|
22
|
-
test 'rake db:create (and db:drop) in memory db' do
|
23
|
-
Rake::Task["db:create"].invoke
|
24
|
-
# assert_true File.exists?("#{db_name}.lck")
|
25
|
-
|
26
|
-
Rake::Task["db:drop"].invoke
|
27
|
-
# assert_false File.exists?("#{db_name}.lck")
|
28
|
-
end
|
29
|
-
|
30
|
-
test 'rake db:test:purge' do
|
31
|
-
# Rake::Task["db:create"].invoke
|
32
|
-
create_rake_test_database do |connection|
|
33
|
-
connection.create_table('loosers') { |t| t.string :name }
|
34
|
-
end
|
35
|
-
|
36
|
-
Rake::Task["db:test:purge"].invoke
|
37
|
-
|
38
|
-
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
39
|
-
assert_false ActiveRecord::Base.connection.table_exists?('loosers')
|
40
|
-
ActiveRecord::Base.connection.disconnect!
|
41
|
-
end
|
42
|
-
|
43
|
-
test 'rake db:structure:dump (and db:structure:load)' do
|
44
|
-
db_name = @db_name = 'test-dump-rake'
|
45
|
-
create_rake_test_database(db_name) do |connection|
|
46
|
-
create_schema_migrations_table(connection)
|
47
|
-
connection.create_table('loosers') { |t| t.string :name; t.timestamps }
|
48
|
-
end
|
49
|
-
|
50
|
-
structure_sql = File.join('db', structure_sql_filename)
|
51
|
-
begin
|
52
|
-
Dir.mkdir 'db' # db/structure.sql
|
53
|
-
Rake::Task["db:structure:dump"].invoke
|
54
|
-
|
55
|
-
assert File.exists?(structure_sql)
|
56
|
-
# CREATE CACHED TABLE PUBLIC.LOOSERS
|
57
|
-
assert_match /CREATE .*? TABLE PUBLIC.LOOSERS/i, File.read(structure_sql)
|
58
|
-
|
59
|
-
# db:structure:load
|
60
|
-
drop_rake_test_database(:silence)
|
61
|
-
Rake::Task["db:structure:load"].invoke
|
62
|
-
|
63
|
-
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
64
|
-
assert ActiveRecord::Base.connection.table_exists?('loosers')
|
65
|
-
ActiveRecord::Base.connection.disconnect!
|
66
|
-
ensure
|
67
|
-
File.delete(structure_sql) if File.exists?(structure_sql)
|
68
|
-
Dir.rmdir 'db'
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# test 'rake db:charset' do
|
73
|
-
# expect_rake_output('UTF-8')
|
74
|
-
# Rake::Task["db:charset"].invoke
|
75
|
-
# end
|
76
|
-
|
77
|
-
def create_rake_test_database(db_name = self.db_name)
|
78
|
-
ActiveRecord::Base.establish_connection db_config.merge :database => db_name
|
79
|
-
if block_given?
|
80
|
-
yield ActiveRecord::Base.connection
|
81
|
-
end
|
82
|
-
ActiveRecord::Base.connection.disconnect!
|
83
|
-
end
|
84
|
-
|
85
|
-
def drop_rake_test_database(silence = nil)
|
86
|
-
# ActiveRecord::Base.establish_connection db_config.merge :database => @db_name
|
87
|
-
# ActiveRecord::Base.connection.disconnect!
|
88
|
-
|
89
|
-
File.delete("#{@db_name}.lock.db") if File.exist? "#{@db_name}.lock.db"
|
90
|
-
File.delete("#{@db_name}.trace.db") if File.exist? "#{@db_name}.trace.db"
|
91
|
-
if silence
|
92
|
-
File.delete("#{@db_name}.h2.db") if File.exist? "#{@db_name}.h2.db"
|
93
|
-
else
|
94
|
-
File.delete("#{@db_name}.h2.db")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|