activerecord-jdbc-adapter 1.2.5 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +5 -1
  3. data/Appraisals +5 -5
  4. data/Gemfile +9 -1
  5. data/Gemfile.lock +44 -10
  6. data/History.txt +126 -2
  7. data/README.md +246 -0
  8. data/Rakefile +34 -25
  9. data/activerecord-jdbc-adapter.gemspec +1 -1
  10. data/gemfiles/rails23.gemfile +5 -3
  11. data/gemfiles/rails23.gemfile.lock +26 -18
  12. data/gemfiles/rails30.gemfile +4 -2
  13. data/gemfiles/rails30.gemfile.lock +16 -8
  14. data/gemfiles/rails31.gemfile +4 -2
  15. data/gemfiles/rails31.gemfile.lock +16 -9
  16. data/gemfiles/rails32.gemfile +4 -2
  17. data/gemfiles/rails32.gemfile.lock +15 -8
  18. data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
  19. data/lib/arel/visitors/sql_server.rb +3 -0
  20. data/lib/arjdbc.rb +3 -5
  21. data/lib/arjdbc/db2.rb +1 -0
  22. data/lib/arjdbc/db2/adapter.rb +302 -196
  23. data/lib/arjdbc/db2/connection_methods.rb +18 -0
  24. data/lib/arjdbc/derby/active_record_patch.rb +12 -0
  25. data/lib/arjdbc/derby/adapter.rb +180 -158
  26. data/lib/arjdbc/derby/connection_methods.rb +5 -1
  27. data/lib/arjdbc/firebird/adapter.rb +27 -19
  28. data/lib/arjdbc/h2/adapter.rb +162 -7
  29. data/lib/arjdbc/h2/connection_methods.rb +5 -1
  30. data/lib/arjdbc/hsqldb.rb +1 -1
  31. data/lib/arjdbc/hsqldb/adapter.rb +96 -61
  32. data/lib/arjdbc/hsqldb/connection_methods.rb +5 -1
  33. data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
  34. data/lib/arjdbc/informix/adapter.rb +56 -55
  35. data/lib/arjdbc/jdbc/adapter.rb +173 -86
  36. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  37. data/lib/arjdbc/jdbc/column.rb +28 -23
  38. data/lib/arjdbc/jdbc/connection.rb +10 -6
  39. data/lib/arjdbc/jdbc/driver.rb +13 -5
  40. data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +21 -0
  41. data/lib/arjdbc/mssql.rb +1 -1
  42. data/lib/arjdbc/mssql/adapter.rb +51 -53
  43. data/lib/arjdbc/mssql/connection_methods.rb +8 -1
  44. data/lib/arjdbc/mysql.rb +1 -1
  45. data/lib/arjdbc/mysql/adapter.rb +186 -150
  46. data/lib/arjdbc/mysql/connection_methods.rb +9 -9
  47. data/lib/arjdbc/mysql/explain_support.rb +85 -0
  48. data/lib/arjdbc/oracle.rb +1 -1
  49. data/lib/arjdbc/oracle/adapter.rb +232 -125
  50. data/lib/arjdbc/oracle/connection_methods.rb +2 -2
  51. data/lib/arjdbc/postgresql.rb +1 -1
  52. data/lib/arjdbc/postgresql/adapter.rb +134 -86
  53. data/lib/arjdbc/postgresql/connection_methods.rb +6 -4
  54. data/lib/arjdbc/postgresql/explain_support.rb +55 -0
  55. data/lib/arjdbc/sqlite3.rb +1 -1
  56. data/lib/arjdbc/sqlite3/adapter.rb +176 -108
  57. data/lib/arjdbc/sqlite3/connection_methods.rb +5 -5
  58. data/lib/arjdbc/sqlite3/explain_support.rb +32 -0
  59. data/lib/arjdbc/sybase/adapter.rb +7 -6
  60. data/lib/arjdbc/version.rb +1 -1
  61. data/pom.xml +1 -1
  62. data/rakelib/02-test.rake +9 -11
  63. data/rakelib/rails.rake +18 -10
  64. data/src/java/arjdbc/db2/DB2Module.java +70 -0
  65. data/src/java/arjdbc/derby/DerbyModule.java +24 -5
  66. data/src/java/arjdbc/hsqldb/HSQLDBModule.java +66 -0
  67. data/src/java/arjdbc/jdbc/AdapterJavaService.java +14 -7
  68. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +111 -89
  69. data/src/java/arjdbc/mysql/MySQLModule.java +79 -70
  70. data/src/java/arjdbc/oracle/OracleModule.java +74 -0
  71. data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +5 -10
  72. data/src/java/arjdbc/sqlite3/SQLite3Module.java +77 -0
  73. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +127 -0
  74. data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +25 -111
  75. data/src/java/arjdbc/util/QuotingUtils.java +104 -0
  76. data/test/abstract_db_create.rb +6 -6
  77. data/test/activerecord/connection_adapters/type_conversion_test.rb +2 -2
  78. data/test/assets/flowers.jpg +0 -0
  79. data/test/binary.rb +67 -0
  80. data/test/db/db2.rb +30 -7
  81. data/test/db/jdbc.rb +4 -2
  82. data/test/db/oracle.rb +18 -27
  83. data/test/db2_binary_test.rb +6 -0
  84. data/test/db2_serialize_test.rb +6 -0
  85. data/test/db2_simple_test.rb +20 -25
  86. data/test/db2_test.rb +71 -0
  87. data/test/derby_binary_test.rb +6 -0
  88. data/test/derby_migration_test.rb +42 -35
  89. data/test/derby_reset_column_information_test.rb +1 -0
  90. data/test/derby_row_locking_test.rb +17 -0
  91. data/test/derby_schema_dump_test.rb +9 -0
  92. data/test/derby_serialize_test.rb +6 -0
  93. data/test/derby_simple_test.rb +59 -17
  94. data/test/generic_jdbc_connection_test.rb +112 -5
  95. data/test/h2_binary_test.rb +6 -0
  96. data/test/h2_change_column_test.rb +1 -1
  97. data/test/h2_schema_dump_test.rb +25 -0
  98. data/test/h2_serialize_test.rb +6 -0
  99. data/test/h2_simple_test.rb +23 -9
  100. data/test/has_many_through.rb +18 -4
  101. data/test/hsqldb_binary_test.rb +6 -0
  102. data/test/hsqldb_schema_dump_test.rb +15 -0
  103. data/test/hsqldb_serialize_test.rb +6 -0
  104. data/test/hsqldb_simple_test.rb +1 -0
  105. data/test/informix_simple_test.rb +1 -1
  106. data/test/jdbc/db2.rb +23 -0
  107. data/test/jdbc/oracle.rb +23 -0
  108. data/test/jdbc_common.rb +3 -110
  109. data/test/jndi_callbacks_test.rb +0 -2
  110. data/test/jndi_test.rb +2 -0
  111. data/test/models/binary.rb +18 -0
  112. data/test/models/custom_pk_name.rb +1 -0
  113. data/test/models/data_types.rb +11 -2
  114. data/test/models/entry.rb +1 -1
  115. data/test/models/string_id.rb +2 -2
  116. data/test/models/thing.rb +1 -1
  117. data/test/models/topic.rb +32 -0
  118. data/test/mssql_legacy_types_test.rb +1 -1
  119. data/test/mssql_limit_offset_test.rb +13 -3
  120. data/test/mssql_serialize_test.rb +6 -0
  121. data/test/mysql_binary_test.rb +6 -0
  122. data/test/mysql_schema_dump_test.rb +220 -0
  123. data/test/mysql_serialize_test.rb +6 -0
  124. data/test/mysql_simple_test.rb +22 -2
  125. data/test/mysql_test.rb +93 -0
  126. data/test/oracle_binary_test.rb +6 -0
  127. data/test/oracle_limit_test.rb +2 -1
  128. data/test/oracle_serialize_test.rb +6 -0
  129. data/test/oracle_simple_test.rb +61 -0
  130. data/test/oracle_specific_test.rb +77 -26
  131. data/test/postgres_binary_test.rb +6 -0
  132. data/test/postgres_native_type_mapping_test.rb +12 -11
  133. data/test/postgres_nonseq_pkey_test.rb +1 -0
  134. data/test/postgres_reserved_test.rb +1 -0
  135. data/test/postgres_reset_column_information_test.rb +1 -0
  136. data/test/postgres_row_locking_test.rb +21 -0
  137. data/test/postgres_schema_dump_test.rb +88 -0
  138. data/test/postgres_schema_search_path_test.rb +1 -0
  139. data/test/postgres_simple_test.rb +62 -89
  140. data/test/postgres_table_alias_length_test.rb +1 -0
  141. data/test/postgres_test.rb +31 -0
  142. data/test/postgres_type_conversion_test.rb +16 -16
  143. data/test/row_locking.rb +69 -64
  144. data/test/schema_dump.rb +168 -0
  145. data/test/serialize.rb +277 -0
  146. data/test/simple.rb +326 -122
  147. data/test/sqlite3_serialize_test.rb +6 -0
  148. data/test/sqlite3_simple_test.rb +51 -84
  149. data/test/sqlite3_type_conversion_test.rb +101 -0
  150. data/test/test_helper.rb +224 -0
  151. metadata +325 -366
  152. data/README.rdoc +0 -214
  153. data/test/db/logger.rb +0 -3
  154. data/test/derby_multibyte_test.rb +0 -11
  155. data/test/mysql_info_test.rb +0 -123
@@ -0,0 +1,6 @@
1
+ require 'db/db2'
2
+ require 'binary'
3
+
4
+ class DB2BinaryTest < Test::Unit::TestCase
5
+ include BinaryTestMethods
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'db/db2'
2
+ require 'serialize'
3
+
4
+ class DB2SerializeTest < Test::Unit::TestCase
5
+ include SerializeTestMethods
6
+ end
@@ -15,7 +15,7 @@ class DB2SimpleTest < Test::Unit::TestCase
15
15
  # type cast's it to a Ruby boolean. Need to make sure we don't
16
16
  # break existing apps!
17
17
  def test_boolean_as_integer
18
- e = DbType.find(:first)
18
+ e = DbType.first
19
19
 
20
20
  # true
21
21
  e.sample_boolean = 1
@@ -23,7 +23,7 @@ class DB2SimpleTest < Test::Unit::TestCase
23
23
  assert_equal true, e.sample_boolean?
24
24
  e.save!
25
25
 
26
- e = DbType.find(:first)
26
+ e = DbType.first
27
27
  assert_equal true, e.sample_boolean
28
28
  assert_equal true, e.sample_boolean?
29
29
 
@@ -33,34 +33,29 @@ class DB2SimpleTest < Test::Unit::TestCase
33
33
  assert_equal false, e.sample_boolean?
34
34
  e.save!
35
35
 
36
- e = DbType.find(:first)
36
+ e = DbType.first
37
37
  assert_equal false, e.sample_boolean
38
38
  assert_equal false, e.sample_boolean?
39
39
  end
40
+
41
+ def test_find_by_sql_WITH_statement
42
+ user = User.create! :login => 'ferko'
43
+ Entry.create! :title => 'aaa', :user_id => user.id
44
+ entries = Entry.find_by_sql '' +
45
+ 'WITH EntryAndUser (title, login, updated_on) AS ' +
46
+ '(' +
47
+ ' SELECT e.title, u.login, e.updated_on ' +
48
+ ' FROM entries e INNER JOIN users u ON e.user_id = u.id ' +
49
+ ')' +
50
+ ' ' +
51
+ 'SELECT * FROM EntryAndUser ORDER BY title ASC'
52
+ assert entries.first
53
+ assert entries.first.title
54
+ assert entries.first.login
55
+ end
56
+
40
57
  end
41
58
 
42
59
  class DB2HasManyThroughTest < Test::Unit::TestCase
43
60
  include HasManyThroughMethods
44
61
  end
45
-
46
- class DB2Test < Test::Unit::TestCase
47
- def setup
48
- @inst = Object.new
49
- @inst.extend ArJdbc::DB2
50
- @column = Object.new
51
- class << @column
52
- attr_accessor :type
53
- end
54
- end
55
-
56
- def test_quote_decimal
57
- assert_equal %q{'123.45'}, @inst.quote("123.45")
58
- @column.type = :decimal
59
- assert_equal %q{123.45}, @inst.quote("123.45", @column), "decimal columns should not have quotes"
60
- end
61
-
62
- def test_primary_key_generation
63
- @column.type = :primary_key
64
- assert_equal 'int not null generated by default as identity (start with 1) primary key', @inst.modify_types({:string => {}, :integer => {}, :boolean => {}})[:primary_key]
65
- end
66
- end
@@ -0,0 +1,71 @@
1
+ require 'test_helper'
2
+ require 'arjdbc/db2'
3
+
4
+ class DB2Test < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @adapter = Object.new
8
+ def @adapter.zos?; false; end
9
+ @adapter.extend ArJdbc::DB2
10
+
11
+ @column = Object.new
12
+ class << @column
13
+ attr_accessor :type
14
+ end
15
+ end
16
+
17
+ test 'quotes decimal column' do
18
+ adapter, column = new_adapter_stub, new_column_stub
19
+ assert_equal %q{'123.45'}, adapter.quote("123.45")
20
+ column.type = :decimal
21
+ assert_equal %q{123.45}, adapter.quote("123.45", column), "decimal columns should not have quotes"
22
+ end
23
+
24
+ test 'generated primary key' do
25
+ adapter = new_adapter_stub
26
+ assert_equal 'int not null generated by default as identity (start with 1) primary key',
27
+ adapter.modify_types({:string => {}, :integer => {}, :boolean => {}})[:primary_key]
28
+ end
29
+
30
+ test 'selects correct schema' do
31
+ url = 'jdbc:as400://localhost/schema;naming=system;libraries=lib1,lib2'
32
+ assert_equal 'schema', new_adapter_stub(:url => url).send(:db2_schema)
33
+
34
+ url = 'jdbc:as400://127.0.0.1/SCHEMA1 '
35
+ assert_equal 'SCHEMA1', new_adapter_stub(:url => url).send(:db2_schema)
36
+
37
+ url = 'jdbc:as400://127.0.0.1/SCHEMA2;'
38
+ assert_equal 'SCHEMA2', new_adapter_stub(:url => url).send(:db2_schema)
39
+
40
+ assert_equal nil, new_adapter_stub(:jndi => 'java:comp/env/DB2DS').send(:db2_schema)
41
+
42
+ config = { :host => 'localhost', :username => 'db2inst1' }
43
+ assert_equal 'db2inst1', new_adapter_stub(config).send(:db2_schema)
44
+ end
45
+
46
+ test 'quote column name returns string' do
47
+ adapter = new_adapter_stub
48
+ assert_equal 'version', adapter.quote_column_name(:version)
49
+ assert_equal 'column1', adapter.quote_column_name("column1")
50
+ end
51
+
52
+ private
53
+
54
+ def new_adapter_stub(config = {})
55
+ config = config.merge({ :adapter => 'jdbc', :adapter_spec => ArJdbc::DB2 })
56
+ connection = stub('connection'); logger = nil
57
+ connection.stub_everything
58
+ adapter = ActiveRecord::ConnectionAdapters::JdbcAdapter.new connection, logger, config
59
+ def adapter.zos?; false; end
60
+ adapter
61
+ end
62
+
63
+ def new_column_stub
64
+ column = Object.new
65
+ class << column
66
+ attr_accessor :type
67
+ end
68
+ column
69
+ end
70
+
71
+ end
@@ -0,0 +1,6 @@
1
+ require 'db/derby'
2
+ require 'binary'
3
+
4
+ class DerbyBinaryTest < Test::Unit::TestCase
5
+ include BinaryTestMethods
6
+ end
@@ -1,55 +1,62 @@
1
+ require 'db/derby'
1
2
  require 'jdbc_common'
2
3
 
3
- class CreateDummies < ActiveRecord::Migration
4
- def self.up
5
- create_table :dummies, :force => true do |t|
6
- t.string :year, :default => "", :null => false
4
+ class DerbyMigrationTest < Test::Unit::TestCase
5
+
6
+ class CreateDummies < ActiveRecord::Migration
7
+
8
+ def self.up
9
+ create_table :dummies, :force => true do |t|
10
+ t.string :year, :default => "", :null => false
11
+ end
12
+ add_index :dummies, :year, :unique => true
7
13
  end
8
- add_index :dummies, :year, :unique => true
14
+
9
15
  end
10
16
 
11
- end
17
+ class ChangeColumn < ActiveRecord::Migration
18
+
19
+ def self.up
20
+ create_table :people, :id => false, :force => true do |t|
21
+ t.string :id, :limit => 22, :null => false
22
+ t.string :name, :null => false
23
+ end
24
+ change_column(:people, :name, :string, { :limit => 22 })
25
+ execute("SELECT id FROM people WHERE id = 'some string'")
26
+ end
12
27
 
13
- class ChangeColumn < ActiveRecord::Migration
14
- def self.up
15
- create_table :people, :id => false, :force => true do |t|
16
- t.string :id, :limit => 22, :null => false
17
- t.string :name, :null => false
28
+ def self.down
18
29
  end
19
- change_column(:people, :name, :string, {:limit=>22})
20
- execute("SELECT id FROM people WHERE id = 'some string'")
21
- end
22
30
 
23
- def self.down
24
31
  end
25
32
 
26
- end
33
+ class CreateIndex < ActiveRecord::Migration
34
+ def self.up
35
+ create_table :people, :id => false, :force => true do |t|
36
+ t.string :id, :limit => 22, :null => false
37
+ t.string :first_name, :null => false
38
+ t.string :last_name, :null => false
39
+ t.string :nickname, :null => false
40
+ t.string :long_name, :null => false
41
+ t.string :very_long_name, :null => false
42
+ t.string :extremely_long_name, :null => false
43
+ end
44
+
45
+ add_index(:people, [:first_name, :last_name, :nickname, :long_name, :very_long_name, :extremely_long_name], :unique => true)
27
46
 
28
- class CreateIndex < ActiveRecord::Migration
29
- def self.up
30
- create_table :people, :id => false, :force => true do |t|
31
- t.string :id, :limit => 22, :null => false
32
- t.string :first_name, :null => false
33
- t.string :last_name, :null => false
34
- t.string :nickname, :null => false
35
- t.string :long_name, :null => false
36
- t.string :very_long_name, :null => false
37
- t.string :extremely_long_name, :null => false
47
+ remove_index(:people, [:first_name, :last_name, :nickname, :long_name, :very_long_name, :extremely_long_name])
38
48
  end
39
49
 
40
- add_index(:people, [:first_name, :last_name, :nickname, :long_name, :very_long_name, :extremely_long_name], :unique => true)
50
+ def self.down
51
+ end
41
52
 
42
- remove_index(:people, [:first_name, :last_name, :nickname, :long_name, :very_long_name, :extremely_long_name])
43
53
  end
44
54
 
45
- def self.down
55
+ def self.shutdown
56
+ ActiveRecord::Base.connection.execute("DROP TABLE dummies") rescue nil
57
+ ActiveRecord::Base.connection.execute("DROP TABLE people") rescue nil
46
58
  end
47
-
48
- end
49
-
50
- class DerbyMigrationTest < Test::Unit::TestCase
51
- include FixtureSetup
52
-
59
+
53
60
  def test_create_table_column_quoting_vs_keywords
54
61
  CreateDummies.up
55
62
  end
@@ -1,3 +1,4 @@
1
+ require 'db/derby'
1
2
  require 'jdbc_common'
2
3
 
3
4
  class DerbyResetColumnInformationTest < Test::Unit::TestCase
@@ -1,6 +1,23 @@
1
+ require 'db/derby'
1
2
  require 'jdbc_common'
3
+ require 'row_locking'
2
4
 
3
5
  class DerbyRowLockingTest < Test::Unit::TestCase
4
6
  include MigrationSetup
5
7
  include RowLockingTestMethods
8
+
9
+ DbTypeMigration.big_decimal_precision = 31
10
+
11
+ # def self.startup
12
+ # MigrationSetup.setup!
13
+ # end
14
+ #
15
+ # def setup!; nil; end
16
+ #
17
+ # def self.shutdown
18
+ # MigrationSetup.teardown!
19
+ # end
20
+ #
21
+ # def teardown!; nil; end
22
+
6
23
  end
@@ -0,0 +1,9 @@
1
+ require 'db/derby'
2
+ require 'schema_dump'
3
+
4
+ class DerbySchemaDumpTest < Test::Unit::TestCase
5
+ include SchemaDumpTestMethods
6
+
7
+ DbTypeMigration.big_decimal_precision = 31 # DECIMAL precision between 1 and 31
8
+
9
+ end
@@ -0,0 +1,6 @@
1
+ require 'db/derby'
2
+ require 'serialize'
3
+
4
+ class DerbySerializeTest < Test::Unit::TestCase
5
+ include SerializeTestMethods
6
+ end
@@ -1,14 +1,13 @@
1
- # To run this script, run the following in a mysql instance:
2
- #
3
- # drop database if exists weblog_development;
4
- # create database weblog_development;
5
- # grant all on weblog_development.* to blog@localhost;
6
-
1
+ # encoding: ASCII-8BIT
7
2
  require 'jdbc_common'
3
+ require 'db/derby'
4
+
5
+ DbTypeMigration.big_decimal_precision = 31
8
6
 
9
7
  class DerbySimpleTest < Test::Unit::TestCase
10
8
  include SimpleTestMethods
11
-
9
+ include ActiveRecord3TestMethods
10
+
12
11
  # Check that a table-less VALUES(xxx) query (like SELECT works.
13
12
  def test_values
14
13
  value = nil
@@ -19,13 +18,13 @@ class DerbySimpleTest < Test::Unit::TestCase
19
18
  end
20
19
 
21
20
  def test_find_with_include_and_order
22
- users = User.find(:all, :include=>[:entries], :order=>"entries.rating DESC", :limit=>2)
21
+ users = User.find(:all, :include=>[:entries], :order=>"entries.rating DESC", :limit => 2)
23
22
 
24
23
  assert users.include?(@user)
25
24
  end
26
25
 
27
26
  def test_text_and_string_conversions
28
- e = DbType.find(:first)
27
+ e = DbType.first
29
28
 
30
29
  # Derby will normally reject any non text value.
31
30
  # The adapter has been patched to convert non text values to strings
@@ -97,26 +96,28 @@ class DerbySimpleTest < Test::Unit::TestCase
97
96
  end
98
97
 
99
98
  def test_data_types
100
- # From test/models/data_types.rb, with the modifications as noted in the comments.
99
+ # from test/models/data_types.rb, with the modifications as noted in the comments.
101
100
  expected_types = [
102
101
  ["id", :integer, { }],
103
- ["sample_timestamp", :datetime, { }], # :timestamp is just an alias for :datetime in Derby
102
+ ["sample_timestamp", :datetime, { }], # :timestamp is just an alias for :datetime in Derby
104
103
  ["sample_datetime", :datetime, { }],
105
104
  ["sample_date", :date, { }],
106
105
  ["sample_time", :time, { }],
107
- ["sample_decimal", :integer, { :precision => 15, :scale => 0 }], # it's an :integer because the :scale is 0 (...right?)
108
- ["sample_small_decimal", :decimal, { :precision => 3, :scale => 2 }],
109
- ["sample_default_decimal", :integer, { }], # decimal and integer are the same type in Derby
106
+ # NOTE: it's an :integer because the :scale is 0 (...right?) :
107
+ ["sample_decimal", :integer, { :precision => 9, :scale => 0 }],
108
+ ["sample_small_decimal", :decimal, { :precision => 3, :scale => 2, :default => 3.14 }],
109
+ ["sample_default_decimal", :integer, { }], # decimal by default assumes :scale => 0
110
110
  ["sample_float", :float, { }],
111
111
  ["sample_binary", :binary, { }],
112
112
  ["sample_boolean", :boolean, { }],
113
113
  ["sample_string", :string, { :default => '' }],
114
- ["sample_integer", :integer, { }], # don't care about the limit
115
- ["sample_integer_with_limit_2", :integer, { }], # don't care about the limit
116
- ["sample_integer_with_limit_8", :integer, { }], # don't care about the limit
114
+ ["sample_integer", :integer, { }], # don't care about the limit
115
+ ["sample_integer_with_limit_2", :integer, { }], # don't care about the limit
116
+ ["sample_integer_with_limit_8", :integer, { }], # don't care about the limit
117
117
  ["sample_integer_no_limit", :integer, { }],
118
118
  ["sample_integer_neg_default", :integer, { :default => -1 }],
119
119
  ["sample_text", :text, { }],
120
+ ["big_decimal", :integer, { :precision => 31, :scale => 0 }],
120
121
  ].sort{|a,b| a[0] <=> b[0]}
121
122
 
122
123
  column_names = (expected_types.map{|et| et[0]} + DbType.column_names).sort.uniq
@@ -136,3 +137,44 @@ class DerbySimpleTest < Test::Unit::TestCase
136
137
  assert_equal expected_types, result
137
138
  end
138
139
  end
140
+
141
+ class DerbyMultibyteTest < Test::Unit::TestCase
142
+ include MultibyteTestMethods
143
+ end
144
+
145
+ class DerbyHasManyThroughTest < Test::Unit::TestCase
146
+ include HasManyThroughMethods
147
+ end
148
+
149
+ # encoding: ASCII-8BIT
150
+ require 'test_helper'
151
+
152
+ class DerbyTest < Test::Unit::TestCase
153
+
154
+ class DerbyImpl
155
+ include ArJdbc::Derby
156
+ def initialize; end
157
+ end
158
+ derby = DerbyImpl.new
159
+
160
+ test "quote (string) without column passed" do
161
+ s = "'"; q = "''"
162
+ assert_equal q, derby.quote_string(s)
163
+ assert_equal "'string #{q}'", derby.quote(v = "string #{s}"), "while quoting #{v.inspect}"
164
+ assert_equal "' #{q}'", derby.quote(v = " #{s}", nil), "while quoting #{v.inspect}"
165
+ assert_equal "'#{q}str'", derby.quote(v = "#{s}str", nil), "while quoting #{v.inspect}"
166
+ end
167
+
168
+ test "quote (string) keeps original" do
169
+ s = "kôň ůň löw9876qűáéőú.éáű-mehehehehehehe0 \x01 \x02"
170
+ q = "'kôň ůň löw9876qűáéőú.éáű-mehehehehehehe0 \x01 \x02'"
171
+ assert_equal q, derby.quote(s.dup)
172
+
173
+ if s.respond_to?(:force_encoding)
174
+ s.force_encoding('UTF-8')
175
+ q.force_encoding('UTF-8')
176
+ assert_equal q, derby.quote(s.dup)
177
+ end
178
+ end
179
+
180
+ end
@@ -8,15 +8,108 @@ class GenericJdbcConnectionTest < Test::Unit::TestCase
8
8
  assert ActiveRecord::Base.connected?
9
9
  end
10
10
 
11
+ test 'configures driver/connection properties' do
12
+ config = JDBC_CONFIG.dup
13
+ config[:properties] = {
14
+ 'autoDeserialize' => true,
15
+ 'maxAllowedPacket' => 128,
16
+ 'metadataCacheSize' => '5'
17
+ }
18
+ ActiveRecord::Base.remove_connection
19
+ begin
20
+ ActiveRecord::Base.establish_connection config
21
+ connection = ActiveRecord::Base.connection.jdbc_connection
22
+ # assuming MySQL internals :
23
+ assert_equal 'true', connection.getProperties['autoDeserialize']
24
+ assert_equal '128', connection.getProperties['maxAllowedPacket']
25
+ assert_equal '5', connection.getProperties['metadataCacheSize']
26
+ ensure
27
+ ActiveRecord::Base.establish_connection JDBC_CONFIG
28
+ end
29
+ end
30
+
31
+ test 'driver runtime errors do not get swallowed' do
32
+ config = JDBC_CONFIG.dup
33
+ config[:properties] = Java::JavaUtil::Properties.new
34
+ config[:properties]['invalid_property'] = java.lang.Object.new
35
+ ActiveRecord::Base.remove_connection
36
+ begin
37
+ ActiveRecord::Base.establish_connection config
38
+ ActiveRecord::Base.connection.jdbc_connection
39
+ fail "exception not thrown"
40
+ rescue Java::JavaLang::NullPointerException # OK :
41
+ # java.util.Hashtable.put(Hashtable.java:394)
42
+ # java.util.Properties.setProperty(Properties.java:143)
43
+ # com.mysql.jdbc.NonRegisteringDriver.parseURL(NonRegisteringDriver.java:849)
44
+ # com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
45
+ ensure
46
+ ActiveRecord::Base.establish_connection JDBC_CONFIG
47
+ end
48
+ end
49
+
50
+ class MockDriver < ActiveRecord::ConnectionAdapters::JdbcDriver
51
+
52
+ class DriverImpl
53
+ include Java::JavaSql::Driver
54
+
55
+ def connect(url, info)
56
+ if url =~ /invalid_authorization_spec/i
57
+ raise Java::JavaSql::SQLInvalidAuthorizationSpecException.new
58
+ else
59
+ reason = "#{url} connect with #{info.inspect} failed"
60
+ raise Java::JavaSql::SQLException.new(reason, '42000', 1042)
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ def driver_class; DriverImpl; end
67
+
68
+ end
69
+
70
+ test 'driver sql exceptions are wrapped into jdbc errors' do
71
+ config = JDBC_CONFIG.dup
72
+ config[:driver_instance] = MockDriver.new('MockDriver')
73
+ ActiveRecord::Base.remove_connection
74
+ begin
75
+ ActiveRecord::Base.establish_connection config
76
+ ActiveRecord::Base.connection.jdbc_connection
77
+ fail "jdbc error not thrown"
78
+ rescue ActiveRecord::JDBCError => e
79
+ assert_match /connect with {"user"=>"arjdbc", "password"=>"arjdbc"} failed/, e.to_s
80
+ assert_equal 1042, e.errno
81
+ assert_kind_of Java::JavaSql::SQLException, e.sql_exception
82
+ ensure
83
+ ActiveRecord::Base.establish_connection JDBC_CONFIG
84
+ end
85
+ end
86
+
87
+ test 'driver sql exceptions without message and sql state' do
88
+ config = JDBC_CONFIG.dup
89
+ config[:url] = 'jdbc:mysql://127.0.0.1:1234/invalid_authorization_spec'
90
+ config[:driver_instance] = MockDriver.new('MockDriver')
91
+ ActiveRecord::Base.remove_connection
92
+ begin
93
+ ActiveRecord::Base.establish_connection config
94
+ ActiveRecord::Base.connection.jdbc_connection
95
+ fail "jdbc error not thrown"
96
+ rescue ActiveRecord::JDBCError => e
97
+ assert_match /driver encountered an unknown error: java.sql.SQLInvalidAuthorizationSpecException/, e.to_s
98
+ assert_kind_of Java::JavaSql::SQLNonTransientException, e.sql_exception
99
+ ensure
100
+ ActiveRecord::Base.establish_connection JDBC_CONFIG
101
+ end
102
+ end
103
+
11
104
  class ConfigHelperTest < Test::Unit::TestCase
12
105
 
13
106
  test 'configure connection url' do
14
107
  connection = Object.new
15
108
  connection.extend ActiveRecord::ConnectionAdapters::JdbcConnection::ConfigHelper
16
- connection.config = { :url => "jdbc://somehost", :options => { :hoge => "true", :fuya => "false"} }
109
+ connection.config = { :url => "jdbc://somehost", :options => { :hoge => "true", :fuya => "false" } }
17
110
  assert_equal "jdbc://somehost?hoge=true&fuya=false", connection.send(:configure_url)
18
111
 
19
- connection.config = { :url => "jdbc://somehost?param=0", :options => { :hoge => "true", :fuya => "false"} }
112
+ connection.config = { :url => "jdbc://somehost?param=0", :options => { :hoge => "true", :fuya => false } }
20
113
  assert_equal "jdbc://somehost?param=0&hoge=true&fuya=false", connection.send(:configure_url)
21
114
  end
22
115
 
@@ -37,7 +130,7 @@ class GenericJdbcConnectionTest < Test::Unit::TestCase
37
130
  end
38
131
  end
39
132
  end
40
-
133
+
41
134
  test 'connection does not fail with driver_instance and url' do
42
135
  load_derby_driver
43
136
  with_connection_removed do
@@ -57,7 +150,21 @@ class GenericJdbcConnectionTest < Test::Unit::TestCase
57
150
  end
58
151
  end
59
152
  end
60
-
153
+
154
+ test 'configures driver instance' do
155
+ load_derby_driver
156
+ with_connection_removed do
157
+ ActiveRecord::Base.establish_connection :adapter => 'jdbc',
158
+ :url => 'jdbc:derby:memory:TestDB;create=true', :driver => 'org.apache.derby.jdbc.EmbeddedDriver'
159
+ assert_nothing_raised do
160
+ ActiveRecord::Base.connection
161
+ end
162
+ assert config = ActiveRecord::Base.connection.config
163
+ assert_instance_of ActiveRecord::ConnectionAdapters::JdbcDriver, config[:driver_instance]
164
+ assert_equal 'org.apache.derby.jdbc.EmbeddedDriver', config[:driver_instance].name
165
+ end
166
+ end
167
+
61
168
  private
62
169
 
63
170
  def with_connection_removed
@@ -65,7 +172,7 @@ class GenericJdbcConnectionTest < Test::Unit::TestCase
65
172
  begin
66
173
  yield
67
174
  ensure
68
- ActiveRecord::Base.establish_connection connection
175
+ ActiveRecord::Base.establish_connection connection
69
176
  end
70
177
  end
71
178