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.
@@ -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
- values << self[col.name]
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/ || /10/ # DB2 for zOS version 9 and version 10
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
 
Binary file
Binary file
@@ -1,205 +1,207 @@
1
1
  require "cases/helper"
2
2
 
3
- class AdapterTest < ActiveRecord::TestCase
4
- def setup
5
- @connection = ActiveRecord::Base.connection
6
- end
3
+ module ActiveRecord
4
+ class AdapterTest < ActiveRecord::TestCase
5
+ def setup
6
+ @connection = ActiveRecord::Base.connection
7
+ end
7
8
 
8
- if current_adapter?(:IBM_DBAdapter)
9
- def test_a_connection_attributes
10
- if @connection.servertype.class.name.include?('::IBM_IDS')
11
- return
12
- end
13
- if @connection.respond_to?(:schema)
14
- previous_schema = ActiveRecord::Base.connection.schema
15
- ActiveRecord::Base.connection.schema = 'SYSCAT'
16
- assert_equal 'SYSCAT', ActiveRecord::Base.connection.schema
17
- ActiveRecord::Base.connection.schema = previous_schema
18
- else
19
- warn "#{@connection.class} does not support client connection attribute schema_name"
20
- end
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
- if @connection.respond_to?(:app_user)
23
- ActiveRecord::Base.connection.app_user = 'new_user'
24
- assert_equal 'new_user', ActiveRecord::Base.connection.app_user
25
- else
26
- warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_USER"
27
- end
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
- if @connection.respond_to?(:account)
30
- ActiveRecord::Base.connection.account = 'new_acct'
31
- assert_equal 'new_acct', ActiveRecord::Base.connection.account
32
- else
33
- warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_ACCTSTR"
34
- end
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
- if @connection.respond_to?(:application)
37
- ActiveRecord::Base.connection.application = 'new_app'
38
- assert_equal 'new_app', ActiveRecord::Base.connection.application
39
- else
40
- warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_APPLNAME"
41
- end
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
- if @connection.respond_to?(:workstation)
44
- ActiveRecord::Base.connection.workstation = 'new_wrkst'
45
- assert_equal 'new_wrkst', ActiveRecord::Base.connection.workstation
46
- else
47
- warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_WRKSTNNAME"
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
- end
51
-
52
- def test_tables
53
- tables = @connection.tables
54
- assert tables.include?("accounts")
55
- assert tables.include?("authors")
56
- assert tables.include?("tasks")
57
- assert tables.include?("topics")
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
- def test_indexes
66
- idx_name = "accounts_idx"
67
-
68
- if @connection.respond_to?(:indexes)
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
- ensure
85
- @connection.remove_index(:accounts, :name => idx_name) rescue nil
86
- end
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
- def test_current_database
89
- if @connection.respond_to?(:current_database)
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
- if current_adapter?(:MysqlAdapter)
95
- def test_charset
96
- assert_not_nil @connection.charset
97
- assert_not_equal 'character_set_database', @connection.charset
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
- def test_collation
102
- assert_not_nil @connection.collation
103
- assert_not_equal 'collation_database', @connection.collation
104
- assert_equal @connection.show_variable('collation_database'), @connection.collation
105
- end
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
- def test_show_nonexistent_variable_returns_nil
108
- assert_nil @connection.show_variable('foo_bar_baz')
109
- end
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
- def test_not_specifying_database_name_for_cross_database_selects
112
- begin
113
- assert_nothing_raised do
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
- config = ARTest.connection_config
117
- ActiveRecord::Base.connection.execute(
118
- "SELECT #{config['arunit']['database']}.pirates.*, #{config['arunit2']['database']}.courses.* " \
119
- "FROM #{config['arunit']['database']}.pirates, #{config['arunit2']['database']}.courses"
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
- def test_table_alias
135
- def @connection.test_table_alias_length() 10; end
136
- class << @connection
137
- alias_method :old_table_alias_length, :table_alias_length
138
- alias_method :table_alias_length, :test_table_alias_length
139
- end
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
- assert_equal 'posts', @connection.table_alias_for('posts')
142
- assert_equal 'posts_comm', @connection.table_alias_for('posts_comments')
143
- assert_equal 'dbo_posts', @connection.table_alias_for('dbo.posts')
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
- class << @connection
146
- remove_method :table_alias_length
147
- alias_method :table_alias_length, :old_table_alias_length
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
- # test resetting sequences in odd tables in postgreSQL
152
- if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
153
- require 'models/movie'
154
- require 'models/subscriber'
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
- def test_reset_empty_table_with_custom_pk
157
- Movie.delete_all
158
- Movie.connection.reset_pk_sequence! 'movies'
159
- assert_equal 1, Movie.create(:name => 'fight club').id
160
- end
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
- if ActiveRecord::Base.connection.adapter_name != "FrontBase"
163
- def test_reset_table_with_non_integer_pk
164
- Subscriber.delete_all
165
- Subscriber.connection.reset_pk_sequence! 'subscribers'
166
- sub = Subscriber.new(:name => 'robert drake')
167
- sub.id = 'bob drake'
168
- assert_nothing_raised { sub.save! }
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
- def test_uniqueness_violations_are_translated_to_specific_exception
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
- def test_foreign_key_violations_are_translated_to_specific_exception
183
- unless @connection.adapter_name == 'SQLite' || @connection.adapter_name == 'IBM_DB'
184
- assert_raises(ActiveRecord::InvalidForeignKey) do
185
- # Oracle adapter uses prefetched primary key values from sequence and passes them to connection adapter insert method
186
- if @connection.prefetch_primary_key?
187
- id_value = @connection.next_sequence_value(@connection.default_sequence_name("fk_test_has_fk", "id"))
188
- @connection.execute "INSERT INTO fk_test_has_fk (id, fk_id) VALUES (#{id_value},0)"
189
- else
190
- @connection.execute "INSERT INTO fk_test_has_fk (fk_id) VALUES (0)"
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
- def test_deprecated_visitor_for
197
- visitor_klass = Class.new(Arel::Visitors::ToSql)
198
- Arel::Visitors::VISITORS['fuuu'] = visitor_klass
199
- pool = stub(:spec => stub(:config => { :adapter => 'fuuu' }))
200
- visitor = assert_deprecated {
201
- ActiveRecord::ConnectionAdapters::AbstractAdapter.visitor_for(pool)
202
- }
203
- assert visitor.is_a?(visitor_klass)
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