cmoran92-activerecord-jdbc-adapter 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +22 -0
- data/.travis.yml +8 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +42 -0
- data/History.txt +469 -0
- data/LICENSE.txt +21 -0
- data/README.rdoc +199 -0
- data/Rakefile +60 -0
- data/activerecord-jdbc-adapter.gemspec +23 -0
- data/bench/bench_attributes.rb +13 -0
- data/bench/bench_attributes_new.rb +14 -0
- data/bench/bench_create.rb +12 -0
- data/bench/bench_find_all.rb +12 -0
- data/bench/bench_find_all_mt.rb +25 -0
- data/bench/bench_model.rb +85 -0
- data/bench/bench_new.rb +12 -0
- data/bench/bench_new_valid.rb +12 -0
- data/bench/bench_valid.rb +13 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +8 -0
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +9 -0
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +15 -0
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +6 -0
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +46 -0
- data/lib/arel/visitors/compat.rb +13 -0
- data/lib/arel/visitors/db2.rb +17 -0
- data/lib/arel/visitors/derby.rb +25 -0
- data/lib/arel/visitors/firebird.rb +24 -0
- data/lib/arel/visitors/hsqldb.rb +26 -0
- data/lib/arel/visitors/sql_server.rb +44 -0
- data/lib/arjdbc.rb +24 -0
- data/lib/arjdbc/db2.rb +2 -0
- data/lib/arjdbc/db2/adapter.rb +510 -0
- data/lib/arjdbc/derby.rb +7 -0
- data/lib/arjdbc/derby/adapter.rb +351 -0
- data/lib/arjdbc/derby/connection_methods.rb +19 -0
- data/lib/arjdbc/discover.rb +92 -0
- data/lib/arjdbc/firebird.rb +2 -0
- data/lib/arjdbc/firebird/adapter.rb +136 -0
- data/lib/arjdbc/h2.rb +4 -0
- data/lib/arjdbc/h2/adapter.rb +54 -0
- data/lib/arjdbc/h2/connection_methods.rb +13 -0
- data/lib/arjdbc/hsqldb.rb +4 -0
- data/lib/arjdbc/hsqldb/adapter.rb +184 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +15 -0
- data/lib/arjdbc/informix.rb +3 -0
- data/lib/arjdbc/informix/adapter.rb +138 -0
- data/lib/arjdbc/informix/connection_methods.rb +11 -0
- data/lib/arjdbc/jdbc.rb +2 -0
- data/lib/arjdbc/jdbc/adapter.rb +354 -0
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/callbacks.rb +44 -0
- data/lib/arjdbc/jdbc/column.rb +47 -0
- data/lib/arjdbc/jdbc/compatibility.rb +51 -0
- data/lib/arjdbc/jdbc/connection.rb +134 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +16 -0
- data/lib/arjdbc/jdbc/core_ext.rb +24 -0
- data/lib/arjdbc/jdbc/discover.rb +18 -0
- data/lib/arjdbc/jdbc/driver.rb +35 -0
- data/lib/arjdbc/jdbc/extension.rb +47 -0
- data/lib/arjdbc/jdbc/java.rb +14 -0
- data/lib/arjdbc/jdbc/jdbc.rake +131 -0
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +87 -0
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +28 -0
- data/lib/arjdbc/jdbc/railtie.rb +9 -0
- data/lib/arjdbc/jdbc/rake_tasks.rb +10 -0
- data/lib/arjdbc/jdbc/require_driver.rb +16 -0
- data/lib/arjdbc/jdbc/type_converter.rb +126 -0
- data/lib/arjdbc/mimer.rb +2 -0
- data/lib/arjdbc/mimer/adapter.rb +142 -0
- data/lib/arjdbc/mssql.rb +4 -0
- data/lib/arjdbc/mssql/adapter.rb +468 -0
- data/lib/arjdbc/mssql/connection_methods.rb +31 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +108 -0
- data/lib/arjdbc/mssql/tsql_helper.rb +61 -0
- data/lib/arjdbc/mysql.rb +4 -0
- data/lib/arjdbc/mysql/adapter.rb +505 -0
- data/lib/arjdbc/mysql/connection_methods.rb +28 -0
- data/lib/arjdbc/oracle.rb +3 -0
- data/lib/arjdbc/oracle/adapter.rb +428 -0
- data/lib/arjdbc/oracle/connection_methods.rb +12 -0
- data/lib/arjdbc/postgresql.rb +4 -0
- data/lib/arjdbc/postgresql/adapter.rb +825 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +23 -0
- data/lib/arjdbc/sqlite3.rb +4 -0
- data/lib/arjdbc/sqlite3/adapter.rb +387 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +35 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +46 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/USAGE +10 -0
- data/lib/generators/jdbc/jdbc_generator.rb +9 -0
- data/lib/jdbc_adapter.rb +2 -0
- data/lib/jdbc_adapter/rake_tasks.rb +3 -0
- data/lib/jdbc_adapter/version.rb +3 -0
- data/lib/pg.rb +26 -0
- data/pom.xml +57 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +7 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +8 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/compile.rake +23 -0
- data/rakelib/db.rake +39 -0
- data/rakelib/rails.rake +41 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +62 -0
- data/src/java/arjdbc/derby/DerbyModule.java +324 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +70 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +74 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +68 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +36 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1331 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +48 -0
- data/src/java/arjdbc/mssql/MssqlRubyJdbcConnection.java +127 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +134 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +161 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +85 -0
- data/src/java/arjdbc/postgresql/PostgresqlRubyJdbcConnection.java +82 -0
- data/src/java/arjdbc/sqlite3/Sqlite3RubyJdbcConnection.java +126 -0
- data/test/abstract_db_create.rb +135 -0
- data/test/activerecord/connection_adapters/type_conversion_test.rb +31 -0
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +25 -0
- data/test/activerecord/jall.sh +7 -0
- data/test/activerecord/jtest.sh +3 -0
- data/test/db/db2.rb +11 -0
- data/test/db/derby.rb +12 -0
- data/test/db/h2.rb +11 -0
- data/test/db/hsqldb.rb +13 -0
- data/test/db/informix.rb +11 -0
- data/test/db/jdbc.rb +12 -0
- data/test/db/jndi_config.rb +40 -0
- data/test/db/logger.rb +3 -0
- data/test/db/mssql.rb +9 -0
- data/test/db/mysql.rb +10 -0
- data/test/db/oracle.rb +34 -0
- data/test/db/postgres.rb +9 -0
- data/test/db/sqlite3.rb +11 -0
- data/test/db2_simple_test.rb +66 -0
- data/test/derby_migration_test.rb +68 -0
- data/test/derby_multibyte_test.rb +12 -0
- data/test/derby_simple_test.rb +99 -0
- data/test/generic_jdbc_connection_test.rb +29 -0
- data/test/h2_change_column_test.rb +68 -0
- data/test/h2_simple_test.rb +41 -0
- data/test/has_many_through.rb +79 -0
- data/test/helper.rb +85 -0
- data/test/hsqldb_simple_test.rb +6 -0
- data/test/informix_simple_test.rb +48 -0
- data/test/jdbc_common.rb +27 -0
- data/test/jndi_callbacks_test.rb +40 -0
- data/test/jndi_test.rb +25 -0
- data/test/manualTestDatabase.rb +191 -0
- data/test/models/add_not_null_column_to_table.rb +9 -0
- data/test/models/auto_id.rb +15 -0
- data/test/models/data_types.rb +30 -0
- data/test/models/entry.rb +40 -0
- data/test/models/mixed_case.rb +22 -0
- data/test/models/reserved_word.rb +15 -0
- data/test/models/string_id.rb +17 -0
- data/test/models/thing.rb +16 -0
- data/test/models/validates_uniqueness_of_string.rb +19 -0
- data/test/mssql_db_create_test.rb +26 -0
- data/test/mssql_identity_insert_test.rb +19 -0
- data/test/mssql_legacy_types_test.rb +58 -0
- data/test/mssql_limit_offset_test.rb +136 -0
- data/test/mssql_multibyte_test.rb +18 -0
- data/test/mssql_simple_test.rb +55 -0
- data/test/mysql_db_create_test.rb +27 -0
- data/test/mysql_index_length_test.rb +58 -0
- data/test/mysql_info_test.rb +123 -0
- data/test/mysql_multibyte_test.rb +10 -0
- data/test/mysql_nonstandard_primary_key_test.rb +42 -0
- data/test/mysql_simple_test.rb +125 -0
- data/test/oracle_simple_test.rb +18 -0
- data/test/oracle_specific_test.rb +83 -0
- data/test/postgres_db_create_test.rb +32 -0
- data/test/postgres_drop_db_test.rb +16 -0
- data/test/postgres_information_schema_leak_test.rb +29 -0
- data/test/postgres_mixed_case_test.rb +29 -0
- data/test/postgres_native_type_mapping_test.rb +89 -0
- data/test/postgres_nonseq_pkey_test.rb +38 -0
- data/test/postgres_reserved_test.rb +22 -0
- data/test/postgres_schema_search_path_test.rb +48 -0
- data/test/postgres_simple_test.rb +167 -0
- data/test/postgres_table_alias_length_test.rb +15 -0
- data/test/postgres_type_conversion_test.rb +34 -0
- data/test/simple.rb +658 -0
- data/test/sqlite3_simple_test.rb +284 -0
- data/test/sybase_jtds_simple_test.rb +28 -0
- metadata +261 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/mssql'
|
|
3
|
+
|
|
4
|
+
ActiveRecord::Schema.verbose = false
|
|
5
|
+
|
|
6
|
+
class CreateLongShips < ActiveRecord::Migration
|
|
7
|
+
|
|
8
|
+
def self.up
|
|
9
|
+
create_table "long_ships", :force => true do |t|
|
|
10
|
+
t.string "name", :limit => 50, :null => false
|
|
11
|
+
t.integer "width", :default => 123
|
|
12
|
+
t.integer "length", :default => 456
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.down
|
|
17
|
+
drop_table "long_ships"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class LongShip < ActiveRecord::Base
|
|
23
|
+
has_many :vikings
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class CreateVikings < ActiveRecord::Migration
|
|
27
|
+
|
|
28
|
+
def self.up
|
|
29
|
+
create_table "vikings", :force => true do |t|
|
|
30
|
+
t.integer "long_ship_id", :null => false
|
|
31
|
+
t.string "name", :limit => 50, :default => "Sven"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.down
|
|
36
|
+
drop_table "vikings"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class Viking < ActiveRecord::Base
|
|
42
|
+
belongs_to :long_ship
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class CreateNoIdVikings < ActiveRecord::Migration
|
|
47
|
+
def self.up
|
|
48
|
+
create_table "no_id_vikings", :force => true do |t|
|
|
49
|
+
t.string "name", :limit => 50, :default => "Sven"
|
|
50
|
+
end
|
|
51
|
+
remove_column "no_id_vikings", "id"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.down
|
|
55
|
+
drop_table "no_id_vikings"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
class NoIdViking < ActiveRecord::Base
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class MsSQLLimitOffsetTest < Test::Unit::TestCase
|
|
65
|
+
|
|
66
|
+
def setup
|
|
67
|
+
CreateLongShips.up
|
|
68
|
+
CreateVikings.up
|
|
69
|
+
CreateNoIdVikings.up
|
|
70
|
+
@connection = ActiveRecord::Base.connection
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def teardown
|
|
74
|
+
CreateVikings.down
|
|
75
|
+
CreateLongShips.down
|
|
76
|
+
CreateNoIdVikings.down
|
|
77
|
+
ActiveRecord::Base.clear_active_connections!
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def test_limit_with_no_id_column_available
|
|
81
|
+
NoIdViking.create!(:name => 'Erik')
|
|
82
|
+
assert_nothing_raised(ActiveRecord::StatementInvalid) do
|
|
83
|
+
NoIdViking.find(:first)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_limit_and_offset
|
|
88
|
+
%w(one two three four five six seven eight).each do |name|
|
|
89
|
+
LongShip.create!(:name => name)
|
|
90
|
+
end
|
|
91
|
+
ship_names = LongShip.find(:all, :offset => 2, :limit => 3).map(&:name)
|
|
92
|
+
assert_equal(%w(three four five), ship_names)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def test_limit_and_offset_with_order
|
|
96
|
+
%w(one two three four five six seven eight).each do |name|
|
|
97
|
+
LongShip.create!(:name => name)
|
|
98
|
+
end
|
|
99
|
+
ship_names = LongShip.find(:all, :order => "name", :offset => 4, :limit => 2).map(&:name)
|
|
100
|
+
assert_equal(%w(seven six), ship_names)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# TODO: work out how to fix DISTINCT support without breaking :include
|
|
104
|
+
# def test_limit_and_offset_with_distinct
|
|
105
|
+
# %w(c a b a b a c d c d).each do |name|
|
|
106
|
+
# LongShip.create!(:name => name)
|
|
107
|
+
# end
|
|
108
|
+
# ship_names = LongShip.find(:all, :select => "DISTINCT name", :order => "name", :offset => 1, :limit => 2).map(&:name)
|
|
109
|
+
# assert_equal(%w(b c), ship_names)
|
|
110
|
+
# end
|
|
111
|
+
|
|
112
|
+
def test_limit_and_offset_with_include
|
|
113
|
+
skei = LongShip.create!(:name => "Skei")
|
|
114
|
+
skei.vikings.create!(:name => "Bob")
|
|
115
|
+
skei.vikings.create!(:name => "Ben")
|
|
116
|
+
skei.vikings.create!(:name => "Basil")
|
|
117
|
+
ships = Viking.find(:all, :include => :long_ship, :offset => 1, :limit => 2)
|
|
118
|
+
assert_equal(2, ships.size)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def test_limit_and_offset_with_include_and_order
|
|
122
|
+
|
|
123
|
+
boat1 = LongShip.create!(:name => "1-Skei")
|
|
124
|
+
boat2 = LongShip.create!(:name => "2-Skei")
|
|
125
|
+
|
|
126
|
+
boat1.vikings.create!(:name => "Adam")
|
|
127
|
+
boat2.vikings.create!(:name => "Ben")
|
|
128
|
+
boat1.vikings.create!(:name => "Carl")
|
|
129
|
+
boat2.vikings.create!(:name => "Donald")
|
|
130
|
+
|
|
131
|
+
vikings = Viking.find(:all, :include => :long_ship, :order => "long_ships.name, vikings.name", :offset => 0, :limit => 3)
|
|
132
|
+
assert_equal(["Adam", "Carl", "Ben"], vikings.map(&:name))
|
|
133
|
+
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#! /usr/bin/env jruby
|
|
2
|
+
|
|
3
|
+
require 'jdbc_common'
|
|
4
|
+
require 'db/mssql'
|
|
5
|
+
|
|
6
|
+
class MsSQLMultibyteTest < Test::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
include MultibyteTestMethods
|
|
9
|
+
|
|
10
|
+
def test_select_multibyte_string
|
|
11
|
+
Entry.create!(:title => 'テスト', :content => '本文')
|
|
12
|
+
entry = Entry.find(:last)
|
|
13
|
+
assert_equal "テスト", entry.title
|
|
14
|
+
assert_equal "本文", entry.content
|
|
15
|
+
assert_equal entry, Entry.find_by_title("テスト")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/mssql'
|
|
3
|
+
|
|
4
|
+
class MsSQLSimpleTest < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
include SimpleTestMethods
|
|
7
|
+
|
|
8
|
+
# MS SQL 2005 doesn't have a DATE class, only TIMESTAMP.
|
|
9
|
+
undef_method :test_save_date
|
|
10
|
+
|
|
11
|
+
# String comparisons are insensitive by default
|
|
12
|
+
undef_method :test_validates_uniqueness_of_strings_case_sensitive
|
|
13
|
+
|
|
14
|
+
def test_does_not_munge_quoted_strings
|
|
15
|
+
example_quoted_values = [%{'quoted'}, %{D\'oh!}]
|
|
16
|
+
example_quoted_values.each do |value|
|
|
17
|
+
entry = Entry.create!(:title => value)
|
|
18
|
+
entry.reload
|
|
19
|
+
assert_equal(value, entry.title)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_change_column_default
|
|
24
|
+
|
|
25
|
+
Entry.connection.change_column "entries", "title", :string, :default => "new default"
|
|
26
|
+
Entry.reset_column_information
|
|
27
|
+
assert_equal("new default", Entry.new.title)
|
|
28
|
+
|
|
29
|
+
Entry.connection.change_column "entries", "title", :string, :default => nil
|
|
30
|
+
Entry.reset_column_information
|
|
31
|
+
assert_equal(nil, Entry.new.title)
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_change_column_nullability
|
|
36
|
+
|
|
37
|
+
Entry.connection.change_column "entries", "title", :string, :null => true
|
|
38
|
+
Entry.reset_column_information
|
|
39
|
+
title_column = Entry.columns.find { |c| c.name == "title" }
|
|
40
|
+
assert(title_column.null)
|
|
41
|
+
|
|
42
|
+
Entry.connection.change_column "entries", "title", :string, :null => false
|
|
43
|
+
Entry.reset_column_information
|
|
44
|
+
title_column = Entry.columns.find { |c| c.name == "title" }
|
|
45
|
+
assert(!title_column.null)
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# ACTIVERECORD_JDBC-124
|
|
50
|
+
def test_model_does_not_have_row_num_column
|
|
51
|
+
entry = Entry.first
|
|
52
|
+
assert !entry.attributes.keys.include?("_row_num")
|
|
53
|
+
assert !entry.respond_to?(:_row_num)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'abstract_db_create'
|
|
2
|
+
require 'db/mysql'
|
|
3
|
+
|
|
4
|
+
class MysqlDbCreateTest < Test::Unit::TestCase
|
|
5
|
+
include AbstractDbCreate
|
|
6
|
+
|
|
7
|
+
def db_config
|
|
8
|
+
MYSQL_CONFIG
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_rake_db_create
|
|
12
|
+
Rake::Task["db:create"].invoke
|
|
13
|
+
if find_executable?("mysql")
|
|
14
|
+
output = nil
|
|
15
|
+
IO.popen("mysql -u #{MYSQL_CONFIG[:username]} --password=#{MYSQL_CONFIG[:password]}", "r+") do |mysql|
|
|
16
|
+
mysql << "show databases where `Database` = '#{@db_name}';"
|
|
17
|
+
mysql.close_write
|
|
18
|
+
assert mysql.read =~ /#{@db_name}/m
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_rake_db_test_purge
|
|
24
|
+
Rake::Task["db:create"].invoke
|
|
25
|
+
Rake::Task["db:test:purge"].invoke
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/mysql'
|
|
3
|
+
|
|
4
|
+
class MySQLIndexLengthDBSetup < ActiveRecord::Migration
|
|
5
|
+
def self.up
|
|
6
|
+
execute <<-SQL
|
|
7
|
+
CREATE TABLE index_length_test (
|
|
8
|
+
int_column INT,
|
|
9
|
+
text_column TEXT,
|
|
10
|
+
second_text_column TEXT,
|
|
11
|
+
INDEX ix_int (int_column),
|
|
12
|
+
INDEX ix_length_text (text_column(255))
|
|
13
|
+
)
|
|
14
|
+
SQL
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.down
|
|
18
|
+
drop_table 'index_length_test'
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class MySQLIndexLengthTest < Test::Unit::TestCase
|
|
23
|
+
def setup
|
|
24
|
+
MySQLIndexLengthDBSetup.up
|
|
25
|
+
@connection = ActiveRecord::Base.connection
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def teardown
|
|
29
|
+
MySQLIndexLengthDBSetup.down
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_index_length
|
|
33
|
+
index = @connection.indexes('index_length_test').find { |idx| idx.name == 'ix_length_text' }
|
|
34
|
+
assert_not_nil index
|
|
35
|
+
assert_equal "index_length_test", index.table
|
|
36
|
+
assert_equal "ix_length_text", index.name
|
|
37
|
+
assert !index.unique
|
|
38
|
+
assert_equal ["text_column"], index.columns
|
|
39
|
+
assert_equal [255], index.lengths
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_add_index
|
|
43
|
+
@connection.add_index 'index_length_test', ['text_column', 'second_text_column'],
|
|
44
|
+
:name => 'added_index', :length => {'text_column' => 32, 'second_text_column' => 64}
|
|
45
|
+
|
|
46
|
+
index = @connection.indexes('index_length_test').find { |idx| idx.name == 'added_index' }
|
|
47
|
+
assert_not_nil index
|
|
48
|
+
assert_equal ['text_column', 'second_text_column'], index.columns
|
|
49
|
+
assert_equal [32, 64], index.lengths
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_index_without_length
|
|
53
|
+
index = @connection.indexes('index_length_test').find { |idx| idx.name == 'ix_int' }
|
|
54
|
+
assert_not_nil index
|
|
55
|
+
assert_equal ['int_column'], index.columns
|
|
56
|
+
assert_equal [nil], index.lengths
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/mysql'
|
|
3
|
+
begin; require 'active_support/core_ext/numeric/bytes'; rescue LoadError; end
|
|
4
|
+
|
|
5
|
+
class DBSetup < ActiveRecord::Migration
|
|
6
|
+
|
|
7
|
+
def self.up
|
|
8
|
+
create_table :books do |t|
|
|
9
|
+
t.string :title
|
|
10
|
+
t.timestamps
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
create_table :cars, :primary_key => 'legacy_id' do |t|
|
|
14
|
+
t.string :name
|
|
15
|
+
t.date :production_started_on
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
create_table :cats, :id => false do |t|
|
|
19
|
+
t.string :name
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
create_table :memos do |t|
|
|
23
|
+
t.text :text, :limit => 16.megabytes
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.down
|
|
28
|
+
drop_table :books
|
|
29
|
+
drop_table :cars
|
|
30
|
+
drop_table :cats
|
|
31
|
+
drop_table :memos
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class MysqlInfoTest < Test::Unit::TestCase
|
|
37
|
+
|
|
38
|
+
def setup
|
|
39
|
+
DBSetup.up
|
|
40
|
+
@connection = ActiveRecord::Base.connection
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def teardown
|
|
44
|
+
DBSetup.down
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
## primary_key
|
|
48
|
+
def test_should_return_the_primary_key_of_a_table
|
|
49
|
+
assert_equal 'id', @connection.primary_key('books')
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_should_be_able_to_return_a_custom_primary_key
|
|
53
|
+
assert_equal 'legacy_id', @connection.primary_key('cars')
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_should_return_nil_for_a_table_without_a_primary_key
|
|
57
|
+
assert_nil @connection.primary_key('cats')
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
## structure_dump
|
|
61
|
+
def test_should_include_the_tables_in_a_structure_dump
|
|
62
|
+
# TODO: Improve these tests, I added this one because no other tests exists for this method.
|
|
63
|
+
dump = @connection.structure_dump
|
|
64
|
+
assert dump.include?('CREATE TABLE `books`')
|
|
65
|
+
assert dump.include?('CREATE TABLE `cars`')
|
|
66
|
+
assert dump.include?('CREATE TABLE `cats`')
|
|
67
|
+
assert dump.include?('CREATE TABLE `memos`')
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_should_include_longtext_in_schema_dump
|
|
71
|
+
strio = StringIO.new
|
|
72
|
+
ActiveRecord::SchemaDumper::dump(@connection, strio)
|
|
73
|
+
dump = strio.string
|
|
74
|
+
assert_match %r{t.text\s+"text",\s+:limit => 2147483647$}, dump
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# JRUBY-5040
|
|
78
|
+
def test_schema_dump_should_not_have_limits_on_datetime
|
|
79
|
+
strio = StringIO.new
|
|
80
|
+
ActiveRecord::SchemaDumper::dump(@connection, strio)
|
|
81
|
+
dump = strio.string
|
|
82
|
+
dump.lines.grep(/datetime/).each {|line| assert line !~ /limit/ }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def test_schema_dump_should_not_have_limits_on_date
|
|
86
|
+
strio = StringIO.new
|
|
87
|
+
ActiveRecord::SchemaDumper::dump(@connection, strio)
|
|
88
|
+
dump = strio.string
|
|
89
|
+
dump.lines.grep(/date/).each {|line| assert line !~ /limit/ }
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_should_include_limit
|
|
93
|
+
text_column = @connection.columns('memos').find { |c| c.name == 'text' }
|
|
94
|
+
assert_equal 2147483647, text_column.limit
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_should_set_sqltype_to_longtext
|
|
98
|
+
text_column = @connection.columns('memos').find { |c| c.name == 'text' }
|
|
99
|
+
assert text_column.sql_type =~ /^longtext/i
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def test_should_set_type_to_text
|
|
103
|
+
text_column = @connection.columns('memos').find { |c| c.name == 'text' }
|
|
104
|
+
assert_equal :text, text_column.type
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def test_verify_url_has_options
|
|
108
|
+
url = @connection.config[:url]
|
|
109
|
+
assert url =~ /characterEncoding=utf8/
|
|
110
|
+
assert url =~ /useUnicode=true/
|
|
111
|
+
assert url =~ /zeroDateTimeBehavior=convertToNull/
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def test_no_limits_for_some_data_types
|
|
115
|
+
DbTypeMigration.up
|
|
116
|
+
strio = StringIO.new
|
|
117
|
+
ActiveRecord::SchemaDumper.dump(@connection, strio)
|
|
118
|
+
dump_lines = strio.string
|
|
119
|
+
assert_nil dump_lines.lines.detect {|l| l =~ /\.(float|date|datetime|integer|time|timestamp) .* :limit/ && l !~ /sample_integer/ }
|
|
120
|
+
ensure
|
|
121
|
+
DbTypeMigration.down
|
|
122
|
+
end
|
|
123
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'jdbc_common'
|
|
2
|
+
require 'db/mysql'
|
|
3
|
+
|
|
4
|
+
class Project < ActiveRecord::Migration
|
|
5
|
+
def self.up
|
|
6
|
+
create_table :project, :primary_key => "project_id" do |t|
|
|
7
|
+
t.string :projectType, :limit => 31
|
|
8
|
+
t.boolean :published
|
|
9
|
+
t.datetime :created_date
|
|
10
|
+
t.text :abstract, :title
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.down
|
|
15
|
+
drop_table :project
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class MysqlNonstandardPrimaryKeyTest < Test::Unit::TestCase
|
|
21
|
+
|
|
22
|
+
def setup
|
|
23
|
+
Project.up
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def teardown
|
|
27
|
+
Project.down
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def standard_dump
|
|
31
|
+
stream = StringIO.new
|
|
32
|
+
ActiveRecord::SchemaDumper.ignore_tables = []
|
|
33
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
|
34
|
+
stream.string
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_nonstandard_primary_key
|
|
38
|
+
output = standard_dump
|
|
39
|
+
assert_match %r(:primary_key => "project_id"), output, "non-standard primary key not preserved"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|