ibm_db 4.0.0 → 5.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README +2 -2
- data/ext/Makefile +266 -0
- data/ext/extconf.rb +34 -3
- data/ext/gil_release_version +3 -0
- data/ext/ibm_db.c +100 -108
- data/ext/mkmf.log +103 -0
- data/ext/unicode_support_version +3 -0
- data/lib/active_record/connection_adapters/ibm_db_adapter.rb +256 -175
- data/test/cases/attribute_decorators_test.rb +2 -1
- data/test/cases/cache_key_test.rb +2 -1
- data/test/cases/comment_test.rb +4 -2
- data/test/cases/date_time_precision_test.rb +2 -1
- data/test/cases/defaults_test.rb +2 -1
- data/test/cases/migration/foreign_key_test.rb +4 -2
- data/test/cases/migration/helper.rb +1 -1
- data/test/cases/migration/references_foreign_key_test.rb +10 -5
- data/test/cases/migrator_test.rb +2 -1
- data/test/cases/schema_dumper_test.rb +3 -3
- data/test/cases/time_precision_test.rb +2 -1
- data/test/cases/transactions_test.rb +3 -2
- data/test/config.yml +154 -154
- data/test/connections/native_ibm_db/connection.rb +44 -0
- data/test/fixtures/admin/randomly_named_a9.yml +7 -7
- data/test/fixtures/admin/randomly_named_b0.yml +7 -7
- data/test/fixtures/developers.yml +1 -1
- data/test/fixtures/pirates.yml +0 -3
- data/test/fixtures/randomly_named_a9.yml +7 -7
- data/test/ibm_db_test.rb +24 -24
- data/test/models/admin.rb +1 -1
- data/test/models/admin/account.rb +1 -1
- data/test/models/admin/randomly_named_c1.rb +7 -7
- data/test/models/binary.rb +1 -1
- data/test/models/event.rb +1 -1
- data/test/models/guid.rb +1 -1
- data/test/models/randomly_named_c1.rb +3 -3
- data/test/models/ship_part.rb +1 -1
- data/test/schema/i5/ibm_db_specific_schema.rb +137 -0
- data/test/schema/ids/ibm_db_specific_schema.rb +140 -0
- data/test/schema/luw/ibm_db_specific_schema.rb +137 -0
- data/test/schema/zOS/ibm_db_specific_schema.rb +208 -0
- metadata +24 -13
- data/test/fixtures/author_addresses.original +0 -11
- data/test/fixtures/authors.original +0 -17
data/ext/mkmf.log
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
gil_release_version is:
|
2
|
+
/* begin */
|
3
|
+
1: #ifndef GIL_RELEASE_VERSION
|
4
|
+
2: #define GIL_RELEASE_VERSION
|
5
|
+
3: #endif
|
6
|
+
/* end */
|
7
|
+
|
8
|
+
unicode_support_version is:
|
9
|
+
/* begin */
|
10
|
+
1: #ifndef UNICODE_SUPPORT_VERSION
|
11
|
+
2: #define UNICODE_SUPPORT_VERSION
|
12
|
+
3: #endif
|
13
|
+
/* end */
|
14
|
+
|
15
|
+
have_library: checking for SQLConnect() in -ldb2... -------------------- yes
|
16
|
+
|
17
|
+
"gcc -o conftest -I/home/rakhil/ruby_exe/include/ruby-2.6.0/x86_64-linux -I/home/rakhil/ruby_exe/include/ruby-2.6.0/ruby/backward -I/home/rakhil/ruby_exe/include/ruby-2.6.0 -I. -I/home/rakhil/clidriver/include -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wrestrict -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable conftest.c -L. -L/home/rakhil/ruby_exe/lib -Wl,-rpath,/home/rakhil/ruby_exe/lib -L/home/rakhil/clidriver/lib -Wl,-rpath,/home/rakhil/clidriver/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-rpath,/home/rakhil/ruby_exe/lib -L/home/rakhil/ruby_exe/lib -lruby-static -lz -lpthread -lrt -lrt -ldl -lcrypt -lm -lm -lc"
|
18
|
+
/home/rakhil/ruby_exe/lib/ruby/2.6.0/mkmf.rb:406: warning: Insecure world writable dir /work/rakhil in PATH, mode 040777
|
19
|
+
checked program was:
|
20
|
+
/* begin */
|
21
|
+
1: #include "ruby.h"
|
22
|
+
2:
|
23
|
+
3: int main(int argc, char **argv)
|
24
|
+
4: {
|
25
|
+
5: return 0;
|
26
|
+
6: }
|
27
|
+
/* end */
|
28
|
+
|
29
|
+
"gcc -o conftest -I/home/rakhil/ruby_exe/include/ruby-2.6.0/x86_64-linux -I/home/rakhil/ruby_exe/include/ruby-2.6.0/ruby/backward -I/home/rakhil/ruby_exe/include/ruby-2.6.0 -I. -I/home/rakhil/clidriver/include -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wrestrict -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable conftest.c -L. -L/home/rakhil/ruby_exe/lib -Wl,-rpath,/home/rakhil/ruby_exe/lib -L/home/rakhil/clidriver/lib -Wl,-rpath,/home/rakhil/clidriver/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-rpath,/home/rakhil/ruby_exe/lib -L/home/rakhil/ruby_exe/lib -lruby-static -lz -lpthread -lrt -lrt -ldl -lcrypt -lm -ldb2 -lm -lc"
|
30
|
+
conftest.c: In function 't':
|
31
|
+
conftest.c:14:57: error: 'SQLConnect' undeclared (first use in this function)
|
32
|
+
int t(void) { void ((*volatile p)()); p = (void ((*)()))SQLConnect; return !p; }
|
33
|
+
^~~~~~~~~~
|
34
|
+
conftest.c:14:57: note: each undeclared identifier is reported only once for each function it appears in
|
35
|
+
conftest.c: At top level:
|
36
|
+
cc1: warning: unrecognized command line option '-Wno-self-assign'
|
37
|
+
cc1: warning: unrecognized command line option '-Wno-parentheses-equality'
|
38
|
+
cc1: warning: unrecognized command line option '-Wno-constant-logical-operand'
|
39
|
+
cc1: warning: unrecognized command line option '-Wno-cast-function-type'
|
40
|
+
checked program was:
|
41
|
+
/* begin */
|
42
|
+
1: #include "ruby.h"
|
43
|
+
2:
|
44
|
+
3: /*top*/
|
45
|
+
4: extern int t(void);
|
46
|
+
5: int main(int argc, char **argv)
|
47
|
+
6: {
|
48
|
+
7: if (argc > 1000000) {
|
49
|
+
8: int (* volatile tp)(void)=(int (*)(void))&t;
|
50
|
+
9: printf("%d", (*tp)());
|
51
|
+
10: }
|
52
|
+
11:
|
53
|
+
12: return 0;
|
54
|
+
13: }
|
55
|
+
14: int t(void) { void ((*volatile p)()); p = (void ((*)()))SQLConnect; return !p; }
|
56
|
+
/* end */
|
57
|
+
|
58
|
+
"gcc -o conftest -I/home/rakhil/ruby_exe/include/ruby-2.6.0/x86_64-linux -I/home/rakhil/ruby_exe/include/ruby-2.6.0/ruby/backward -I/home/rakhil/ruby_exe/include/ruby-2.6.0 -I. -I/home/rakhil/clidriver/include -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wrestrict -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable conftest.c -L. -L/home/rakhil/ruby_exe/lib -Wl,-rpath,/home/rakhil/ruby_exe/lib -L/home/rakhil/clidriver/lib -Wl,-rpath,/home/rakhil/clidriver/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-rpath,/home/rakhil/ruby_exe/lib -L/home/rakhil/ruby_exe/lib -lruby-static -lz -lpthread -lrt -lrt -ldl -lcrypt -lm -ldb2 -lm -lc"
|
59
|
+
checked program was:
|
60
|
+
/* begin */
|
61
|
+
1: #include "ruby.h"
|
62
|
+
2:
|
63
|
+
3: /*top*/
|
64
|
+
4: extern int t(void);
|
65
|
+
5: int main(int argc, char **argv)
|
66
|
+
6: {
|
67
|
+
7: if (argc > 1000000) {
|
68
|
+
8: int (* volatile tp)(void)=(int (*)(void))&t;
|
69
|
+
9: printf("%d", (*tp)());
|
70
|
+
10: }
|
71
|
+
11:
|
72
|
+
12: return 0;
|
73
|
+
13: }
|
74
|
+
14: extern void SQLConnect();
|
75
|
+
15: int t(void) { SQLConnect(); return 0; }
|
76
|
+
/* end */
|
77
|
+
|
78
|
+
--------------------
|
79
|
+
|
80
|
+
have_header: checking for gil_release_version... -------------------- yes
|
81
|
+
|
82
|
+
"gcc -E -I/home/rakhil/ruby_exe/include/ruby-2.6.0/x86_64-linux -I/home/rakhil/ruby_exe/include/ruby-2.6.0/ruby/backward -I/home/rakhil/ruby_exe/include/ruby-2.6.0 -I. -I/home/rakhil/clidriver/include -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wrestrict -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable conftest.c -o conftest.i"
|
83
|
+
checked program was:
|
84
|
+
/* begin */
|
85
|
+
1: #include "ruby.h"
|
86
|
+
2:
|
87
|
+
3: #include <gil_release_version>
|
88
|
+
/* end */
|
89
|
+
|
90
|
+
--------------------
|
91
|
+
|
92
|
+
have_header: checking for unicode_support_version... -------------------- yes
|
93
|
+
|
94
|
+
"gcc -E -I/home/rakhil/ruby_exe/include/ruby-2.6.0/x86_64-linux -I/home/rakhil/ruby_exe/include/ruby-2.6.0/ruby/backward -I/home/rakhil/ruby_exe/include/ruby-2.6.0 -I. -I/home/rakhil/clidriver/include -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wrestrict -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable conftest.c -o conftest.i"
|
95
|
+
checked program was:
|
96
|
+
/* begin */
|
97
|
+
1: #include "ruby.h"
|
98
|
+
2:
|
99
|
+
3: #include <unicode_support_version>
|
100
|
+
/* end */
|
101
|
+
|
102
|
+
--------------------
|
103
|
+
|
@@ -9,8 +9,9 @@
|
|
9
9
|
# | : Arvind Gupta <arvindgu@in.ibm.com> |
|
10
10
|
# +----------------------------------------------------------------------+
|
11
11
|
|
12
|
+
|
12
13
|
require 'active_record/connection_adapters/abstract_adapter'
|
13
|
-
require 'arel/visitors/
|
14
|
+
require 'arel/visitors/visitor'
|
14
15
|
require 'active_support/core_ext/string/strip'
|
15
16
|
require 'active_record/type'
|
16
17
|
require 'active_record/connection_adapters/sql_type_metadata'
|
@@ -18,14 +19,14 @@ require 'active_record/connection_adapters/sql_type_metadata'
|
|
18
19
|
|
19
20
|
|
20
21
|
module CallChain
|
21
|
-
|
22
|
+
def self.caller_method(depth=1)
|
22
23
|
parse_caller(caller(depth+1).first).last
|
23
24
|
end
|
24
25
|
|
25
26
|
private
|
26
27
|
|
27
28
|
# Copied from ActionMailer
|
28
|
-
|
29
|
+
def self.parse_caller(at)
|
29
30
|
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
|
30
31
|
file = Regexp.last_match[1]
|
31
32
|
line = Regexp.last_match[2].to_i
|
@@ -38,20 +39,19 @@ end
|
|
38
39
|
|
39
40
|
module ActiveRecord
|
40
41
|
|
41
|
-
|
42
42
|
|
43
43
|
class SchemaMigration < ActiveRecord::Base
|
44
44
|
class << self
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
def create_table
|
46
|
+
#puts "Calling method : " << CallChain.caller_method << "\n"
|
47
|
+
#puts "Calling method for create_table(): " << String(caller(start=1, length=nil) )
|
48
48
|
unless table_exists?
|
49
49
|
version_options = connection.internal_string_options_for_primary_key
|
50
50
|
|
51
|
-
connection.create_table(table_name,
|
51
|
+
connection.create_table(table_name,id:false) do |t|
|
52
52
|
t.string :version, version_options
|
53
53
|
end
|
54
|
-
|
54
|
+
end
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -60,7 +60,7 @@ module ActiveRecord
|
|
60
60
|
|
61
61
|
class Relation
|
62
62
|
|
63
|
-
|
63
|
+
def insert(values)
|
64
64
|
primary_key_value = nil
|
65
65
|
|
66
66
|
if primary_key && Hash === values
|
@@ -96,7 +96,6 @@ module ActiveRecord
|
|
96
96
|
else
|
97
97
|
im.insert substitutes
|
98
98
|
end
|
99
|
-
|
100
99
|
conn.insert(
|
101
100
|
im,
|
102
101
|
'SQL',
|
@@ -210,16 +209,16 @@ module ActiveRecord
|
|
210
209
|
end
|
211
210
|
|
212
211
|
#if( config.has_key?(:parameterized) && config[:parameterized] == true )
|
213
|
-
|
214
|
-
|
212
|
+
# require 'active_record/connection_adapters/ibm_db_pstmt'
|
213
|
+
# end
|
215
214
|
|
216
215
|
# Check if class TableDefinition responds to indexes method to determine if we are on AR 3 or AR 4.
|
217
216
|
# This is a interim hack ti ensure backward compatibility. To remove as we move out of AR 3 support or have a better way to determine which version of AR being run against.
|
218
|
-
|
217
|
+
checkClass = ActiveRecord::ConnectionAdapters::TableDefinition.new(self,nil)
|
219
218
|
if(checkClass.respond_to?(:indexes))
|
220
219
|
isAr3 = false
|
221
220
|
else
|
222
|
-
isAr3
|
221
|
+
isAr3= true
|
223
222
|
end
|
224
223
|
# Converts all +config+ keys to symbols
|
225
224
|
config = config.symbolize_keys
|
@@ -302,7 +301,6 @@ module ActiveRecord
|
|
302
301
|
conn_string << "SECURITY=#{config[:security]};" if config.has_key?(:security)
|
303
302
|
conn_string << "AUTHENTICATION=#{config[:authentication]};" if config.has_key?(:authentication)
|
304
303
|
conn_string << "CONNECTTIMEOUT=#{config[:timeout]};" if config.has_key?(:timeout)
|
305
|
-
|
306
304
|
connection = IBM_DB.connect( conn_string, '', '', conn_options, set_quoted_literal_replacement )
|
307
305
|
else
|
308
306
|
# No host implies a local catalog-based connection: +database+ represents catalog alias
|
@@ -339,21 +337,20 @@ module ActiveRecord
|
|
339
337
|
end
|
340
338
|
|
341
339
|
module Quoting
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
end
|
340
|
+
def lookup_cast_type_from_column(column) # :nodoc:
|
341
|
+
lookup_cast_type(column.sql_type_metadata)
|
342
|
+
end
|
346
343
|
end
|
347
344
|
|
348
345
|
module Savepoints
|
349
|
-
|
346
|
+
def create_savepoint(name = current_savepoint_name)
|
350
347
|
execute("SAVEPOINT #{name} ON ROLLBACK RETAIN CURSORS")
|
351
348
|
end
|
352
349
|
end
|
353
350
|
|
354
351
|
|
355
352
|
module ColumnDumper
|
356
|
-
|
353
|
+
def prepare_column_options(column)
|
357
354
|
spec = {}
|
358
355
|
|
359
356
|
if limit = schema_limit(column)
|
@@ -409,25 +406,26 @@ module ActiveRecord
|
|
409
406
|
|
410
407
|
module SchemaStatements
|
411
408
|
|
412
|
-
|
409
|
+
def internal_string_options_for_primary_key # :nodoc:
|
413
410
|
{ primary_key: true}
|
414
411
|
{ version_options: "PRIMARY KEY NOT NULL"}
|
412
|
+
end
|
413
|
+
|
414
|
+
def drop_table(table_name,options={})
|
415
|
+
execute("DROP TABLE #{quote_table_name(table_name)}", options)
|
416
|
+
#execute("DROP TABLE#{' IF EXISTS' if options[:if_exists]} #{quote_table_name(table_name)}"
|
415
417
|
end
|
416
|
-
|
417
|
-
def drop_table(table_name, options = {})
|
418
|
-
execute "DROP TABLE #{quote_table_name(table_name)}"
|
419
|
-
end
|
420
|
-
|
418
|
+
|
421
419
|
=begin
|
422
420
|
def create_table_definition(name, temporary, options,as = nil)
|
423
421
|
TableDefinition.new self, name, temporary, options
|
424
422
|
end
|
425
423
|
=end
|
426
|
-
|
427
|
-
TableDefinition.new(*args)
|
424
|
+
def create_table_definition(*args, **options)
|
425
|
+
TableDefinition.new(self, *args, **options)
|
428
426
|
end
|
429
427
|
|
430
|
-
|
428
|
+
def remove_foreign_key(from_table, options_or_to_table = {})
|
431
429
|
return unless supports_foreign_keys?
|
432
430
|
|
433
431
|
if options_or_to_table.is_a?(Hash)
|
@@ -458,8 +456,8 @@ module ActiveRecord
|
|
458
456
|
class IBM_DBColumn < ConnectionAdapters::Column # :nodoc:
|
459
457
|
# delegate :precision, :scale, :limit, :type, :sql_type, to: :sql_type_metadata, allow_nil: true
|
460
458
|
|
461
|
-
|
462
|
-
|
459
|
+
def initialize(*)
|
460
|
+
super
|
463
461
|
end
|
464
462
|
|
465
463
|
#def initialize(column_name, column_default_value, sqltype_metadata, column_nullable, table_name, default_function, collation, comment)
|
@@ -487,9 +485,9 @@ module ActiveRecord
|
|
487
485
|
|
488
486
|
module ColumnMethods
|
489
487
|
|
490
|
-
|
491
|
-
|
492
|
-
|
488
|
+
def primary_key(name, type = :primary_key, **options)
|
489
|
+
column(name, type, options.merge(primary_key: true))
|
490
|
+
end
|
493
491
|
|
494
492
|
##class Table
|
495
493
|
class Table < ActiveRecord::ConnectionAdapters::Table
|
@@ -511,7 +509,7 @@ module ActiveRecord
|
|
511
509
|
#This method is different as compared to def char (sql is being issued explicitly
|
512
510
|
#as compared to def char where method column(which will generate the sql is being called)
|
513
511
|
#in order to handle the DEFAULT and NULL option for the native XML datatype
|
514
|
-
def xml(*args )
|
512
|
+
def xml(*args )
|
515
513
|
options = {}
|
516
514
|
if args.last.is_a?(Hash)
|
517
515
|
options = args.delete_at(args.length-1)
|
@@ -583,7 +581,8 @@ module ActiveRecord
|
|
583
581
|
end
|
584
582
|
=end
|
585
583
|
|
586
|
-
|
584
|
+
def initialize(conn, name, temporary = false, options = nil, as = nil, comment: nil)
|
585
|
+
@connection = conn
|
587
586
|
@columns_hash = {}
|
588
587
|
@indexes = []
|
589
588
|
@foreign_keys = []
|
@@ -653,15 +652,15 @@ module ActiveRecord
|
|
653
652
|
|
654
653
|
#Method to support the new syntax of rails 2.0 migrations (short-hand definitions) for columns of type char [character]
|
655
654
|
def char(*args)
|
656
|
-
|
657
|
-
|
655
|
+
ibm_parse_column_attributes_args('char',*args)
|
656
|
+
return self
|
658
657
|
end
|
659
658
|
alias_method :character, :char
|
660
659
|
|
661
660
|
# Overrides the abstract adapter in order to handle
|
662
661
|
# the DEFAULT option for the native XML datatype
|
663
662
|
def column(name, type, options ={})
|
664
|
-
|
663
|
+
# construct a column definition where @base is adaptor instance
|
665
664
|
column = ColumnDefinition.new(name, type)
|
666
665
|
|
667
666
|
# DB2 does not accept DEFAULT NULL option for XML
|
@@ -745,11 +744,12 @@ module ActiveRecord
|
|
745
744
|
end
|
746
745
|
|
747
746
|
class BindSubstitution < Arel::Visitors::IBM_DB # :nodoc:
|
748
|
-
include Arel::Visitors
|
747
|
+
include Arel::Visitors
|
749
748
|
end
|
750
749
|
|
751
750
|
def initialize(connection, ar3, logger, config, conn_options)
|
752
|
-
# Caching database connection configuration (+connect+ or +reconnect+ support)
|
751
|
+
# Caching database connection configuration (+connect+ or +reconnect+ support)\
|
752
|
+
@config = config
|
753
753
|
@connection = connection
|
754
754
|
@isAr3 = ar3
|
755
755
|
@conn_options = conn_options
|
@@ -779,7 +779,7 @@ module ActiveRecord
|
|
779
779
|
|
780
780
|
# Calls the parent class +ConnectionAdapters+' initializer
|
781
781
|
# which sets @connection, @logger, @runtime and @last_verification
|
782
|
-
super(@connection, logger)
|
782
|
+
super(@connection, logger, @config)
|
783
783
|
|
784
784
|
if @connection
|
785
785
|
server_info = IBM_DB.server_info( @connection )
|
@@ -911,7 +911,7 @@ module ActiveRecord
|
|
911
911
|
rescue
|
912
912
|
@arelVersion = 0
|
913
913
|
end
|
914
|
-
|
914
|
+
if(@arelVersion < 6 )
|
915
915
|
def to_sql(arel, binds = [])
|
916
916
|
if arel.respond_to?(:ast)
|
917
917
|
visitor.accept(arel.ast) do
|
@@ -933,9 +933,11 @@ module ActiveRecord
|
|
933
933
|
|
934
934
|
def supports_foreign_keys?
|
935
935
|
true
|
936
|
+
end
|
937
|
+
|
938
|
+
def supports_datetime_with_precision?
|
939
|
+
true
|
936
940
|
end
|
937
|
-
|
938
|
-
|
939
941
|
|
940
942
|
# This Adapter supports DDL transactions.
|
941
943
|
# This means CREATE TABLE and other DDL statements can be carried out as a transaction.
|
@@ -1020,21 +1022,20 @@ module ActiveRecord
|
|
1020
1022
|
|
1021
1023
|
def create_table(name, options = {})
|
1022
1024
|
@servertype.setup_for_lob_table
|
1023
|
-
super
|
1024
|
-
|
1025
1025
|
#Table definition is complete only when a unique index is created on the primarykey column for DB2 V8 on zOS
|
1026
1026
|
|
1027
1027
|
#create index on id column if options[:id] is nil or id ==true
|
1028
1028
|
#else check if options[:primary_key]is not nil then create an unique index on that column
|
1029
1029
|
if !options[:id].nil? || !options[:primary_key].nil?
|
1030
1030
|
if (!options[:id].nil? && options[:id] == true)
|
1031
|
-
|
1031
|
+
@servertype.create_index_after_table(name,"id")
|
1032
1032
|
elsif !options[:primary_key].nil?
|
1033
|
-
|
1033
|
+
@servertype.create_index_after_table(name,options[:primary_key].to_s)
|
1034
1034
|
end
|
1035
1035
|
else
|
1036
|
-
|
1037
|
-
end
|
1036
|
+
@servertype.create_index_after_table(name,"id")
|
1037
|
+
end
|
1038
|
+
super(name, options)
|
1038
1039
|
end
|
1039
1040
|
|
1040
1041
|
# Returns an array of hashes with the column names as keys and
|
@@ -1125,9 +1126,8 @@ module ActiveRecord
|
|
1125
1126
|
end
|
1126
1127
|
|
1127
1128
|
def select(sql, name = nil, binds = [])
|
1128
|
-
|
1129
|
-
|
1130
|
-
sql.gsub!( /(=\s*NULL|IN\s*\(NULL\))/i, " IS NULL" )
|
1129
|
+
# Replaces {"= NULL" with " IS NULL"} OR {"IN (NULL)" with " IS NULL"
|
1130
|
+
sql.gsub( /(=\s*NULL|IN\s*\(NULL\))/i, " IS NULL" )
|
1131
1131
|
|
1132
1132
|
results = []
|
1133
1133
|
|
@@ -1155,7 +1155,7 @@ module ActiveRecord
|
|
1155
1155
|
#+sql+ is the select query and +name+ is an optional description for logging
|
1156
1156
|
def select_rows(sql, name = nil,binds = [])
|
1157
1157
|
# Replaces {"= NULL" with " IS NULL"} OR {"IN (NULL)" with " IS NULL"}
|
1158
|
-
sql.gsub
|
1158
|
+
sql.gsub( /(=\s*NULL|IN\s*\(NULL\))/i, " IS NULL" )
|
1159
1159
|
|
1160
1160
|
results = []
|
1161
1161
|
# Invokes the method +execute+ in order to log and execute the SQL
|
@@ -1287,12 +1287,12 @@ module ActiveRecord
|
|
1287
1287
|
end
|
1288
1288
|
end
|
1289
1289
|
|
1290
|
-
def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds
|
1291
|
-
if(@arelVersion < 6
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1290
|
+
def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds=[])
|
1291
|
+
if(@arelVersion < 6)
|
1292
|
+
sql, binds = [to_sql(arel), binds]
|
1293
|
+
else
|
1294
|
+
sql, binds = [to_sql(arel),binds] #sql_for_insert(to_sql(arel, binds), binds) #[to_sql(arel),binds]
|
1295
|
+
end
|
1296
1296
|
|
1297
1297
|
#unless IBM_DBAdapter.respond_to?(:exec_insert)
|
1298
1298
|
if binds.nil? || binds.empty?
|
@@ -1395,14 +1395,18 @@ module ActiveRecord
|
|
1395
1395
|
|
1396
1396
|
# Executes and logs +sql+ commands and
|
1397
1397
|
# returns a +IBM_DB.Statement+ object.
|
1398
|
-
def execute(sql, name
|
1398
|
+
def execute(sql, name=nil)
|
1399
1399
|
# Logs and execute the sql instructions.
|
1400
1400
|
# The +log+ method is defined in the parent class +AbstractAdapter+
|
1401
|
-
|
1401
|
+
#sql='INSERT INTO ar_internal_metadata (key, value, created_at, updated_at) VALUES ('10', '10', '10', '10')
|
1402
|
+
log(sql , name) do
|
1402
1403
|
@servertype.execute(sql, name)
|
1403
1404
|
end
|
1404
1405
|
end
|
1405
1406
|
|
1407
|
+
def exec_insert(sql,name,binds,pk,sequence_name)
|
1408
|
+
end
|
1409
|
+
|
1406
1410
|
# Executes an "UPDATE" SQL statement
|
1407
1411
|
def update_direct(sql, name = nil)
|
1408
1412
|
if @handle_lobs_triggered #Ensure the array of sql is cleared if they have been handled in the callback
|
@@ -1454,10 +1458,10 @@ module ActiveRecord
|
|
1454
1458
|
|
1455
1459
|
def update(arel, name = nil, binds = [])
|
1456
1460
|
if(@arelVersion < 6 )
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
+
sql = to_sql(arel)
|
1462
|
+
else
|
1463
|
+
sql = to_sql(arel,binds)
|
1464
|
+
end
|
1461
1465
|
|
1462
1466
|
# Make sure the WHERE clause handles NULL's correctly
|
1463
1467
|
sqlarray = sql.split(/\s*WHERE\s*/)
|
@@ -1515,6 +1519,7 @@ module ActiveRecord
|
|
1515
1519
|
end
|
1516
1520
|
|
1517
1521
|
def get_limit_offset_clauses(limit,offset)
|
1522
|
+
|
1518
1523
|
if limit && limit == 0
|
1519
1524
|
clauses = @servertype.get_limit_offset_clauses(limit,0)
|
1520
1525
|
else
|
@@ -1584,7 +1589,6 @@ module ActiveRecord
|
|
1584
1589
|
end
|
1585
1590
|
end
|
1586
1591
|
=end
|
1587
|
-
|
1588
1592
|
def quote_value_for_pstmt(value, column=nil)
|
1589
1593
|
|
1590
1594
|
return value.quoted_id if value.respond_to?(:quoted_id)
|
@@ -1613,75 +1617,82 @@ module ActiveRecord
|
|
1613
1617
|
end
|
1614
1618
|
end
|
1615
1619
|
end
|
1616
|
-
|
1617
1620
|
# Properly quotes the various data types.
|
1618
1621
|
# +value+ contains the data, +column+ is optional and contains info on the field
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1622
|
+
# def quote(value, column=nil)
|
1623
|
+
# return value.quoted_id if value.respond_to?(:quoted_id)
|
1624
|
+
# case value
|
1625
|
+
# # If it's a numeric value and the column sql_type is not a string, it shouldn't be quoted
|
1626
|
+
# # (IBM_DB doesn't accept quotes on numeric types)
|
1627
|
+
# when Numeric
|
1628
|
+
# # If the column sql_type is text or string, return the quote value
|
1629
|
+
# if (column && ( column.sql_type.to_s =~ /text|char/i ))
|
1630
|
+
# unless caller[0] =~ /insert_fixture/i
|
1631
|
+
# "'#{value}'"
|
1632
|
+
# else
|
1633
|
+
# "#{value}"
|
1634
|
+
# end
|
1635
|
+
# else
|
1636
|
+
# # value is Numeric, column.sql_type is not a string,
|
1637
|
+
# # therefore it converts the number to string without quoting it
|
1638
|
+
# value.to_s
|
1639
|
+
# end
|
1640
|
+
# when String, ActiveSupport::Multibyte::Chars
|
1641
|
+
# if column && column.sql_type.to_s =~ /binary|blob/i && !(column.sql_type.to_s =~ /for bit data/i)
|
1642
|
+
# # If quoting is required for the insert/update of a BLOB
|
1643
|
+
# unless caller[0] =~ /add_column_options/i
|
1644
|
+
# # Invokes a convertion from string to binary
|
1645
|
+
# @servertype.set_binary_value
|
1646
|
+
# else
|
1647
|
+
# # Quoting required for the default value of a column
|
1648
|
+
# @servertype.set_binary_default(value)
|
1649
|
+
# end
|
1650
|
+
# elsif column && column.sql_type.to_s =~ /text|clob/i
|
1651
|
+
# unless caller[0] =~ /add_column_options/i
|
1652
|
+
# @servertype.set_text_default(quote_string(value))
|
1653
|
+
# else
|
1654
|
+
# @servertype.set_text_default(quote_string(value))
|
1655
|
+
# end
|
1656
|
+
# elsif column && column.sql_type.to_s =~ /xml/i
|
1657
|
+
# unless caller[0] =~ /add_column_options/i
|
1658
|
+
# "#{value}"
|
1659
|
+
# else
|
1660
|
+
# "#{value}"
|
1661
|
+
# end
|
1662
|
+
# else
|
1663
|
+
# unless caller[0] =~ /insert_fixture/i
|
1664
|
+
# super(value)
|
1665
|
+
# else
|
1666
|
+
# "#{value}"
|
1667
|
+
# end
|
1668
|
+
# end
|
1669
|
+
# #when TrueClass then quoted_true # return '1' for true
|
1670
|
+
# when TrueClass
|
1671
|
+
# quoted_true
|
1672
|
+
# #when FalseClass then quoted_false # return '0' for false
|
1673
|
+
# when FalseClass
|
1674
|
+
# quoted_false
|
1675
|
+
# when nil
|
1676
|
+
# "NULL"
|
1677
|
+
# when Date
|
1678
|
+
# "'#{quoted_date(value)}'"
|
1679
|
+
# when Time
|
1680
|
+
# "'#{quoted_date(value)}'"
|
1681
|
+
# when Symbol
|
1682
|
+
# "'#{quote_string(value)}'"
|
1683
|
+
# else
|
1684
|
+
# unless caller[0] =~ /insert_fixture/i
|
1685
|
+
# "'#{quote_string(YAML.dump(value))}'"
|
1686
|
+
# else
|
1687
|
+
# "#{quote_string(YAML.dump(value))}"
|
1688
|
+
# end
|
1689
|
+
# end
|
1690
|
+
# end
|
1691
|
+
# # Quotes a given string, escaping single quote (') characters.
|
1692
|
+
# def quote_string(string)
|
1693
|
+
# #string.gsub(/'/, "''")
|
1694
|
+
# string.gsub('\\', '\&\&').gsub("'", "''")
|
1695
|
+
# end
|
1685
1696
|
|
1686
1697
|
# *true* is represented by a smallint 1, *false*
|
1687
1698
|
# by 0, as no native boolean type exists in DB2.
|
@@ -1711,9 +1722,9 @@ module ActiveRecord
|
|
1711
1722
|
:text => { :name => "clob" },
|
1712
1723
|
:integer => { :name => "integer" },
|
1713
1724
|
:float => { :name => "float" },
|
1714
|
-
:datetime => { :name =>
|
1715
|
-
:timestamp => { :name =>
|
1716
|
-
:time => { :name =>
|
1725
|
+
:datetime => { :name => "timestamp" },
|
1726
|
+
:timestamp => { :name => "timestamp" },
|
1727
|
+
:time => { :name => "time" },
|
1717
1728
|
:date => { :name => "date" },
|
1718
1729
|
:binary => { :name => "blob" },
|
1719
1730
|
|
@@ -1801,14 +1812,40 @@ module ActiveRecord
|
|
1801
1812
|
|
1802
1813
|
# IBM data servers do not support limits on certain data types (unlike MySQL)
|
1803
1814
|
# Limit is supported for the {float, decimal, numeric, varchar, clob, blob, graphic, vargraphic} data types.
|
1804
|
-
def type_to_sql(type, limit
|
1815
|
+
def type_to_sql(type, limit=nil, precision=nil, scale=nil )
|
1816
|
+
if type.to_sym == :decimal
|
1817
|
+
if limit.class == Hash
|
1818
|
+
if limit.has_key?("precision".to_sym)
|
1819
|
+
precision = limit[:precision]
|
1820
|
+
end
|
1821
|
+
end
|
1822
|
+
if limit.class == Hash
|
1823
|
+
if limit.has_key?("scale".to_sym)
|
1824
|
+
scale = limit[:scale]
|
1825
|
+
end
|
1826
|
+
end
|
1827
|
+
sql_segment = native_database_types[type.to_sym][:name].to_s
|
1828
|
+
if !precision.nil? && !scale.nil?
|
1829
|
+
sql_segment << "(#{precision},#{scale})"
|
1830
|
+
return sql_segment
|
1831
|
+
elsif scale.nil? && !precision.nil?
|
1832
|
+
sql_segment << "(#{precision})"
|
1833
|
+
else
|
1834
|
+
return sql_segment
|
1835
|
+
end
|
1836
|
+
end
|
1837
|
+
|
1805
1838
|
if type.to_sym == :decfloat
|
1806
1839
|
sql_segment = native_database_types[type.to_sym][:name].to_s
|
1807
1840
|
sql_segment << "(#{precision})" if !precision.nil?
|
1808
1841
|
return sql_segment
|
1809
1842
|
end
|
1810
|
-
|
1811
|
-
|
1843
|
+
|
1844
|
+
if limit.class == Hash
|
1845
|
+
return super if limit.has_key?("limit".to_sym).nil?
|
1846
|
+
else
|
1847
|
+
return super if limit.nil?
|
1848
|
+
end
|
1812
1849
|
|
1813
1850
|
# strip off limits on data types not supporting them
|
1814
1851
|
if @servertype.limit_not_supported_types.include? type.to_sym
|
@@ -1816,9 +1853,10 @@ module ActiveRecord
|
|
1816
1853
|
elsif type.to_sym == :boolean
|
1817
1854
|
return "smallint"
|
1818
1855
|
else
|
1819
|
-
return super
|
1856
|
+
return super(type)
|
1820
1857
|
end
|
1821
|
-
|
1858
|
+
|
1859
|
+
end
|
1822
1860
|
|
1823
1861
|
|
1824
1862
|
|
@@ -1952,7 +1990,7 @@ module ActiveRecord
|
|
1952
1990
|
|
1953
1991
|
# Returns an array of non-primary key indexes for a specified table name
|
1954
1992
|
def indexes(table_name, name = nil)
|
1955
|
-
|
1993
|
+
# to_s required because +table_name+ may be a symbol.
|
1956
1994
|
table_name = table_name.to_s
|
1957
1995
|
# Checks if a blank table name has been given.
|
1958
1996
|
# If so it returns an empty array of columns.
|
@@ -2015,7 +2053,7 @@ module ActiveRecord
|
|
2015
2053
|
if(stmt)
|
2016
2054
|
begin
|
2017
2055
|
while ( index_stats = IBM_DB.fetch_array(stmt) )
|
2018
|
-
|
2056
|
+
is_composite = false
|
2019
2057
|
if index_stats[5] # INDEX_NAME
|
2020
2058
|
index_name = index_stats[5].downcase
|
2021
2059
|
index_unique = (index_stats[3] == 0)
|
@@ -2025,7 +2063,8 @@ module ActiveRecord
|
|
2025
2063
|
i = 0;
|
2026
2064
|
indexes.each do |index|
|
2027
2065
|
if index.name == index_name && index_schema[i] == index_qualifier
|
2028
|
-
index.columns = index.columns + index_columns
|
2066
|
+
#index.columns = index.columns + index_columns
|
2067
|
+
index.columns.concat index_columns
|
2029
2068
|
is_composite = true
|
2030
2069
|
end
|
2031
2070
|
i = i+1
|
@@ -2153,8 +2192,8 @@ module ActiveRecord
|
|
2153
2192
|
|
2154
2193
|
|
2155
2194
|
# Returns an array of Column objects for the table specified by +table_name+
|
2156
|
-
def columns(table_name
|
2157
|
-
|
2195
|
+
def columns(table_name)
|
2196
|
+
# to_s required because it may be a symbol.
|
2158
2197
|
table_name = @servertype.set_case(table_name.to_s)
|
2159
2198
|
|
2160
2199
|
# Checks if a blank table name has been given.
|
@@ -2229,7 +2268,7 @@ module ActiveRecord
|
|
2229
2268
|
scale: column_scale,
|
2230
2269
|
)
|
2231
2270
|
|
2232
|
-
columns << Column.new(column_name, column_default_value, sqltype_metadata, column_nullable, table_name
|
2271
|
+
columns << Column.new(column_name, column_default_value, sqltype_metadata, column_nullable, table_name)
|
2233
2272
|
|
2234
2273
|
#else
|
2235
2274
|
# columns << IBM_DBColumn.new(column_name, column_default_value, column_type, column_nullable)
|
@@ -2260,7 +2299,7 @@ module ActiveRecord
|
|
2260
2299
|
return columns
|
2261
2300
|
end
|
2262
2301
|
|
2263
|
-
def foreign_keys(table_name)
|
2302
|
+
def foreign_keys(table_name)
|
2264
2303
|
#fetch the foreign keys of the table using function foreign_keys
|
2265
2304
|
#PKTABLE_NAME:: fk_row[2] Name of the table containing the primary key.
|
2266
2305
|
#PKCOLUMN_NAME:: fk_row[3] Name of the column containing the primary key.
|
@@ -2309,8 +2348,9 @@ module ActiveRecord
|
|
2309
2348
|
end
|
2310
2349
|
#Returns the foreignKeys array
|
2311
2350
|
return foreignKeys
|
2312
|
-
|
2313
|
-
|
2351
|
+
end
|
2352
|
+
|
2353
|
+
def extract_foreign_key_action(specifier) # :nodoc:
|
2314
2354
|
case specifier
|
2315
2355
|
when 0; :cascade
|
2316
2356
|
when 1; :restrict
|
@@ -2321,9 +2361,9 @@ module ActiveRecord
|
|
2321
2361
|
|
2322
2362
|
def supports_disable_referential_integrity? #:nodoc:
|
2323
2363
|
true
|
2324
|
-
|
2364
|
+
end
|
2325
2365
|
|
2326
|
-
|
2366
|
+
def disable_referential_integrity #:nodoc:
|
2327
2367
|
if supports_disable_referential_integrity?
|
2328
2368
|
alter_foreign_keys(tables, true)
|
2329
2369
|
end
|
@@ -2334,7 +2374,7 @@ module ActiveRecord
|
|
2334
2374
|
alter_foreign_keys(tables, false)
|
2335
2375
|
end
|
2336
2376
|
|
2337
|
-
|
2377
|
+
end
|
2338
2378
|
|
2339
2379
|
def alter_foreign_keys(tables, not_enforced)
|
2340
2380
|
enforced = not_enforced ? 'NOT ENFORCED' : 'ENFORCED'
|
@@ -2343,7 +2383,7 @@ module ActiveRecord
|
|
2343
2383
|
execute("ALTER TABLE #{@servertype.set_case(fk.from_table)} ALTER FOREIGN KEY #{@servertype.set_case(fk.name)} #{enforced}")
|
2344
2384
|
end
|
2345
2385
|
end
|
2346
|
-
|
2386
|
+
end
|
2347
2387
|
|
2348
2388
|
# Renames a table.
|
2349
2389
|
# ==== Example
|
@@ -2384,7 +2424,7 @@ module ActiveRecord
|
|
2384
2424
|
#Add distinct clause to the sql if there is no order by specified
|
2385
2425
|
def distinct(columns, order_by)
|
2386
2426
|
if order_by.nil?
|
2387
|
-
"DISTINCT #{columns}"
|
2427
|
+
"DISTINCT #{columns}"
|
2388
2428
|
else
|
2389
2429
|
"#{columns}"
|
2390
2430
|
end
|
@@ -2431,7 +2471,7 @@ module ActiveRecord
|
|
2431
2471
|
# remove_index :accounts, :username
|
2432
2472
|
# Overriden to use the IBM data servers SQL syntax.
|
2433
2473
|
def remove_index(table_name, options = {})
|
2434
|
-
|
2474
|
+
execute("DROP INDEX #{index_name(table_name, options)}")
|
2435
2475
|
end
|
2436
2476
|
|
2437
2477
|
protected
|
@@ -2481,7 +2521,7 @@ module ActiveRecord
|
|
2481
2521
|
class IBM_DataServer
|
2482
2522
|
def initialize(adapter, ar3)
|
2483
2523
|
@adapter = adapter
|
2484
|
-
|
2524
|
+
@isAr3 = ar3
|
2485
2525
|
end
|
2486
2526
|
|
2487
2527
|
def last_generated_id(stmt)
|
@@ -2588,7 +2628,9 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
2588
2628
|
end
|
2589
2629
|
end
|
2590
2630
|
|
2591
|
-
|
2631
|
+
# Akhil Tcheck for if_exits added so that it will try to drop even if the table does not exit.
|
2632
|
+
def execute(sql, name = nil)
|
2633
|
+
if name == nil || name.class == String
|
2592
2634
|
begin
|
2593
2635
|
if stmt = IBM_DB.exec(@adapter.connection, sql)
|
2594
2636
|
stmt # Return the statement object
|
@@ -2602,6 +2644,25 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
2602
2644
|
raise
|
2603
2645
|
end
|
2604
2646
|
end
|
2647
|
+
else
|
2648
|
+
if name[:if_exists]
|
2649
|
+
IBM_DB.exec(@adapter.connection, sql)
|
2650
|
+
else
|
2651
|
+
begin
|
2652
|
+
if stmt = IBM_DB.exec(@adapter.connection, sql)
|
2653
|
+
stmt # Return the statement object
|
2654
|
+
else
|
2655
|
+
raise StatementInvalid, IBM_DB.getErrormsg(@adapter.connection, IBM_DB::DB_CONN )
|
2656
|
+
end
|
2657
|
+
rescue StandardError => exec_err
|
2658
|
+
if exec_err && !exec_err.message.empty?
|
2659
|
+
raise "Failed to execute statement due to: #{exec_err}"
|
2660
|
+
else
|
2661
|
+
raise
|
2662
|
+
end
|
2663
|
+
end
|
2664
|
+
end
|
2665
|
+
end
|
2605
2666
|
end
|
2606
2667
|
|
2607
2668
|
def set_schema(schema)
|
@@ -2660,7 +2721,7 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
2660
2721
|
end
|
2661
2722
|
|
2662
2723
|
def primary_key_definition(start_id)
|
2663
|
-
return "INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH #{start_id}) PRIMARY KEY"
|
2724
|
+
return "INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH #{start_id}) PRIMARY KEY NOT NULL"
|
2664
2725
|
end
|
2665
2726
|
|
2666
2727
|
# Returns the last automatically generated ID.
|
@@ -2710,6 +2771,9 @@ To remove the column, the table must be dropped and recreated without the #{colu
|
|
2710
2771
|
end
|
2711
2772
|
|
2712
2773
|
def change_column(table_name, column_name, type, options)
|
2774
|
+
if !options[:default].nil?
|
2775
|
+
change_column_default(table_name, column_name, options[:default])
|
2776
|
+
else
|
2713
2777
|
data_type = @adapter.type_to_sql(type, options[:limit], options[:precision], options[:scale])
|
2714
2778
|
begin
|
2715
2779
|
execute "ALTER TABLE #{table_name} ALTER #{column_name} SET DATA TYPE #{data_type}"
|
@@ -2727,6 +2791,7 @@ The column datatype change to [#{data_type}] is not supported by this data serve
|
|
2727
2791
|
change_column_default(table_name, column_name, options[:default])
|
2728
2792
|
reorg_table(table_name)
|
2729
2793
|
end
|
2794
|
+
end
|
2730
2795
|
|
2731
2796
|
# DB2 specific ALTER TABLE statement to add a default clause
|
2732
2797
|
def change_column_default(table_name, column_name, default)
|
@@ -2811,7 +2876,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
|
|
2811
2876
|
return retHash
|
2812
2877
|
end
|
2813
2878
|
|
2814
|
-
def query_offset_limit(sql, offset, limit)
|
2879
|
+
def query_offset_limit(sql, offset, limit)
|
2815
2880
|
if(offset.nil? && limit.nil?)
|
2816
2881
|
return sql
|
2817
2882
|
end
|
@@ -3327,7 +3392,7 @@ end
|
|
3327
3392
|
rescue
|
3328
3393
|
arelVersion = 0
|
3329
3394
|
end
|
3330
|
-
if(arelVersion >= 6)
|
3395
|
+
if(arelVersion >= 6 && arelVersion <= 9)
|
3331
3396
|
class ToSql < Arel::Visitors::Reduce #opening and closing the class to ensure backward compatibility
|
3332
3397
|
# In case when using Rails-2.3.x there is no arel used due to which the constructor has to be defined explicitly
|
3333
3398
|
# to ensure the same code works on any version of Rails
|
@@ -3381,19 +3446,36 @@ end
|
|
3381
3446
|
private
|
3382
3447
|
|
3383
3448
|
|
3384
|
-
|
3449
|
+
def visit_Arel_Nodes_Limit o,collector
|
3385
3450
|
visit o.expr, collector
|
3386
3451
|
end
|
3387
3452
|
|
3388
3453
|
def visit_Arel_Nodes_Offset o,collector
|
3389
3454
|
visit o.expr,collector
|
3390
3455
|
end
|
3391
|
-
|
3392
|
-
|
3393
|
-
|
3456
|
+
def visit_Arel_Nodes_ValuesList(o, collector)
|
3457
|
+
collector << "VALUES "
|
3458
|
+
o.rows.each_with_index do |row, i|
|
3459
|
+
collector << ", " unless i == 0
|
3460
|
+
collector << "("
|
3461
|
+
row.each_with_index do |value, k|
|
3462
|
+
collector << ", " unless k == 0
|
3463
|
+
case value
|
3464
|
+
when Nodes::SqlLiteral, Nodes::BindParam
|
3465
|
+
collector = visit(value, collector)
|
3466
|
+
#collector << quote(value).to_s
|
3467
|
+
else
|
3468
|
+
collector << value.to_s
|
3469
|
+
end
|
3470
|
+
end
|
3471
|
+
collector << ")"
|
3472
|
+
end
|
3473
|
+
collector
|
3474
|
+
end
|
3475
|
+
def visit_Arel_Nodes_SelectStatement o, collector
|
3394
3476
|
if o.with
|
3395
3477
|
collector = visit o.with, collector
|
3396
|
-
collector <<
|
3478
|
+
collector << " "
|
3397
3479
|
end
|
3398
3480
|
|
3399
3481
|
collector = o.cores.inject(collector) { |c,x|
|
@@ -3401,11 +3483,11 @@ end
|
|
3401
3483
|
}
|
3402
3484
|
|
3403
3485
|
unless o.orders.empty?
|
3404
|
-
collector <<
|
3486
|
+
collector << " ORDER BY "
|
3405
3487
|
len = o.orders.length - 1
|
3406
3488
|
o.orders.each_with_index { |x, i|
|
3407
3489
|
collector = visit(x, collector)
|
3408
|
-
collector <<
|
3490
|
+
collector << "," unless len == i
|
3409
3491
|
}
|
3410
3492
|
end
|
3411
3493
|
|
@@ -3435,7 +3517,7 @@ end
|
|
3435
3517
|
|
3436
3518
|
if( !limOffClause["endSegment"].empty? )
|
3437
3519
|
#collector.changeEndSegment(limOffClause["endSegment"])
|
3438
|
-
collector <<
|
3520
|
+
collector << " "
|
3439
3521
|
collector << limOffClause["endSegment"]
|
3440
3522
|
end
|
3441
3523
|
|
@@ -3443,9 +3525,8 @@ end
|
|
3443
3525
|
#collector.reset(sql)
|
3444
3526
|
|
3445
3527
|
collector = maybe_visit o.lock, collector
|
3446
|
-
|
3447
3528
|
return collector
|
3448
|
-
|
3529
|
+
end
|
3449
3530
|
|
3450
3531
|
end
|
3451
3532
|
end
|