ibm_db 0.10.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +15 -0
- data/README +3 -3
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +287 -125
- data/test/cases/associations/cascaded_eager_loading_test.rb +13 -1
- data/test/cases/associations/eager_test.rb +34 -1
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +29 -5
- data/test/cases/associations/has_many_through_associations_test.rb +202 -0
- data/test/cases/associations/join_model_test.rb +6 -0
- data/test/cases/base_test.rb +89 -48
- data/test/cases/calculations_test.rb +55 -3
- data/test/cases/finder_test.rb +483 -468
- data/test/cases/migration_test.rb +221 -61
- data/test/cases/query_cache_test.rb +77 -76
- data/test/cases/schema_dumper_test.rb +186 -0
- data/test/cases/validations_test.rb +37 -5
- data/test/schema/schema.rb +8 -0
- metadata +35 -32
data/CHANGES
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
Change Log
|
2
2
|
==============
|
3
|
+
2008/11/06 (IBM_DB adapter 1.0.0, driver 0.10.0):
|
4
|
+
- Support for short-hand migration syntax for datatype char and double in create_table
|
5
|
+
- Support for short-hand migration syntax for datatypes xml, char and double in change_table
|
6
|
+
- Support for secure connections using SSL (SECURITY=SSL) feature of DB2 in Adapter
|
7
|
+
Note: - This is supported from client version V9.5fp2 and onwards
|
8
|
+
- Support for altering the nullability constraint of a column.
|
9
|
+
- Added correct mapping for datatype :double for DB2 and Informix (double precision)
|
10
|
+
- Method support_ddl_transactions? overridden to return true. Feature of Rails2.2
|
11
|
+
IBM Dataservers support transactional migrations.
|
12
|
+
- Change in the style of accessing driver methods
|
13
|
+
Changed from scope resolution operator to dot operator
|
14
|
+
IBM_DB::connect '<db_name>','<username>','<pwd>' to IBM_DB.connect '<db_name>','<username>','<pwd>'
|
15
|
+
- Fixed Bug [#22430] --> Fixed limit ignorance for type character [char]
|
16
|
+
- ActiveRecord-2.1.2 test suite changes for IBM_DB
|
17
|
+
|
3
18
|
2008/09/01 (IBM_DB adapter 0.10.0, driver 0.10.0):
|
4
19
|
- Added Trusted Context support in Driver
|
5
20
|
- Made changes for the correct Mapping of Informix DataTypes to Ruby DataTypes
|
data/README
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
=====================================================================
|
2
|
-
README for the IBM_DB Adapter (0.
|
2
|
+
README for the IBM_DB Adapter (1.0.0) and Driver (0.10.0) (2008/11/06)
|
3
3
|
For ActiveRecord Version >= 1.15.5 (and Rails >= 1.2.5)
|
4
4
|
=====================================================================
|
5
5
|
|
@@ -60,7 +60,7 @@ Note : - 1) If using activerecord version below 2.0 then it requires that the ib
|
|
60
60
|
D:\NewApp>irb
|
61
61
|
irb(main):001:0> gem 'ibm_db'
|
62
62
|
irb(main):002:0> require 'mswin32/ibm_db' // notice the [mswin32] in the library path
|
63
|
-
irb(main):003:0> IBM_DB
|
63
|
+
irb(main):003:0> IBM_DB.connect 'sample', 'db2admin', 'secret'
|
64
64
|
D:\NewApp>ruby script\console
|
65
65
|
|
66
66
|
|
@@ -99,7 +99,7 @@ Note : - 1) If using activerecord version below 2.0 then it requires that the ib
|
|
99
99
|
$ irb
|
100
100
|
irb(main):001:0> gem 'ibm_db'
|
101
101
|
irb(main):002:0> require 'ibm_db' // notice the library path (different on win32, use require 'mswin32/ibm_db')
|
102
|
-
irb(main):003:0> IBM_DB
|
102
|
+
irb(main):003:0> IBM_DB.connect 'sample', 'db2admin', 'secret'
|
103
103
|
$
|
104
104
|
|
105
105
|
BUILD (optionally) ibm_db gem from sources (ibm_db-x.x.x.tar.gz):
|
@@ -1,9 +1,11 @@
|
|
1
1
|
# +----------------------------------------------------------------------+
|
2
2
|
# | Licensed Materials - Property of IBM |
|
3
3
|
# | |
|
4
|
-
# | (C) Copyright IBM Corporation 2006, 2007.
|
4
|
+
# | (C) Copyright IBM Corporation 2006, 2007, 2008. |
|
5
5
|
# +----------------------------------------------------------------------+
|
6
|
-
# |
|
6
|
+
# | Authors: Antonio Cangiano <cangiano@ca.ibm.com> |
|
7
|
+
# | : Mario Ds Briggs <mario.briggs@in.ibm.com> |
|
8
|
+
# | : Praveen Devarao <praveendrl@in.ibm.com> |
|
7
9
|
# +----------------------------------------------------------------------+
|
8
10
|
|
9
11
|
require 'active_record/connection_adapters/abstract_adapter'
|
@@ -62,8 +64,8 @@ module ActiveRecord
|
|
62
64
|
end
|
63
65
|
update_query << " WHERE #{self.class.primary_key} = #{id}"
|
64
66
|
|
65
|
-
unless stmt = IBM_DB
|
66
|
-
error_msg = IBM_DB
|
67
|
+
unless stmt = IBM_DB.prepare(connection.connection, update_query)
|
68
|
+
error_msg = IBM_DB.conn_errormsg ? IBM_DB.conn_errormsg : IBM_DB.stmt_errormsg
|
67
69
|
if error_msg && !error_msg.empty?
|
68
70
|
raise "Failed to rename table due to error: #{error_msg}"
|
69
71
|
else
|
@@ -73,11 +75,11 @@ module ActiveRecord
|
|
73
75
|
connection.log_query(update_query,'update of LOB/XML field(s)in handle_lobs')
|
74
76
|
|
75
77
|
# rollback any failed LOB/XML field updates (and remove associated marker)
|
76
|
-
unless IBM_DB
|
78
|
+
unless IBM_DB.execute(stmt, values)
|
77
79
|
connection.execute("ROLLBACK")
|
78
|
-
raise "Failed to insert/update LOB/XML field(s) due to: #{IBM_DB
|
80
|
+
raise "Failed to insert/update LOB/XML field(s) due to: #{IBM_DB.stmt_errormsg(stmt)}"
|
79
81
|
else
|
80
|
-
IBM_DB
|
82
|
+
IBM_DB.free_result stmt
|
81
83
|
end
|
82
84
|
end # if connection.sql
|
83
85
|
end # if connection.kind_of?
|
@@ -138,7 +140,7 @@ requires credentials: username and password"
|
|
138
140
|
end
|
139
141
|
|
140
142
|
# Checks if a host name or address has been specified. If so, this implies a TCP/IP connection
|
141
|
-
# Returns IBM_DB
|
143
|
+
# Returns IBM_DB.Connection object upon succesful DB connection to the database
|
142
144
|
# If otherwise the connection fails, +false+ is returned
|
143
145
|
if config.has_key?(:host)
|
144
146
|
# Retrieves the host address/name
|
@@ -146,16 +148,22 @@ requires credentials: username and password"
|
|
146
148
|
# A net address connection requires a port. If no port has been specified, 50000 is used by default
|
147
149
|
port = config[:port] || 50000
|
148
150
|
# Connects to the database using the database, host, port, username and password specified
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
151
|
+
# Starting with DB2 9.1FP5 secure connections using SSL are supported.
|
152
|
+
# On the client side using CLI this is supported from CLI version V95FP2 and onwards.
|
153
|
+
# This feature is set by specifying SECURITY=SSL in the connection string.
|
154
|
+
# Below connection string is constructed and SECURITY parameter is appended if the user has specified the :security option
|
155
|
+
conn_string = "DRIVER={IBM DB2 ODBC DRIVER};\
|
156
|
+
DATABASE=#{database};\
|
157
|
+
HOSTNAME=#{host};\
|
158
|
+
PORT=#{port};\
|
159
|
+
PROTOCOL=TCPIP;\
|
160
|
+
UID=#{username};\
|
161
|
+
PWD=#{password};"
|
162
|
+
conn_string << "SECURITY=#{config[:security]};" if config.has_key?(:security)
|
163
|
+
connection = IBM_DB.connect conn_string, '', '', conn_options
|
156
164
|
else
|
157
165
|
# No host implies a local catalog-based connection: +database+ represents catalog alias
|
158
|
-
connection = IBM_DB
|
166
|
+
connection = IBM_DB.connect( database, username, password, conn_options )
|
159
167
|
end
|
160
168
|
|
161
169
|
# Verifies that the connection was succesfull
|
@@ -165,7 +173,7 @@ requires credentials: username and password"
|
|
165
173
|
ConnectionAdapters::IBM_DBAdapter.new(connection, logger, config, conn_options)
|
166
174
|
else
|
167
175
|
# If the connection failed, it raises a Runtime error
|
168
|
-
raise "Failed to connect to the [#{database}] due to: #{IBM_DB
|
176
|
+
raise "Failed to connect to the [#{database}] due to: #{IBM_DB.conn_errormsg}"
|
169
177
|
end
|
170
178
|
end # method self.ibm_db_connection
|
171
179
|
end # class Base
|
@@ -221,23 +229,87 @@ requires credentials: username and password"
|
|
221
229
|
when /rowid/i # rowid is a supported datatype on z/OS and i/5
|
222
230
|
:rowid
|
223
231
|
end
|
224
|
-
|
225
|
-
|
232
|
+
end # method simplified_type
|
233
|
+
end #class IBM_DBColumn
|
226
234
|
|
227
|
-
class
|
235
|
+
class Table
|
228
236
|
|
229
|
-
#Method to
|
230
|
-
def
|
237
|
+
#Method to parse the passed arguments and create the ColumnDefinition object of the specified type
|
238
|
+
def ibm_parse_column_attributes_args(type, *args)
|
231
239
|
options = {}
|
232
240
|
if args.last.is_a?(Hash)
|
233
241
|
options = args.delete_at(args.length-1)
|
234
242
|
end
|
235
243
|
args.each do | name |
|
236
|
-
column
|
244
|
+
column name,type.to_sym,options
|
237
245
|
end # end args.each
|
246
|
+
end
|
247
|
+
private :ibm_parse_column_attributes_args
|
248
|
+
|
249
|
+
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type xml
|
250
|
+
#This method is different as compared to def char (sql is being issued explicitly
|
251
|
+
#as compared to def char where method column(which will generate the sql is being called)
|
252
|
+
#in order to handle the DEFAULT and NULL option for the native XML datatype
|
253
|
+
def xml(*args )
|
254
|
+
options = {}
|
255
|
+
if args.last.is_a?(Hash)
|
256
|
+
options = args.delete_at(args.length-1)
|
257
|
+
end
|
258
|
+
sql = "ALTER TABLE #{@base.quote_table_name(@table_name)} ADD COLUMN "
|
259
|
+
args.each do | name |
|
260
|
+
sql << "#{@base.quote_column_name(name)} xml"
|
261
|
+
@base.execute(sql,"add_xml_column")
|
262
|
+
end
|
263
|
+
return self
|
264
|
+
end
|
265
|
+
|
266
|
+
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type double
|
267
|
+
def double(*args)
|
268
|
+
ibm_parse_column_attributes_args('double',*args)
|
269
|
+
return self
|
270
|
+
end
|
271
|
+
|
272
|
+
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type char [character]
|
273
|
+
def char(*args)
|
274
|
+
ibm_parse_column_attributes_args('char',*args)
|
275
|
+
return self
|
276
|
+
end
|
277
|
+
alias_method :character, :char
|
278
|
+
end
|
279
|
+
|
280
|
+
class TableDefinition
|
281
|
+
|
282
|
+
#Method to parse the passed arguments and create the ColumnDefinition object of the specified type
|
283
|
+
def ibm_parse_column_attributes_args(type, *args)
|
284
|
+
options = {}
|
285
|
+
if args.last.is_a?(Hash)
|
286
|
+
options = args.delete_at(args.length-1)
|
287
|
+
end
|
288
|
+
args.each do | name |
|
289
|
+
column(name,type,options)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
private :ibm_parse_column_attributes_args
|
293
|
+
|
294
|
+
#Method to support the new syntax of rails 2.0 migrations for columns of type xml
|
295
|
+
def xml(*args )
|
296
|
+
ibm_parse_column_attributes_args('xml', *args)
|
297
|
+
return self
|
298
|
+
end
|
299
|
+
|
300
|
+
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type double
|
301
|
+
def double(*args)
|
302
|
+
ibm_parse_column_attributes_args('double',*args)
|
238
303
|
return self
|
239
304
|
end
|
240
305
|
|
306
|
+
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type char [character]
|
307
|
+
def char(*args)
|
308
|
+
ibm_parse_column_attributes_args('char',*args)
|
309
|
+
return self
|
310
|
+
end
|
311
|
+
alias_method :character, :char
|
312
|
+
|
241
313
|
# Overrides the abstract adapter in order to handle
|
242
314
|
# the DEFAULT option for the native XML datatype
|
243
315
|
def column(name, type, options ={})
|
@@ -296,6 +368,8 @@ requires credentials: username and password"
|
|
296
368
|
# == remote TCP/IP connection (required when no local database catalog entry available)
|
297
369
|
# host: 'socrates' // fully qualified hostname or IP address
|
298
370
|
# port: '50000' // data server TCP/IP port number
|
371
|
+
# security: 'SSL' // optional parameter enabling SSL encryption -
|
372
|
+
# // - Available only from CLI version V95fp2 and above
|
299
373
|
#
|
300
374
|
# When schema is not specified, the username value is used instead.
|
301
375
|
#
|
@@ -321,7 +395,8 @@ requires credentials: username and password"
|
|
321
395
|
@port = config[:port] || 50000 # default port
|
322
396
|
end
|
323
397
|
@schema = config[:schema]
|
324
|
-
|
398
|
+
@security = config[:security] || nil
|
399
|
+
|
325
400
|
# Caching database connection options (auditing and billing support)
|
326
401
|
@app_user = conn_options[:app_user] if conn_options.has_key?(:app_user)
|
327
402
|
@account = conn_options[:account] if conn_options.has_key?(:account)
|
@@ -333,7 +408,7 @@ requires credentials: username and password"
|
|
333
408
|
super(@connection, logger)
|
334
409
|
|
335
410
|
if @connection
|
336
|
-
server_info = IBM_DB
|
411
|
+
server_info = IBM_DB.server_info( @connection )
|
337
412
|
case server_info.DBMS_NAME
|
338
413
|
when /DB2\//i # DB2 for Linux, Unix and Windows (LUW)
|
339
414
|
@servertype = IBM_DB2_LUW.new(self)
|
@@ -369,8 +444,8 @@ requires credentials: username and password"
|
|
369
444
|
def app_user=(name)
|
370
445
|
unless name == @app_user
|
371
446
|
option = {IBM_DB::SQL_ATTR_INFO_USERID => "#{name}"}
|
372
|
-
if IBM_DB
|
373
|
-
@app_user = IBM_DB
|
447
|
+
if IBM_DB.set_option( @connection, option, 1 )
|
448
|
+
@app_user = IBM_DB.get_option( @connection, IBM_DB::SQL_ATTR_INFO_USERID, 1 )
|
374
449
|
end
|
375
450
|
end
|
376
451
|
end
|
@@ -379,8 +454,8 @@ requires credentials: username and password"
|
|
379
454
|
def account=(name)
|
380
455
|
unless name == @account
|
381
456
|
option = {IBM_DB::SQL_ATTR_INFO_ACCTSTR => "#{name}"}
|
382
|
-
if IBM_DB
|
383
|
-
@account = IBM_DB
|
457
|
+
if IBM_DB.set_option( @connection, option, 1 )
|
458
|
+
@account = IBM_DB.get_option( @connection, IBM_DB::SQL_ATTR_INFO_ACCTSTR, 1 )
|
384
459
|
end
|
385
460
|
end
|
386
461
|
end
|
@@ -389,8 +464,8 @@ requires credentials: username and password"
|
|
389
464
|
def application=(name)
|
390
465
|
unless name == @application
|
391
466
|
option = {IBM_DB::SQL_ATTR_INFO_APPLNAME => "#{name}"}
|
392
|
-
if IBM_DB
|
393
|
-
@application = IBM_DB
|
467
|
+
if IBM_DB.set_option( @connection, option, 1 )
|
468
|
+
@application = IBM_DB.get_option( @connection, IBM_DB::SQL_ATTR_INFO_APPLNAME, 1 )
|
394
469
|
end
|
395
470
|
end
|
396
471
|
end
|
@@ -399,8 +474,8 @@ requires credentials: username and password"
|
|
399
474
|
def workstation=(name)
|
400
475
|
unless name == @workstation
|
401
476
|
option = {IBM_DB::SQL_ATTR_INFO_WRKSTNNAME => "#{name}"}
|
402
|
-
if IBM_DB
|
403
|
-
@workstation = IBM_DB
|
477
|
+
if IBM_DB.set_option( @connection, option, 1 )
|
478
|
+
@workstation = IBM_DB.get_option( @connection, IBM_DB::SQL_ATTR_INFO_WRKSTNNAME, 1 )
|
404
479
|
end
|
405
480
|
end
|
406
481
|
end
|
@@ -413,7 +488,14 @@ requires credentials: username and password"
|
|
413
488
|
def supports_migrations?
|
414
489
|
true
|
415
490
|
end
|
416
|
-
|
491
|
+
|
492
|
+
# This Adapter supports DDL transactions.
|
493
|
+
# This means CREATE TABLE and other DDL statements can be carried out as a transaction.
|
494
|
+
# That is the statements executed can be ROLLED BACK in case of any error during the process.
|
495
|
+
def supports_ddl_transactions?
|
496
|
+
true
|
497
|
+
end
|
498
|
+
|
417
499
|
def log_query(sql, name) #:nodoc:
|
418
500
|
# Used by handle_lobs
|
419
501
|
log(sql,name){}
|
@@ -425,7 +507,7 @@ requires credentials: username and password"
|
|
425
507
|
|
426
508
|
# Tests the connection status
|
427
509
|
def active?
|
428
|
-
IBM_DB
|
510
|
+
IBM_DB.active @connection
|
429
511
|
rescue
|
430
512
|
false
|
431
513
|
end
|
@@ -435,18 +517,20 @@ requires credentials: username and password"
|
|
435
517
|
def connect
|
436
518
|
# If the type of connection is net based
|
437
519
|
if @host
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
520
|
+
@conn_string = "DRIVER={IBM DB2 ODBC DRIVER};\
|
521
|
+
DATABASE=#{@database};\
|
522
|
+
HOSTNAME=#{@host};\
|
523
|
+
PORT=#{@port};\
|
524
|
+
PROTOCOL=TCPIP;\
|
525
|
+
UID=#{@username};\
|
526
|
+
PWD=#{@password};"
|
527
|
+
@conn_string << "SECURITY=#{@security};" if @security
|
528
|
+
# Connects and assigns the resulting IBM_DB.Connection to the +@connection+ instance variable
|
529
|
+
@connection = IBM_DB.connect(@conn_string, '', '', @conn_options)
|
446
530
|
else
|
447
531
|
# Connects to the database using the local alias (@database)
|
448
|
-
# and assigns the connection object (IBM_DB
|
449
|
-
@connection = IBM_DB
|
532
|
+
# and assigns the connection object (IBM_DB.Connection) to @connection
|
533
|
+
@connection = IBM_DB.connect(@database, @username, @password, @conn_options)
|
450
534
|
end
|
451
535
|
# Sets the schema if different from default (username)
|
452
536
|
if @schema && @schema != @username
|
@@ -467,7 +551,7 @@ requires credentials: username and password"
|
|
467
551
|
# * true if succesfull
|
468
552
|
# * false if the connection is already closed
|
469
553
|
# * nil if an error is raised
|
470
|
-
IBM_DB
|
554
|
+
IBM_DB.close(@connection) rescue nil
|
471
555
|
end
|
472
556
|
|
473
557
|
#==============================================
|
@@ -502,13 +586,13 @@ requires credentials: username and password"
|
|
502
586
|
|
503
587
|
results = []
|
504
588
|
# Invokes the method +execute+ in order to log and execute the SQL
|
505
|
-
# IBM_DB
|
589
|
+
# IBM_DB.Statement is returned from which results can be fetched
|
506
590
|
if stmt = execute(sql, name)
|
507
591
|
begin
|
508
592
|
@servertype.select_all(sql, name, stmt, results)
|
509
593
|
ensure
|
510
594
|
# Ensures to free the resources associated with the statement
|
511
|
-
IBM_DB
|
595
|
+
IBM_DB.free_result stmt
|
512
596
|
end
|
513
597
|
end
|
514
598
|
# The array of record hashes is returned
|
@@ -524,13 +608,13 @@ requires credentials: username and password"
|
|
524
608
|
|
525
609
|
results = []
|
526
610
|
# Invokes the method +execute+ in order to log and execute the SQL
|
527
|
-
# IBM_DB
|
611
|
+
# IBM_DB.Statement is returned from which results can be fetched
|
528
612
|
if stmt = execute(sql, name)
|
529
613
|
begin
|
530
614
|
@servertype.select_rows(sql, name, stmt, results)
|
531
615
|
ensure
|
532
616
|
# Ensures to free the resources associated with the statement
|
533
|
-
IBM_DB
|
617
|
+
IBM_DB.free_result stmt
|
534
618
|
end
|
535
619
|
end
|
536
620
|
# The array of record hashes is returned
|
@@ -584,8 +668,8 @@ requires credentials: username and password"
|
|
584
668
|
end
|
585
669
|
|
586
670
|
insert_query << " VALUES ("+ params.join(',') + ")"
|
587
|
-
unless stmt = IBM_DB
|
588
|
-
error_msg = IBM_DB
|
671
|
+
unless stmt = IBM_DB.prepare(@connection, insert_query)
|
672
|
+
error_msg = IBM_DB.conn_errormsg ? IBM_DB.conn_errormsg : IBM_DB.stmt_errormsg
|
589
673
|
if error_msg && !error_msg.empty?
|
590
674
|
raise "Failed to prepare statement due to : #{error_msg}"
|
591
675
|
else
|
@@ -595,10 +679,10 @@ requires credentials: username and password"
|
|
595
679
|
|
596
680
|
#log_query(insert_query,'fixture insert')
|
597
681
|
log(insert_query,'fixture insert') do
|
598
|
-
unless IBM_DB
|
599
|
-
raise "Failed to insert due to: #{IBM_DB
|
682
|
+
unless IBM_DB.execute(stmt, insert_values)
|
683
|
+
raise "Failed to insert due to: #{IBM_DB.stmt_errormsg(stmt)}"
|
600
684
|
else
|
601
|
-
IBM_DB
|
685
|
+
IBM_DB.free_result stmt
|
602
686
|
end
|
603
687
|
end
|
604
688
|
end
|
@@ -613,13 +697,13 @@ requires credentials: username and password"
|
|
613
697
|
return id_value || @servertype.last_generated_id(stmt)
|
614
698
|
# Ensures to free the resources associated with the statement
|
615
699
|
ensure
|
616
|
-
IBM_DB
|
700
|
+
IBM_DB.free_result(stmt)
|
617
701
|
end
|
618
702
|
end
|
619
703
|
end
|
620
704
|
|
621
705
|
# Executes and logs +sql+ commands and
|
622
|
-
# returns a +IBM_DB
|
706
|
+
# returns a +IBM_DB.Statement+ object.
|
623
707
|
def execute(sql, name = nil)
|
624
708
|
# Logs and execute the sql instructions.
|
625
709
|
# The +log+ method is defined in the parent class +AbstractAdapter+
|
@@ -642,10 +726,10 @@ requires credentials: username and password"
|
|
642
726
|
begin
|
643
727
|
@sql = sql
|
644
728
|
# Retrieves the number of affected rows
|
645
|
-
IBM_DB
|
729
|
+
IBM_DB.num_rows(stmt)
|
646
730
|
# Ensures to free the resources associated with the statement
|
647
731
|
ensure
|
648
|
-
IBM_DB
|
732
|
+
IBM_DB.free_result(stmt)
|
649
733
|
end
|
650
734
|
end
|
651
735
|
end
|
@@ -658,24 +742,24 @@ requires credentials: username and password"
|
|
658
742
|
# Begins the transaction (and turns off auto-committing)
|
659
743
|
def begin_db_transaction
|
660
744
|
# Turns off the auto-commit
|
661
|
-
IBM_DB
|
745
|
+
IBM_DB.autocommit(@connection, IBM_DB::SQL_AUTOCOMMIT_OFF)
|
662
746
|
end
|
663
747
|
|
664
748
|
# Commits the transaction and turns on auto-committing
|
665
749
|
def commit_db_transaction
|
666
750
|
# Commits the transaction
|
667
|
-
IBM_DB
|
751
|
+
IBM_DB.commit @connection rescue nil
|
668
752
|
# Turns on auto-committing
|
669
|
-
IBM_DB
|
753
|
+
IBM_DB.autocommit @connection, IBM_DB::SQL_AUTOCOMMIT_ON
|
670
754
|
end
|
671
755
|
|
672
756
|
# Rolls back the transaction and turns on auto-committing. Must be
|
673
757
|
# done if the transaction block raises an exception or returns false
|
674
758
|
def rollback_db_transaction
|
675
759
|
# ROLLBACK the transaction
|
676
|
-
IBM_DB
|
760
|
+
IBM_DB.rollback(@connection) rescue nil
|
677
761
|
# Turns on auto-committing
|
678
|
-
IBM_DB
|
762
|
+
IBM_DB.autocommit @connection, IBM_DB::SQL_AUTOCOMMIT_ON
|
679
763
|
end
|
680
764
|
|
681
765
|
|
@@ -829,7 +913,9 @@ requires credentials: username and password"
|
|
829
913
|
:xml => { :name => "xml"},
|
830
914
|
:decimal => { :name => "decimal" },
|
831
915
|
:rowid => { :name => "rowid" }, # rowid is a supported datatype on z/OS and i/5
|
832
|
-
:serial => { :name => "serial" } # rowid is a supported datatype on Informix Dynamic Server
|
916
|
+
:serial => { :name => "serial" }, # rowid is a supported datatype on Informix Dynamic Server
|
917
|
+
:char => { :name => "char" },
|
918
|
+
:double => { :name => @servertype.get_double_mapping }
|
833
919
|
}
|
834
920
|
end
|
835
921
|
|
@@ -839,8 +925,8 @@ requires credentials: username and password"
|
|
839
925
|
return super if limit.nil?
|
840
926
|
|
841
927
|
# strip off limits on data types not supporting them
|
842
|
-
if [:integer, :double, :date, :time, :timestamp, :xml].include? type
|
843
|
-
return type.to_s
|
928
|
+
if [:integer, :double, :date, :time, :timestamp, :xml].include? type.to_sym
|
929
|
+
return native_database_types[type.to_sym][:name].to_s
|
844
930
|
elsif type.to_sym == :boolean
|
845
931
|
return "smallint"
|
846
932
|
else
|
@@ -859,21 +945,21 @@ requires credentials: username and password"
|
|
859
945
|
# Initializes the tables array
|
860
946
|
tables = []
|
861
947
|
# Retrieve table's metadata through IBM_DB driver
|
862
|
-
if stmt = IBM_DB
|
948
|
+
if stmt = IBM_DB.tables(@connection, nil,
|
863
949
|
@servertype.set_case(@schema))
|
864
950
|
begin
|
865
951
|
# Fetches all the records available
|
866
|
-
while tab = IBM_DB
|
952
|
+
while tab = IBM_DB.fetch_assoc(stmt)
|
867
953
|
# Adds the lowercase table name to the array
|
868
|
-
if(tab["table_type"]== 'TABLE') #check, so that only tables are dumped,IBM_DB
|
954
|
+
if(tab["table_type"]== 'TABLE') #check, so that only tables are dumped,IBM_DB.tables also returns views,alias etc in the schema
|
869
955
|
tables << tab["table_name"].downcase
|
870
956
|
end
|
871
957
|
end
|
872
958
|
ensure
|
873
|
-
IBM_DB
|
959
|
+
IBM_DB.free_result(stmt) # Free resources associated with the statement
|
874
960
|
end
|
875
961
|
else # Handle driver execution errors
|
876
|
-
error_msg = IBM_DB
|
962
|
+
error_msg = IBM_DB.conn_errormsg ? IBM_DB.conn_errormsg : IBM_DB.stmt_errormsg
|
877
963
|
if error_msg && !error_msg.empty?
|
878
964
|
raise "Failed to retrieve tables metadata due to error: #{error_msg}"
|
879
965
|
else
|
@@ -901,11 +987,11 @@ requires credentials: username and password"
|
|
901
987
|
#TABLE_NAME:: pk_index[2]
|
902
988
|
#COLUMN_NAME:: pk_index[3]
|
903
989
|
#PK_NAME:: pk_index[5]
|
904
|
-
if stmt = IBM_DB
|
990
|
+
if stmt = IBM_DB.primary_keys( @connection, nil,
|
905
991
|
@servertype.set_case(@schema),
|
906
992
|
@servertype.set_case(table_name))
|
907
993
|
begin
|
908
|
-
while ( pk_index_row = IBM_DB
|
994
|
+
while ( pk_index_row = IBM_DB.fetch_array(stmt) )
|
909
995
|
if pk_index_row[5]
|
910
996
|
pk_index_name = pk_index_row[5].downcase
|
911
997
|
pk_index_columns = pk_index_row[3].map{|c| c.downcase} # COLUMN_NAME
|
@@ -917,10 +1003,10 @@ requires credentials: username and password"
|
|
917
1003
|
end
|
918
1004
|
end
|
919
1005
|
ensure # Free resources associated with the statement
|
920
|
-
IBM_DB
|
1006
|
+
IBM_DB.free_result(stmt) if stmt
|
921
1007
|
end
|
922
1008
|
else # Handle driver execution errors
|
923
|
-
error_msg = IBM_DB
|
1009
|
+
error_msg = IBM_DB.conn_errormsg ? IBM_DB.conn_errormsg : IBM_DB.stmt_errormsg
|
924
1010
|
if error_msg && !error_msg.empty?
|
925
1011
|
raise "Failed to retrieve primary key metadata due to error: #{error_msg}"
|
926
1012
|
else
|
@@ -934,11 +1020,11 @@ requires credentials: username and password"
|
|
934
1020
|
# "NON_UNIQUE: #{index_stats[3]}"
|
935
1021
|
# "INDEX_NAME: #{index_stats[5]}"
|
936
1022
|
# "COLUMN_NAME: #{index_stats[8]}"
|
937
|
-
if stmt = IBM_DB
|
1023
|
+
if stmt = IBM_DB.statistics( @connection, nil,
|
938
1024
|
@servertype.set_case(@schema),
|
939
1025
|
@servertype.set_case(table_name), 1 )
|
940
1026
|
begin
|
941
|
-
while ( index_stats = IBM_DB
|
1027
|
+
while ( index_stats = IBM_DB.fetch_array(stmt) )
|
942
1028
|
is_composite = false
|
943
1029
|
if index_stats[5] # INDEX_NAME
|
944
1030
|
index_name = index_stats[5].downcase
|
@@ -962,10 +1048,10 @@ requires credentials: username and password"
|
|
962
1048
|
end
|
963
1049
|
end
|
964
1050
|
ensure # Free resources associated with the statement
|
965
|
-
IBM_DB
|
1051
|
+
IBM_DB.free_result(stmt) if stmt
|
966
1052
|
end
|
967
1053
|
else # Handle driver execution errors
|
968
|
-
error_msg = IBM_DB
|
1054
|
+
error_msg = IBM_DB.conn_errormsg ? IBM_DB.conn_errormsg : IBM_DB.stmt_errormsg
|
969
1055
|
if error_msg && !error_msg.empty?
|
970
1056
|
raise "Failed to retrieve index metadata due to error: #{error_msg}"
|
971
1057
|
else
|
@@ -996,13 +1082,13 @@ requires credentials: username and password"
|
|
996
1082
|
# +columns+ will contain the resulting array
|
997
1083
|
columns = []
|
998
1084
|
# Statement required to access all the columns information
|
999
|
-
if stmt = IBM_DB
|
1085
|
+
if stmt = IBM_DB.columns( @connection, nil,
|
1000
1086
|
@servertype.set_case(@schema),
|
1001
1087
|
@servertype.set_case(table_name) )
|
1002
1088
|
begin
|
1003
1089
|
# Fetches all the columns and assigns them to col.
|
1004
1090
|
# +col+ is an hash with keys/value pairs for a column
|
1005
|
-
while col = IBM_DB
|
1091
|
+
while col = IBM_DB.fetch_assoc(stmt)
|
1006
1092
|
column_name = col["column_name"].downcase
|
1007
1093
|
# Assigns the column default value.
|
1008
1094
|
column_default_value = col["column_def"]
|
@@ -1041,17 +1127,17 @@ requires credentials: username and password"
|
|
1041
1127
|
end
|
1042
1128
|
end
|
1043
1129
|
rescue StandardError # Handle driver fetch errors
|
1044
|
-
error_msg = IBM_DB
|
1130
|
+
error_msg = IBM_DB.conn_errormsg ? IBM_DB.conn_errormsg : IBM_DB.stmt_errormsg
|
1045
1131
|
if error_msg && !error_msg.empty?
|
1046
1132
|
raise "Failed to retrieve column metadata during fetch: #{error_msg}"
|
1047
1133
|
else
|
1048
1134
|
raise
|
1049
1135
|
end
|
1050
1136
|
ensure # Free resources associated with the statement
|
1051
|
-
IBM_DB
|
1137
|
+
IBM_DB.free_result(stmt)
|
1052
1138
|
end
|
1053
1139
|
else # Handle driver execution errors
|
1054
|
-
error_msg = IBM_DB
|
1140
|
+
error_msg = IBM_DB.conn_errormsg ? IBM_DB.conn_errormsg : IBM_DB.stmt_errormsg
|
1055
1141
|
if error_msg && !error_msg.empty?
|
1056
1142
|
raise "Failed to retrieve column metadata due to error: #{error_msg}"
|
1057
1143
|
else
|
@@ -1072,7 +1158,7 @@ requires credentials: username and password"
|
|
1072
1158
|
stmt = execute(rename_table_sql)
|
1073
1159
|
# Ensures to free the resources associated with the statement
|
1074
1160
|
ensure
|
1075
|
-
IBM_DB
|
1161
|
+
IBM_DB.free_result stmt if stmt
|
1076
1162
|
end
|
1077
1163
|
|
1078
1164
|
# Renames a column.
|
@@ -1121,6 +1207,7 @@ requires credentials: username and password"
|
|
1121
1207
|
end
|
1122
1208
|
end
|
1123
1209
|
end
|
1210
|
+
|
1124
1211
|
# Sets a new default value for a column. This does not set the default
|
1125
1212
|
# value to +NULL+, instead, it needs DatabaseStatements#execute which
|
1126
1213
|
# can execute the appropriate SQL statement for setting the value.
|
@@ -1131,7 +1218,12 @@ requires credentials: username and password"
|
|
1131
1218
|
def change_column_default(table_name, column_name, default)
|
1132
1219
|
@servertype.change_column_default(table_name, column_name, default)
|
1133
1220
|
end
|
1134
|
-
|
1221
|
+
|
1222
|
+
#Changes the nullability value of a column
|
1223
|
+
def change_column_null(table_name, column_name, null, default = nil)
|
1224
|
+
@servertype.change_column_null(table_name, column_name, null, default)
|
1225
|
+
end
|
1226
|
+
|
1135
1227
|
# Remove the given index from the table.
|
1136
1228
|
#
|
1137
1229
|
# Remove the suppliers_name_index in the suppliers table (legacy support, use the second or third forms).
|
@@ -1191,20 +1283,20 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
1191
1283
|
end
|
1192
1284
|
|
1193
1285
|
def select_all(sql, name, stmt, results)
|
1194
|
-
# Fetches all the results available. IBM_DB
|
1286
|
+
# Fetches all the results available. IBM_DB.fetch_assoc(stmt) returns
|
1195
1287
|
# an hash for each single record.
|
1196
1288
|
# The loop stops when there aren't any more valid records to fetch
|
1197
|
-
while single_hash = IBM_DB
|
1289
|
+
while single_hash = IBM_DB.fetch_assoc(stmt)
|
1198
1290
|
# Add the record to the +results+ array
|
1199
1291
|
results << single_hash
|
1200
1292
|
end
|
1201
1293
|
end
|
1202
1294
|
|
1203
1295
|
def select_rows(sql, name, stmt, results)
|
1204
|
-
# Fetches all the results available. IBM_DB
|
1296
|
+
# Fetches all the results available. IBM_DB.fetch_array(stmt) returns
|
1205
1297
|
# an array representing a row in a result set.
|
1206
1298
|
# The loop stops when there aren't any more valid records to fetch
|
1207
|
-
while single_array = IBM_DB
|
1299
|
+
while single_array = IBM_DB.fetch_array(stmt)
|
1208
1300
|
#Add the array to results array
|
1209
1301
|
results << single_array
|
1210
1302
|
end
|
@@ -1212,13 +1304,13 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
1212
1304
|
|
1213
1305
|
def execute(sql, name = nil)
|
1214
1306
|
begin
|
1215
|
-
if stmt = IBM_DB
|
1307
|
+
if stmt = IBM_DB.exec(@adapter.connection, sql)
|
1216
1308
|
stmt # Return the statement object
|
1217
1309
|
else
|
1218
|
-
raise StatementInvalid, IBM_DB
|
1310
|
+
raise StatementInvalid, IBM_DB.stmt_errormsg
|
1219
1311
|
end
|
1220
1312
|
rescue StandardError
|
1221
|
-
error_msg = IBM_DB
|
1313
|
+
error_msg = IBM_DB.conn_errormsg ? IBM_DB.conn_errormsg : IBM_DB.stmt_errormsg
|
1222
1314
|
if error_msg && !error_msg.empty?
|
1223
1315
|
raise "Failed to execute statement due to error: #{error_msg}"
|
1224
1316
|
else
|
@@ -1240,9 +1332,15 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
1240
1332
|
def get_time_mapping
|
1241
1333
|
end
|
1242
1334
|
|
1335
|
+
def get_double_mapping
|
1336
|
+
end
|
1337
|
+
|
1243
1338
|
def change_column_default(table_name, column_name, default)
|
1244
1339
|
end
|
1245
1340
|
|
1341
|
+
def change_column_null(table_name, column_name, null, default)
|
1342
|
+
end
|
1343
|
+
|
1246
1344
|
def set_binary_default(value)
|
1247
1345
|
end
|
1248
1346
|
|
@@ -1271,17 +1369,17 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
1271
1369
|
def last_generated_id(stmt)
|
1272
1370
|
# Queries the db to obtain the last ID that was automatically generated
|
1273
1371
|
sql = "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1"
|
1274
|
-
if stmt = IBM_DB
|
1372
|
+
if stmt = IBM_DB.exec(@adapter.connection, sql)
|
1275
1373
|
begin
|
1276
1374
|
# Fetches the only record available (containing the last id)
|
1277
|
-
IBM_DB
|
1375
|
+
IBM_DB.fetch_row(stmt)
|
1278
1376
|
# Retrieves and returns the result of the query with the last id.
|
1279
|
-
IBM_DB
|
1377
|
+
IBM_DB.result(stmt,0)
|
1280
1378
|
ensure # Free resources associated with the statement
|
1281
|
-
IBM_DB
|
1379
|
+
IBM_DB.free_result stmt
|
1282
1380
|
end
|
1283
1381
|
else
|
1284
|
-
error_msg = IBM_DB
|
1382
|
+
error_msg = IBM_DB.conn_errormsg ? IBM_DB.conn_errormsg : IBM_DB.stmt_errormsg
|
1285
1383
|
if error_msg && !error_msg.empty?
|
1286
1384
|
raise "Failed to retrieve last generated id due to error: #{error_msg}"
|
1287
1385
|
else
|
@@ -1304,25 +1402,45 @@ The column datatype change to [#{data_type}] is not supported by this data serve
|
|
1304
1402
|
end
|
1305
1403
|
end
|
1306
1404
|
reorg_table(table_name)
|
1307
|
-
|
1308
|
-
|
1309
|
-
end
|
1310
|
-
if !options[:default].nil?
|
1311
|
-
change_column_default(table_name, column_name, options[:default])
|
1312
|
-
end
|
1405
|
+
change_column_null(table_name,column_name,options[:null],nil)
|
1406
|
+
change_column_default(table_name, column_name, options[:default])
|
1313
1407
|
reorg_table(table_name)
|
1314
1408
|
end
|
1315
1409
|
|
1316
1410
|
# DB2 specific ALTER TABLE statement to add a default clause
|
1317
1411
|
def change_column_default(table_name, column_name, default)
|
1318
1412
|
# SQL statement which alters column's default value
|
1319
|
-
|
1413
|
+
if default.nil?
|
1414
|
+
change_column_sql = "ALTER TABLE #{table_name} ALTER #{column_name} DROP DEFAULT"
|
1415
|
+
else
|
1416
|
+
change_column_sql = "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} \
|
1320
1417
|
SET WITH DEFAULT #{@adapter.quote(default)}"
|
1418
|
+
end
|
1321
1419
|
stmt = execute(change_column_sql)
|
1420
|
+
reorg_table(table_name)
|
1322
1421
|
ensure
|
1323
|
-
IBM_DB
|
1422
|
+
IBM_DB.free_result stmt if stmt
|
1324
1423
|
end
|
1325
1424
|
|
1425
|
+
#DB2 specific ALTER TABLE statement to change the nullability of a column
|
1426
|
+
def change_column_null(table_name, column_name, null, default)
|
1427
|
+
if !default.nil?
|
1428
|
+
change_column_default(table_name, column_name, default)
|
1429
|
+
end
|
1430
|
+
reorg_table(table_name)
|
1431
|
+
if !null.nil?
|
1432
|
+
if null
|
1433
|
+
change_column_sql = "ALTER TABLE #{table_name} ALTER #{column_name} DROP NOT NULL"
|
1434
|
+
else
|
1435
|
+
change_column_sql = "ALTER TABLE #{table_name} ALTER #{column_name} SET NOT NULL"
|
1436
|
+
end
|
1437
|
+
end
|
1438
|
+
stmt = execute(change_column_sql)
|
1439
|
+
reorg_table(table_name)
|
1440
|
+
ensure
|
1441
|
+
IBM_DB.free_result stmt if stmt
|
1442
|
+
end
|
1443
|
+
|
1326
1444
|
# This method returns the DB2 SQL type corresponding to the Rails
|
1327
1445
|
# datetime/timestamp type
|
1328
1446
|
def get_datetime_mapping
|
@@ -1335,21 +1453,26 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1335
1453
|
return "time"
|
1336
1454
|
end
|
1337
1455
|
|
1338
|
-
#
|
1456
|
+
#This method returns the DB2 SQL type corresponding to Rails double type
|
1457
|
+
def get_double_mapping
|
1458
|
+
return "double"
|
1459
|
+
end
|
1460
|
+
|
1461
|
+
# Fetches all the results available. IBM_DB.fetch_assoc(stmt) returns
|
1339
1462
|
# an hash for each single record.
|
1340
1463
|
# The loop stops when there aren't any more valid records to fetch
|
1341
1464
|
def select_all(sql, name, stmt, results)
|
1342
1465
|
if (!@offset.nil? && @offset >= 0) || (!@limit.nil? && @limit > 0)
|
1343
1466
|
# We know at this point that there is an offset and/or a limit
|
1344
1467
|
# Check if the cursor type is set correctly
|
1345
|
-
cursor_type = IBM_DB
|
1468
|
+
cursor_type = IBM_DB.get_option stmt, IBM_DB::SQL_ATTR_CURSOR_TYPE, 0
|
1346
1469
|
@offset = 0 if @offset.nil?
|
1347
1470
|
if (cursor_type == IBM_DB::SQL_CURSOR_STATIC)
|
1348
1471
|
index = 0
|
1349
1472
|
# Get @limit rows starting at @offset
|
1350
1473
|
while (index < @limit)
|
1351
1474
|
# We increment the offset by 1 because for DB2 the offset of the initial row is 1 instead of 0
|
1352
|
-
if single_hash = IBM_DB
|
1475
|
+
if single_hash = IBM_DB.fetch_assoc(stmt, @offset + index + 1)
|
1353
1476
|
# Add the record to the +results+ array
|
1354
1477
|
results << single_hash
|
1355
1478
|
index = index + 1
|
@@ -1365,7 +1488,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1365
1488
|
# at @offset to @offset + @limit
|
1366
1489
|
index = 0
|
1367
1490
|
while (index < @offset + @limit)
|
1368
|
-
if single_hash = IBM_DB
|
1491
|
+
if single_hash = IBM_DB.fetch_assoc(stmt)
|
1369
1492
|
# Add the record to the +results+ array only from row @offset to @offset + @limit
|
1370
1493
|
if (index >= @offset)
|
1371
1494
|
results << single_hash
|
@@ -1383,7 +1506,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1383
1506
|
results
|
1384
1507
|
# No limits or offsets specified
|
1385
1508
|
else
|
1386
|
-
while single_hash = IBM_DB
|
1509
|
+
while single_hash = IBM_DB.fetch_assoc(stmt)
|
1387
1510
|
# Add the record to the +results+ array
|
1388
1511
|
results << single_hash
|
1389
1512
|
end
|
@@ -1393,21 +1516,21 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1393
1516
|
@limit = nil
|
1394
1517
|
end
|
1395
1518
|
|
1396
|
-
# Fetches all the results available. IBM_DB
|
1519
|
+
# Fetches all the results available. IBM_DB.fetch_array(stmt) returns
|
1397
1520
|
# an array for each single record.
|
1398
1521
|
# The loop stops when there aren't any more valid records to fetch
|
1399
1522
|
def select_rows(sql, name, stmt, results)
|
1400
1523
|
if (!@offset.nil? && @offset >= 0) || (!@limit.nil? && @limit > 0)
|
1401
1524
|
# We know at this point that there is an offset and/or a limit
|
1402
1525
|
# Check if the cursor type is set correctly
|
1403
|
-
cursor_type = IBM_DB
|
1526
|
+
cursor_type = IBM_DB.get_option stmt, IBM_DB::SQL_ATTR_CURSOR_TYPE, 0
|
1404
1527
|
@offset = 0 if @offset.nil?
|
1405
1528
|
if (cursor_type == IBM_DB::SQL_CURSOR_STATIC)
|
1406
1529
|
index = 0
|
1407
1530
|
# Get @limit rows starting at @offset
|
1408
1531
|
while (index < @limit)
|
1409
1532
|
# We increment the offset by 1 because for DB2 the offset of the initial row is 1 instead of 0
|
1410
|
-
if single_array = IBM_DB
|
1533
|
+
if single_array = IBM_DB.fetch_array(stmt, @offset + index + 1)
|
1411
1534
|
# Add the array to the +results+ array
|
1412
1535
|
results << single_array
|
1413
1536
|
index = index + 1
|
@@ -1423,7 +1546,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1423
1546
|
# at @offset to @offset + @limit
|
1424
1547
|
index = 0
|
1425
1548
|
while (index < @offset + @limit)
|
1426
|
-
if single_array = IBM_DB
|
1549
|
+
if single_array = IBM_DB.fetch_array(stmt)
|
1427
1550
|
# Add the array to the +results+ array only from row @offset to @offset + @limit
|
1428
1551
|
if (index >= @offset)
|
1429
1552
|
results << single_array
|
@@ -1441,7 +1564,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1441
1564
|
results
|
1442
1565
|
# No limits or offsets specified
|
1443
1566
|
else
|
1444
|
-
while single_array = IBM_DB
|
1567
|
+
while single_array = IBM_DB.fetch_array(stmt)
|
1445
1568
|
# Add the array to the +results+ array
|
1446
1569
|
results << single_array
|
1447
1570
|
end
|
@@ -1457,14 +1580,14 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1457
1580
|
if (!@offset.nil? && @offset >= 0) || (!@limit.nil? && @limit > 0)
|
1458
1581
|
begin
|
1459
1582
|
# Set the cursor type to static so we can later utilize the offset and limit correctly
|
1460
|
-
if stmt = IBM_DB
|
1583
|
+
if stmt = IBM_DB.exec(@adapter.connection, sql,
|
1461
1584
|
{IBM_DB::SQL_ATTR_CURSOR_TYPE => IBM_DB::SQL_CURSOR_STATIC})
|
1462
1585
|
stmt # Return the statement object
|
1463
1586
|
else
|
1464
|
-
raise StatementInvalid, IBM_DB
|
1587
|
+
raise StatementInvalid, IBM_DB.stmt_errormsg
|
1465
1588
|
end
|
1466
1589
|
rescue StandardError
|
1467
|
-
error_msg = IBM_DB
|
1590
|
+
error_msg = IBM_DB.conn_errormsg ? IBM_DB.conn_errormsg : IBM_DB.stmt_errormsg
|
1468
1591
|
if error_msg && !error_msg.empty?
|
1469
1592
|
raise "Failed to execute statement due to error: #{error_msg}"
|
1470
1593
|
else
|
@@ -1473,13 +1596,13 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1473
1596
|
end
|
1474
1597
|
else
|
1475
1598
|
begin
|
1476
|
-
if stmt = IBM_DB
|
1599
|
+
if stmt = IBM_DB.exec(@adapter.connection, sql)
|
1477
1600
|
stmt # Return the statement object
|
1478
1601
|
else
|
1479
|
-
raise StatementInvalid, IBM_DB
|
1602
|
+
raise StatementInvalid, IBM_DB.stmt_errormsg
|
1480
1603
|
end
|
1481
1604
|
rescue StandardError
|
1482
|
-
error_msg = IBM_DB
|
1605
|
+
error_msg = IBM_DB.conn_errormsg ? IBM_DB.conn_errormsg : IBM_DB.stmt_errormsg
|
1483
1606
|
if error_msg && !error_msg.empty?
|
1484
1607
|
raise "Failed to execute statement due to error: #{error_msg}"
|
1485
1608
|
else
|
@@ -1587,6 +1710,11 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1587
1710
|
super
|
1588
1711
|
end
|
1589
1712
|
end
|
1713
|
+
|
1714
|
+
def change_column_null(table_name, column_name, null, default)
|
1715
|
+
raise NotImplementedError,
|
1716
|
+
"DB2 for zOS data server does not support changing the column's nullability"
|
1717
|
+
end
|
1590
1718
|
end # class IBM_DB2_ZOS
|
1591
1719
|
|
1592
1720
|
class IBM_DB2_ZOS_8 < IBM_DB2_ZOS
|
@@ -1609,6 +1737,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1609
1737
|
raise NotImplementedError,
|
1610
1738
|
"DB2 for zOS data server version 8 does not support changing the column default"
|
1611
1739
|
end
|
1740
|
+
|
1612
1741
|
end # class IBM_DB2_ZOS_8
|
1613
1742
|
|
1614
1743
|
class IBM_DB2_I5 < IBM_DB2
|
@@ -1645,17 +1774,45 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1645
1774
|
# DEFAULT clause
|
1646
1775
|
def change_column_default(table_name, column_name, default)
|
1647
1776
|
sql_type = nil
|
1777
|
+
is_nullable = true
|
1648
1778
|
@adapter.columns(table_name).select do |col|
|
1649
1779
|
if (col.name == column_name)
|
1650
1780
|
sql_type = @adapter.type_to_sql(col.type, col.limit, col.precision, col.scale)
|
1781
|
+
is_nullable = col.null
|
1651
1782
|
end
|
1652
1783
|
end
|
1653
1784
|
# SQL statement which alters column's default value
|
1654
1785
|
change_column_sql = "ALTER TABLE #{table_name} MODIFY #{column_name} #{sql_type} DEFAULT #{@adapter.quote(default)}"
|
1786
|
+
change_column_sql << " NOT NULL" unless is_nullable
|
1655
1787
|
stmt = execute(change_column_sql)
|
1788
|
+
reorg_table(table_name)
|
1656
1789
|
# Ensures to free the resources associated with the statement
|
1657
1790
|
ensure
|
1658
|
-
IBM_DB
|
1791
|
+
IBM_DB.free_result stmt if stmt
|
1792
|
+
end
|
1793
|
+
|
1794
|
+
# IDS specific ALTER TABLE statement to change the nullability of a column
|
1795
|
+
def change_column_null(table_name,column_name,null,default)
|
1796
|
+
if !default.nil?
|
1797
|
+
change_column_default table_name, column_name, default
|
1798
|
+
end
|
1799
|
+
sql_type = nil
|
1800
|
+
@adapter.columns(table_name).select do |col|
|
1801
|
+
if (col.name == column_name)
|
1802
|
+
sql_type = @adapter.type_to_sql(col.type, col.limit, col.precision, col.scale)
|
1803
|
+
end
|
1804
|
+
end
|
1805
|
+
if !null.nil?
|
1806
|
+
if !null
|
1807
|
+
change_column_sql = "ALTER TABLE #{table_name} MODIFY #{column_name} #{sql_type} NOT NULL"
|
1808
|
+
else
|
1809
|
+
change_column_sql = "ALTER TABLE #{table_name} MODIFY #{column_name} #{sql_type}"
|
1810
|
+
end
|
1811
|
+
end
|
1812
|
+
stmt = execute(change_column_sql)
|
1813
|
+
reorg_table(table_name)
|
1814
|
+
ensure
|
1815
|
+
IBM_DB.free_result stmt if stmt
|
1659
1816
|
end
|
1660
1817
|
|
1661
1818
|
# Reorganizes the table for column changes
|
@@ -1675,6 +1832,11 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1675
1832
|
return "datetime hour to second"
|
1676
1833
|
end
|
1677
1834
|
|
1835
|
+
# This method returns the IDS SQL type corresponding to Rails double type
|
1836
|
+
def get_double_mapping
|
1837
|
+
return "double precision"
|
1838
|
+
end
|
1839
|
+
|
1678
1840
|
# Handling offset/limit as per Informix requirements
|
1679
1841
|
def query_offset_limit(sql, offset, limit)
|
1680
1842
|
if limit != 0
|
@@ -1699,7 +1861,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
1699
1861
|
# IDENTITY_VAL_LOCAL function. We used the "stmt" parameter to identify
|
1700
1862
|
# the statement resource from which to get the last generated value
|
1701
1863
|
def last_generated_id(stmt)
|
1702
|
-
IBM_DB
|
1864
|
+
IBM_DB.get_last_serial_value(stmt)
|
1703
1865
|
end
|
1704
1866
|
|
1705
1867
|
# This method throws an error when trying to create a default value on a
|