ibm_db 0.9.5 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/CHANGES +5 -0
  2. data/README +63 -97
  3. data/ext/ibm_db.c +20 -4
  4. data/ext/ruby_ibm_db.h +10 -0
  5. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +2 -4
  6. data/test/{adapter_test.rb → cases/adapter_test.rb} +39 -14
  7. data/test/cases/associations/cascaded_eager_loading_test.rb +113 -0
  8. data/test/{associations → cases/associations}/eager_test.rb +231 -65
  9. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +686 -0
  10. data/test/cases/associations/join_model_test.rb +797 -0
  11. data/test/{base_test.rb → cases/base_test.rb} +605 -385
  12. data/test/cases/calculations_test.rb +275 -0
  13. data/test/cases/finder_test.rb +885 -0
  14. data/test/cases/fixtures_test.rb +630 -0
  15. data/test/{migration_test.rb → cases/migration_test.rb} +530 -146
  16. data/test/cases/query_cache_test.rb +127 -0
  17. data/test/cases/validations_test.rb +1509 -0
  18. data/test/connections/native_ibm_db/connection.rb +1 -1
  19. data/test/models/warehouse_thing.rb +5 -0
  20. data/test/schema/i5/ibm_db_specific_schema.rb +133 -0
  21. data/test/schema/ids/ibm_db_specific_schema.rb +136 -0
  22. data/test/schema/luw/ibm_db_specific_schema.rb +133 -0
  23. data/test/schema/schema.rb +432 -0
  24. data/test/schema/zOS/ibm_db_specific_schema.rb +204 -0
  25. metadata +29 -33
  26. data/test/associations_test.rb +0 -2151
  27. data/test/fixtures/db_definitions/i5/ibm_db.drop.sql +0 -33
  28. data/test/fixtures/db_definitions/i5/ibm_db.sql +0 -236
  29. data/test/fixtures/db_definitions/i5/ibm_db2.drop.sql +0 -2
  30. data/test/fixtures/db_definitions/i5/ibm_db2.sql +0 -5
  31. data/test/fixtures/db_definitions/ids/ibm_db.drop.sql +0 -33
  32. data/test/fixtures/db_definitions/ids/ibm_db.sql +0 -237
  33. data/test/fixtures/db_definitions/ids/ibm_db2.drop.sql +0 -2
  34. data/test/fixtures/db_definitions/ids/ibm_db2.sql +0 -5
  35. data/test/fixtures/db_definitions/luw/ibm_db.drop.sql +0 -33
  36. data/test/fixtures/db_definitions/luw/ibm_db.sql +0 -236
  37. data/test/fixtures/db_definitions/luw/ibm_db2.drop.sql +0 -2
  38. data/test/fixtures/db_definitions/luw/ibm_db2.sql +0 -5
  39. data/test/fixtures/db_definitions/schema.rb +0 -361
  40. data/test/fixtures/db_definitions/zOS/ibm_db.drop.sql +0 -33
  41. data/test/fixtures/db_definitions/zOS/ibm_db.sql +0 -288
  42. data/test/fixtures/db_definitions/zOS/ibm_db2.drop.sql +0 -2
  43. data/test/fixtures/db_definitions/zOS/ibm_db2.sql +0 -7
  44. data/test/locking_test.rb +0 -282
data/CHANGES CHANGED
@@ -1,5 +1,10 @@
1
1
  Change Log
2
2
  ==============
3
+ 2008/09/01 (IBM_DB adapter 0.10.0, driver 0.10.0):
4
+ - Added Trusted Context support in Driver
5
+ - Made changes for the correct Mapping of Informix DataTypes to Ruby DataTypes
6
+ - ActiveRecord-2.1.0 test suite changes appropriate for DB2/IDS is been updated
7
+
3
8
  2008/06/24 (IBM_DB adapter 0.9.5, driver 0.9.5):
4
9
  - Fixed Bug [#19222] --> Fixed fixture insertion of LOB columns for DB2
5
10
  - Fixed Bug [#19970] --> Fixed Table schema dumper also dump views
data/README CHANGED
@@ -1,5 +1,5 @@
1
1
  =====================================================================
2
- README for the IBM_DB Adapter 0.9.5 and Driver 0.9.5 (2008/06/24)
2
+ README for the IBM_DB Adapter (0.10.0) and Driver (0.10.0) (2008/09/01)
3
3
  For ActiveRecord Version >= 1.15.5 (and Rails >= 1.2.5)
4
4
  =====================================================================
5
5
 
@@ -14,7 +14,7 @@ Supported Operating Systems
14
14
 
15
15
  Supported Databases
16
16
  ====================
17
- - IBM DB2 Universal Database on Linux/Unix/Windows versions 8 and 9
17
+ - IBM DB2 Universal Database on Linux/Unix/Windows versions 8 Fixpak15 or 9 Fixpak2 and above
18
18
  - Remote connections to IBM DB2 Universal Database on i5/OS versions V5R3 and V5R4.
19
19
  Please ensure PTF SI27358 (includes SI27250) is installed in i5/OS version 5R3 and
20
20
  and PTF SI27256 is installed while using i5/OS version 5R4.
@@ -23,19 +23,15 @@ Supported Databases
23
23
  Please ensure that the IBM DataServer Viper 2 client is installed.
24
24
 
25
25
 
26
- There are two alternatives for installing the IBM_DB adapter and driver:
27
- A. Installing as a Ruby gem in the Ruby runtime
28
- B. Installing as a Rails plugin in a specific Rails application runtime
29
- Note: The IBM_DB driver can also be built separately (from source) and used in direct API calls.
30
-
31
- A. Installing the IBM_DB adapter and driver as a Ruby gem
26
+ Installing the IBM_DB adapter and driver as a Ruby gem
32
27
  =======================================================
33
- The IBM_DB gem is an ActiveRecord adapter and requires the abstract adapter to register it
34
- in the list of RAILS_CONNECTION_ADAPTERS (active_record.rb) before it can be utilized in
35
- the Rails framework. Once registered, the IBM_DB adapter and its dependencies (ibm_db Ruby
36
- driver and the IBM Driver for ODBC and CLI) are loaded. This enables any application in the
28
+ The IBM_DB gem is an ActiveRecord adapter. Installing the IBM_DB adapter and driver as a gem enables any application in the
37
29
  Ruby environment, including Rails, to interact with IBM data servers.
38
30
 
31
+ Note : - 1) If using activerecord version below 2.0 then it requires that the ibm_db adapter be registered with the list of connection adapters by manually adding ibm_db at line 77 (approx) in the file activerecord.rb (GEM_HOME\activerecord-<version>\lib\).
32
+
33
+ 2) The IBM_DB driver can also be built separately (from source) and used in direct API calls.
34
+
39
35
  1. Windows platforms:
40
36
  =====================
41
37
  INSTALL (as Ruby gem)
@@ -47,31 +43,26 @@ Ruby environment, including Rails, to interact with IBM data servers.
47
43
  D:\>gem install ibm_db
48
44
  Bulk updating gem source index for: http://gems.rubyforge.org
49
45
  Select which gem to install for your platform (i386-mswin32)
50
- 1. ibm_db 0.6.5 (mswin32)
51
- 2. ibm_db 0.6.5 (ruby)
52
- 3. ibm_db 0.6.0 (mswin32)
53
- 4. ibm_db 0.6.0 (ruby)
46
+ 1. ibm_db 0.9.5 (mswin32)
47
+ 2. ibm_db 0.9.5 (ruby)
48
+ 3. ibm_db 0.9.4 (mswin32)
49
+ 4. ibm_db 0.9.4 (ruby)
54
50
 
55
51
  Running gem install ibm_db you are presented with two choices for each release
56
- (mswin32 or ruby). Choose mswin32 and the native extension (ibm_db driver)
57
- binary file for Windows is installed.
52
+ (mswin32 or ruby)choose mswin32. This will install the IBM_DB gem containing
53
+ the pre-built binary file of the driver which is a C-extension of Ruby.
58
54
 
59
55
  TEST (simple gem install verification)
60
- Note: IBM_DB gem requires a manual step after install:
61
- add ibm_db into gems\1.8\gems\activerecord-1.15.3\lib\active_record.rb (Line 77)
62
- D:\NewApp>dir vendor\plugins
56
+ Note: The manual step after install if using activerecord version below 2.0:
57
+ add ibm_db into GEM_HOME\1.8\gems\activerecord-1.15.3\lib\active_record.rb (Line 77)
58
+ D:\rails NewApp
59
+ D:\cd NewApp
63
60
  D:\NewApp>irb
64
61
  irb(main):001:0> gem 'ibm_db'
65
62
  irb(main):002:0> require 'mswin32/ibm_db' // notice the [mswin32] in the library path
66
63
  irb(main):003:0> IBM_DB::connect 'sample', 'db2admin', 'secret'
67
64
  D:\NewApp>ruby script\console
68
65
 
69
- BUILD (optionally) ibm_db gem from sources (ibm_db-x.x.x.tar.gz):
70
- 1. Download source from Rubyforge
71
- http://rubyforge.org/frs/?group_id=2361
72
- 2. Build gem from specification (IBM_DB.gemspec)
73
- D:\IBM_DB_Adapter\ibm_db>gem build IBM_DB.gemspec
74
-
75
66
 
76
67
  2. Linux and Unix platforms:
77
68
  ============================
@@ -88,13 +79,13 @@ Ruby environment, including Rails, to interact with IBM data servers.
88
79
  $ export IBM_DB_LIB=/opt/ibm/db2/V9.1/lib32
89
80
  $ gem install ibm_db
90
81
  Select which gem to install for your platform (i686-linux)
91
- 1. ibm_db 0.6.5 (mswin32)
92
- 2. ibm_db 0.6.5 (ruby)
93
- 3. ibm_db 0.6.0 (ruby)
94
- 4. ibm_db 0.6.0 (mswin32)
82
+ 1. ibm_db 0.9.5 (mswin32)
83
+ 2. ibm_db 0.9.5 (ruby)
84
+ 3. ibm_db 0.9.4 (ruby)
85
+ 4. ibm_db 0.9.4 (mswin32)
95
86
  ...
96
87
  Running gem install ibm_db you are presented with two choices for each release
97
- (mswin32 or ruby). Choose ruby and the native extension (ibm_db driver) is built.
88
+ (mswin32 or ruby) choose ruby. This will build the native extension (ibm_db driver) and installs the ibm_db gem.
98
89
  ...
99
90
  > 2
100
91
  Building native extensions. This could take a while...
@@ -103,14 +94,13 @@ Ruby environment, including Rails, to interact with IBM data servers.
103
94
  Installing RDoc documentation for ibm_db-0.6.5...
104
95
 
105
96
  TEST (simple gem install verification)
106
- Note: IBM_DB gem requires a manual step after install:
107
- add ibm_db into /gems/activerecord-1.15.3/lib/active_record.rb (Line 77)
108
- $ ls -al vendor/plugins/
97
+ Note: The manual step after install if using activerecord version below 2.0 is:
98
+ add ibm_db into GEM_HOME\1.8\gems\activerecord-1.15.3\lib\active_record.rb (Line 77)
109
99
  $ irb
110
100
  irb(main):001:0> gem 'ibm_db'
111
101
  irb(main):002:0> require 'ibm_db' // notice the library path (different on win32, use require 'mswin32/ibm_db')
112
102
  irb(main):003:0> IBM_DB::connect 'sample', 'db2admin', 'secret'
113
- $ ./script/console
103
+ $
114
104
 
115
105
  BUILD (optionally) ibm_db gem from sources (ibm_db-x.x.x.tar.gz):
116
106
  1. Download source from Rubyforge
@@ -120,66 +110,11 @@ Ruby environment, including Rails, to interact with IBM data servers.
120
110
  $ gem build IBM_DB.gemspec
121
111
 
122
112
 
123
- B. Installing the IBM_DB adapter and driver as a Rails plugin
124
- =============================================================
125
- IBM_DB adapter and driver install as plugin provides support for IBM data servers
126
- within the scope of a specific and individual Rails application. Rails plugins do
127
- not offer the version management specific to Ruby gems, but does provide an
128
- initialization mechanism which allows the IBM_DB plugin to self-insert into the
129
- ActiveRecord's list of supported adapters: RAILS_CONNECTION_ADAPTERS. Therefore,
130
- after installing IBM_DB as plugin in your Rails application, no manual step is required
131
- for the Rails framework to load it.
132
-
133
- 1. Windows platforms
134
- =====================
135
- Register Repository and Query:
136
-
137
- A. Download and install Subversion (SVN) client from:
138
- http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91
139
- Register rubyibm project as plugin source
140
- D:\NewApp>ruby script\plugin source svn://rubyforge.org/var/svn/rubyibm/trunk/IBM_DB_Adapter/
141
-
142
- B. Accessing RubyForge repository through HTTP (no SVN client required) is NOT YET ENABLED
143
- D:\NewApp>ruby script\plugin source http://rubyibm.rubyforge.org/IBM_DB_Adapter/
144
-
145
- LIST plugin
146
- D:\NewApp>ruby script\plugin list
147
-
148
- INSTALL (as Rails plugin)
149
- D:\NewApp>ruby script\plugin install ibm_db
150
-
151
- TEST (simple plugin install verification)
152
- Note: Make sure there's no ibm_db in gems\1.8\gems\activerecord-1.15.3\lib\active_record.rb (Line 77)
153
- D:\NewApp>ruby script\console
154
-
155
- 2. Linux and Unix platforms
156
- ===========================
157
- Register Repository and Query:
158
-
159
- A. Ensure Subversion (SVN) client is installed or download from:
160
- http://subversion.tigris.org/project_packages.html
161
- Register rubyibm project as plugin source
162
- $ ./script/plugin source svn://rubyforge.org/var/svn/rubyibm/trunk/IBM_DB_Adapter/
163
-
164
- B. Accessing RubyForge repository through HTTP (no SVN client required) is NOT YET ENABLED
165
- $ ./script/plugin source http://rubyibm.rubyforge.org/IBM_DB_Adapter/
166
-
167
- LIST plugin
168
- $ ./script/plugin list
169
-
170
- INSTALL (as Rails plugin)
171
- $ ./script/plugin install ibm_db
172
-
173
- TEST (simple plugin install verification)
174
- Note: Make sure there's no ibm_db in /gems/activerecord-1.15.3/lib/active_record.rb (Line 77)
175
- $ ./script/console
176
-
177
-
178
113
  Instructions for building and installing the IBM_DB driver from source
179
114
  =======================================================================
180
- Building the driver manually as described below is not required if any the install
181
- alternatives above have been pursued. This manual procedure is in fact automated
182
- on Linux and UNIX platforms by the IBM_DB gem and plugin install, but is presented
115
+ Building the driver manually as described below is not required if the install
116
+ process above has been pursued. This manual procedure is in fact automated
117
+ on Linux and UNIX platforms by the IBM_DB gem install, but is presented
183
118
  here only for reference, and also involves running the unit tests.
184
119
 
185
120
  Prerequisites:
@@ -235,7 +170,7 @@ Limitations and known problems
235
170
  ==============================
236
171
  - ActiveRecord rename_column method is not supported for DB2 LUW, zOS and i5
237
172
  - ActiveRecord remove_column method is not supported for DB2 zOS
238
- - The following tests from the ActiveRecord 1.15.3 test suite are expected to fail
173
+ - The following tests from the ActiveRecord 1.15.3 test suite with ibm_db gem < 0.9.5 are expected to fail
239
174
  - test_limited_eager_with_multiple_order_columns
240
175
  - test_limited_eager_with_order
241
176
  - test_assign_ids_ignoring_blanks
@@ -267,7 +202,7 @@ Limitations and known problems
267
202
  To enable this parameter, you need to restart your DB2 instance.
268
203
  - If you see connectivity issues with Informix Dynamic Server, please ensure that the server is configured to accept DRDA connections.
269
204
  Please refer to http://publib.boulder.ibm.com/infocenter/idshelp/v111/index.jsp?topic=/com.ibm.admin.doc/admin154.htm for more information.
270
- - The following tests from the ActiveRecord 1.15.3 test suite are expected to fail on Informix Dynamic Server
205
+ - The following tests from the ActiveRecord 1.15.3 test suite with ibm_db gem < 0.9.5 are expected to fail on Informix Dynamic Server
271
206
  - test_quote
272
207
  - test_to_xml
273
208
  - test_should_calculate_grouped_by_function
@@ -292,7 +227,38 @@ Limitations and known problems
292
227
  The patch is required because, ActiveRecord 2.1.0 generates a non-standard SQL identifier,while preloading has_and_belongs_to_many associations,
293
228
  which standard compliant databases like DB2 do not support. The bug report, against ActiveRecord, can be found in the link below
294
229
  http://rails.lighthouseapp.com/projects/8994/tickets/394-patch-fixed-non-standard-sql-generated-by-preloading-has_and_belongs_to_many-associations
295
- - ActiveRecord-2.1.0 test suite changes appropriate for DB2/IDS will be updated in the next release of the gem.
230
+ - ActiveRecord-2.1.0 test suite changes appropriate for DB2/IDS will be updated in the next release of the gem.(Updated in release 0.10.0)
231
+ - The following tests from the ActiveRecord 2.1.0 test suite with ibm_db gem 0.10.0 are expected to fail on DB2 LUW
232
+ - test_read_attributes_before_type_cast_on_datetime
233
+ - test_to_xml
234
+ - test_native_types
235
+ - test_counting
236
+ - test_counting_with_column_name_and_hash
237
+ - test_counting_with_empty_hash_conditions
238
+ - test_counting_with_single_conditions
239
+ - test_counting_with_single_hash
240
+ Note :- 1) The test cases from HasManyAssociations (4-8) above are found failing only when run as part of
241
+ the complete suite. However they pass when run standalone.
242
+ 2) Also there are two test cases (test_validate_uniqueness_with_non_standard_table_names, test_update_all_with_non_standard_table_name)which run against table with non-standard name. Given that DB2/IDS is standard compliant these test cases are expected to fail.
243
+ To have these test cases passing rename the fixtures file warehouse-things to warehouse_things.
244
+ - The following tests from the ActiveRecord 2.1.0 test suite with ibm_db gem 0.10.0 are expected to fail on Informix Dynamic Server
245
+ - test_attributes_on_dummy_time
246
+ - test_quote
247
+ - test_read_attributes_before_type_cast_on_datetime
248
+ - test_save_for_record_with_only_primary_key
249
+ - test_save_for_record_with_only_primary_key_that_is_provided
250
+ - test_to_xml
251
+ - test_utc_as_time_zone
252
+ - test_should_calculate_grouped_by_function
253
+ - test_should_calculate_grouped_by_function_with_table_alias
254
+ - test_include_query
255
+ - test_binary_in_fixtures
256
+ - test_inserts_with_pre_and_suffix
257
+ - test_create
258
+ - test_add_column_with_precision_and_scale
259
+ - test_add_table_with_decimals
260
+ - test_native_types
261
+ - test_schema_dump_includes_decimal_options
296
262
 
297
263
  To Do
298
264
  ====
data/ext/ibm_db.c CHANGED
@@ -10,7 +10,7 @@
10
10
  +----------------------------------------------------------------------+
11
11
  */
12
12
 
13
- #define MODULE_RELEASE "0.9.5"
13
+ #define MODULE_RELEASE "0.10.0"
14
14
 
15
15
  #ifdef HAVE_CONFIG_H
16
16
  #include "config.h"
@@ -559,6 +559,14 @@ void ruby_init_ibm_db()
559
559
  rb_define_const(mDB, "SQL_AUTOCOMMIT_ON", INT2NUM(SQL_AUTOCOMMIT_ON));
560
560
  /* Specifies whether to use auto-commit or manual commit mode */
561
561
  rb_define_const(mDB, "SQL_ATTR_AUTOCOMMIT", INT2NUM(SQL_ATTR_AUTOCOMMIT));
562
+ /* Specifies whether to enable trusted context mode */
563
+ rb_define_const(mDB, "SQL_TRUE", INT2NUM(SQL_TRUE));
564
+ /* Specifies whether to enable trusted context mode */
565
+ rb_define_const(mDB, "SQL_ATTR_USE_TRUSTED_CONTEXT", INT2NUM(SQL_ATTR_USE_TRUSTED_CONTEXT));
566
+ /* Specifies whether to siwtch trusted user */
567
+ rb_define_const(mDB, "SQL_ATTR_TRUSTED_CONTEXT_USERID", INT2NUM(SQL_ATTR_TRUSTED_CONTEXT_USERID));
568
+ /* Specifies when trusted user is specified */
569
+ rb_define_const(mDB, "SQL_ATTR_TRUSTED_CONTEXT_PASSWORD", INT2NUM(SQL_ATTR_TRUSTED_CONTEXT_PASSWORD));
562
570
  /* String used to identify the client user ID sent to the host database */
563
571
  rb_define_const(mDB, "SQL_ATTR_INFO_USERID", INT2NUM(SQL_ATTR_INFO_USERID));
564
572
  /* String used to identify the client workstation name sent to the host database */
@@ -815,6 +823,7 @@ static int _ruby_ibm_db_parse_options ( VALUE options, int type, void *handle )
815
823
  VALUE keys;
816
824
  VALUE key; /* Holds the Option Index Key */
817
825
  VALUE data;
826
+ VALUE tc_pass = Qnil;
818
827
 
819
828
  if ( !NIL_P(options) ) {
820
829
  keys = rb_funcall(options, id_keys, 0);
@@ -824,9 +833,16 @@ static int _ruby_ibm_db_parse_options ( VALUE options, int type, void *handle )
824
833
  key = rb_ary_entry(keys,i);
825
834
  data = rb_hash_aref(options,key);
826
835
 
827
- /* Assign options to handle. */
828
- /* Sets the options in the handle with CLI/ODBC calls */
829
- _ruby_ibm_db_assign_options( handle, type, NUM2LONG(key), data );
836
+ if (NUM2LONG(key) == SQL_ATTR_TRUSTED_CONTEXT_PASSWORD) {
837
+ tc_pass = data;
838
+ } else {
839
+ /* Assign options to handle. */
840
+ /* Sets the options in the handle with CLI/ODBC calls */
841
+ _ruby_ibm_db_assign_options( handle, type, NUM2LONG(key), data );
842
+ }
843
+ }
844
+ if ( !NIL_P(tc_pass) ) {
845
+ _ruby_ibm_db_assign_options( handle, type, SQL_ATTR_TRUSTED_CONTEXT_PASSWORD, tc_pass );
830
846
  }
831
847
  }
832
848
 
data/ext/ruby_ibm_db.h CHANGED
@@ -21,6 +21,16 @@
21
21
  #define SQL_XML -370
22
22
  #endif
23
23
 
24
+ /* SQL_ATTR_USE_TRUSTED_CONTEXT,
25
+ * SQL_ATTR_TRUSTED_CONTEXT_USERID and
26
+ * SQL_ATTR_TRUSTED_CONTEXT_PASSWORD
27
+ * not defined prior to DB2 v9 */
28
+ #ifndef SQL_ATTR_USE_TRUSTED_CONTEXT
29
+ #define SQL_ATTR_USE_TRUSTED_CONTEXT 2561
30
+ #define SQL_ATTR_TRUSTED_CONTEXT_USERID 2562
31
+ #define SQL_ATTR_TRUSTED_CONTEXT_PASSWORD 2563
32
+ #endif
33
+
24
34
  #ifndef SQL_ATTR_REPLACE_QUOTED_LITERALS
25
35
  #define SQL_ATTR_REPLACE_QUOTED_LITERALS 2586
26
36
  #endif
@@ -196,13 +196,13 @@ requires credentials: username and password"
196
196
  :binary
197
197
  when /smallint/i
198
198
  :boolean
199
- when /int/i
199
+ when /int|serial/i
200
200
  :integer
201
201
  when /float|double|real/i
202
202
  :float
203
203
  when /decimal|numeric/i
204
204
  :decimal
205
- when /timestamp/i
205
+ when /timestamp|datetime/i
206
206
  :timestamp
207
207
  when /time/i
208
208
  :time
@@ -218,8 +218,6 @@ requires credentials: username and password"
218
218
  :string
219
219
  when /boolean/i
220
220
  :boolean
221
- when /serial/i
222
- :serial
223
221
  when /rowid/i # rowid is a supported datatype on z/OS and i/5
224
222
  :rowid
225
223
  end
@@ -1,6 +1,6 @@
1
- require 'abstract_unit'
1
+ require "cases/helper"
2
2
 
3
- class IBMDBAdapterTest < Test::Unit::TestCase
3
+ class AdapterTest < ActiveRecord::TestCase
4
4
  def setup
5
5
  @connection = ActiveRecord::Base.connection
6
6
  end
@@ -34,7 +34,7 @@ class IBMDBAdapterTest < Test::Unit::TestCase
34
34
  end
35
35
 
36
36
  if @connection.respond_to?(:application)
37
- ActiveRecord::Base.connection.application = 'new_app'
37
+ ActiveRecord::Base.connection.application = 'new_app'
38
38
  assert_equal 'new_app', ActiveRecord::Base.connection.application
39
39
  else
40
40
  warn "#{@connection.class} does not support client connection attribute SQL_ATTR_INFO_APPLNAME"
@@ -50,15 +50,16 @@ class IBMDBAdapterTest < Test::Unit::TestCase
50
50
  end
51
51
 
52
52
  def test_tables
53
- if @connection.respond_to?(: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
- else
60
- warn "#{@connection.class} does not respond to #tables"
61
- end
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")
62
63
  end
63
64
 
64
65
  def test_indexes
@@ -120,14 +121,15 @@ class IBMDBAdapterTest < Test::Unit::TestCase
120
121
  assert_equal 'dbo_posts', @connection.table_alias_for('dbo.posts')
121
122
 
122
123
  class << @connection
124
+ remove_method :table_alias_length
123
125
  alias_method :table_alias_length, :old_table_alias_length
124
126
  end
125
127
  end
126
128
 
127
129
  # test resetting sequences in odd tables in postgreSQL
128
130
  if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
129
- require 'fixtures/movie'
130
- require 'fixtures/subscriber'
131
+ require 'models/movie'
132
+ require 'models/subscriber'
131
133
 
132
134
  def test_reset_empty_table_with_custom_pk
133
135
  Movie.delete_all
@@ -146,4 +148,27 @@ class IBMDBAdapterTest < Test::Unit::TestCase
146
148
  end
147
149
  end
148
150
 
151
+ unless current_adapter?(:IBM_DBAdapter)
152
+ def test_add_limit_offset_should_sanitize_sql_injection_for_limit_without_comas
153
+ sql_inject = "1 select * from schema"
154
+ assert_equal " LIMIT 1", @connection.add_limit_offset!("", :limit=>sql_inject)
155
+ if current_adapter?(:MysqlAdapter)
156
+ assert_equal " LIMIT 7, 1", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
157
+ else
158
+ assert_equal " LIMIT 1 OFFSET 7", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
159
+ end
160
+ end
161
+
162
+ def test_add_limit_offset_should_sanitize_sql_injection_for_limit_with_comas
163
+ sql_inject = "1, 7 procedure help()"
164
+ if current_adapter?(:MysqlAdapter)
165
+ assert_equal " LIMIT 1,7", @connection.add_limit_offset!("", :limit=>sql_inject)
166
+ assert_equal " LIMIT 7, 1", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
167
+ else
168
+ assert_equal " LIMIT 1,7", @connection.add_limit_offset!("", :limit=>sql_inject)
169
+ assert_equal " LIMIT 1,7 OFFSET 7", @connection.add_limit_offset!("", :limit=>sql_inject, :offset=>7)
170
+ end
171
+ end
172
+ end
173
+
149
174
  end
@@ -0,0 +1,113 @@
1
+ require "cases/helper"
2
+ require 'models/post'
3
+ require 'models/comment'
4
+ require 'models/author'
5
+ require 'models/category'
6
+ require 'models/categorization'
7
+ require 'models/company'
8
+ require 'models/topic'
9
+ require 'models/reply'
10
+
11
+ class CascadedEagerLoadingTest < ActiveRecord::TestCase
12
+ fixtures :authors, :mixins, :companies, :posts, :topics
13
+
14
+ def test_eager_association_loading_with_cascaded_two_levels
15
+ authors = Author.find(:all, :include=>{:posts=>:comments}, :order=>"authors.id")
16
+ assert_equal 2, authors.size
17
+ assert_equal 5, authors[0].posts.size
18
+ assert_equal 1, authors[1].posts.size
19
+ assert_equal 9, authors[0].posts.collect{|post| post.comments.size }.inject(0){|sum,i| sum+i}
20
+ end
21
+
22
+ def test_eager_association_loading_with_cascaded_two_levels_and_one_level
23
+ authors = Author.find(:all, :include=>[{:posts=>:comments}, :categorizations], :order=>"authors.id")
24
+ assert_equal 2, authors.size
25
+ assert_equal 5, authors[0].posts.size
26
+ assert_equal 1, authors[1].posts.size
27
+ assert_equal 9, authors[0].posts.collect{|post| post.comments.size }.inject(0){|sum,i| sum+i}
28
+ assert_equal 1, authors[0].categorizations.size
29
+ assert_equal 2, authors[1].categorizations.size
30
+ end
31
+
32
+ def test_eager_association_loading_with_cascaded_two_levels_with_two_has_many_associations
33
+ authors = Author.find(:all, :include=>{:posts=>[:comments, :categorizations]}, :order=>"authors.id")
34
+ assert_equal 2, authors.size
35
+ assert_equal 5, authors[0].posts.size
36
+ assert_equal 1, authors[1].posts.size
37
+ assert_equal 9, authors[0].posts.collect{|post| post.comments.size }.inject(0){|sum,i| sum+i}
38
+ end
39
+
40
+ def test_eager_association_loading_with_cascaded_two_levels_and_self_table_reference
41
+ authors = Author.find(:all, :include=>{:posts=>[:comments, :author]}, :order=>"authors.id")
42
+ assert_equal 2, authors.size
43
+ assert_equal 5, authors[0].posts.size
44
+ assert_equal authors(:david).name, authors[0].name
45
+ assert_equal [authors(:david).name], authors[0].posts.collect{|post| post.author.name}.uniq
46
+ end
47
+
48
+ def test_eager_association_loading_with_cascaded_two_levels_with_condition
49
+ authors = Author.find(:all, :include=>{:posts=>:comments}, :conditions=>"authors.id=1", :order=>"authors.id")
50
+ assert_equal 1, authors.size
51
+ assert_equal 5, authors[0].posts.size
52
+ end
53
+
54
+ def test_eager_association_loading_with_cascaded_three_levels_by_ping_pong
55
+ firms = Firm.find(:all, :include=>{:account=>{:firm=>:account}}, :order=>"companies.id")
56
+ assert_equal 2, firms.size
57
+ assert_equal firms.first.account, firms.first.account.firm.account
58
+ assert_equal companies(:first_firm).account, assert_no_queries { firms.first.account.firm.account }
59
+ assert_equal companies(:first_firm).account.firm.account, assert_no_queries { firms.first.account.firm.account }
60
+ end
61
+
62
+ def test_eager_association_loading_with_has_many_sti
63
+ topics = Topic.find(:all, :include => :replies, :order => 'topics.id')
64
+ first, second, = topics(:first).replies.size, topics(:second).replies.size
65
+ assert_no_queries do
66
+ assert_equal first, topics[0].replies.size
67
+ assert_equal second, topics[1].replies.size
68
+ end
69
+ end
70
+
71
+ def test_eager_association_loading_with_belongs_to_sti
72
+ replies = Reply.find(:all, :include => :topic, :order => 'topics.id')
73
+ assert replies.include?(topics(:second))
74
+ assert !replies.include?(topics(:first))
75
+ assert_equal topics(:first), assert_no_queries { replies.first.topic }
76
+ end
77
+
78
+ unless current_adapter?(:IBM_DBAdapter)
79
+ def test_eager_association_loading_with_multiple_stis_and_order
80
+ author = Author.find(:first, :include => { :posts => [ :special_comments , :very_special_comment ] }, :order => 'authors.name, comments.body, very_special_comments_posts.body', :conditions => 'posts.id = 4')
81
+ assert_equal authors(:david), author
82
+ assert_no_queries do
83
+ author.posts.first.special_comments
84
+ author.posts.first.very_special_comment
85
+ end
86
+ end
87
+ end
88
+
89
+ def test_eager_association_loading_of_stis_with_multiple_references
90
+ authors = Author.find(:all, :include => { :posts => { :special_comments => { :post => [ :special_comments, :very_special_comment ] } } }, :order => 'comments.body, very_special_comments_posts.body', :conditions => 'posts.id = 4')
91
+ assert_equal [authors(:david)], authors
92
+ assert_no_queries do
93
+ authors.first.posts.first.special_comments.first.post.special_comments
94
+ authors.first.posts.first.special_comments.first.post.very_special_comment
95
+ end
96
+ end
97
+ end
98
+
99
+ require 'models/vertex'
100
+ require 'models/edge'
101
+ class CascadedEagerLoadingTest < ActiveRecord::TestCase
102
+ fixtures :edges, :vertices
103
+
104
+ def test_eager_association_loading_with_recursive_cascading_four_levels_has_many_through
105
+ source = Vertex.find(:first, :include=>{:sinks=>{:sinks=>{:sinks=>:sinks}}}, :order => 'vertices.id')
106
+ assert_equal vertices(:vertex_4), assert_no_queries { source.sinks.first.sinks.first.sinks.first }
107
+ end
108
+
109
+ def test_eager_association_loading_with_recursive_cascading_four_levels_has_and_belongs_to_many
110
+ sink = Vertex.find(:first, :include=>{:sources=>{:sources=>{:sources=>:sources}}}, :order => 'vertices.id DESC')
111
+ assert_equal vertices(:vertex_1), assert_no_queries { sink.sources.first.sources.first.sources.first.sources.first }
112
+ end
113
+ end