ibm_db 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,11 @@
1
1
  Change Log
2
2
  ==============
3
+ 2009/07/28 (IBM_DB adapter 1.1.1, driver 1.1.0) :
4
+ - Fixed bug [26705] --> Fixed the problem of primary key value starting with 100
5
+ - Support for Activerecord-2.3.3
6
+ - Added method primary_key, which returns the primary key column name of the specified table
7
+ - Test suite updated
8
+
3
9
  2009/06/17 (IBM_DB adapter 1.1.0, driver 1.1.0) :
4
10
  - Support for Activerecord's Query Cache Mechanism
5
11
  - rename_column support for DB2 on LUW version 9.7, DB2 on zOS 9 and enhanced rename_column support for Informix Dynamic Server
@@ -466,6 +466,13 @@ module ActiveRecord
466
466
 
467
467
  # Executes the +set schema+ statement using the schema identifier provided
468
468
  @servertype.set_schema(@schema) if @schema && @schema != @username
469
+
470
+ # Check for the start value for id (primary key column). By default it is 1
471
+ if config.has_key?(:start_id)
472
+ @start_id = config[:start_id]
473
+ else
474
+ @start_id = 1
475
+ end
469
476
  end
470
477
 
471
478
  # Optional connection attribute: database name space qualifier
@@ -973,7 +980,7 @@ module ActiveRecord
973
980
  # database types
974
981
  def native_database_types
975
982
  {
976
- :primary_key => { :name => @servertype.primary_key},
983
+ :primary_key => { :name => @servertype.primary_key_definition(@start_id)},
977
984
  :string => { :name => "varchar", :limit => 255 },
978
985
  :text => { :name => "clob" },
979
986
  :integer => { :name => "integer" },
@@ -1064,6 +1071,31 @@ module ActiveRecord
1064
1071
  return tables
1065
1072
  end
1066
1073
 
1074
+ # Returns the primary key of the mentioned table
1075
+ def primary_key(table_name)
1076
+ pk_name = nil
1077
+ if stmt = IBM_DB.primary_keys( @connection, nil,
1078
+ @servertype.set_case(@schema),
1079
+ @servertype.set_case(table_name))
1080
+ begin
1081
+ if ( pk_index_row = IBM_DB.fetch_array(stmt) )
1082
+ pk_name = pk_index_row[3].downcase
1083
+ end
1084
+ rescue StandardError # Handle driver fetch errors
1085
+ error_msg = IBM_DB.conn_errormsg
1086
+ error_msg = IBM_DB.stmt_errormsg if error_msg.empty?
1087
+ if error_msg && !error_msg.empty?
1088
+ raise "Failed to retrieve primarykey metadata during fetch: #{error_msg}"
1089
+ else
1090
+ raise "An unexpected error occurred during retrieval of primary metadata"
1091
+ end
1092
+ ensure # Free resources associated with the statement
1093
+ IBM_DB.free_result(stmt) if stmt
1094
+ end
1095
+ end
1096
+ return pk_name
1097
+ end
1098
+
1067
1099
  # Returns an array of non-primary key indexes for a specified table name
1068
1100
  def indexes(table_name, name = nil)
1069
1101
  # to_s required because +table_name+ may be a symbol.
@@ -1176,8 +1208,8 @@ module ActiveRecord
1176
1208
  i = 0
1177
1209
  indexes.each do |index|
1178
1210
  if pk_index && index.columns == pk_index.columns
1179
- indexes.delete_at(i)
1180
- end
1211
+ indexes.delete_at(i)
1212
+ end
1181
1213
  i = i+1
1182
1214
  end
1183
1215
  # Returns the indexes array
@@ -1503,8 +1535,8 @@ To remove the column, the table must be dropped and recreated without the #{colu
1503
1535
  raise NotImplementedError, "rename_column is not implemented yet in the IBM_DB Adapter"
1504
1536
  end
1505
1537
 
1506
- def primary_key
1507
- return "INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 100) PRIMARY KEY"
1538
+ def primary_key_definition(start_id)
1539
+ return "INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH #{start_id}) PRIMARY KEY"
1508
1540
  end
1509
1541
 
1510
1542
  # Returns the last automatically generated ID.
@@ -2040,8 +2072,8 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2040
2072
  end #End of begin
2041
2073
  end # End of rename_column
2042
2074
 
2043
- def primary_key
2044
- return "SERIAL(100) PRIMARY KEY"
2075
+ def primary_key_definition(start_id)
2076
+ return "SERIAL(#{start_id}) PRIMARY KEY"
2045
2077
  end
2046
2078
 
2047
2079
  def change_column(table_name, column_name, type, options)
@@ -223,6 +223,18 @@ class EagerAssociationTest < ActiveRecord::TestCase
223
223
  end
224
224
  end
225
225
 
226
+ def test_eager_association_loading_with_belongs_to_and_conditions_hash
227
+ comments = []
228
+ assert_nothing_raised do
229
+ comments = Comment.find(:all, :include => :post, :conditions => {:posts => {:id => 4}}, :limit => 3, :order => 'comments.id')
230
+ end
231
+ assert_equal 3, comments.length
232
+ assert_equal [5,6,7], comments.collect { |c| c.id }
233
+ assert_no_queries do
234
+ comments.first.post
235
+ end
236
+ end
237
+
226
238
  def test_eager_association_loading_with_belongs_to_and_conditions_string_with_quoted_table_name
227
239
  quoted_posts_id= Comment.connection.quote_table_name('posts') + '.' + Comment.connection.quote_column_name('id')
228
240
  assert_nothing_raised do
@@ -1763,7 +1763,7 @@ class BasicsTest < ActiveRecord::TestCase
1763
1763
  end
1764
1764
 
1765
1765
  def test_scoped_find_with_group_and_having
1766
- developers = Developer.with_scope(:find => { :group => 'salary', :having => "SUM(salary) > 10000", :select => "SUM(salary) as salary" }) do
1766
+ developers = Developer.with_scope(:find => { :group => 'developers.salary', :having => "SUM(salary) > 10000", :select => "SUM(salary) as salary" }) do
1767
1767
  Developer.find(:all)
1768
1768
  end
1769
1769
  assert_equal 3, developers.size
@@ -2021,7 +2021,7 @@ class BasicsTest < ActiveRecord::TestCase
2021
2021
 
2022
2022
  def test_inspect_instance
2023
2023
  topic = topics(:first)
2024
- assert_equal %(#<Topic id: 1, title: "The First Topic", author_name: "David", author_email_address: "david@loudthinking.com", written_on: "#{topic.written_on.to_s(:db)}", bonus_time: "#{topic.bonus_time.to_s(:db)}", last_read: "#{topic.last_read.to_s(:db)}", content: "Have a nice day", approved: false, replies_count: 1, parent_id: nil, type: nil>), topic.inspect
2024
+ assert_equal %(#<Topic id: 1, title: "The First Topic", author_name: "David", author_email_address: "david@loudthinking.com", written_on: "#{topic.written_on.to_s(:db)}", bonus_time: "#{topic.bonus_time.to_s(:db)}", last_read: "#{topic.last_read.to_s(:db)}", content: "Have a nice day", approved: false, replies_count: 1, parent_id: nil, parent_title: nil, type: nil>), topic.inspect
2025
2025
  end
2026
2026
 
2027
2027
  def test_inspect_new_instance
@@ -2,6 +2,9 @@ require "cases/helper"
2
2
  require 'models/company'
3
3
  require 'models/topic'
4
4
  require 'models/edge'
5
+ require 'models/owner'
6
+ require 'models/pet'
7
+ require 'models/toy'
5
8
 
6
9
  Company.has_many :accounts
7
10
 
@@ -10,7 +13,7 @@ class NumericData < ActiveRecord::Base
10
13
  end
11
14
 
12
15
  class CalculationsTest < ActiveRecord::TestCase
13
- fixtures :companies, :accounts, :topics
16
+ fixtures :companies, :accounts, :topics, :owners, :pets, :toys
14
17
 
15
18
  def test_should_sum_field
16
19
  assert_equal 318, Account.sum(:credit_limit)
@@ -264,19 +267,6 @@ class CalculationsTest < ActiveRecord::TestCase
264
267
  assert_equal 4, Account.count(:distinct => true, :include => :firm, :select => :credit_limit)
265
268
  end
266
269
 
267
- def test_should_count_scoped_select
268
- Account.update_all("credit_limit = NULL")
269
- assert_equal 0, Account.scoped(:select => "credit_limit").count
270
- end
271
-
272
- def test_should_count_scoped_select_with_options
273
- Account.update_all("credit_limit = NULL")
274
- Account.last.update_attribute('credit_limit', 49)
275
- Account.first.update_attribute('credit_limit', 51)
276
-
277
- assert_equal 1, Account.scoped(:select => "credit_limit").count(:conditions => ['credit_limit >= 50'])
278
- end
279
-
280
270
  def test_should_count_manual_select_with_include
281
271
  assert_equal 6, Account.count(:select => "DISTINCT accounts.id", :include => :firm)
282
272
  end
@@ -297,6 +287,10 @@ class CalculationsTest < ActiveRecord::TestCase
297
287
  assert_raise(ArgumentError) { Account.count(1, 2, 3) }
298
288
  end
299
289
 
290
+ def test_count_with_scoped_has_many_through_association
291
+ assert_equal 1, owners(:blackbeard).toys.with_name('Bone').count
292
+ end
293
+
300
294
  def test_should_sum_expression
301
295
  if current_adapter?(:IBM_DBAdapter) && !ActiveRecord::Base.connection.servertype.class.name.include?('::IBM_IDS')
302
296
  assert_equal 636, Account.sum("2 * credit_limit")
@@ -118,7 +118,13 @@ class FinderTest < ActiveRecord::TestCase
118
118
  assert !Customer.exists?(:address =>
119
119
  Address.new(existing_address.street + "1", existing_address.city, existing_address.country))
120
120
  end
121
-
121
+
122
+ def test_exists_with_scoped_include
123
+ Developer.with_scope(:find => { :include => :projects, :order => "projects.name" }) do
124
+ assert Developer.exists?
125
+ end
126
+ end
127
+
122
128
  def test_find_by_array_of_one_id
123
129
  assert_kind_of(Array, Topic.find([ 1 ]))
124
130
  assert_equal(1, Topic.find([ 1 ]).length)
@@ -522,6 +522,11 @@ class FoxyFixturesTest < ActiveRecord::TestCase
522
522
  assert_equal(Fixtures.identify(:foo), Fixtures.identify(:foo))
523
523
  end
524
524
 
525
+ def test_identifies_consistently
526
+ assert_equal 1281023246, Fixtures.identify(:ruby)
527
+ assert_equal 2140105598, Fixtures.identify(:sapphire_2)
528
+ end
529
+
525
530
  TIMESTAMP_COLUMNS = %w(created_at created_on updated_at updated_on)
526
531
 
527
532
  def test_populates_timestamp_columns
@@ -1,5 +1,6 @@
1
1
  require "cases/helper"
2
2
  require 'bigdecimal/util'
3
+ require 'mocha'
3
4
 
4
5
  require 'models/person'
5
6
  require 'models/topic'
@@ -22,6 +22,13 @@ class SchemaDumperTest < ActiveRecord::TestCase
22
22
  assert_no_match %r{create_table "sqlite_sequence"}, output
23
23
  end
24
24
 
25
+ unless current_adapter?(:IBM_DBAdapter) #DB2 is case insensitive
26
+ def test_schema_dump_includes_camelcase_table_name
27
+ output = standard_dump
28
+ assert_match %r{create_table "CamelCase"}, output
29
+ end
30
+ end
31
+
25
32
  def assert_line_up(lines, pattern, required = false)
26
33
  return assert(true) if lines.empty?
27
34
  matches = lines.map { |line| line.match(pattern) }
@@ -149,19 +156,24 @@ class SchemaDumperTest < ActiveRecord::TestCase
149
156
  end
150
157
  end
151
158
 
159
+ def test_schema_dumps_index_columns_in_right_order
160
+ index_definition = standard_dump.split(/\n/).grep(/add_index.*companies/).first.strip
161
+ assert_equal 'add_index "companies", ["firm_id", "type", "rating", "ruby_type"], :name => "company_index"', index_definition
162
+ end
163
+
164
+ def test_schema_dump_should_honor_nonstandard_primary_keys
165
+ output = standard_dump
166
+ match = output.match(%r{create_table "movies"(.*)do})
167
+ assert_not_nil(match, "nonstandardpk table not found")
168
+ assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
169
+ end
170
+
152
171
  if current_adapter?(:MysqlAdapter)
153
172
  def test_schema_dump_should_not_add_default_value_for_mysql_text_field
154
173
  output = standard_dump
155
174
  assert_match %r{t.text\s+"body",\s+:null => false$}, output
156
175
  end
157
176
 
158
- def test_mysql_schema_dump_should_honor_nonstandard_primary_keys
159
- output = standard_dump
160
- match = output.match(%r{create_table "movies"(.*)do})
161
- assert_not_nil(match, "nonstandardpk table not found")
162
- assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
163
- end
164
-
165
177
  def test_schema_dump_includes_length_for_mysql_blob_and_text_fields
166
178
  output = standard_dump
167
179
  assert_match %r{t.binary\s+"tiny_blob",\s+:limit => 255$}, output
@@ -1,5 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "cases/helper"
3
+ require 'mocha'
4
+
3
5
  require 'models/topic'
4
6
  require 'models/reply'
5
7
  require 'models/person'
@@ -17,6 +17,7 @@ ActiveRecord::Base.configurations = {
17
17
  :app_user => 'tester_11',
18
18
  :application => 'rails_tests',
19
19
  :workstation => 'auckland',
20
+ :start_id => 100,
20
21
  :database => 'ARUNIT'
21
22
  },
22
23
  'arunit2' => {
@@ -30,6 +31,7 @@ ActiveRecord::Base.configurations = {
30
31
  :app_user => 'tester_11',
31
32
  :application => 'rails_tests',
32
33
  :workstation => 'auckland',
34
+ :start_id => 100,
33
35
  :database => 'ARUNIT2'
34
36
  }
35
37
  }
@@ -125,6 +125,7 @@ execute <<_SQL
125
125
  approved SMALLINT DEFAULT 1,
126
126
  replies_count INT DEFAULT 0,
127
127
  parent_id INT DEFAULT NULL,
128
+ parent_title VARCHAR(255) DEFAULT NULL,
128
129
  type VARCHAR(255) DEFAULT NULL,
129
130
  PRIMARY KEY (id)
130
131
  );
@@ -111,6 +111,7 @@ execute <<_SQL
111
111
  approved SMALLINT DEFAULT 1,
112
112
  replies_count INT DEFAULT 0,
113
113
  parent_id INT DEFAULT NULL,
114
+ parent_title VARCHAR(255) DEFAULT NULL,
114
115
  type VARCHAR(50) DEFAULT NULL,
115
116
  PRIMARY KEY (id)
116
117
  );
@@ -125,6 +125,7 @@ execute <<_SQL
125
125
  approved SMALLINT DEFAULT 1,
126
126
  replies_count INT DEFAULT 0,
127
127
  parent_id INT DEFAULT NULL,
128
+ parent_title VARCHAR(255) DEFAULT NULL,
128
129
  type VARCHAR(255) DEFAULT NULL,
129
130
  PRIMARY KEY (id)
130
131
  );
@@ -68,6 +68,10 @@ ActiveRecord::Schema.define do
68
68
  t.boolean :value
69
69
  end
70
70
 
71
+ create_table :camelcase, :force => true do |t|
72
+ t.string :name
73
+ end
74
+
71
75
  create_table :categories, :force => true do |t|
72
76
  t.string :name, :null => false
73
77
  t.string :type
@@ -116,6 +120,8 @@ ActiveRecord::Schema.define do
116
120
  t.integer :rating, :default => 1
117
121
  end
118
122
 
123
+ add_index :companies, [:firm_id, :type, :rating, :ruby_type], :name => "company_index"
124
+
119
125
  create_table :computers, :force => true do |t|
120
126
  t.integer :developer, :null => false
121
127
  t.integer :extendedWarranty, :null => false
@@ -157,6 +163,12 @@ ActiveRecord::Schema.define do
157
163
  t.integer :course_id, :null => false
158
164
  end
159
165
 
166
+ create_table :essays, :force => true do |t|
167
+ t.string :name
168
+ t.string :writer_id
169
+ t.string :writer_type
170
+ end
171
+
160
172
  create_table :events, :force => true do |t|
161
173
  t.string :title, :limit => 5
162
174
  end
@@ -285,6 +297,8 @@ ActiveRecord::Schema.define do
285
297
 
286
298
  create_table :owners, :primary_key => :owner_id ,:force => true do |t|
287
299
  t.string :name
300
+ t.column :updated_at, :datetime
301
+ t.column :happy_at, :datetime
288
302
  end
289
303
 
290
304
  except 'IBM_DB' do
@@ -418,6 +432,7 @@ ActiveRecord::Schema.define do
418
432
  t.boolean :approved, :default => true
419
433
  t.integer :replies_count, :default => 0
420
434
  t.integer :parent_id
435
+ t.string :parent_title
421
436
  t.string :type
422
437
  end
423
438
  end
@@ -175,6 +175,7 @@ execute <<_SQL
175
175
  approved SMALLINT DEFAULT 1,
176
176
  replies_count INT DEFAULT 0,
177
177
  parent_id INT DEFAULT NULL,
178
+ parent_title VARCHAR(255) DEFAULT NULL,
178
179
  type VARCHAR(50) DEFAULT NULL,
179
180
  PRIMARY KEY (id)
180
181
  );
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibm_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - IBM
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-16 00:00:00 +05:30
12
+ date: 2009-07-30 00:00:00 +05:30
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - ActiveRecord, at least 1.15.1
93
93
  rubyforge_project: rubyibm
94
- rubygems_version: 1.3.3
94
+ rubygems_version: 1.3.5
95
95
  signing_key:
96
96
  specification_version: 3
97
97
  summary: "Rails Driver and Adapter for IBM Data Servers: {DB2 on Linux/Unix/Windows, DB2 on zOS, DB2 on i5/OS, Informix (IDS)}"