ibm_db 4.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/README +2 -2
  3. data/ext/Makefile +266 -0
  4. data/ext/Makefile.nt32.191 +1 -1
  5. data/ext/extconf.rb +38 -7
  6. data/ext/gil_release_version.h +3 -0
  7. data/ext/ibm_db.c +387 -395
  8. data/ext/ibm_db.o +0 -0
  9. data/ext/ibm_db.so +0 -0
  10. data/ext/mkmf.log +103 -0
  11. data/ext/ruby_ibm_db.h +1 -1
  12. data/ext/ruby_ibm_db_cli.c +23 -23
  13. data/ext/ruby_ibm_db_cli.h +5 -5
  14. data/ext/ruby_ibm_db_cli.o +0 -0
  15. data/ext/unicode_support_version.h +3 -0
  16. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +348 -207
  17. data/test/cases/attribute_decorators_test.rb +2 -1
  18. data/test/cases/cache_key_test.rb +2 -1
  19. data/test/cases/comment_test.rb +4 -2
  20. data/test/cases/date_time_precision_test.rb +2 -1
  21. data/test/cases/defaults_test.rb +2 -1
  22. data/test/cases/migration/foreign_key_test.rb +4 -2
  23. data/test/cases/migration/helper.rb +1 -1
  24. data/test/cases/migration/references_foreign_key_test.rb +10 -5
  25. data/test/cases/migrator_test.rb +2 -1
  26. data/test/cases/schema_dumper_test.rb +3 -3
  27. data/test/cases/time_precision_test.rb +2 -1
  28. data/test/cases/transactions_test.rb +3 -2
  29. data/test/config.yml +154 -154
  30. data/test/connections/native_ibm_db/connection.rb +44 -0
  31. data/test/fixtures/admin/randomly_named_a9.yml +7 -7
  32. data/test/fixtures/admin/randomly_named_b0.yml +7 -7
  33. data/test/fixtures/developers.yml +1 -1
  34. data/test/fixtures/pirates.yml +0 -3
  35. data/test/fixtures/randomly_named_a9.yml +7 -7
  36. data/test/ibm_db_test.rb +24 -24
  37. data/test/models/admin.rb +1 -1
  38. data/test/models/admin/account.rb +1 -1
  39. data/test/models/admin/randomly_named_c1.rb +7 -7
  40. data/test/models/binary.rb +1 -1
  41. data/test/models/event.rb +1 -1
  42. data/test/models/guid.rb +1 -1
  43. data/test/models/randomly_named_c1.rb +3 -3
  44. data/test/models/ship_part.rb +1 -1
  45. data/test/schema/i5/ibm_db_specific_schema.rb +137 -0
  46. data/test/schema/ids/ibm_db_specific_schema.rb +140 -0
  47. data/test/schema/luw/ibm_db_specific_schema.rb +137 -0
  48. data/test/schema/zOS/ibm_db_specific_schema.rb +208 -0
  49. metadata +27 -13
  50. data/test/fixtures/author_addresses.original +0 -11
  51. data/test/fixtures/authors.original +0 -17
Binary file
Binary file
@@ -0,0 +1,103 @@
1
+ gil_release_version.h is:
2
+ /* begin */
3
+ 1: #ifndef GIL_RELEASE_VERSION_H
4
+ 2: #define GIL_RELEASE_VERSION_H
5
+ 3: #endif
6
+ /* end */
7
+
8
+ unicode_support_version.h is:
9
+ /* begin */
10
+ 1: #ifndef UNICODE_SUPPORT_VERSION_H
11
+ 2: #define UNICODE_SUPPORT_VERSION_H
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/work/rakhil/ruby_5.1.0/ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext/../lib/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/work/rakhil/ruby_5.1.0/ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext/../lib/clidriver/lib -Wl,-rpath,/work/rakhil/ruby_5.1.0/ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext/../lib/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/work/rakhil/ruby_5.1.0/ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext/../lib/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/work/rakhil/ruby_5.1.0/ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext/../lib/clidriver/lib -Wl,-rpath,/work/rakhil/ruby_5.1.0/ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext/../lib/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/work/rakhil/ruby_5.1.0/ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext/../lib/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/work/rakhil/ruby_5.1.0/ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext/../lib/clidriver/lib -Wl,-rpath,/work/rakhil/ruby_5.1.0/ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext/../lib/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.h... -------------------- 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/work/rakhil/ruby_5.1.0/ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext/../lib/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.h>
88
+ /* end */
89
+
90
+ --------------------
91
+
92
+ have_header: checking for unicode_support_version.h... -------------------- 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/work/rakhil/ruby_5.1.0/ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext/../lib/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.h>
100
+ /* end */
101
+
102
+ --------------------
103
+
@@ -206,7 +206,7 @@ VALUE ibm_db_active(int argc, VALUE *argv, VALUE self);
206
206
  */
207
207
  struct _ibm_db_globals {
208
208
  int bin_mode;
209
- #ifdef UNICODE_SUPPORT_VERSION
209
+ #ifdef UNICODE_SUPPORT_VERSION_H
210
210
  SQLWCHAR __ruby_conn_err_msg[DB2_MAX_ERR_MSG_LEN];
211
211
  SQLWCHAR __ruby_stmt_err_msg[DB2_MAX_ERR_MSG_LEN];
212
212
  SQLWCHAR __ruby_conn_err_state[SQL_SQLSTATE_SIZE + 1];
@@ -31,7 +31,7 @@
31
31
  */
32
32
  int _ruby_ibm_db_SQLConnect_helper(connect_args *data) {
33
33
  if(data->ctlg_conn == 1) {
34
- #ifndef UNICODE_SUPPORT_VERSION
34
+ #ifndef UNICODE_SUPPORT_VERSION_H
35
35
  return SQLConnect( (SQLHDBC)*(data->hdbc), (SQLCHAR *)data->database,
36
36
  (SQLSMALLINT)data->database_len, (SQLCHAR *)data->uid, (SQLSMALLINT)data->uid_len,
37
37
  (SQLCHAR *)data->password, (SQLSMALLINT)data->password_len );
@@ -41,7 +41,7 @@ int _ruby_ibm_db_SQLConnect_helper(connect_args *data) {
41
41
  data->password, data->password_len );
42
42
  #endif
43
43
  } else {
44
- #ifndef UNICODE_SUPPORT_VERSION
44
+ #ifndef UNICODE_SUPPORT_VERSION_H
45
45
  return SQLDriverConnect( (SQLHDBC) *(data->hdbc), (SQLHWND)NULL,
46
46
  (SQLCHAR*)data->database, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );
47
47
  #else
@@ -100,7 +100,7 @@ int _ruby_ibm_db_SQLDescribeCol_helper(describecol_args *data) {
100
100
 
101
101
  data->stmt_res->is_executing = 1;
102
102
 
103
- #ifdef UNICODE_SUPPORT_VERSION
103
+ #ifdef UNICODE_SUPPORT_VERSION_H
104
104
  rc = SQLDescribeColW( (SQLHSTMT)data->stmt_res->hstmt, (SQLSMALLINT)(data->col_no),
105
105
  data->stmt_res->column_info[i].name, data->buff_length, &(data->name_length),
106
106
  &(data->stmt_res->column_info[i].type), &(data->stmt_res->column_info[i].size),
@@ -140,7 +140,7 @@ int _ruby_ibm_db_SQLColumnPrivileges_helper(metadata_args *data) {
140
140
 
141
141
  data->stmt_res->is_executing = 1;
142
142
 
143
- #ifndef UNICODE_SUPPORT_VERSION
143
+ #ifndef UNICODE_SUPPORT_VERSION_H
144
144
  rc = SQLColumnPrivileges( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
145
145
  data->owner, data->owner_len, data->table_name, data->table_name_len,
146
146
  data->column_name, data->column_name_len );
@@ -164,7 +164,7 @@ int _ruby_ibm_db_SQLColumns_helper(metadata_args *data) {
164
164
 
165
165
  data->stmt_res->is_executing = 1;
166
166
 
167
- #ifndef UNICODE_SUPPORT_VERSION
167
+ #ifndef UNICODE_SUPPORT_VERSION_H
168
168
  rc = SQLColumns( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
169
169
  data->owner, data->owner_len, data->table_name, data->table_name_len,
170
170
  data->column_name, data->column_name_len );
@@ -187,7 +187,7 @@ int _ruby_ibm_db_SQLPrimaryKeys_helper(metadata_args *data) {
187
187
 
188
188
  data->stmt_res->is_executing = 1;
189
189
 
190
- #ifndef UNICODE_SUPPORT_VERSION
190
+ #ifndef UNICODE_SUPPORT_VERSION_H
191
191
  rc = SQLPrimaryKeys( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
192
192
  data->owner, data->owner_len, data->table_name, data->table_name_len );
193
193
  #else
@@ -210,7 +210,7 @@ int _ruby_ibm_db_SQLForeignKeys_helper(metadata_args *data) {
210
210
 
211
211
  if(!NIL_P(data->table_type))
212
212
  {
213
- #ifndef UNICODE_SUPPORT_VERSION
213
+ #ifndef UNICODE_SUPPORT_VERSION_H
214
214
  rc = SQLForeignKeys( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
215
215
  data->owner, data->owner_len, NULL , SQL_NTS, NULL, SQL_NTS,
216
216
  NULL, SQL_NTS, data->table_name, data->table_name_len );
@@ -222,7 +222,7 @@ int _ruby_ibm_db_SQLForeignKeys_helper(metadata_args *data) {
222
222
  }
223
223
  else
224
224
  {
225
- #ifndef UNICODE_SUPPORT_VERSION
225
+ #ifndef UNICODE_SUPPORT_VERSION_H
226
226
  rc = SQLForeignKeys( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
227
227
  data->owner, data->owner_len, data->table_name , data->table_name_len, NULL, SQL_NTS,
228
228
  NULL, SQL_NTS, NULL, SQL_NTS );
@@ -247,7 +247,7 @@ int _ruby_ibm_db_SQLProcedureColumns_helper(metadata_args *data) {
247
247
 
248
248
  data->stmt_res->is_executing = 1;
249
249
 
250
- #ifndef UNICODE_SUPPORT_VERSION
250
+ #ifndef UNICODE_SUPPORT_VERSION_H
251
251
  rc = SQLProcedureColumns( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
252
252
  data->owner_len, data->proc_name, data->proc_name_len, data->column_name, data->column_name_len );
253
253
  #else
@@ -269,7 +269,7 @@ int _ruby_ibm_db_SQLProcedures_helper(metadata_args *data) {
269
269
 
270
270
  data->stmt_res->is_executing = 1;
271
271
 
272
- #ifndef UNICODE_SUPPORT_VERSION
272
+ #ifndef UNICODE_SUPPORT_VERSION_H
273
273
  rc = SQLProcedures( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
274
274
  data->owner_len, data->proc_name, data->proc_name_len );
275
275
  #else
@@ -291,7 +291,7 @@ int _ruby_ibm_db_SQLSpecialColumns_helper(metadata_args *data) {
291
291
 
292
292
  data->stmt_res->is_executing = 1;
293
293
 
294
- #ifndef UNICODE_SUPPORT_VERSION
294
+ #ifndef UNICODE_SUPPORT_VERSION_H
295
295
  rc = SQLSpecialColumns( (SQLHSTMT) data->stmt_res->hstmt, SQL_BEST_ROWID, data->qualifier, data->qualifier_len,
296
296
  data->owner, data->owner_len, data->table_name, data->table_name_len,
297
297
  (SQLUSMALLINT)data->scope, SQL_NULLABLE );
@@ -314,7 +314,7 @@ int _ruby_ibm_db_SQLStatistics_helper(metadata_args *data) {
314
314
 
315
315
  data->stmt_res->is_executing = 1;
316
316
 
317
- #ifndef UNICODE_SUPPORT_VERSION
317
+ #ifndef UNICODE_SUPPORT_VERSION_H
318
318
  rc = SQLStatistics( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
319
319
  data->owner_len, data->table_name, data->table_name_len, (SQLUSMALLINT)data->unique, SQL_QUICK );
320
320
  #else
@@ -336,7 +336,7 @@ int _ruby_ibm_db_SQLTablePrivileges_helper(metadata_args *data) {
336
336
 
337
337
  data->stmt_res->is_executing = 1;
338
338
 
339
- #ifndef UNICODE_SUPPORT_VERSION
339
+ #ifndef UNICODE_SUPPORT_VERSION_H
340
340
  rc = SQLTablePrivileges( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
341
341
  data->owner, data->owner_len, data->table_name, data->table_name_len );
342
342
  #else
@@ -358,7 +358,7 @@ int _ruby_ibm_db_SQLTables_helper(metadata_args *data) {
358
358
 
359
359
  data->stmt_res->is_executing = 1;
360
360
 
361
- #ifndef UNICODE_SUPPORT_VERSION
361
+ #ifndef UNICODE_SUPPORT_VERSION_H
362
362
  rc = SQLTables( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
363
363
  data->owner_len, data->table_name, data->table_name_len, data->table_type, data->table_type_len );
364
364
  #else
@@ -379,7 +379,7 @@ int _ruby_ibm_db_SQLExecDirect_helper(exec_cum_prepare_args *data) {
379
379
 
380
380
  data->stmt_res->is_executing = 1;
381
381
 
382
- #ifndef UNICODE_SUPPORT_VERSION
382
+ #ifndef UNICODE_SUPPORT_VERSION_H
383
383
  rc = SQLExecDirect( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
384
384
  #else
385
385
  rc = SQLExecDirectW( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
@@ -395,7 +395,7 @@ int _ruby_ibm_db_SQLExecDirect_helper(exec_cum_prepare_args *data) {
395
395
  */
396
396
  int _ruby_ibm_db_SQLCreateDB_helper(create_drop_db_args *data) {
397
397
  int rc = 0;
398
- #ifndef UNICODE_SUPPORT_VERSION
398
+ #ifndef UNICODE_SUPPORT_VERSION_H
399
399
  #ifdef _WIN32
400
400
  HINSTANCE cliLib = NULL;
401
401
  FARPROC sqlcreatedb;
@@ -450,7 +450,7 @@ int _ruby_ibm_db_SQLCreateDB_helper(create_drop_db_args *data) {
450
450
  */
451
451
  int _ruby_ibm_db_SQLDropDB_helper(create_drop_db_args *data) {
452
452
  int rc = 0;
453
- #ifndef UNICODE_SUPPORT_VERSION
453
+ #ifndef UNICODE_SUPPORT_VERSION_H
454
454
  #ifdef _WIN32
455
455
  HINSTANCE cliLib = NULL;
456
456
  FARPROC sqldropdb;
@@ -506,7 +506,7 @@ int _ruby_ibm_db_SQLPrepare_helper(exec_cum_prepare_args *data) {
506
506
 
507
507
  data->stmt_res->is_executing = 1;
508
508
 
509
- #ifndef UNICODE_SUPPORT_VERSION
509
+ #ifndef UNICODE_SUPPORT_VERSION_H
510
510
  rc = SQLPrepare( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
511
511
  #else
512
512
  rc = SQLPrepareW( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
@@ -742,7 +742,7 @@ int _ruby_ibm_db_SQLRowCount_helper(sql_row_count_args *data) {
742
742
  This function calls SQLGetInfo cli call to get general information about DBMS, which the app is connected to
743
743
  */
744
744
  int _ruby_ibm_db_SQLGetInfo_helper(get_info_args *data) {
745
- #ifndef UNICODE_SUPPORT_VERSION
745
+ #ifndef UNICODE_SUPPORT_VERSION_H
746
746
  return SQLGetInfo( data->conn_res->hdbc, data->infoType, data->infoValue, data->buff_length, data->out_length);
747
747
  #else
748
748
  return SQLGetInfoW( data->conn_res->hdbc, data->infoType, data->infoValue, data->buff_length, data->out_length);
@@ -753,7 +753,7 @@ int _ruby_ibm_db_SQLGetInfo_helper(get_info_args *data) {
753
753
  This function calls SQLGetDiagRec cli call to get the current values of a diagnostic record that contains error
754
754
  */
755
755
  int _ruby_ibm_db_SQLGetDiagRec_helper(get_diagRec_args *data) {
756
- #ifdef UNICODE_SUPPORT_VERSION
756
+ #ifdef UNICODE_SUPPORT_VERSION_H
757
757
  int rc= SQLGetDiagRecW( data->hType, data->handle, data->recNum, data->SQLState, data->NativeErrorPtr,
758
758
  data->msgText, data->buff_length, data->text_length_ptr );
759
759
  data->return_code=rc;
@@ -768,7 +768,7 @@ int _ruby_ibm_db_SQLGetDiagRec_helper(get_diagRec_args *data) {
768
768
  This function calls SQLSetStmtAttr cli call to set attributes related to a statement
769
769
  */
770
770
  int _ruby_ibm_db_SQLSetStmtAttr_helper(set_handle_attr_args *data) {
771
- #ifndef UNICODE_SUPPORT_VERSION
771
+ #ifndef UNICODE_SUPPORT_VERSION_H
772
772
  return SQLSetStmtAttr( (SQLHSTMT) *(data->handle), data->attribute, data->valuePtr, data->strLength );
773
773
  #else
774
774
  return SQLSetStmtAttrW( (SQLHSTMT) *(data->handle), data->attribute, data->valuePtr, data->strLength );
@@ -779,7 +779,7 @@ int _ruby_ibm_db_SQLSetStmtAttr_helper(set_handle_attr_args *data) {
779
779
  This function calls SQLSetConnectAttr cli call to set attributes that govern aspects of connections
780
780
  */
781
781
  int _ruby_ibm_db_SQLSetConnectAttr_helper(set_handle_attr_args *data) {
782
- #ifndef UNICODE_SUPPORT_VERSION
782
+ #ifndef UNICODE_SUPPORT_VERSION_H
783
783
  return SQLSetConnectAttr( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr, data->strLength );
784
784
  #else
785
785
  return SQLSetConnectAttrW( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr, data->strLength );
@@ -809,7 +809,7 @@ int _ruby_ibm_db_SQLGetStmtAttr_helper(get_handle_attr_args *data) {
809
809
  This function calls SQLGetConnectAttr cli call to set an environment attribute
810
810
  */
811
811
  int _ruby_ibm_db_SQLGetConnectAttr_helper(get_handle_attr_args *data) {
812
- #ifndef UNICODE_SUPPORT_VERSION
812
+ #ifndef UNICODE_SUPPORT_VERSION_H
813
813
  return SQLGetConnectAttr( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr,
814
814
  data->buff_length, data->out_length);
815
815
  #else
@@ -105,7 +105,7 @@ typedef struct {
105
105
  } ibm_db_row_type;
106
106
 
107
107
  typedef struct _ibm_db_result_set_info_struct {
108
- #ifdef UNICODE_SUPPORT_VERSION
108
+ #ifdef UNICODE_SUPPORT_VERSION_H
109
109
  SQLWCHAR *name;
110
110
  long name_length;
111
111
  #else
@@ -157,7 +157,7 @@ typedef struct _stmt_handle_struct {
157
157
  Structure holding the data to be passed to SQLConnect or SQLDriverConnect CLI call
158
158
  */
159
159
  typedef struct _ibm_db_connect_args_struct {
160
- #ifdef UNICODE_SUPPORT_VERSION
160
+ #ifdef UNICODE_SUPPORT_VERSION_H
161
161
  SQLWCHAR *database;
162
162
  SQLWCHAR *uid;
163
163
  SQLWCHAR *password;
@@ -211,7 +211,7 @@ typedef struct _ibm_db_describecol_args_struct {
211
211
  */
212
212
  typedef struct _ibm_db_metadata_args_struct {
213
213
  stmt_handle *stmt_res;
214
- #ifdef UNICODE_SUPPORT_VERSION
214
+ #ifdef UNICODE_SUPPORT_VERSION_H
215
215
  SQLWCHAR *qualifier;
216
216
  SQLWCHAR *owner;
217
217
  SQLWCHAR *table_name;
@@ -243,7 +243,7 @@ typedef struct _ibm_db_metadata_args_struct {
243
243
  */
244
244
  typedef struct _ibm_db_exec_direct_args_struct {
245
245
  stmt_handle *stmt_res;
246
- #ifdef UNICODE_SUPPORT_VERSION
246
+ #ifdef UNICODE_SUPPORT_VERSION_H
247
247
  SQLWCHAR *stmt_string;
248
248
  #else
249
249
  SQLCHAR *stmt_string;
@@ -257,7 +257,7 @@ typedef struct _ibm_db_exec_direct_args_struct {
257
257
  */
258
258
  typedef struct _ibm_db_create_drop_db_args_struct {
259
259
  conn_handle *conn_res;
260
- #ifdef UNICODE_SUPPORT_VERSION
260
+ #ifdef UNICODE_SUPPORT_VERSION_H
261
261
  SQLWCHAR *dbName;
262
262
  SQLWCHAR *codeSet;
263
263
  SQLWCHAR *mode;
Binary file
@@ -0,0 +1,3 @@
1
+ #ifndef UNICODE_SUPPORT_VERSION_H
2
+ #define UNICODE_SUPPORT_VERSION_H
3
+ #endif
@@ -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/bind_visitor'
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
- def self.caller_method(depth=1)
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
- def self.parse_caller(at)
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
- def create_table
46
- #puts "Calling method : " << CallChain.caller_method << "\n"
47
- #puts "Calling method for create_table(): " << String(caller(start=1, length=nil) )
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, id: false) do |t|
51
+ connection.create_table(table_name,id:false) do |t|
52
52
  t.string :version, version_options
53
53
  end
54
- end
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
- def insert(values)
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
- # require 'active_record/connection_adapters/ibm_db_pstmt'
214
- #end
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
- checkClass = ActiveRecord::ConnectionAdapters::TableDefinition.new(nil)
217
+ checkClass = ActiveRecord::ConnectionAdapters::TableDefinition.new(self,nil)
219
218
  if(checkClass.respond_to?(:indexes))
220
219
  isAr3 = false
221
220
  else
222
- isAr3 = true
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
- def lookup_cast_type_from_column(column) # :nodoc:
343
- #type_map.lookup(column.oid, column.fmod, column.sql_type)
344
- lookup_cast_type(column.sql_type_metadata)
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
- def create_savepoint(name = current_savepoint_name)
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
- def prepare_column_options(column)
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
- def internal_string_options_for_primary_key # :nodoc:
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
- def create_table_definition(*args)
427
- TableDefinition.new(*args)
424
+ def create_table_definition(*args, **options)
425
+ TableDefinition.new(self, *args, **options)
428
426
  end
429
427
 
430
- def remove_foreign_key(from_table, options_or_to_table = {})
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
- def initialize(*)
462
- super
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
- def primary_key(name, type = :primary_key, **options)
491
- column(name, type, options.merge(primary_key: true))
492
- end
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
- def initialize(name, temporary = false, options = nil, as = nil, comment: nil)
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
- ibm_parse_column_attributes_args('char',*args)
657
- return self
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
- # construct a column definition where @base is adaptor instance
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::BindVisitor
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 )
@@ -800,6 +800,10 @@ module ActiveRecord
800
800
  @servertype = IBM_DB2_ZOS.new(self, @isAr3)
801
801
  when /10/
802
802
  @servertype = IBM_DB2_ZOS.new(self, @isAr3)
803
+ when /11/
804
+ @servertype = IBM_DB2_ZOS.new(self, @isAr3)
805
+ when /12/
806
+ @servertype = IBM_DB2_ZOS.new(self, @isAr3)
803
807
  when /08/ # DB2 for zOS version 8
804
808
  @servertype = IBM_DB2_ZOS_8.new(self, @isAr3)
805
809
  else # DB2 for zOS version 7
@@ -911,7 +915,7 @@ module ActiveRecord
911
915
  rescue
912
916
  @arelVersion = 0
913
917
  end
914
- if(@arelVersion < 6)
918
+ if(@arelVersion < 6 )
915
919
  def to_sql(arel, binds = [])
916
920
  if arel.respond_to?(:ast)
917
921
  visitor.accept(arel.ast) do
@@ -933,9 +937,11 @@ module ActiveRecord
933
937
 
934
938
  def supports_foreign_keys?
935
939
  true
940
+ end
941
+
942
+ def supports_datetime_with_precision?
943
+ true
936
944
  end
937
-
938
-
939
945
 
940
946
  # This Adapter supports DDL transactions.
941
947
  # This means CREATE TABLE and other DDL statements can be carried out as a transaction.
@@ -1020,21 +1026,20 @@ module ActiveRecord
1020
1026
 
1021
1027
  def create_table(name, options = {})
1022
1028
  @servertype.setup_for_lob_table
1023
- super
1024
-
1025
1029
  #Table definition is complete only when a unique index is created on the primarykey column for DB2 V8 on zOS
1026
1030
 
1027
1031
  #create index on id column if options[:id] is nil or id ==true
1028
1032
  #else check if options[:primary_key]is not nil then create an unique index on that column
1029
1033
  if !options[:id].nil? || !options[:primary_key].nil?
1030
1034
  if (!options[:id].nil? && options[:id] == true)
1031
- @servertype.create_index_after_table(name,"id")
1035
+ @servertype.create_index_after_table(name,"id")
1032
1036
  elsif !options[:primary_key].nil?
1033
- @servertype.create_index_after_table(name,options[:primary_key].to_s)
1037
+ @servertype.create_index_after_table(name,options[:primary_key].to_s)
1034
1038
  end
1035
1039
  else
1036
- @servertype.create_index_after_table(name,"id")
1037
- end
1040
+ @servertype.create_index_after_table(name,"id")
1041
+ end
1042
+ super(name, options)
1038
1043
  end
1039
1044
 
1040
1045
  # Returns an array of hashes with the column names as keys and
@@ -1125,9 +1130,8 @@ module ActiveRecord
1125
1130
  end
1126
1131
 
1127
1132
  def select(sql, name = nil, binds = [])
1128
-
1129
- # Replaces {"= NULL" with " IS NULL"} OR {"IN (NULL)" with " IS NULL"}
1130
- sql.gsub!( /(=\s*NULL|IN\s*\(NULL\))/i, " IS NULL" )
1133
+ # Replaces {"= NULL" with " IS NULL"} OR {"IN (NULL)" with " IS NULL"
1134
+ sql.gsub( /(=\s*NULL|IN\s*\(NULL\))/i, " IS NULL" )
1131
1135
 
1132
1136
  results = []
1133
1137
 
@@ -1155,7 +1159,7 @@ module ActiveRecord
1155
1159
  #+sql+ is the select query and +name+ is an optional description for logging
1156
1160
  def select_rows(sql, name = nil,binds = [])
1157
1161
  # Replaces {"= NULL" with " IS NULL"} OR {"IN (NULL)" with " IS NULL"}
1158
- sql.gsub!( /(=\s*NULL|IN\s*\(NULL\))/i, " IS NULL" )
1162
+ sql.gsub( /(=\s*NULL|IN\s*\(NULL\))/i, " IS NULL" )
1159
1163
 
1160
1164
  results = []
1161
1165
  # Invokes the method +execute+ in order to log and execute the SQL
@@ -1287,12 +1291,12 @@ module ActiveRecord
1287
1291
  end
1288
1292
  end
1289
1293
 
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 = sql_for_insert(to_sql(arel, binds), pk, id_value, sequence_name, binds) #[to_sql(arel),binds]
1295
- end
1294
+ def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds=[])
1295
+ if(@arelVersion < 6)
1296
+ sql, binds = [to_sql(arel), binds]
1297
+ else
1298
+ sql, binds = [to_sql(arel),binds] #sql_for_insert(to_sql(arel, binds), binds) #[to_sql(arel),binds]
1299
+ end
1296
1300
 
1297
1301
  #unless IBM_DBAdapter.respond_to?(:exec_insert)
1298
1302
  if binds.nil? || binds.empty?
@@ -1395,14 +1399,18 @@ module ActiveRecord
1395
1399
 
1396
1400
  # Executes and logs +sql+ commands and
1397
1401
  # returns a +IBM_DB.Statement+ object.
1398
- def execute(sql, name = nil)
1402
+ def execute(sql, name=nil)
1399
1403
  # Logs and execute the sql instructions.
1400
1404
  # The +log+ method is defined in the parent class +AbstractAdapter+
1401
- log(sql, name) do
1405
+ #sql='INSERT INTO ar_internal_metadata (key, value, created_at, updated_at) VALUES ('10', '10', '10', '10')
1406
+ log(sql , name) do
1402
1407
  @servertype.execute(sql, name)
1403
1408
  end
1404
1409
  end
1405
1410
 
1411
+ def exec_insert(sql,name,binds,pk,sequence_name)
1412
+ end
1413
+
1406
1414
  # Executes an "UPDATE" SQL statement
1407
1415
  def update_direct(sql, name = nil)
1408
1416
  if @handle_lobs_triggered #Ensure the array of sql is cleared if they have been handled in the callback
@@ -1454,10 +1462,10 @@ module ActiveRecord
1454
1462
 
1455
1463
  def update(arel, name = nil, binds = [])
1456
1464
  if(@arelVersion < 6 )
1457
- sql = to_sql(arel)
1458
- else
1459
- sql = to_sql(arel,binds)
1460
- end
1465
+ sql = to_sql(arel)
1466
+ else
1467
+ sql = to_sql(arel,binds)
1468
+ end
1461
1469
 
1462
1470
  # Make sure the WHERE clause handles NULL's correctly
1463
1471
  sqlarray = sql.split(/\s*WHERE\s*/)
@@ -1515,6 +1523,7 @@ module ActiveRecord
1515
1523
  end
1516
1524
 
1517
1525
  def get_limit_offset_clauses(limit,offset)
1526
+
1518
1527
  if limit && limit == 0
1519
1528
  clauses = @servertype.get_limit_offset_clauses(limit,0)
1520
1529
  else
@@ -1584,7 +1593,6 @@ module ActiveRecord
1584
1593
  end
1585
1594
  end
1586
1595
  =end
1587
-
1588
1596
  def quote_value_for_pstmt(value, column=nil)
1589
1597
 
1590
1598
  return value.quoted_id if value.respond_to?(:quoted_id)
@@ -1613,75 +1621,82 @@ module ActiveRecord
1613
1621
  end
1614
1622
  end
1615
1623
  end
1616
-
1617
1624
  # Properly quotes the various data types.
1618
1625
  # +value+ contains the data, +column+ is optional and contains info on the field
1619
- def quote(value, column = nil)
1620
- return value.quoted_id if value.respond_to?(:quoted_id)
1621
-
1622
- case value
1623
- # If it's a numeric value and the column sql_type is not a string, it shouldn't be quoted
1624
- # (IBM_DB doesn't accept quotes on numeric types)
1625
- when Numeric
1626
- # If the column sql_type is text or string, return the quote value
1627
- if (column && ( column.sql_type.to_s =~ /text|char/i ))
1628
- unless caller[0] =~ /insert_fixture/i
1629
- "'#{value}'"
1630
- else
1631
- "#{value}"
1632
- end
1633
- else
1634
- # value is Numeric, column.sql_type is not a string,
1635
- # therefore it converts the number to string without quoting it
1636
- value.to_s
1637
- end
1638
- when String, ActiveSupport::Multibyte::Chars
1639
- if column && column.sql_type.to_s =~ /binary|blob/i && !(column.sql_type.to_s =~ /for bit data/i)
1640
- # If quoting is required for the insert/update of a BLOB
1641
- unless caller[0] =~ /add_column_options/i
1642
- # Invokes a convertion from string to binary
1643
- @servertype.set_binary_value
1644
- else
1645
- # Quoting required for the default value of a column
1646
- @servertype.set_binary_default(value)
1647
- end
1648
- elsif column && column.sql_type.to_s =~ /text|clob/i
1649
- unless caller[0] =~ /add_column_options/i
1650
- @servertype.set_text_default(quote_string(value))
1651
- else
1652
- @servertype.set_text_default(quote_string(value))
1653
- end
1654
- elsif column && column.sql_type.to_s =~ /xml/i
1655
- unless caller[0] =~ /add_column_options/i
1656
- "#{value}"
1657
- else
1658
- "#{value}"
1659
- end
1660
- else
1661
- unless caller[0] =~ /insert_fixture/i
1662
- super
1663
- else
1664
- "#{value}"
1665
- end
1666
- end
1667
- when TrueClass then quoted_true # return '1' for true
1668
- when FalseClass then quoted_false # return '0' for false
1669
- when nil then "NULL"
1670
- when Date, Time then "'#{quoted_date(value)}'"
1671
- when Symbol then "'#{quote_string(value.to_s)}'"
1672
- else
1673
- unless caller[0] =~ /insert_fixture/i
1674
- "'#{quote_string(YAML.dump(value))}'"
1675
- else
1676
- "#{quote_string(YAML.dump(value))}"
1677
- end
1678
- end
1679
- end
1680
-
1681
- # Quotes a given string, escaping single quote (') characters.
1682
- def quote_string(string)
1683
- string.gsub(/'/, "''")
1684
- end
1626
+ # def quote(value, column=nil)
1627
+ # return value.quoted_id if value.respond_to?(:quoted_id)
1628
+ # case value
1629
+ # # If it's a numeric value and the column sql_type is not a string, it shouldn't be quoted
1630
+ # # (IBM_DB doesn't accept quotes on numeric types)
1631
+ # when Numeric
1632
+ # # If the column sql_type is text or string, return the quote value
1633
+ # if (column && ( column.sql_type.to_s =~ /text|char/i ))
1634
+ # unless caller[0] =~ /insert_fixture/i
1635
+ # "'#{value}'"
1636
+ # else
1637
+ # "#{value}"
1638
+ # end
1639
+ # else
1640
+ # # value is Numeric, column.sql_type is not a string,
1641
+ # # therefore it converts the number to string without quoting it
1642
+ # value.to_s
1643
+ # end
1644
+ # when String, ActiveSupport::Multibyte::Chars
1645
+ # if column && column.sql_type.to_s =~ /binary|blob/i && !(column.sql_type.to_s =~ /for bit data/i)
1646
+ # # If quoting is required for the insert/update of a BLOB
1647
+ # unless caller[0] =~ /add_column_options/i
1648
+ # # Invokes a convertion from string to binary
1649
+ # @servertype.set_binary_value
1650
+ # else
1651
+ # # Quoting required for the default value of a column
1652
+ # @servertype.set_binary_default(value)
1653
+ # end
1654
+ # elsif column && column.sql_type.to_s =~ /text|clob/i
1655
+ # unless caller[0] =~ /add_column_options/i
1656
+ # @servertype.set_text_default(quote_string(value))
1657
+ # else
1658
+ # @servertype.set_text_default(quote_string(value))
1659
+ # end
1660
+ # elsif column && column.sql_type.to_s =~ /xml/i
1661
+ # unless caller[0] =~ /add_column_options/i
1662
+ # "#{value}"
1663
+ # else
1664
+ # "#{value}"
1665
+ # end
1666
+ # else
1667
+ # unless caller[0] =~ /insert_fixture/i
1668
+ # super(value)
1669
+ # else
1670
+ # "#{value}"
1671
+ # end
1672
+ # end
1673
+ # #when TrueClass then quoted_true # return '1' for true
1674
+ # when TrueClass
1675
+ # quoted_true
1676
+ # #when FalseClass then quoted_false # return '0' for false
1677
+ # when FalseClass
1678
+ # quoted_false
1679
+ # when nil
1680
+ # "NULL"
1681
+ # when Date
1682
+ # "'#{quoted_date(value)}'"
1683
+ # when Time
1684
+ # "'#{quoted_date(value)}'"
1685
+ # when Symbol
1686
+ # "'#{quote_string(value)}'"
1687
+ # else
1688
+ # unless caller[0] =~ /insert_fixture/i
1689
+ # "'#{quote_string(YAML.dump(value))}'"
1690
+ # else
1691
+ # "#{quote_string(YAML.dump(value))}"
1692
+ # end
1693
+ # end
1694
+ # end
1695
+ # # Quotes a given string, escaping single quote (') characters.
1696
+ # def quote_string(string)
1697
+ # #string.gsub(/'/, "''")
1698
+ # string.gsub('\\', '\&\&').gsub("'", "''")
1699
+ # end
1685
1700
 
1686
1701
  # *true* is represented by a smallint 1, *false*
1687
1702
  # by 0, as no native boolean type exists in DB2.
@@ -1711,9 +1726,9 @@ module ActiveRecord
1711
1726
  :text => { :name => "clob" },
1712
1727
  :integer => { :name => "integer" },
1713
1728
  :float => { :name => "float" },
1714
- :datetime => { :name => @servertype.get_datetime_mapping },
1715
- :timestamp => { :name => @servertype.get_datetime_mapping },
1716
- :time => { :name => @servertype.get_time_mapping },
1729
+ :datetime => { :name => "timestamp" },
1730
+ :timestamp => { :name => "timestamp" },
1731
+ :time => { :name => "time" },
1717
1732
  :date => { :name => "date" },
1718
1733
  :binary => { :name => "blob" },
1719
1734
 
@@ -1728,8 +1743,8 @@ module ActiveRecord
1728
1743
  :char => { :name => "char" },
1729
1744
  :double => { :name => @servertype.get_double_mapping },
1730
1745
  :decfloat => { :name => "decfloat"},
1731
- :graphic => { :name => "graphic", :limit => 1},
1732
- :vargraphic => { :name => "vargraphic", :limit => 1},
1746
+ :graphic => { :name => "graphic"},
1747
+ :vargraphic => { :name => "vargraphic"},
1733
1748
  :bigint => { :name => "bigint"}
1734
1749
  }
1735
1750
  end
@@ -1801,14 +1816,80 @@ module ActiveRecord
1801
1816
 
1802
1817
  # IBM data servers do not support limits on certain data types (unlike MySQL)
1803
1818
  # Limit is supported for the {float, decimal, numeric, varchar, clob, blob, graphic, vargraphic} data types.
1804
- def type_to_sql(type, limit = nil, precision = nil, scale = nil)
1819
+ def type_to_sql(type, limit=nil, precision=nil, scale=nil )
1820
+ if type.to_sym == :decimal
1821
+ if limit.class == Hash
1822
+ if limit.has_key?("precision".to_sym)
1823
+ precision = limit[:precision]
1824
+ end
1825
+ end
1826
+ if limit.class == Hash
1827
+ if limit.has_key?("scale".to_sym)
1828
+ scale = limit[:scale]
1829
+ end
1830
+ end
1831
+ sql_segment = native_database_types[type.to_sym][:name].to_s
1832
+ if !precision.nil? && !scale.nil?
1833
+ sql_segment << "(#{precision},#{scale})"
1834
+ return sql_segment
1835
+ elsif scale.nil? && !precision.nil?
1836
+ sql_segment << "(#{precision})"
1837
+ else
1838
+ return sql_segment
1839
+ end
1840
+ end
1841
+
1805
1842
  if type.to_sym == :decfloat
1806
1843
  sql_segment = native_database_types[type.to_sym][:name].to_s
1807
1844
  sql_segment << "(#{precision})" if !precision.nil?
1808
1845
  return sql_segment
1809
1846
  end
1810
-
1811
- return super if limit.nil?
1847
+
1848
+ if type.to_sym == :vargraphic
1849
+ sql_segment = native_database_types[type.to_sym][:name].to_s
1850
+ if limit.class == Hash
1851
+ if limit.has_key?("limit".to_sym)
1852
+ limit1 = limit[:limit]
1853
+ sql_segment << "(#{limit1})"
1854
+ else
1855
+ return "vargraphic(1)"
1856
+ end
1857
+ else
1858
+ if limit != nil
1859
+ sql_segment << "(#{limit})"
1860
+ else
1861
+ return "vargraphic(1)"
1862
+ end
1863
+ end
1864
+ return sql_segment
1865
+ end
1866
+
1867
+ if type.to_sym == :graphic
1868
+ sql_segment = native_database_types[type.to_sym][:name].to_s
1869
+ if limit.class == Hash
1870
+ if limit.has_key?("limit".to_sym)
1871
+ limit1 = limit[:limit]
1872
+ sql_segment << "(#{limit1})"
1873
+ else
1874
+ return "graphic(1)"
1875
+ end
1876
+ else
1877
+ if limit != nil
1878
+ sql_segment << "(#{limit})"
1879
+ else
1880
+ return "graphic(1)"
1881
+ end
1882
+ end
1883
+ return sql_segment
1884
+ end
1885
+
1886
+
1887
+
1888
+ if limit.class == Hash
1889
+ return super if limit.has_key?("limit".to_sym).nil?
1890
+ else
1891
+ return super if limit.nil?
1892
+ end
1812
1893
 
1813
1894
  # strip off limits on data types not supporting them
1814
1895
  if @servertype.limit_not_supported_types.include? type.to_sym
@@ -1816,9 +1897,10 @@ module ActiveRecord
1816
1897
  elsif type.to_sym == :boolean
1817
1898
  return "smallint"
1818
1899
  else
1819
- return super
1900
+ return super(type)
1820
1901
  end
1821
- end
1902
+
1903
+ end
1822
1904
 
1823
1905
 
1824
1906
 
@@ -1952,7 +2034,7 @@ module ActiveRecord
1952
2034
 
1953
2035
  # Returns an array of non-primary key indexes for a specified table name
1954
2036
  def indexes(table_name, name = nil)
1955
- # to_s required because +table_name+ may be a symbol.
2037
+ # to_s required because +table_name+ may be a symbol.
1956
2038
  table_name = table_name.to_s
1957
2039
  # Checks if a blank table name has been given.
1958
2040
  # If so it returns an empty array of columns.
@@ -2015,7 +2097,7 @@ module ActiveRecord
2015
2097
  if(stmt)
2016
2098
  begin
2017
2099
  while ( index_stats = IBM_DB.fetch_array(stmt) )
2018
- is_composite = false
2100
+ is_composite = false
2019
2101
  if index_stats[5] # INDEX_NAME
2020
2102
  index_name = index_stats[5].downcase
2021
2103
  index_unique = (index_stats[3] == 0)
@@ -2025,7 +2107,8 @@ module ActiveRecord
2025
2107
  i = 0;
2026
2108
  indexes.each do |index|
2027
2109
  if index.name == index_name && index_schema[i] == index_qualifier
2028
- index.columns = index.columns + index_columns
2110
+ #index.columns = index.columns + index_columns
2111
+ index.columns.concat index_columns
2029
2112
  is_composite = true
2030
2113
  end
2031
2114
  i = i+1
@@ -2153,8 +2236,8 @@ module ActiveRecord
2153
2236
 
2154
2237
 
2155
2238
  # Returns an array of Column objects for the table specified by +table_name+
2156
- def columns(table_name, name = nil)
2157
- # to_s required because it may be a symbol.
2239
+ def columns(table_name)
2240
+ # to_s required because it may be a symbol.
2158
2241
  table_name = @servertype.set_case(table_name.to_s)
2159
2242
 
2160
2243
  # Checks if a blank table name has been given.
@@ -2229,7 +2312,7 @@ module ActiveRecord
2229
2312
  scale: column_scale,
2230
2313
  )
2231
2314
 
2232
- columns << Column.new(column_name, column_default_value, sqltype_metadata, column_nullable, table_name, nil, nil)
2315
+ columns << Column.new(column_name, column_default_value, sqltype_metadata, column_nullable, table_name)
2233
2316
 
2234
2317
  #else
2235
2318
  # columns << IBM_DBColumn.new(column_name, column_default_value, column_type, column_nullable)
@@ -2260,7 +2343,7 @@ module ActiveRecord
2260
2343
  return columns
2261
2344
  end
2262
2345
 
2263
- def foreign_keys(table_name)
2346
+ def foreign_keys(table_name)
2264
2347
  #fetch the foreign keys of the table using function foreign_keys
2265
2348
  #PKTABLE_NAME:: fk_row[2] Name of the table containing the primary key.
2266
2349
  #PKCOLUMN_NAME:: fk_row[3] Name of the column containing the primary key.
@@ -2309,8 +2392,9 @@ module ActiveRecord
2309
2392
  end
2310
2393
  #Returns the foreignKeys array
2311
2394
  return foreignKeys
2312
- end
2313
- def extract_foreign_key_action(specifier) # :nodoc:
2395
+ end
2396
+
2397
+ def extract_foreign_key_action(specifier) # :nodoc:
2314
2398
  case specifier
2315
2399
  when 0; :cascade
2316
2400
  when 1; :restrict
@@ -2321,9 +2405,9 @@ module ActiveRecord
2321
2405
 
2322
2406
  def supports_disable_referential_integrity? #:nodoc:
2323
2407
  true
2324
- end
2408
+ end
2325
2409
 
2326
- def disable_referential_integrity #:nodoc:
2410
+ def disable_referential_integrity #:nodoc:
2327
2411
  if supports_disable_referential_integrity?
2328
2412
  alter_foreign_keys(tables, true)
2329
2413
  end
@@ -2334,7 +2418,7 @@ module ActiveRecord
2334
2418
  alter_foreign_keys(tables, false)
2335
2419
  end
2336
2420
 
2337
- end
2421
+ end
2338
2422
 
2339
2423
  def alter_foreign_keys(tables, not_enforced)
2340
2424
  enforced = not_enforced ? 'NOT ENFORCED' : 'ENFORCED'
@@ -2343,7 +2427,7 @@ module ActiveRecord
2343
2427
  execute("ALTER TABLE #{@servertype.set_case(fk.from_table)} ALTER FOREIGN KEY #{@servertype.set_case(fk.name)} #{enforced}")
2344
2428
  end
2345
2429
  end
2346
- end
2430
+ end
2347
2431
 
2348
2432
  # Renames a table.
2349
2433
  # ==== Example
@@ -2384,7 +2468,7 @@ module ActiveRecord
2384
2468
  #Add distinct clause to the sql if there is no order by specified
2385
2469
  def distinct(columns, order_by)
2386
2470
  if order_by.nil?
2387
- "DISTINCT #{columns}"
2471
+ "DISTINCT #{columns}"
2388
2472
  else
2389
2473
  "#{columns}"
2390
2474
  end
@@ -2431,7 +2515,7 @@ module ActiveRecord
2431
2515
  # remove_index :accounts, :username
2432
2516
  # Overriden to use the IBM data servers SQL syntax.
2433
2517
  def remove_index(table_name, options = {})
2434
- execute("DROP INDEX #{index_name(table_name, options)}")
2518
+ execute("DROP INDEX #{index_name(table_name, options)}")
2435
2519
  end
2436
2520
 
2437
2521
  protected
@@ -2481,7 +2565,7 @@ module ActiveRecord
2481
2565
  class IBM_DataServer
2482
2566
  def initialize(adapter, ar3)
2483
2567
  @adapter = adapter
2484
- @isAr3 = ar3
2568
+ @isAr3 = ar3
2485
2569
  end
2486
2570
 
2487
2571
  def last_generated_id(stmt)
@@ -2588,7 +2672,9 @@ To remove the column, the table must be dropped and recreated without the #{colu
2588
2672
  end
2589
2673
  end
2590
2674
 
2591
- def execute(sql, name = nil)
2675
+ # Akhil Tcheck for if_exits added so that it will try to drop even if the table does not exit.
2676
+ def execute(sql, name = nil)
2677
+ if name == nil || name.class == String
2592
2678
  begin
2593
2679
  if stmt = IBM_DB.exec(@adapter.connection, sql)
2594
2680
  stmt # Return the statement object
@@ -2602,6 +2688,25 @@ To remove the column, the table must be dropped and recreated without the #{colu
2602
2688
  raise
2603
2689
  end
2604
2690
  end
2691
+ else
2692
+ if name[:if_exists]
2693
+ IBM_DB.exec(@adapter.connection, sql)
2694
+ else
2695
+ begin
2696
+ if stmt = IBM_DB.exec(@adapter.connection, sql)
2697
+ stmt # Return the statement object
2698
+ else
2699
+ raise StatementInvalid, IBM_DB.getErrormsg(@adapter.connection, IBM_DB::DB_CONN )
2700
+ end
2701
+ rescue StandardError => exec_err
2702
+ if exec_err && !exec_err.message.empty?
2703
+ raise "Failed to execute statement due to: #{exec_err}"
2704
+ else
2705
+ raise
2706
+ end
2707
+ end
2708
+ end
2709
+ end
2605
2710
  end
2606
2711
 
2607
2712
  def set_schema(schema)
@@ -2660,7 +2765,7 @@ To remove the column, the table must be dropped and recreated without the #{colu
2660
2765
  end
2661
2766
 
2662
2767
  def primary_key_definition(start_id)
2663
- return "INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH #{start_id}) PRIMARY KEY"
2768
+ return "INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH #{start_id}) PRIMARY KEY NOT NULL"
2664
2769
  end
2665
2770
 
2666
2771
  # Returns the last automatically generated ID.
@@ -2710,6 +2815,9 @@ To remove the column, the table must be dropped and recreated without the #{colu
2710
2815
  end
2711
2816
 
2712
2817
  def change_column(table_name, column_name, type, options)
2818
+ if !options[:default].nil?
2819
+ change_column_default(table_name, column_name, options[:default])
2820
+ else
2713
2821
  data_type = @adapter.type_to_sql(type, options[:limit], options[:precision], options[:scale])
2714
2822
  begin
2715
2823
  execute "ALTER TABLE #{table_name} ALTER #{column_name} SET DATA TYPE #{data_type}"
@@ -2727,6 +2835,7 @@ The column datatype change to [#{data_type}] is not supported by this data serve
2727
2835
  change_column_default(table_name, column_name, options[:default])
2728
2836
  reorg_table(table_name)
2729
2837
  end
2838
+ end
2730
2839
 
2731
2840
  # DB2 specific ALTER TABLE statement to add a default clause
2732
2841
  def change_column_default(table_name, column_name, default)
@@ -2811,7 +2920,7 @@ SET WITH DEFAULT #{@adapter.quote(default)}"
2811
2920
  return retHash
2812
2921
  end
2813
2922
 
2814
- def query_offset_limit(sql, offset, limit)
2923
+ def query_offset_limit(sql, offset, limit)
2815
2924
  if(offset.nil? && limit.nil?)
2816
2925
  return sql
2817
2926
  end
@@ -3327,7 +3436,7 @@ end
3327
3436
  rescue
3328
3437
  arelVersion = 0
3329
3438
  end
3330
- if(arelVersion >= 6)
3439
+ if(arelVersion >= 6 && arelVersion <= 9)
3331
3440
  class ToSql < Arel::Visitors::Reduce #opening and closing the class to ensure backward compatibility
3332
3441
  # In case when using Rails-2.3.x there is no arel used due to which the constructor has to be defined explicitly
3333
3442
  # to ensure the same code works on any version of Rails
@@ -3381,19 +3490,38 @@ end
3381
3490
  private
3382
3491
 
3383
3492
 
3384
- def visit_Arel_Nodes_Limit o,collector
3493
+ def visit_Arel_Nodes_Limit o,collector
3494
+ collector << " FETCH FIRST "
3385
3495
  visit o.expr, collector
3496
+ collector << " ROWS ONLY "
3386
3497
  end
3387
3498
 
3388
3499
  def visit_Arel_Nodes_Offset o,collector
3389
3500
  visit o.expr,collector
3390
3501
  end
3391
-
3392
- def visit_Arel_Nodes_SelectStatement o, collector
3393
-
3502
+ def visit_Arel_Nodes_ValuesList(o, collector)
3503
+ collector << "VALUES "
3504
+ o.rows.each_with_index do |row, i|
3505
+ collector << ", " unless i == 0
3506
+ collector << "("
3507
+ row.each_with_index do |value, k|
3508
+ collector << ", " unless k == 0
3509
+ case value
3510
+ when Nodes::SqlLiteral, Nodes::BindParam
3511
+ collector = visit(value, collector)
3512
+ #collector << quote(value).to_s
3513
+ else
3514
+ collector << value.to_s
3515
+ end
3516
+ end
3517
+ collector << ")"
3518
+ end
3519
+ collector
3520
+ end
3521
+ def visit_Arel_Nodes_SelectStatement o, collector
3394
3522
  if o.with
3395
3523
  collector = visit o.with, collector
3396
- collector << SPACE
3524
+ collector << " "
3397
3525
  end
3398
3526
 
3399
3527
  collector = o.cores.inject(collector) { |c,x|
@@ -3401,51 +3529,64 @@ end
3401
3529
  }
3402
3530
 
3403
3531
  unless o.orders.empty?
3404
- collector << ORDER_BY
3532
+ collector << " ORDER BY "
3405
3533
  len = o.orders.length - 1
3406
3534
  o.orders.each_with_index { |x, i|
3407
3535
  collector = visit(x, collector)
3408
- collector << COMMA unless len == i
3536
+ collector << "," unless len == i
3409
3537
  }
3410
3538
  end
3411
3539
 
3412
3540
 
3413
- if o.limit
3414
- limcoll = Arel::Collectors::SQLString.new
3415
- visit(o.limit,limcoll)
3416
- limit = limcoll.value.to_i
3417
- else
3418
- limit = nil
3419
- end
3420
-
3421
- if o.offset
3422
- offcoll = Arel::Collectors::SQLString.new
3423
- visit(o.offset,offcoll)
3424
- offset = offcoll.value.to_i
3425
- else
3426
- offset = nil
3427
- end
3428
-
3429
- limOffClause = @connection.get_limit_offset_clauses(limit,offset)
3430
-
3431
- if( !limOffClause["startSegment"].empty? )
3432
- #collector.changeFirstSegment(limOffClause["startSegment"])
3433
- collector.value.prepend(limOffClause["startSegment"])
3434
- end
3435
-
3436
- if( !limOffClause["endSegment"].empty? )
3437
- #collector.changeEndSegment(limOffClause["endSegment"])
3438
- collector << SPACE
3439
- collector << limOffClause["endSegment"]
3440
- end
3541
+ # if o.limit
3542
+ # limcoll = Arel::Collectors::SQLString.new
3543
+ # visit(o.limit,limcoll)
3544
+ # limit = limcoll.value.to_i
3545
+ # else
3546
+ # limit = nil
3547
+ # end
3548
+ #
3549
+ # if o.offset
3550
+ # offcoll = Arel::Collectors::SQLString.new
3551
+ # visit(o.offset,offcoll)
3552
+ # offset = offcoll.value.to_i
3553
+ # else
3554
+ # offset = nil
3555
+ # end
3556
+ #
3557
+ # limOffClause = @connection.get_limit_offset_clauses(limit,offset)
3558
+ #
3559
+ # if( !limOffClause["startSegment"].empty? )
3560
+ # #collector.changeFirstSegment(limOffClause["startSegment"])
3561
+ # collector.value.prepend(limOffClause["startSegment"])
3562
+ # end
3563
+ #
3564
+ # if( !limOffClause["endSegment"].empty? )
3565
+ # #collector.changeEndSegment(limOffClause["endSegment"])
3566
+ # collector << " "
3567
+ # collector << limOffClause["endSegment"]
3568
+ # end
3441
3569
 
3442
3570
  #Initialize a new Collector and set its value to the sql string built so far with any limit and ofset modifications
3443
3571
  #collector.reset(sql)
3444
-
3445
- collector = maybe_visit o.lock, collector
3446
-
3447
- return collector
3448
- end
3572
+ if (o.limit && o.offset.nil?)
3573
+ visit(o.limit, collector)
3574
+ end
3575
+ if (o.offset && o.limit.nil?)
3576
+ collector.value.prepend(" SELECT O.* FROM (SELECT I.*, ROW_NUMBER() OVER () sys_row_num FROM ( ")
3577
+ collector << (" ) AS I) AS O WHERE sys_row_num > ")
3578
+ visit(o.offset, collector)
3579
+ end
3580
+
3581
+ if (o.offset && o.limit)
3582
+ collector.value.prepend(" SELECT O.* FROM (SELECT I.*, ROW_NUMBER() OVER () sys_row_num FROM ( ")
3583
+ collector << (" ) AS I) AS O WHERE sys_row_num > ")
3584
+ visit(o.offset, collector)
3585
+ visit(o.limit, collector)
3586
+ end
3587
+ collector = maybe_visit o.lock, collector
3588
+ return collector
3589
+ end
3449
3590
 
3450
3591
  end
3451
3592
  end