db2 2.6.1 → 2.6.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,26 +12,26 @@ require 'active_record/connection_adapters/abstract_adapter'
12
12
 
13
13
  module ActiveRecord
14
14
  class Base
15
- # Method required to handle LOBs and XML fields.
15
+ # Method required to handle LOBs and XML fields.
16
16
  # An after save callback checks if a marker has been inserted through
17
- # the insert or update, and then proceeds to update that record with
17
+ # the insert or update, and then proceeds to update that record with
18
18
  # the actual large object through a prepared statement (param binding).
19
19
  after_save :handle_lobs
20
20
  def handle_lobs()
21
21
  if connection.kind_of?(ConnectionAdapters::IBM_DBAdapter)
22
22
  # Checks that the insert or update had at least a BLOB, CLOB or XML field
23
23
  connection.sql.each do |clob_sql|
24
- if clob_sql =~ /BLOB\('(.*)'\)/i ||
25
- clob_sql =~ /@@@IBMTEXT@@@/i ||
24
+ if clob_sql =~ /BLOB\('(.*)'\)/i ||
25
+ clob_sql =~ /@@@IBMTEXT@@@/i ||
26
26
  clob_sql =~ /@@@IBMXML@@@/i ||
27
- clob_sql =~ /@@@IBMBINARY@@@/i
27
+ clob_sql =~ /@@@IBMBINARY@@@/i
28
28
  update_query = "UPDATE #{self.class.table_name} SET ("
29
29
  counter = 0
30
30
  values = []
31
31
  params = []
32
32
  # Selects only binary, text and xml columns
33
- self.class.columns.select{|col| col.type == :binary ||
34
- col.type == :clob ||
33
+ self.class.columns.select{|col| col.type == :binary ||
34
+ col.type == :text ||
35
35
  col.type == :xml}.each do |col|
36
36
  # Adds the selected columns to the query
37
37
  if counter == 0
@@ -40,11 +40,11 @@ module ActiveRecord
40
40
  update_query << ",#{col.name}"
41
41
  end
42
42
 
43
- # Add a '?' for the parameter or a NULL if the value is nil or empty
43
+ # Add a '?' for the parameter or a NULL if the value is nil or empty
44
44
  # (except for a CLOB field where '' can be a value)
45
- if self[col.name].nil? ||
46
- self[col.name] == {} ||
47
- (self[col.name] == '' && col.type != :clob)
45
+ if self[col.name].nil? ||
46
+ self[col.name] == {} ||
47
+ (self[col.name] == '' && col.type != :text)
48
48
  params << 'NULL'
49
49
  else
50
50
  values << self[col.name]
@@ -157,7 +157,7 @@ module ActiveRecord
157
157
  conn_options[IBM_DB::SQL_ATTR_INFO_APPLNAME] = value
158
158
  when :workstation # Set connection's workstation info
159
159
  conn_options[IBM_DB::SQL_ATTR_INFO_WRKSTNNAME] = value
160
- end
160
+ end
161
161
  end
162
162
  end
163
163
 
@@ -171,7 +171,7 @@ module ActiveRecord
171
171
  # A net address connection requires a port. If no port has been specified, 50000 is used by default
172
172
  port = config[:port] || 50000
173
173
  # Connects to the database specified using the hostname, port, authentication type, username and password info
174
- # Starting with DB2 9.1FP5 secure connections using SSL are supported.
174
+ # Starting with DB2 9.1FP5 secure connections using SSL are supported.
175
175
  # On the client side using CLI this is supported from CLI version V95FP2 and onwards.
176
176
  # This feature is set by specifying SECURITY=SSL in the connection string.
177
177
  # Below connection string is constructed and SECURITY parameter is appended if the user has specified the :security option
@@ -185,7 +185,7 @@ module ActiveRecord
185
185
  conn_string << "SECURITY=#{config[:security]};" if config.has_key?(:security)
186
186
  conn_string << "AUTHENTICATION=#{config[:authentication]};" if config.has_key?(:authentication)
187
187
  conn_string << "CONNECTTIMEOUT=#{config[:timeout]};" if config.has_key?(:timeout)
188
-
188
+
189
189
  connection = IBM_DB.connect( conn_string, '', '', conn_options, set_quoted_literal_replacement )
190
190
  else
191
191
  # No host implies a local catalog-based connection: +database+ represents catalog alias
@@ -250,11 +250,13 @@ module ActiveRecord
250
250
  :vargraphic
251
251
  when /graphic/i
252
252
  :graphic
253
+ when /clob|text/i
254
+ :text
253
255
  when /xml/i
254
256
  :xml
255
257
  when /blob|binary/i
256
258
  :binary
257
- when /char|text/i
259
+ when /char/i
258
260
  :string
259
261
  when /boolean/i
260
262
  :boolean
@@ -265,33 +267,33 @@ module ActiveRecord
265
267
  end #class IBM_DBColumn
266
268
 
267
269
  class Table
268
-
270
+
269
271
  #Method to parse the passed arguments and create the ColumnDefinition object of the specified type
270
272
  def ibm_parse_column_attributes_args(type, *args)
271
273
  options = {}
272
- if args.last.is_a?(Hash)
274
+ if args.last.is_a?(Hash)
273
275
  options = args.delete_at(args.length-1)
274
276
  end
275
- args.each do | name |
277
+ args.each do | name |
276
278
  column name,type.to_sym,options
277
279
  end # end args.each
278
280
  end
279
281
  private :ibm_parse_column_attributes_args
280
-
281
- #Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type xml
282
- #This method is different as compared to def char (sql is being issued explicitly
282
+
283
+ #Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type xml
284
+ #This method is different as compared to def char (sql is being issued explicitly
283
285
  #as compared to def char where method column(which will generate the sql is being called)
284
286
  #in order to handle the DEFAULT and NULL option for the native XML datatype
285
- def xml(*args )
287
+ def xml(*args )
286
288
  options = {}
287
- if args.last.is_a?(Hash)
289
+ if args.last.is_a?(Hash)
288
290
  options = args.delete_at(args.length-1)
289
291
  end
290
292
  sql_segment = "ALTER TABLE #{@base.quote_table_name(@table_name)} ADD COLUMN "
291
- args.each do | name |
293
+ args.each do | name |
292
294
  sql = sql_segment + " #{@base.quote_column_name(name)} xml"
293
295
  @base.execute(sql,"add_xml_column")
294
- end
296
+ end
295
297
  return self
296
298
  end
297
299
 
@@ -331,7 +333,7 @@ module ActiveRecord
331
333
  end
332
334
 
333
335
  class TableDefinition
334
-
336
+
335
337
  #Method to parse the passed arguments and create the ColumnDefinition object of the specified type
336
338
  def ibm_parse_column_attributes_args(type, *args)
337
339
  options = {}
@@ -344,7 +346,7 @@ module ActiveRecord
344
346
  end
345
347
  private :ibm_parse_column_attributes_args
346
348
 
347
- #Method to support the new syntax of rails 2.0 migrations for columns of type xml
349
+ #Method to support the new syntax of rails 2.0 migrations for columns of type xml
348
350
  def xml(*args )
349
351
  ibm_parse_column_attributes_args('xml', *args)
350
352
  return self
@@ -388,7 +390,7 @@ module ActiveRecord
388
390
  # The IBM_DB Adapter requires the native Ruby driver (ibm_db)
389
391
  # for IBM data servers (ibm_db.so).
390
392
  # +config+ the hash passed as an initializer argument content:
391
- # == mandatory parameters
393
+ # == mandatory parameters
392
394
  # adapter: 'ibm_db' // IBM_DB Adapter name
393
395
  # username: 'db2user' // data server (database) user
394
396
  # password: 'secret' // data server (database) password
@@ -404,17 +406,17 @@ module ActiveRecord
404
406
  # port: '50000' // data server TCP/IP port number
405
407
  # security: 'SSL' // optional parameter enabling SSL encryption -
406
408
  # // - Available only from CLI version V95fp2 and above
407
- # authentication: 'SERVER' // AUTHENTICATION type which the client uses -
409
+ # authentication: 'SERVER' // AUTHENTICATION type which the client uses -
408
410
  # // - to connect to the database server. By default value is SERVER
409
411
  # timeout: 10 // Specifies the time in seconds (0 - 32767) to wait for a reply from server -
410
412
  # //- when trying to establish a connection before generating a timeout
411
413
  # == Parameterized Queries Support
412
- # parameterized: false // Specifies if the prepared statement support of
414
+ # parameterized: false // Specifies if the prepared statement support of
413
415
  # //- the IBM_DB Adapter is to be turned on or off
414
- #
416
+ #
415
417
  # When schema is not specified, the username value is used instead.
416
418
  # The default setting of parameterized is false.
417
- #
419
+ #
418
420
  class IBM_DBAdapter < AbstractAdapter
419
421
  attr_reader :connection, :servertype
420
422
  attr_accessor :sql,:handle_lobs_triggered, :sql_parameter_values
@@ -449,14 +451,14 @@ module ActiveRecord
449
451
  @pstmt_support_on = false
450
452
  @set_quoted_literal_replacement = IBM_DB::QUOTED_LITERAL_REPLACEMENT_ON
451
453
  end
452
-
454
+
453
455
  @app_user = @account = @application = @workstation = nil
454
456
  # Caching database connection options (auditing and billing support)
455
457
  @app_user = conn_options[:app_user] if conn_options.has_key?(:app_user)
456
458
  @account = conn_options[:account] if conn_options.has_key?(:account)
457
459
  @application = conn_options[:application] if conn_options.has_key?(:application)
458
460
  @workstation = conn_options[:workstation] if conn_options.has_key?(:workstation)
459
-
461
+
460
462
  @sql = []
461
463
  @sql_parameter_values = [] #Used only if pstmt support is turned on
462
464
 
@@ -571,7 +573,7 @@ module ActiveRecord
571
573
  end
572
574
 
573
575
  # This Adapter supports DDL transactions.
574
- # This means CREATE TABLE and other DDL statements can be carried out as a transaction.
576
+ # This means CREATE TABLE and other DDL statements can be carried out as a transaction.
575
577
  # That is the statements executed can be ROLLED BACK in case of any error during the process.
576
578
  def supports_ddl_transactions?
577
579
  true
@@ -649,9 +651,9 @@ module ActiveRecord
649
651
  def create_table(name, options = {})
650
652
  @servertype.setup_for_lob_table
651
653
  super
652
-
654
+
653
655
  #Table definition is complete only when a unique index is created on the primarykey column for DB2 V8 on zOS
654
-
656
+
655
657
  #create index on id column if options[:id] is nil or id ==true
656
658
  #else check if options[:primary_key]is not nil then create an unique index on that column
657
659
  if !options[:id].nil? || !options[:primary_key].nil?
@@ -662,11 +664,11 @@ module ActiveRecord
662
664
  end
663
665
  else
664
666
  @servertype.create_index_after_table(name,"id")
665
- end
667
+ end
666
668
  end
667
669
 
668
670
  # Returns an array of hashes with the column names as keys and
669
- # column values as values. +sql+ is the select query,
671
+ # column values as values. +sql+ is the select query,
670
672
  # and +name+ is an optional description for logging
671
673
  def prepared_select(sql_param_hash, name = nil)
672
674
  # Replaces {"= NULL" with " IS NULL"} OR {"IN (NULL)" with " IS NULL"}
@@ -697,7 +699,7 @@ module ActiveRecord
697
699
  end
698
700
 
699
701
  # Returns an array of hashes with the column names as keys and
700
- # column values as values. +sql+ is the select query,
702
+ # column values as values. +sql+ is the select query,
701
703
  # and +name+ is an optional description for logging
702
704
  def prepared_select_values(sql_param_hash, name = nil)
703
705
  # Replaces {"= NULL" with " IS NULL"} OR {"IN (NULL)" with " IS NULL"}
@@ -733,12 +735,12 @@ module ActiveRecord
733
735
  end
734
736
 
735
737
  # Returns an array of hashes with the column names as keys and
736
- # column values as values. +sql+ is the select query,
738
+ # column values as values. +sql+ is the select query,
737
739
  # and +name+ is an optional description for logging
738
740
  def select(sql, name = nil)
739
741
  # Replaces {"= NULL" with " IS NULL"} OR {"IN (NULL)" with " IS NULL"}
740
742
  sql.gsub!( /(=\s*NULL|IN\s*\(NULL\))/i, " IS NULL" )
741
-
743
+
742
744
  results = []
743
745
  # Invokes the method +execute+ in order to log and execute the SQL
744
746
  # IBM_DB.Statement is returned from which results can be fetched
@@ -770,7 +772,7 @@ module ActiveRecord
770
772
  def select_rows(sql, name = nil)
771
773
  # Replaces {"= NULL" with " IS NULL"} OR {"IN (NULL)" with " IS NULL"}
772
774
  sql.gsub!( /(=\s*NULL|IN\s*\(NULL\))/i, " IS NULL" )
773
-
775
+
774
776
  results = []
775
777
  # Invokes the method +execute+ in order to log and execute the SQL
776
778
  # IBM_DB.Statement is returned from which results can be fetched
@@ -824,25 +826,25 @@ module ActiveRecord
824
826
  break
825
827
  end
826
828
  end
827
- if item.at(1).nil? ||
828
- item.at(1) == {} ||
829
- (item.at(1) == '' && !(col.type.to_sym == :clob))
830
-
829
+ if item.at(1).nil? ||
830
+ item.at(1) == {} ||
831
+ (item.at(1) == '' && !(col.type.to_sym == :text))
832
+
831
833
  params << 'NULL'
832
-
834
+
833
835
  elsif col.type.to_sym == :xml ||
834
- col.type.to_sym == :clob ||
835
- col.type.to_sym == :binary
836
- # Add a '?' for the parameter or a NULL if the value is nil or empty
836
+ col.type.to_sym == :text ||
837
+ col.type.to_sym == :binary
838
+ # Add a '?' for the parameter or a NULL if the value is nil or empty
837
839
  # (except for a CLOB field where '' can be a value)
838
840
  insert_values << item.at(1)
839
841
  params << '?'
840
842
  else
841
843
  insert_values << quote(item.at(1),col)
842
844
  params << '?'
843
- end
845
+ end
844
846
  end
845
-
847
+
846
848
  insert_query << " VALUES ("+ params.join(',') + ")"
847
849
  unless stmt = IBM_DB.prepare(@connection, insert_query)
848
850
  error_msg = IBM_DB.getErrormsg( @connection, IBM_DB::DB_CONN )
@@ -852,7 +854,7 @@ module ActiveRecord
852
854
  raise StandardError.new('An unexpected error occurred during preparing SQL for fixture insert')
853
855
  end
854
856
  end
855
-
857
+
856
858
  #log_query(insert_query,'fixture insert')
857
859
  log(insert_query,'fixture insert') do
858
860
  unless IBM_DB.execute(stmt, insert_values)
@@ -964,7 +966,7 @@ module ActiveRecord
964
966
  end
965
967
 
966
968
  clear_query_cache if defined? clear_query_cache
967
-
969
+
968
970
  # Make sure the WHERE clause handles NULL's correctly
969
971
  sqlarray = sql.split(/\s*WHERE\s*/)
970
972
  size = sqlarray.size
@@ -1141,7 +1143,7 @@ module ActiveRecord
1141
1143
  "'#{value}'"
1142
1144
  else
1143
1145
  "#{value}"
1144
- end
1146
+ end
1145
1147
  else
1146
1148
  # value is Numeric, column.type is not a string,
1147
1149
  # therefore it converts the number to string without quoting it
@@ -1157,7 +1159,7 @@ module ActiveRecord
1157
1159
  # Quoting required for the default value of a column
1158
1160
  @servertype.set_binary_default(value)
1159
1161
  end
1160
- elsif column && column.type.to_sym == :clob
1162
+ elsif column && column.type.to_sym == :text
1161
1163
  unless caller[0] =~ /add_column_options/i
1162
1164
  "'@@@IBMTEXT@@@'"
1163
1165
  else
@@ -1174,7 +1176,7 @@ module ActiveRecord
1174
1176
  "'#{quote_string(value)}'"
1175
1177
  else
1176
1178
  "#{value}"
1177
- end
1179
+ end
1178
1180
  end
1179
1181
  when TrueClass then quoted_true # return '1' for true
1180
1182
  when FalseClass then quoted_false # return '0' for false
@@ -1212,8 +1214,7 @@ module ActiveRecord
1212
1214
  {
1213
1215
  :primary_key => { :name => @servertype.primary_key_definition(@start_id)},
1214
1216
  :string => { :name => "varchar", :limit => 255 },
1215
- :text => { :name => "varchar", :limit => 32672 },
1216
- :clob => { :name => "clob" },
1217
+ :text => { :name => "clob" },
1217
1218
  :integer => { :name => "integer" },
1218
1219
  :float => { :name => "float" },
1219
1220
  :datetime => { :name => @servertype.get_datetime_mapping },
@@ -1247,7 +1248,7 @@ module ActiveRecord
1247
1248
  sql_segment << "(#{precision})" if !precision.nil?
1248
1249
  return sql_segment
1249
1250
  end
1250
-
1251
+
1251
1252
  return super if limit.nil?
1252
1253
 
1253
1254
  # strip off limits on data types not supporting them
@@ -1258,7 +1259,7 @@ module ActiveRecord
1258
1259
  else
1259
1260
  return super
1260
1261
  end
1261
- end
1262
+ end
1262
1263
 
1263
1264
  # Returns the maximum length a table alias identifier can be.
1264
1265
  # IBM data servers (cross-platform) table limit is 128 characters
@@ -1306,10 +1307,10 @@ module ActiveRecord
1306
1307
  # Returns the primary key of the mentioned table
1307
1308
  def primary_key(table_name)
1308
1309
  pk_name = nil
1309
- stmt = IBM_DB.primary_keys( @connection, nil,
1310
- @servertype.set_case(@schema),
1310
+ stmt = IBM_DB.primary_keys( @connection, nil,
1311
+ @servertype.set_case(@schema),
1311
1312
  @servertype.set_case(table_name))
1312
- if(stmt)
1313
+ if(stmt)
1313
1314
  begin
1314
1315
  if ( pk_index_row = IBM_DB.fetch_array(stmt) )
1315
1316
  pk_name = pk_index_row[3].downcase
@@ -1348,27 +1349,27 @@ module ActiveRecord
1348
1349
  indexes = []
1349
1350
  pk_index = nil
1350
1351
  index_schema = []
1351
-
1352
+
1352
1353
  #fetch the primary keys of the table using function primary_keys
1353
1354
  #TABLE_SCHEM:: pk_index[1]
1354
1355
  #TABLE_NAME:: pk_index[2]
1355
1356
  #COLUMN_NAME:: pk_index[3]
1356
1357
  #PK_NAME:: pk_index[5]
1357
- stmt = IBM_DB.primary_keys( @connection, nil,
1358
- @servertype.set_case(@schema),
1358
+ stmt = IBM_DB.primary_keys( @connection, nil,
1359
+ @servertype.set_case(@schema),
1359
1360
  @servertype.set_case(table_name))
1360
1361
  if(stmt)
1361
1362
  begin
1362
1363
  while ( pk_index_row = IBM_DB.fetch_array(stmt) )
1363
- if pk_index_row[5]
1364
+ if pk_index_row[5]
1364
1365
  pk_index_name = pk_index_row[5].downcase
1365
1366
  pk_index_columns = [pk_index_row[3].downcase] # COLUMN_NAME
1366
- if pk_index
1367
+ if pk_index
1367
1368
  pk_index.columns = pk_index.columns + pk_index_columns
1368
1369
  else
1369
1370
  pk_index = IndexDefinition.new(table_name, pk_index_name, true, pk_index_columns)
1370
1371
  end
1371
- end
1372
+ end
1372
1373
  end
1373
1374
  rescue StandardError => fetch_error # Handle driver fetch errors
1374
1375
  error_msg = IBM_DB.getErrormsg(stmt, IBM_DB::DB_STMT )
@@ -1396,8 +1397,8 @@ module ActiveRecord
1396
1397
  # "NON_UNIQUE: #{index_stats[3]}"
1397
1398
  # "INDEX_NAME: #{index_stats[5]}"
1398
1399
  # "COLUMN_NAME: #{index_stats[8]}"
1399
- stmt = IBM_DB.statistics( @connection, nil,
1400
- @servertype.set_case(@schema),
1400
+ stmt = IBM_DB.statistics( @connection, nil,
1401
+ @servertype.set_case(@schema),
1401
1402
  @servertype.set_case(table_name), 1 )
1402
1403
  if(stmt)
1403
1404
  begin
@@ -1414,14 +1415,14 @@ module ActiveRecord
1414
1415
  if index.name == index_name && index_schema[i] == index_qualifier
1415
1416
  index.columns = index.columns + index_columns
1416
1417
  is_composite = true
1417
- end
1418
+ end
1418
1419
  i = i+1
1419
1420
  end
1420
-
1421
- unless is_composite
1421
+
1422
+ unless is_composite
1422
1423
  indexes << IndexDefinition.new(table_name, index_name, index_unique, index_columns)
1423
1424
  index_schema << index_qualifier
1424
- end
1425
+ end
1425
1426
  end
1426
1427
  end
1427
1428
  rescue StandardError => fetch_error # Handle driver fetch errors
@@ -1444,16 +1445,16 @@ module ActiveRecord
1444
1445
  raise StandardError.new('An unexpected error occurred during index retrieval')
1445
1446
  end
1446
1447
  end
1447
-
1448
+
1448
1449
  # remove the primary key index entry.... should not be dumped by the dumper
1449
-
1450
+
1450
1451
  i = 0
1451
1452
  indexes.each do |index|
1452
1453
  if pk_index && index.columns == pk_index.columns
1453
1454
  indexes.delete_at(i)
1454
1455
  end
1455
1456
  i = i+1
1456
- end
1457
+ end
1457
1458
  # Returns the indexes array
1458
1459
  return indexes
1459
1460
  end
@@ -1468,8 +1469,8 @@ module ActiveRecord
1468
1469
  # +columns+ will contain the resulting array
1469
1470
  columns = []
1470
1471
  # Statement required to access all the columns information
1471
- stmt = IBM_DB.columns( @connection, nil,
1472
- @servertype.set_case(@schema),
1472
+ stmt = IBM_DB.columns( @connection, nil,
1473
+ @servertype.set_case(@schema),
1473
1474
  @servertype.set_case(table_name) )
1474
1475
  if(stmt)
1475
1476
  begin
@@ -1488,13 +1489,13 @@ module ActiveRecord
1488
1489
  # Assigns the field length (size) for the column
1489
1490
  column_length = col["column_size"]
1490
1491
  column_scale = col["decimal_digits"]
1491
- # The initializer of the class Column, requires the +column_length+ to be declared
1492
- # between brackets after the datatype(e.g VARCHAR(50)) for :string and :text types.
1492
+ # The initializer of the class Column, requires the +column_length+ to be declared
1493
+ # between brackets after the datatype(e.g VARCHAR(50)) for :string and :text types.
1493
1494
  # If it's a "for bit data" field it does a subsitution in place, if not
1494
1495
  # it appends the (column_length) string on the supported data types
1495
- unless column_length.nil? ||
1496
- column_length == '' ||
1497
- column_type.sub!(/ \(\) for bit data/i,"(#{column_length}) FOR BIT DATA") ||
1496
+ unless column_length.nil? ||
1497
+ column_length == '' ||
1498
+ column_type.sub!(/ \(\) for bit data/i,"(#{column_length}) FOR BIT DATA") ||
1498
1499
  !column_type =~ /char|lob|graphic/i
1499
1500
  if column_type =~ /decimal/i
1500
1501
  column_type << "(#{column_length},#{column_scale})"
@@ -1577,25 +1578,25 @@ module ActiveRecord
1577
1578
  #overrides the abstract adapter method to generate proper sql
1578
1579
  #specifying the column options, like default value and nullability clause
1579
1580
  def add_column_options!(sql,options={})
1580
- #add default null option only if :default option is not specified and
1581
+ #add default null option only if :default option is not specified and
1581
1582
  #:null option is not specified or is true
1582
1583
  if (options[:default].nil? && (options[:null].nil? || options[:null] == true))
1583
1584
  sql << " DEFAULT NULL"
1584
- else
1585
+ else
1585
1586
  if( !options[:default].nil?)
1586
1587
  #check, :column option is passed only in case of create_table but not in case of add_column
1587
- if (!options[:column].nil?)
1588
+ if (!options[:column].nil?)
1588
1589
  sql << " DEFAULT #{quote(options[:default],options[:column])}"
1589
1590
  else
1590
- sql << " DEFAULT #{quote(options[:default])}"
1591
- end
1592
- end
1591
+ sql << " DEFAULT #{quote(options[:default])}"
1592
+ end
1593
+ end
1593
1594
  #append NOT NULL to sql only---
1594
1595
  #---if options[:null] is not nil and is equal to false
1595
- unless options[:null] == nil
1596
+ unless options[:null] == nil
1596
1597
  sql << " NOT NULL" if (options[:null] == false)
1597
1598
  end
1598
- end
1599
+ end
1599
1600
  end
1600
1601
  =end
1601
1602
 
@@ -1664,7 +1665,7 @@ module ActiveRecord
1664
1665
  rescue StandardError => exec_err
1665
1666
  # Provide details on the current XML columns support
1666
1667
  if exec_err.message.include?('SQLCODE=-1242') && exec_err.message.include?('42997')
1667
- raise StatementInvalid,
1668
+ raise StatementInvalid,
1668
1669
  "A column that is part of a table containing an XML column cannot be dropped. \
1669
1670
  To remove the column, the table must be dropped and recreated without the #{column_name} column: #{exec_err}"
1670
1671
  else
@@ -1727,7 +1728,7 @@ To remove the column, the table must be dropped and recreated without the #{colu
1727
1728
  rescue StandardError => prep_err
1728
1729
  if prep_err && !prep_err.message.empty?
1729
1730
  raise "Failed to prepare sql #{sql} due to: #{prep_err}"
1730
- else
1731
+ else
1731
1732
  raise
1732
1733
  end
1733
1734
  end
@@ -1743,7 +1744,7 @@ To remove the column, the table must be dropped and recreated without the #{colu
1743
1744
  rescue StandardError => exec_err
1744
1745
  if exec_err && !exec_err.message.empty?
1745
1746
  raise "Failed to execute statement due to: #{exec_err}"
1746
- else
1747
+ else
1747
1748
  raise
1748
1749
  end
1749
1750
  end
@@ -1758,7 +1759,7 @@ To remove the column, the table must be dropped and recreated without the #{colu
1758
1759
 
1759
1760
  def query_offset_limit!(sql, offset, limit, options)
1760
1761
  end
1761
-
1762
+
1762
1763
  def get_datetime_mapping
1763
1764
  end
1764
1765
 
@@ -1767,13 +1768,13 @@ To remove the column, the table must be dropped and recreated without the #{colu
1767
1768
 
1768
1769
  def get_double_mapping
1769
1770
  end
1770
-
1771
+
1771
1772
  def change_column_default(table_name, column_name, default)
1772
1773
  end
1773
1774
 
1774
1775
  def change_column_null(table_name, column_name, null, default)
1775
1776
  end
1776
-
1777
+
1777
1778
  def set_binary_default(value)
1778
1779
  end
1779
1780
 
@@ -1857,7 +1858,7 @@ To remove the column, the table must be dropped and recreated without the #{colu
1857
1858
  execute "ALTER TABLE #{table_name} ALTER #{column_name} SET DATA TYPE #{data_type}"
1858
1859
  rescue StandardError => exec_err
1859
1860
  if exec_err.message.include?('SQLCODE=-190')
1860
- raise StatementInvalid,
1861
+ raise StatementInvalid,
1861
1862
  "Please consult documentation for compatible data types while changing column datatype. \
1862
1863
  The column datatype change to [#{data_type}] is not supported by this data server: #{exec_err}"
1863
1864
  else
@@ -1886,9 +1887,9 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
1886
1887
  def change_column_null(table_name, column_name, null, default)
1887
1888
  if !default.nil?
1888
1889
  change_column_default(table_name, column_name, default)
1889
- end
1890
+ end
1890
1891
 
1891
- if !null.nil?
1892
+ if !null.nil?
1892
1893
  if null
1893
1894
  change_column_sql = "ALTER TABLE #{table_name} ALTER #{column_name} DROP NOT NULL"
1894
1895
  else
@@ -1899,9 +1900,9 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
1899
1900
  end
1900
1901
 
1901
1902
  ensure
1902
- IBM_DB.free_stmt(stmt) if stmt
1903
+ IBM_DB.free_stmt(stmt) if stmt
1903
1904
  end
1904
-
1905
+
1905
1906
  # This method returns the DB2 SQL type corresponding to the Rails
1906
1907
  # datetime/timestamp type
1907
1908
  def get_datetime_mapping
@@ -1940,13 +1941,13 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
1940
1941
  index = index + 1
1941
1942
  else
1942
1943
  # break from the while loop
1943
- break
1944
+ break
1944
1945
  end
1945
1946
  end
1946
1947
  else # cursor != IBM_DB::SQL_CURSOR_STATIC
1947
1948
  # If the result set contains a LOB, the cursor type will never be SQL_CURSOR_STATIC
1948
- # because DB2 does not allow this. We can't use the offset mechanism because the cursor
1949
- # is not scrollable. In this case, ignore first @offset rows and return rows starting
1949
+ # because DB2 does not allow this. We can't use the offset mechanism because the cursor
1950
+ # is not scrollable. In this case, ignore first @offset rows and return rows starting
1950
1951
  # at @offset to @offset + @limit
1951
1952
  index = 0
1952
1953
  while (index < @offset + @limit)
@@ -2010,13 +2011,13 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2010
2011
  index = index + 1
2011
2012
  else
2012
2013
  # break from the while loop
2013
- break
2014
+ break
2014
2015
  end
2015
2016
  end
2016
2017
  else # cursor != IBM_DB::SQL_CURSOR_STATIC
2017
2018
  # If the result set contains a LOB, the cursor type will never be SQL_CURSOR_STATIC
2018
- # because DB2 does not allow this. We can't use the offset mechanism because the cursor
2019
- # is not scrollable. In this case, ignore first @offset rows and return rows starting
2019
+ # because DB2 does not allow this. We can't use the offset mechanism because the cursor
2020
+ # is not scrollable. In this case, ignore first @offset rows and return rows starting
2020
2021
  # at @offset to @offset + @limit
2021
2022
  index = 0
2022
2023
  while (index < @offset + @limit)
@@ -2066,7 +2067,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2066
2067
  begin
2067
2068
  if (!@offset.nil? && @offset >= 0) || (!@limit.nil? && @limit > 0)
2068
2069
  # Set the cursor type to static so we can later utilize the offset and limit correctly
2069
- if stmt = IBM_DB.prepare(@adapter.connection, sql,
2070
+ if stmt = IBM_DB.prepare(@adapter.connection, sql,
2070
2071
  {IBM_DB::SQL_ATTR_CURSOR_TYPE => IBM_DB::SQL_CURSOR_STATIC})
2071
2072
  stmt # Return the statement object
2072
2073
  else
@@ -2081,7 +2082,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2081
2082
  end
2082
2083
  rescue StandardError => prep_err
2083
2084
  error_msg = "Failed to prepare sql #{sql}"
2084
- error_msg = error_msg + ": #{prep_err.message}" if !prep_err.message.empty?
2085
+ error_msg = error_msg + ": #{prep_err.message}" if !prep_err.message.empty?
2085
2086
  raise error_msg
2086
2087
  end
2087
2088
  end
@@ -2093,7 +2094,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2093
2094
  begin
2094
2095
  if (!@offset.nil? && @offset >= 0) || (!@limit.nil? && @limit > 0)
2095
2096
  # Set the cursor type to static so we can later utilize the offset and limit correctly
2096
- if stmt = IBM_DB.exec(@adapter.connection, sql,
2097
+ if stmt = IBM_DB.exec(@adapter.connection, sql,
2097
2098
  {IBM_DB::SQL_ATTR_CURSOR_TYPE => IBM_DB::SQL_CURSOR_STATIC})
2098
2099
  stmt # Return the statement object
2099
2100
  else
@@ -2108,7 +2109,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2108
2109
  end
2109
2110
  rescue StandardError => exec_err
2110
2111
  error_msg = "Failed to execute statement"
2111
- error_msg = error_msg + ": #{exec_err.message}" if !exec_err.message.empty?
2112
+ error_msg = error_msg + ": #{exec_err.message}" if !exec_err.message.empty?
2112
2113
  raise error_msg
2113
2114
  end
2114
2115
  end
@@ -2130,7 +2131,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2130
2131
  options[:paramArray] = []
2131
2132
  end
2132
2133
 
2133
- # This method generates the default blob value specified for
2134
+ # This method generates the default blob value specified for
2134
2135
  # DB2 Dataservers
2135
2136
  def set_binary_default(value)
2136
2137
  "BLOB('#{value}')"
@@ -2138,10 +2139,10 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2138
2139
 
2139
2140
  # This method generates the blob value specified for DB2 Dataservers
2140
2141
  def set_binary_value
2141
- "BLOB('?')"
2142
+ "BLOB('?')"
2142
2143
  end
2143
2144
 
2144
- # This method generates the default clob value specified for
2145
+ # This method generates the default clob value specified for
2145
2146
  # DB2 Dataservers
2146
2147
  def set_text_default(value)
2147
2148
  "'#{value}'"
@@ -2196,7 +2197,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2196
2197
  end # class IBM_DB2_LUW
2197
2198
 
2198
2199
  class IBM_DB2_LUW_COBRA < IBM_DB2_LUW
2199
- # Cobra supports parameterised timestamp,
2200
+ # Cobra supports parameterised timestamp,
2200
2201
  # hence overriding following method to allow timestamp datatype to be parameterised
2201
2202
  def limit_not_supported_types
2202
2203
  [:integer, :double, :date, :time, :xml, :bigint]
@@ -2210,8 +2211,8 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2210
2211
  _new_column_name = new_column_name.to_s
2211
2212
 
2212
2213
  nil_condition = _table_name.nil? || _column_name.nil? || _new_column_name.nil?
2213
- empty_condition = _table_name.empty? ||
2214
- _column_name.empty? ||
2214
+ empty_condition = _table_name.empty? ||
2215
+ _column_name.empty? ||
2215
2216
  _new_column_name.empty? unless nil_condition
2216
2217
 
2217
2218
  if nil_condition || empty_condition
@@ -2258,15 +2259,15 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2258
2259
  end # module HostedDataServer
2259
2260
 
2260
2261
  class IBM_DB2_ZOS < IBM_DB2
2261
- # since v9 doesn't need, suggest putting it in HostedDataServer?
2262
+ # since v9 doesn't need, suggest putting it in HostedDataServer?
2262
2263
  def create_index_after_table(table_name,column_name)
2263
- @adapter.add_index(table_name, column_name, :unique => true)
2264
+ @adapter.add_index(table_name, column_name, :unique => true)
2264
2265
  end
2265
2266
 
2266
2267
  def remove_column(table_name, column_name)
2267
2268
  raise NotImplementedError,
2268
2269
  "remove_column is not supported by the DB2 for zOS data server"
2269
- end
2270
+ end
2270
2271
 
2271
2272
  #Alter table column for renaming a column
2272
2273
  def rename_column(table_name, column_name, new_column_name)
@@ -2275,8 +2276,8 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2275
2276
  _new_column_name = new_column_name.to_s
2276
2277
 
2277
2278
  nil_condition = _table_name.nil? || _column_name.nil? || _new_column_name.nil?
2278
- empty_condition = _table_name.empty? ||
2279
- _column_name.empty? ||
2279
+ empty_condition = _table_name.empty? ||
2280
+ _column_name.empty? ||
2280
2281
  _new_column_name.empty? unless nil_condition
2281
2282
 
2282
2283
  if nil_condition || empty_condition
@@ -2303,7 +2304,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2303
2304
  end #End of begin
2304
2305
  end # End of rename_column
2305
2306
 
2306
- # DB2 z/OS only allows NULL or "" (empty) string as DEFAULT value for a BLOB column.
2307
+ # DB2 z/OS only allows NULL or "" (empty) string as DEFAULT value for a BLOB column.
2307
2308
  # For non-empty string and non-NULL values, the server returns error
2308
2309
  def set_binary_default(value)
2309
2310
  "#{value}"
@@ -2343,9 +2344,9 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2343
2344
  raise NotImplementedError,
2344
2345
  "DB2 for zOS data server version 8 does not support changing the column default"
2345
2346
  end
2346
-
2347
+
2347
2348
  end # class IBM_DB2_ZOS_8
2348
-
2349
+
2349
2350
  class IBM_DB2_I5 < IBM_DB2
2350
2351
  include HostedDataServer
2351
2352
  end # class IBM_DB2_I5
@@ -2362,8 +2363,8 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2362
2363
  _new_column_name = new_column_name.to_s
2363
2364
 
2364
2365
  nil_condition = _table_name.nil? || _column_name.nil? || _new_column_name.nil?
2365
- empty_condition = _table_name.empty? ||
2366
- _column_name.empty? ||
2366
+ empty_condition = _table_name.empty? ||
2367
+ _column_name.empty? ||
2367
2368
  _new_column_name.empty? unless nil_condition
2368
2369
 
2369
2370
  if nil_condition || empty_condition
@@ -2398,8 +2399,8 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2398
2399
  if !options[:null].nil? && !options[:null]
2399
2400
  execute "ALTER TABLE #{table_name} MODIFY #{column_name} #{@adapter.type_to_sql(type, options[:limit], options[:precision], options[:scale])} NOT NULL"
2400
2401
  else
2401
- execute "ALTER TABLE #{table_name} MODIFY #{column_name} #{@adapter.type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
2402
- end
2402
+ execute "ALTER TABLE #{table_name} MODIFY #{column_name} #{@adapter.type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
2403
+ end
2403
2404
  if !options[:default].nil?
2404
2405
  change_column_default(table_name, column_name, options[:default])
2405
2406
  end
@@ -2407,20 +2408,20 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2407
2408
  end
2408
2409
 
2409
2410
  # IDS specific ALTER TABLE statement to add a default clause
2410
- # IDS requires the data type to be explicitly specified when adding the
2411
+ # IDS requires the data type to be explicitly specified when adding the
2411
2412
  # DEFAULT clause
2412
2413
  def change_column_default(table_name, column_name, default)
2413
2414
  sql_type = nil
2414
2415
  is_nullable = true
2415
- @adapter.columns(table_name).select do |col|
2416
+ @adapter.columns(table_name).select do |col|
2416
2417
  if (col.name == column_name)
2417
2418
  sql_type = @adapter.type_to_sql(col.type, col.limit, col.precision, col.scale)
2418
- is_nullable = col.null
2419
+ is_nullable = col.null
2419
2420
  end
2420
2421
  end
2421
2422
  # SQL statement which alters column's default value
2422
2423
  change_column_sql = "ALTER TABLE #{table_name} MODIFY #{column_name} #{sql_type} DEFAULT #{@adapter.quote(default)}"
2423
- change_column_sql << " NOT NULL" unless is_nullable
2424
+ change_column_sql << " NOT NULL" unless is_nullable
2424
2425
  stmt = execute(change_column_sql)
2425
2426
  reorg_table(table_name)
2426
2427
  # Ensures to free the resources associated with the statement
@@ -2434,7 +2435,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2434
2435
  change_column_default table_name, column_name, default
2435
2436
  end
2436
2437
  sql_type = nil
2437
- @adapter.columns(table_name).select do |col|
2438
+ @adapter.columns(table_name).select do |col|
2438
2439
  if (col.name == column_name)
2439
2440
  sql_type = @adapter.type_to_sql(col.type, col.limit, col.precision, col.scale)
2440
2441
  end
@@ -2443,7 +2444,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2443
2444
  if !null
2444
2445
  change_column_sql = "ALTER TABLE #{table_name} MODIFY #{column_name} #{sql_type} NOT NULL"
2445
2446
  else
2446
- change_column_sql = "ALTER TABLE #{table_name} MODIFY #{column_name} #{sql_type}"
2447
+ change_column_sql = "ALTER TABLE #{table_name} MODIFY #{column_name} #{sql_type}"
2447
2448
  end
2448
2449
  stmt = execute(change_column_sql)
2449
2450
  reorg_table(table_name)
@@ -2510,17 +2511,17 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2510
2511
  end
2511
2512
 
2512
2513
  # Method that returns the last automatically generated ID
2513
- # on the given +@connection+. This method is required by the +insert+
2514
- # method. IDS returns the last generated serial value in the SQLCA unlike
2515
- # DB2 where the generated value has to be retrieved using the
2516
- # IDENTITY_VAL_LOCAL function. We used the "stmt" parameter to identify
2514
+ # on the given +@connection+. This method is required by the +insert+
2515
+ # method. IDS returns the last generated serial value in the SQLCA unlike
2516
+ # DB2 where the generated value has to be retrieved using the
2517
+ # IDENTITY_VAL_LOCAL function. We used the "stmt" parameter to identify
2517
2518
  # the statement resource from which to get the last generated value
2518
2519
  def last_generated_id(stmt)
2519
2520
  IBM_DB.get_last_serial_value(stmt)
2520
2521
  end
2521
2522
 
2522
- # This method throws an error when trying to create a default value on a
2523
- # BLOB/CLOB column for IDS. The documentation states: "if the column is a
2523
+ # This method throws an error when trying to create a default value on a
2524
+ # BLOB/CLOB column for IDS. The documentation states: "if the column is a
2524
2525
  # BLOB or CLOB datatype, NULL is the only valid default value."
2525
2526
  def set_binary_default(value)
2526
2527
  unless (value == 'NULL')
@@ -2528,15 +2529,15 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2528
2529
  end
2529
2530
  end
2530
2531
 
2531
- # For Informix Dynamic Server, we treat binary value same as we treat a
2532
- # text value. We support literals by converting the insert into a dummy
2532
+ # For Informix Dynamic Server, we treat binary value same as we treat a
2533
+ # text value. We support literals by converting the insert into a dummy
2533
2534
  # insert and an update (See handle_lobs method above)
2534
2535
  def set_binary_value
2535
2536
  "'@@@IBMBINARY@@@'"
2536
2537
  end
2537
2538
 
2538
- # This method throws an error when trying to create a default value on a
2539
- # BLOB/CLOB column for IDS. The documentation states: "if the column is
2539
+ # This method throws an error when trying to create a default value on a
2540
+ # BLOB/CLOB column for IDS. The documentation states: "if the column is
2540
2541
  # a BLOB or CLOB datatype, NULL is the only valid default value."
2541
2542
  def set_text_default(value)
2542
2543
  unless (value == 'NULL')
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: db2
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.6.1
5
+ version: 2.6.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - IBM