ibm_db 2.5.9-x86-mingw32 → 2.5.10-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -0
- data/README +79 -141
- data/ext/extconf.rb +74 -13
- data/ext/ibm_db.c +20 -5
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +45 -8
- data/lib/mswin32/rb18x/ibm_db.so +0 -0
- data/lib/mswin32/rb19x/ibm_db.so +0 -0
- data/test/cases/adapter_test.rb +162 -160
- data/test/cases/associations/belongs_to_associations_test.rb +23 -0
- data/test/cases/associations/cascaded_eager_loading_test.rb +3 -7
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +40 -10
- data/test/cases/associations/join_model_test.rb +4 -4
- data/test/cases/attribute_methods_test.rb +169 -33
- data/test/cases/base_test.rb +302 -77
- data/test/cases/calculations_test.rb +37 -1
- data/test/cases/migration_test.rb +183 -115
- data/test/cases/persistence_test.rb +17 -11
- data/test/cases/query_cache_test.rb +18 -3
- data/test/cases/relations_test.rb +178 -15
- data/test/cases/schema_dumper_test.rb +5 -1
- data/test/cases/transaction_callbacks_test.rb +2 -2
- data/test/cases/xml_serialization_test.rb +133 -1
- data/test/schema/schema.rb +22 -3
- metadata +36 -55
@@ -44,10 +44,15 @@ module ActiveRecord
|
|
44
44
|
# (except for a CLOB field where '' can be a value)
|
45
45
|
if self[col.name].nil? ||
|
46
46
|
self[col.name] == {} ||
|
47
|
+
self[col.name] == [] ||
|
47
48
|
(self[col.name] == '' && col.type != :text)
|
48
49
|
params << 'NULL'
|
49
50
|
else
|
50
|
-
|
51
|
+
if self.class.serialized_attributes[col.name]
|
52
|
+
values << YAML.dump(self[col.name])
|
53
|
+
else
|
54
|
+
values << self[col.name]
|
55
|
+
end
|
51
56
|
params << '?'
|
52
57
|
end
|
53
58
|
counter += 1
|
@@ -526,7 +531,8 @@ module ActiveRecord
|
|
526
531
|
end
|
527
532
|
when /DB2/i # DB2 for zOS
|
528
533
|
case server_info.DBMS_VER
|
529
|
-
when /09/
|
534
|
+
when /09/ # DB2 for zOS version 9 and version 10
|
535
|
+
when /10/
|
530
536
|
@servertype = IBM_DB2_ZOS.new(self)
|
531
537
|
when /08/ # DB2 for zOS version 8
|
532
538
|
@servertype = IBM_DB2_ZOS_8.new(self)
|
@@ -558,6 +564,17 @@ module ActiveRecord
|
|
558
564
|
else
|
559
565
|
@start_id = 1
|
560
566
|
end
|
567
|
+
|
568
|
+
#Check Arel version
|
569
|
+
begin
|
570
|
+
@arelVersion = Arel::VERSION.to_i
|
571
|
+
rescue
|
572
|
+
@arelVersion = 0
|
573
|
+
end
|
574
|
+
|
575
|
+
if(@arelVersion >= 3 )
|
576
|
+
@visitor = Arel::Visitors::IBM_DB.new self
|
577
|
+
end
|
561
578
|
end
|
562
579
|
|
563
580
|
# Optional connection attribute: database name space qualifier
|
@@ -612,13 +629,14 @@ module ActiveRecord
|
|
612
629
|
Arel::Visitors::IBM_DB.new(pool)
|
613
630
|
end
|
614
631
|
|
615
|
-
def to_sql(arel)
|
632
|
+
def to_sql(arel, binds = [])
|
616
633
|
if arel.respond_to?(:ast)
|
617
|
-
visitor.accept(arel.ast)
|
634
|
+
visitor.accept(arel.ast) do
|
635
|
+
quote(*binds.shift.reverse)
|
636
|
+
end
|
618
637
|
else
|
619
638
|
arel
|
620
639
|
end
|
621
|
-
|
622
640
|
end
|
623
641
|
|
624
642
|
# This adapter supports migrations.
|
@@ -1881,7 +1899,7 @@ module ActiveRecord
|
|
1881
1899
|
end
|
1882
1900
|
|
1883
1901
|
def check_reserved_words(col_name)
|
1884
|
-
col_name
|
1902
|
+
col_name.to_s
|
1885
1903
|
end
|
1886
1904
|
|
1887
1905
|
# This is supported by the DB2 for Linux, UNIX, Windows data servers
|
@@ -2492,7 +2510,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
2492
2510
|
if RESERVED_WORDS[col_name]
|
2493
2511
|
'"' + RESERVED_WORDS[col_name] + '"'
|
2494
2512
|
else
|
2495
|
-
col_name
|
2513
|
+
col_name.to_s
|
2496
2514
|
end
|
2497
2515
|
end
|
2498
2516
|
else
|
@@ -2816,6 +2834,25 @@ module Arel
|
|
2816
2834
|
end
|
2817
2835
|
|
2818
2836
|
class ToSql < Arel::Visitors::Visitor #opening and closing the class to ensure backward compatibility
|
2837
|
+
# In case when using Rails-2.3.x there is no arel used due to which the constructor has to be defined explicitly
|
2838
|
+
# to ensure the same code works on any version of Rails
|
2839
|
+
|
2840
|
+
#Check Arel version
|
2841
|
+
begin
|
2842
|
+
@arelVersion = Arel::VERSION.to_i
|
2843
|
+
rescue
|
2844
|
+
@arelVersion = 0
|
2845
|
+
end
|
2846
|
+
|
2847
|
+
if(@arelVersion >= 3)
|
2848
|
+
def initialize connection
|
2849
|
+
@connection = connection
|
2850
|
+
@schema_cache = connection.schema_cache if(connection.respond_to?(:schema_cache))
|
2851
|
+
@quoted_tables = {}
|
2852
|
+
@quoted_columns = {}
|
2853
|
+
@last_column = nil
|
2854
|
+
end
|
2855
|
+
end
|
2819
2856
|
end
|
2820
2857
|
|
2821
2858
|
class IBM_DB < Arel::Visitors::ToSql
|
@@ -2834,7 +2871,6 @@ module Arel
|
|
2834
2871
|
(visit(o.with) if o.with),
|
2835
2872
|
o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
|
2836
2873
|
("ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty?),
|
2837
|
-
(visit(o.lock) if o.lock),
|
2838
2874
|
].compact.join ' '
|
2839
2875
|
|
2840
2876
|
if o.limit
|
@@ -2849,6 +2885,7 @@ module Arel
|
|
2849
2885
|
offset = nil
|
2850
2886
|
end
|
2851
2887
|
@connection.add_limit_offset!(sql, {:limit => limit, :offset => offset})
|
2888
|
+
sql << " #{(visit(o.lock) if o.lock)}"
|
2852
2889
|
return sql
|
2853
2890
|
end
|
2854
2891
|
|
data/lib/mswin32/rb18x/ibm_db.so
CHANGED
Binary file
|
data/lib/mswin32/rb19x/ibm_db.so
CHANGED
Binary file
|
data/test/cases/adapter_test.rb
CHANGED
@@ -1,205 +1,207 @@
|
|
1
1
|
require "cases/helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module ActiveRecord
|
4
|
+
class AdapterTest < ActiveRecord::TestCase
|
5
|
+
def setup
|
6
|
+
@connection = ActiveRecord::Base.connection
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
9
|
+
if current_adapter?(:IBM_DBAdapter)
|
10
|
+
def test_a_connection_attributes
|
11
|
+
if @connection.servertype.class.name.include?('::IBM_IDS')
|
12
|
+
return
|
13
|
+
end
|
14
|
+
if @connection.respond_to?(:schema)
|
15
|
+
previous_schema = ActiveRecord::Base.connection.schema
|
16
|
+
ActiveRecord::Base.connection.schema = 'SYSCAT'
|
17
|
+
assert_equal 'SYSCAT', ActiveRecord::Base.connection.schema
|
18
|
+
ActiveRecord::Base.connection.schema = previous_schema
|
19
|
+
else
|
20
|
+
warn "#{@connection.class} does not support client connection attribute schema_name"
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
if @connection.respond_to?(:app_user)
|
24
|
+
ActiveRecord::Base.connection.app_user = 'new_user'
|
25
|
+
assert_equal 'new_user', ActiveRecord::Base.connection.app_user
|
26
|
+
else
|
27
|
+
warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_USER"
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
if @connection.respond_to?(:account)
|
31
|
+
ActiveRecord::Base.connection.account = 'new_acct'
|
32
|
+
assert_equal 'new_acct', ActiveRecord::Base.connection.account
|
33
|
+
else
|
34
|
+
warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_ACCTSTR"
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
if @connection.respond_to?(:application)
|
38
|
+
ActiveRecord::Base.connection.application = 'new_app'
|
39
|
+
assert_equal 'new_app', ActiveRecord::Base.connection.application
|
40
|
+
else
|
41
|
+
warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_APPLNAME"
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
if @connection.respond_to?(:workstation)
|
45
|
+
ActiveRecord::Base.connection.workstation = 'new_wrkst'
|
46
|
+
assert_equal 'new_wrkst', ActiveRecord::Base.connection.workstation
|
47
|
+
else
|
48
|
+
warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_WRKSTNNAME"
|
49
|
+
end
|
48
50
|
end
|
49
51
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_table_exists?
|
61
|
-
assert @connection.table_exists?("accounts")
|
62
|
-
assert !@connection.table_exists?("nonexistingtable")
|
63
|
-
end
|
52
|
+
|
53
|
+
def test_tables
|
54
|
+
tables = @connection.tables
|
55
|
+
assert tables.include?("accounts")
|
56
|
+
assert tables.include?("authors")
|
57
|
+
assert tables.include?("tasks")
|
58
|
+
assert tables.include?("topics")
|
59
|
+
end
|
64
60
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
indexes = @connection.indexes("accounts")
|
70
|
-
assert indexes.empty?
|
71
|
-
|
72
|
-
@connection.add_index :accounts, :firm_id, :name => idx_name
|
73
|
-
indexes = @connection.indexes("accounts")
|
74
|
-
assert_equal "accounts", indexes.first.table
|
75
|
-
# OpenBase does not have the concept of a named index
|
76
|
-
# Indexes are merely properties of columns.
|
77
|
-
assert_equal idx_name, indexes.first.name unless current_adapter?(:OpenBaseAdapter)
|
78
|
-
assert !indexes.first.unique
|
79
|
-
assert_equal ["firm_id"], indexes.first.columns
|
80
|
-
else
|
81
|
-
warn "#{@connection.class} does not respond to #indexes"
|
61
|
+
def test_table_exists?
|
62
|
+
assert @connection.table_exists?("accounts")
|
63
|
+
assert !@connection.table_exists?("nonexistingtable")
|
64
|
+
assert !@connection.table_exists?(nil)
|
82
65
|
end
|
83
66
|
|
84
|
-
|
85
|
-
|
86
|
-
|
67
|
+
def test_indexes
|
68
|
+
idx_name = "accounts_idx"
|
69
|
+
|
70
|
+
if @connection.respond_to?(:indexes)
|
71
|
+
indexes = @connection.indexes("accounts")
|
72
|
+
assert indexes.empty?
|
73
|
+
|
74
|
+
@connection.add_index :accounts, :firm_id, :name => idx_name
|
75
|
+
indexes = @connection.indexes("accounts")
|
76
|
+
assert_equal "accounts", indexes.first.table
|
77
|
+
# OpenBase does not have the concept of a named index
|
78
|
+
# Indexes are merely properties of columns.
|
79
|
+
assert_equal idx_name, indexes.first.name unless current_adapter?(:OpenBaseAdapter)
|
80
|
+
assert !indexes.first.unique
|
81
|
+
assert_equal ["firm_id"], indexes.first.columns
|
82
|
+
else
|
83
|
+
warn "#{@connection.class} does not respond to #indexes"
|
84
|
+
end
|
87
85
|
|
88
|
-
|
89
|
-
|
90
|
-
assert_equal ARTest.connection_config['arunit']['database'], @connection.current_database
|
86
|
+
ensure
|
87
|
+
@connection.remove_index(:accounts, :name => idx_name) rescue nil
|
91
88
|
end
|
92
|
-
end
|
93
89
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
assert_equal @connection.show_variable('character_set_database'), @connection.charset
|
90
|
+
def test_current_database
|
91
|
+
if @connection.respond_to?(:current_database)
|
92
|
+
assert_equal ARTest.connection_config['arunit']['database'], @connection.current_database
|
93
|
+
end
|
99
94
|
end
|
100
95
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
96
|
+
if current_adapter?(:MysqlAdapter)
|
97
|
+
def test_charset
|
98
|
+
assert_not_nil @connection.charset
|
99
|
+
assert_not_equal 'character_set_database', @connection.charset
|
100
|
+
assert_equal @connection.show_variable('character_set_database'), @connection.charset
|
101
|
+
end
|
106
102
|
|
107
|
-
|
108
|
-
|
109
|
-
|
103
|
+
def test_collation
|
104
|
+
assert_not_nil @connection.collation
|
105
|
+
assert_not_equal 'collation_database', @connection.collation
|
106
|
+
assert_equal @connection.show_variable('collation_database'), @connection.collation
|
107
|
+
end
|
110
108
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['arunit'].except(:database))
|
109
|
+
def test_show_nonexistent_variable_returns_nil
|
110
|
+
assert_nil @connection.show_variable('foo_bar_baz')
|
111
|
+
end
|
115
112
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
113
|
+
def test_not_specifying_database_name_for_cross_database_selects
|
114
|
+
begin
|
115
|
+
assert_nothing_raised do
|
116
|
+
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['arunit'].except(:database))
|
117
|
+
|
118
|
+
config = ARTest.connection_config
|
119
|
+
ActiveRecord::Base.connection.execute(
|
120
|
+
"SELECT #{config['arunit']['database']}.pirates.*, #{config['arunit2']['database']}.courses.* " \
|
121
|
+
"FROM #{config['arunit']['database']}.pirates, #{config['arunit2']['database']}.courses"
|
122
|
+
)
|
123
|
+
end
|
124
|
+
ensure
|
125
|
+
ActiveRecord::Base.establish_connection 'arunit'
|
121
126
|
end
|
122
|
-
ensure
|
123
|
-
ActiveRecord::Base.establish_connection 'arunit'
|
124
127
|
end
|
125
128
|
end
|
126
|
-
end
|
127
|
-
|
128
|
-
if current_adapter?(:PostgreSQLAdapter)
|
129
|
-
def test_encoding
|
130
|
-
assert_not_nil @connection.encoding
|
131
|
-
end
|
132
|
-
end
|
133
129
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
130
|
+
def test_table_alias
|
131
|
+
def @connection.test_table_alias_length() 10; end
|
132
|
+
class << @connection
|
133
|
+
alias_method :old_table_alias_length, :table_alias_length
|
134
|
+
alias_method :table_alias_length, :test_table_alias_length
|
135
|
+
end
|
140
136
|
|
141
|
-
|
142
|
-
|
143
|
-
|
137
|
+
assert_equal 'posts', @connection.table_alias_for('posts')
|
138
|
+
assert_equal 'posts_comm', @connection.table_alias_for('posts_comments')
|
139
|
+
assert_equal 'dbo_posts', @connection.table_alias_for('dbo.posts')
|
144
140
|
|
145
|
-
|
146
|
-
|
147
|
-
|
141
|
+
class << @connection
|
142
|
+
remove_method :table_alias_length
|
143
|
+
alias_method :table_alias_length, :old_table_alias_length
|
144
|
+
end
|
148
145
|
end
|
149
|
-
end
|
150
146
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
147
|
+
# test resetting sequences in odd tables in postgreSQL
|
148
|
+
if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
|
149
|
+
require 'models/movie'
|
150
|
+
require 'models/subscriber'
|
155
151
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
152
|
+
def test_reset_empty_table_with_custom_pk
|
153
|
+
Movie.delete_all
|
154
|
+
Movie.connection.reset_pk_sequence! 'movies'
|
155
|
+
assert_equal 1, Movie.create(:name => 'fight club').id
|
156
|
+
end
|
161
157
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
158
|
+
if ActiveRecord::Base.connection.adapter_name != "FrontBase"
|
159
|
+
def test_reset_table_with_non_integer_pk
|
160
|
+
Subscriber.delete_all
|
161
|
+
Subscriber.connection.reset_pk_sequence! 'subscribers'
|
162
|
+
sub = Subscriber.new(:name => 'robert drake')
|
163
|
+
sub.id = 'bob drake'
|
164
|
+
assert_nothing_raised { sub.save! }
|
165
|
+
end
|
169
166
|
end
|
170
167
|
end
|
171
|
-
end
|
172
168
|
|
173
|
-
|
174
|
-
unless @connection.adapter_name == 'IBM_DB'
|
169
|
+
def test_uniqueness_violations_are_translated_to_specific_exception
|
175
170
|
@connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
|
176
171
|
assert_raises(ActiveRecord::RecordNotUnique) do
|
177
172
|
@connection.execute "INSERT INTO subscribers(nick) VALUES('me')"
|
178
173
|
end
|
179
174
|
end
|
180
|
-
end
|
181
175
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
176
|
+
def test_foreign_key_violations_are_translated_to_specific_exception
|
177
|
+
unless @connection.adapter_name == 'SQLite'
|
178
|
+
assert_raises(ActiveRecord::InvalidForeignKey) do
|
179
|
+
# Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
|
180
|
+
if @connection.prefetch_primary_key?
|
181
|
+
id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id"))
|
182
|
+
@connection.execute "INSERT INTO fk_test_has_fk (id, fk_id) VALUES (#{id_value},0)"
|
183
|
+
else
|
184
|
+
@connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
|
185
|
+
end
|
191
186
|
end
|
192
187
|
end
|
193
188
|
end
|
194
|
-
end
|
195
189
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
190
|
+
def test_disable_referential_integrity
|
191
|
+
assert_nothing_raised do
|
192
|
+
@connection.disable_referential_integrity do
|
193
|
+
# Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
|
194
|
+
if @connection.prefetch_primary_key?
|
195
|
+
id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id"))
|
196
|
+
@connection.execute "INSERT INTO fk_test_has_fk (id, fk_id) VALUES (#{id_value},0)"
|
197
|
+
else
|
198
|
+
@connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
|
199
|
+
end
|
200
|
+
# should deleted created record as otherwise disable_referential_integrity will try to enable contraints after executed block
|
201
|
+
# and will fail (at least on Oracle)
|
202
|
+
@connection.execute "DELETE FROM fk_test_has_fk"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
204
206
|
end
|
205
207
|
end
|