db2 2.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGES +181 -0
  3. data/LICENSE +18 -0
  4. data/MANIFEST +14 -0
  5. data/ParameterizedQueries README +39 -0
  6. data/README +282 -0
  7. data/ext/Makefile.nt32 +181 -0
  8. data/ext/extconf.rb +66 -0
  9. data/ext/ibm_db.c +11166 -0
  10. data/ext/ruby_ibm_db.h +236 -0
  11. data/ext/ruby_ibm_db_cli.c +738 -0
  12. data/ext/ruby_ibm_db_cli.h +431 -0
  13. data/init.rb +42 -0
  14. data/lib/IBM_DB.rb +2 -0
  15. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +2558 -0
  16. data/lib/active_record/connection_adapters/ibm_db_pstmt.rb +1965 -0
  17. data/lib/active_record/vendor/db2-i5-zOS.yaml +328 -0
  18. data/test/cases/adapter_test.rb +202 -0
  19. data/test/cases/associations/belongs_to_associations_test.rb +486 -0
  20. data/test/cases/associations/cascaded_eager_loading_test.rb +183 -0
  21. data/test/cases/associations/eager_test.rb +862 -0
  22. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +917 -0
  23. data/test/cases/associations/has_many_through_associations_test.rb +461 -0
  24. data/test/cases/associations/join_model_test.rb +793 -0
  25. data/test/cases/attribute_methods_test.rb +621 -0
  26. data/test/cases/base_test.rb +1486 -0
  27. data/test/cases/calculations_test.rb +362 -0
  28. data/test/cases/finder_test.rb +1088 -0
  29. data/test/cases/fixtures_test.rb +684 -0
  30. data/test/cases/migration_test.rb +2014 -0
  31. data/test/cases/schema_dumper_test.rb +232 -0
  32. data/test/cases/validations/uniqueness_validation_test.rb +283 -0
  33. data/test/connections/native_ibm_db/connection.rb +42 -0
  34. data/test/ibm_db_test.rb +25 -0
  35. data/test/models/warehouse_thing.rb +5 -0
  36. data/test/schema/i5/ibm_db_specific_schema.rb +135 -0
  37. data/test/schema/ids/ibm_db_specific_schema.rb +138 -0
  38. data/test/schema/luw/ibm_db_specific_schema.rb +135 -0
  39. data/test/schema/schema.rb +647 -0
  40. data/test/schema/zOS/ibm_db_specific_schema.rb +206 -0
  41. metadata +105 -0
@@ -0,0 +1,236 @@
1
+ /*
2
+ +----------------------------------------------------------------------+
3
+ | Licensed Materials - Property of IBM |
4
+ | |
5
+ | (C) Copyright IBM Corporation 2006, 2007, 2008, 2009, 2010 |
6
+ +----------------------------------------------------------------------+
7
+ | Authors: Sushant Koduru, Lynh Nguyen, Kanchana Padmanabhan, |
8
+ | Dan Scott, Helmut Tessarek, Kellen Bombardier, Sam Ruby |
9
+ | Ambrish Bhargava, Tarun Pasrija, Praveen Devarao |
10
+ +----------------------------------------------------------------------+
11
+ */
12
+
13
+ #ifndef RUBY_IBM_DB_H
14
+ #define RUBY_IBM_DB_H
15
+
16
+ #include <stdio.h>
17
+ #include <string.h>
18
+ #include <stdlib.h>
19
+ #include <sqlcli1.h>
20
+
21
+ #ifndef SQL_XML
22
+ #define SQL_XML -370
23
+ #endif
24
+
25
+ /* Needed for Backward compatibility */
26
+ #ifndef SQL_DECFLOAT
27
+ #define SQL_DECFLOAT -360
28
+ #endif
29
+
30
+ /* needed for backward compatibility (SQL_ATTR_ROWCOUNT_PREFETCH not defined prior to DB2 9.5.0.3) */
31
+ #ifndef SQL_ATTR_ROWCOUNT_PREFETCH
32
+ #define SQL_ATTR_ROWCOUNT_PREFETCH 2592
33
+ #define SQL_ROWCOUNT_PREFETCH_OFF 0
34
+ #define SQL_ROWCOUNT_PREFETCH_ON 1
35
+ #endif
36
+
37
+ /* SQL_ATTR_USE_TRUSTED_CONTEXT,
38
+ * SQL_ATTR_TRUSTED_CONTEXT_USERID and
39
+ * SQL_ATTR_TRUSTED_CONTEXT_PASSWORD
40
+ * not defined prior to DB2 v9 */
41
+ #ifndef SQL_ATTR_USE_TRUSTED_CONTEXT
42
+ #define SQL_ATTR_USE_TRUSTED_CONTEXT 2561
43
+ #define SQL_ATTR_TRUSTED_CONTEXT_USERID 2562
44
+ #define SQL_ATTR_TRUSTED_CONTEXT_PASSWORD 2563
45
+ #endif
46
+
47
+ #ifndef SQL_ATTR_REPLACE_QUOTED_LITERALS
48
+ #define SQL_ATTR_REPLACE_QUOTED_LITERALS 2586
49
+ #endif
50
+
51
+ /* CLI v9.1 FP3 and below has a SQL_ATTR_REPLACE_QUOTED_LITERALS value of 116
52
+ * We need to support both the new and old values for compatibility with older
53
+ * versions of CLI. CLI v9.1 FP4 and beyond changed this value to 2586
54
+ */
55
+ #define SQL_ATTR_REPLACE_QUOTED_LITERALS_OLDVALUE 116
56
+
57
+ /* If using a DB2 CLI version which doesn't support this functionality, explicitly
58
+ * define this. We will rely on DB2 CLI to throw an error when SQLGetStmtAttr is
59
+ * called.
60
+ */
61
+ #ifndef SQL_ATTR_GET_GENERATED_VALUE
62
+ #define SQL_ATTR_GET_GENERATED_VALUE 2578
63
+ #endif
64
+
65
+ #ifdef _WIN32
66
+ #define RUBY_IBM_DB_API __declspec(dllexport)
67
+ #else
68
+ #define RUBY_IBM_DB_API
69
+ #endif
70
+
71
+ /* strlen(" SQLCODE=") added in */
72
+ #define DB2_MAX_ERR_MSG_LEN (SQL_MAX_MESSAGE_LENGTH + SQL_SQLSTATE_SIZE + 10)
73
+
74
+ /*Used to find the type of resource and the error type required*/
75
+ #define DB_ERRMSG 1
76
+ #define DB_ERR_STATE 2
77
+
78
+ #define DB_CONN 1
79
+ #define DB_STMT 2
80
+
81
+ #define CONN_ERROR 1
82
+ #define STMT_ERROR 2
83
+
84
+ /*Used to decide if LITERAL REPLACEMENT should be turned on or not*/
85
+ #define SET_QUOTED_LITERAL_REPLACEMENT_ON 1
86
+ #define SET_QUOTED_LITERAL_REPLACEMENT_OFF 0
87
+
88
+ /* DB2 instance environment variable */
89
+ #define DB2_VAR_INSTANCE "DB2INSTANCE="
90
+
91
+ /******** Makes code compatible with the options used by the user */
92
+ #define BINARY 1
93
+ #define CONVERT 2
94
+ #define PASSTHRU 3
95
+ #define PARAM_FILE 11
96
+
97
+ #ifdef PASE
98
+ #define SQL_IS_INTEGER 0
99
+ #define SQL_BEST_ROWID 0
100
+ #define SQLLEN long
101
+ #define SQLFLOAT double
102
+ #endif
103
+
104
+ /*fetch*/
105
+ #define FETCH_INDEX 0x01
106
+ #define FETCH_ASSOC 0x02
107
+ #define FETCH_BOTH 0x03
108
+
109
+ /* Change column case */
110
+ #define ATTR_CASE 3271982
111
+ #define CASE_NATURAL 0
112
+ #define CASE_LOWER 1
113
+ #define CASE_UPPER 2
114
+
115
+ /* maximum sizes */
116
+ #define USERID_LEN 16
117
+ #define ACCTSTR_LEN 200
118
+ #define APPLNAME_LEN 32
119
+ #define WRKSTNNAME_LEN 18
120
+
121
+ /*
122
+ * Enum for Decfloat Rounding Modes
123
+ * */
124
+ enum
125
+ {
126
+ ROUND_HALF_EVEN = 0,
127
+ ROUND_HALF_UP,
128
+ ROUND_DOWN,
129
+ ROUND_CEILING,
130
+ ROUND_FLOOR
131
+ }ROUNDING_MODE;
132
+
133
+ void Init_ibm_db();
134
+
135
+ /* Function Declarations */
136
+
137
+ VALUE ibm_db_connect(int argc, VALUE *argv, VALUE self);
138
+ VALUE ibm_db_commit(int argc, VALUE *argv, VALUE self);
139
+ VALUE ibm_db_pconnect(int argc, VALUE *argv, VALUE self);
140
+ VALUE ibm_db_autocommit(int argc, VALUE *argv, VALUE self);
141
+ VALUE ibm_db_bind_param(int argc, VALUE *argv, VALUE self);
142
+ VALUE ibm_db_close(int argc, VALUE *argv, VALUE self);
143
+ VALUE ibm_db_columnprivileges(int argc, VALUE *argv, VALUE self);
144
+ VALUE ibm_db_column_privileges(int argc, VALUE *argv, VALUE self);
145
+ VALUE ibm_db_columns(int argc, VALUE *argv, VALUE self);
146
+ VALUE ibm_db_foreignkeys(int argc, VALUE *argv, VALUE self);
147
+ VALUE ibm_db_foreign_keys(int argc, VALUE *argv, VALUE self);
148
+ VALUE ibm_db_primarykeys(int argc, VALUE *argv, VALUE self);
149
+ VALUE ibm_db_primary_keys(int argc, VALUE *argv, VALUE self);
150
+ VALUE ibm_db_procedure_columns(int argc, VALUE *argv, VALUE self);
151
+ VALUE ibm_db_procedures(int argc, VALUE *argv, VALUE self);
152
+ VALUE ibm_db_specialcolumns(int argc, VALUE *argv, VALUE self);
153
+ VALUE ibm_db_special_columns(int argc, VALUE *argv, VALUE self);
154
+ VALUE ibm_db_statistics(int argc, VALUE *argv, VALUE self);
155
+ VALUE ibm_db_tableprivileges(int argc, VALUE *argv, VALUE self);
156
+ VALUE ibm_db_table_privileges(int argc, VALUE *argv, VALUE self);
157
+ VALUE ibm_db_tables(int argc, VALUE *argv, VALUE self);
158
+ VALUE ibm_db_commit(int argc, VALUE *argv, VALUE self);
159
+ VALUE ibm_db_exec(int argc, VALUE *argv, VALUE self);
160
+ VALUE ibm_db_prepare(int argc, VALUE *argv, VALUE self);
161
+ VALUE ibm_db_execute(int argc, VALUE *argv, VALUE self);
162
+ VALUE ibm_db_conn_errormsg(int argc, VALUE *argv, VALUE self);
163
+ VALUE ibm_db_stmt_errormsg(int argc, VALUE *argv, VALUE self);
164
+ VALUE ibm_db_getErrormsg(int argc, VALUE *argv, VALUE self);
165
+ VALUE ibm_db_getErrorstate(int argc, VALUE *argv, VALUE self);
166
+ VALUE ibm_db_conn_error(int argc, VALUE *argv, VALUE self);
167
+ VALUE ibm_db_stmt_error(int argc, VALUE *argv, VALUE self);
168
+ VALUE ibm_db_next_result(int argc, VALUE *argv, VALUE self);
169
+ VALUE ibm_db_num_fields(int argc, VALUE *argv, VALUE self);
170
+ VALUE ibm_db_num_rows(int argc, VALUE *argv, VALUE self);
171
+ VALUE ibm_db_field_name(int argc, VALUE *argv, VALUE self);
172
+ VALUE ibm_db_field_display_size(int argc, VALUE *argv, VALUE self);
173
+ VALUE ibm_db_field_num(int argc, VALUE *argv, VALUE self);
174
+ VALUE ibm_db_field_precision(int argc, VALUE *argv, VALUE self);
175
+ VALUE ibm_db_field_scale(int argc, VALUE *argv, VALUE self);
176
+ VALUE ibm_db_field_type(int argc, VALUE *argv, VALUE self);
177
+ VALUE ibm_db_field_width(int argc, VALUE *argv, VALUE self);
178
+ VALUE ibm_db_cursor_type(int argc, VALUE *argv, VALUE self);
179
+ VALUE ibm_db_rollback(int argc, VALUE *argv, VALUE self);
180
+ VALUE ibm_db_free_stmt(int argc, VALUE *argv, VALUE self);
181
+ VALUE ibm_db_result(int argc, VALUE *argv, VALUE self);
182
+ VALUE ibm_db_fetch_row(int argc, VALUE *argv, VALUE self);
183
+ VALUE ibm_db_fetch_assoc(int argc, VALUE *argv, VALUE self);
184
+ VALUE ibm_db_fetch_array(int argc, VALUE *argv, VALUE self);
185
+ VALUE ibm_db_fetch_both(int argc, VALUE *argv, VALUE self);
186
+ VALUE ibm_db_result_all(int argc, VALUE *argv, VALUE self);
187
+ VALUE ibm_db_free_result(int argc, VALUE *argv, VALUE self);
188
+ VALUE ibm_db_set_option(int argc, VALUE *argv, VALUE self);
189
+ VALUE ibm_db_setoption(int argc, VALUE *argv, VALUE self);
190
+ VALUE ibm_db_get_option(int argc, VALUE *argv, VALUE self);
191
+ VALUE ibm_db_get_last_serial_value(int argc, VALUE *argv, VALUE self);
192
+ VALUE ibm_db_getoption(int argc, VALUE *argv, VALUE self);
193
+ VALUE ibm_db_fetch_object(int argc, VALUE *argv, VALUE self);
194
+ VALUE ibm_db_server_info(int argc, VALUE *argv, VALUE self);
195
+ VALUE ibm_db_client_info(int argc, VALUE *argv, VALUE self);
196
+ VALUE ibm_db_active(int argc, VALUE *argv, VALUE self);
197
+
198
+ /*
199
+ Declare any global variables you may need between the BEGIN
200
+ and END macros here:
201
+ */
202
+ struct _ibm_db_globals {
203
+ int bin_mode;
204
+ #ifdef UNICODE_SUPPORT_VERSION
205
+ SQLWCHAR __ruby_conn_err_msg[DB2_MAX_ERR_MSG_LEN];
206
+ SQLWCHAR __ruby_stmt_err_msg[DB2_MAX_ERR_MSG_LEN];
207
+ SQLWCHAR __ruby_conn_err_state[SQL_SQLSTATE_SIZE + 1];
208
+ SQLWCHAR __ruby_stmt_err_state[SQL_SQLSTATE_SIZE + 1];
209
+ #else
210
+ char __ruby_conn_err_msg[DB2_MAX_ERR_MSG_LEN];
211
+ char __ruby_stmt_err_msg[DB2_MAX_ERR_MSG_LEN];
212
+ char __ruby_conn_err_state[SQL_SQLSTATE_SIZE + 1];
213
+ char __ruby_stmt_err_state[SQL_SQLSTATE_SIZE + 1];
214
+ #endif
215
+
216
+ #ifdef PASE /* i5/OS ease of use turn off commit */
217
+ long i5_allow_commit;
218
+ #endif /* PASE */
219
+ };
220
+
221
+ /*
222
+ TODO: make this threadsafe
223
+ */
224
+
225
+ #define IBM_DB_G(v) (ibm_db_globals->v)
226
+
227
+ #endif /* RUBY_IBM_DB_H */
228
+
229
+
230
+ /*
231
+ * Local variables:
232
+ * tab-width: 4
233
+ * c-basic-offset: 4
234
+ * indent-tabs-mode: t
235
+ * End:
236
+ */
@@ -0,0 +1,738 @@
1
+ /*
2
+ +----------------------------------------------------------------------+
3
+ | Licensed Materials - Property of IBM |
4
+ | |
5
+ | (C) Copyright IBM Corporation 2009, 2010 |
6
+ +----------------------------------------------------------------------+
7
+ | Authors: Praveen Devarao |
8
+ +----------------------------------------------------------------------+
9
+ */
10
+
11
+
12
+ /*
13
+ This C file contains functions that perform DB operations, which can take long time to complete.
14
+ For Eg: - Like SQLConnect, SQLFetch etc.
15
+
16
+ This file in general will contain functions that make CLI calls and
17
+ depending on whether the call will be transferred to server or not the functions are termed long time comsuming or not.
18
+
19
+ The functions which will contact the server and hence can be time consuming will be called by ruby's (1.9 onwards)
20
+ rb_thread_blocking_region method, which inturn will release the GVL while these operations are being performed.
21
+ With this the executing thread will become unblocking allowing concurrent threads perform operations simultaneously.
22
+ */
23
+
24
+ #include "ruby_ibm_db_cli.h"
25
+
26
+ /*
27
+ This function connects to the database using either SQLConnect or SQLDriverConnect CLI API
28
+ depending on whether it is a cataloged or an uncataloged connection.
29
+ */
30
+ int _ruby_ibm_db_SQLConnect_helper(connect_args *data) {
31
+ if(data->ctlg_conn == 1) {
32
+ #ifndef UNICODE_SUPPORT_VERSION
33
+ return SQLConnect( (SQLHDBC)*(data->hdbc), (SQLCHAR *)data->database,
34
+ (SQLSMALLINT)data->database_len, (SQLCHAR *)data->uid, (SQLSMALLINT)data->uid_len,
35
+ (SQLCHAR *)data->password, (SQLSMALLINT)data->password_len );
36
+ #else
37
+ return SQLConnectW( (SQLHDBC)*(data->hdbc), data->database,
38
+ data->database_len, data->uid, data->uid_len,
39
+ data->password, data->password_len );
40
+ #endif
41
+ } else {
42
+ #ifndef UNICODE_SUPPORT_VERSION
43
+ return SQLDriverConnect( (SQLHDBC) *(data->hdbc), (SQLHWND)NULL,
44
+ (SQLCHAR*)data->database, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );
45
+ #else
46
+ return SQLDriverConnectW( (SQLHDBC) *(data->hdbc), (SQLHWND)NULL,
47
+ data->database, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );
48
+ #endif
49
+ }
50
+ }
51
+
52
+ /*
53
+ This function issues SQLDisconnect to disconnect from the Dataserver
54
+ */
55
+ int _ruby_ibm_db_SQLDisconnect_helper(SQLHANDLE *hdbc) {
56
+ return SQLDisconnect( (SQLHDBC) *hdbc );
57
+ }
58
+
59
+ /*
60
+ Connection level Unblock function. This function is called when a thread interruput is issued while executing a
61
+ connection level SQL call
62
+ */
63
+ void _ruby_ibm_db_Connection_level_UBF(void *data) {
64
+ return;
65
+ }
66
+
67
+ /*
68
+ This function will commit and end the inprogress transaction by issuing a SQLCommit
69
+ */
70
+ int _ruby_ibm_db_SQLEndTran(end_tran_args *endtran_args) {
71
+ return SQLEndTran( endtran_args->handleType, *(endtran_args->hdbc), endtran_args->completionType );
72
+ }
73
+
74
+ /*
75
+ This function call the SQLDescribeParam cli call to get the description of the parameter in the sql specified
76
+ */
77
+ int _ruby_ibm_db_SQLDescribeParam_helper(describeparam_args *data) {
78
+ int rc = 0;
79
+ data->stmt_res->is_executing = 1;
80
+
81
+ rc = SQLDescribeParam( (SQLHSTMT) data->stmt_res->hstmt, (SQLUSMALLINT)data->param_no, &(data->sql_data_type),
82
+ &(data->sql_precision), &(data->sql_scale), &(data->sql_nullable) );
83
+
84
+ data->stmt_res->is_executing = 0;
85
+
86
+ return rc;
87
+ }
88
+
89
+ /*
90
+ This function call the SQLDescribeCol cli call to get the description of the parameter in the sql specified
91
+ */
92
+ int _ruby_ibm_db_SQLDescribeCol_helper(describecol_args *data) {
93
+ int i = data->col_no - 1;
94
+ int rc = 0;
95
+
96
+ data->stmt_res->is_executing = 1;
97
+
98
+ #ifdef UNICODE_SUPPORT_VERSION
99
+ rc = SQLDescribeColW( (SQLHSTMT)data->stmt_res->hstmt, (SQLSMALLINT)(data->col_no),
100
+ data->stmt_res->column_info[i].name, data->buff_length, &(data->name_length),
101
+ &(data->stmt_res->column_info[i].type), &(data->stmt_res->column_info[i].size),
102
+ &(data->stmt_res->column_info[i].scale), &(data->stmt_res->column_info[i].nullable) );
103
+ #else
104
+ rc = SQLDescribeCol( (SQLHSTMT)data->stmt_res->hstmt, (SQLSMALLINT)(data->col_no),
105
+ data->stmt_res->column_info[i].name, data->buff_length, &(data->name_length),
106
+ &(data->stmt_res->column_info[i].type), &(data->stmt_res->column_info[i].size),
107
+ &(data->stmt_res->column_info[i].scale), &(data->stmt_res->column_info[i].nullable) );
108
+ #endif
109
+
110
+ data->stmt_res->is_executing = 0;
111
+
112
+ return rc;
113
+ }
114
+
115
+ /*
116
+ This function call the SQLBindCol cli call to get the description of the parameter in the sql specified
117
+ */
118
+ int _ruby_ibm_db_SQLBindCol_helper(bind_col_args *data) {
119
+ int rc = 0;
120
+
121
+ data->stmt_res->is_executing = 1;
122
+
123
+ rc = SQLBindCol( (SQLHSTMT) data->stmt_res->hstmt, (SQLUSMALLINT)(data->col_num),
124
+ data->TargetType, data->TargetValuePtr, data->buff_length,
125
+ data->out_length );
126
+
127
+ data->stmt_res->is_executing = 0;
128
+
129
+ return rc;
130
+ }
131
+
132
+ /*
133
+ This function calls SQLColumnPrivileges cli call to get the list of columns and the associated privileges
134
+ */
135
+ int _ruby_ibm_db_SQLColumnPrivileges_helper(metadata_args *data) {
136
+ int rc = 0;
137
+
138
+ data->stmt_res->is_executing = 1;
139
+
140
+ #ifndef UNICODE_SUPPORT_VERSION
141
+ rc = SQLColumnPrivileges( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
142
+ data->owner, data->owner_len, data->table_name, data->table_name_len,
143
+ data->column_name, data->column_name_len );
144
+ #else
145
+ rc = SQLColumnPrivilegesW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
146
+ data->owner, data->owner_len, data->table_name, data->table_name_len,
147
+ data->column_name, data->column_name_len );
148
+ #endif
149
+
150
+ data->stmt_res->is_executing = 0;
151
+
152
+ return rc;
153
+
154
+ }
155
+
156
+ /*
157
+ This function calls SQLColumns cli call to get the list of columns and the associated metadata of the table
158
+ */
159
+ int _ruby_ibm_db_SQLColumns_helper(metadata_args *data) {
160
+ int rc = 0;
161
+
162
+ data->stmt_res->is_executing = 1;
163
+
164
+ #ifndef UNICODE_SUPPORT_VERSION
165
+ rc = SQLColumns( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
166
+ data->owner, data->owner_len, data->table_name, data->table_name_len,
167
+ data->column_name, data->column_name_len );
168
+ #else
169
+ rc = SQLColumnsW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
170
+ data->owner, data->owner_len, data->table_name, data->table_name_len,
171
+ data->column_name, data->column_name_len );
172
+ #endif
173
+
174
+ data->stmt_res->is_executing = 0;
175
+
176
+ return rc;
177
+ }
178
+
179
+ /*
180
+ This function calls SQLPrimaryKeys cli call to get the list of primay key columns and the associated metadata
181
+ */
182
+ int _ruby_ibm_db_SQLPrimaryKeys_helper(metadata_args *data) {
183
+ int rc = 0;
184
+
185
+ data->stmt_res->is_executing = 1;
186
+
187
+ #ifndef UNICODE_SUPPORT_VERSION
188
+ rc = SQLPrimaryKeys( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
189
+ data->owner, data->owner_len, data->table_name, data->table_name_len );
190
+ #else
191
+ rc = SQLPrimaryKeysW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
192
+ data->owner, data->owner_len, data->table_name, data->table_name_len );
193
+ #endif
194
+
195
+ data->stmt_res->is_executing = 0;
196
+
197
+ return rc;
198
+ }
199
+
200
+ /*
201
+ This function calls SQLForeignKeys cli call to get the list of foreign key columns and the associated metadata
202
+ */
203
+ int _ruby_ibm_db_SQLForeignKeys_helper(metadata_args *data) {
204
+ int rc = 0;
205
+
206
+ data->stmt_res->is_executing = 1;
207
+
208
+ #ifndef UNICODE_SUPPORT_VERSION
209
+ rc = SQLForeignKeys( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
210
+ data->owner, data->owner_len, data->table_name , data->table_name_len, NULL, SQL_NTS,
211
+ NULL, SQL_NTS, NULL, SQL_NTS );
212
+ #else
213
+ rc = SQLForeignKeysW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
214
+ data->owner, data->owner_len, data->table_name , data->table_name_len, NULL, SQL_NTS,
215
+ NULL, SQL_NTS, NULL, SQL_NTS );
216
+ #endif
217
+
218
+ data->stmt_res->is_executing = 0;
219
+
220
+ return rc;
221
+ }
222
+
223
+ /*
224
+ This function calls SQLProcedureColumns cli call to get the list of parameters
225
+ and associated metadata of the stored procedure
226
+ */
227
+ int _ruby_ibm_db_SQLProcedureColumns_helper(metadata_args *data) {
228
+ int rc = 0;
229
+
230
+ data->stmt_res->is_executing = 1;
231
+
232
+ #ifndef UNICODE_SUPPORT_VERSION
233
+ rc = SQLProcedureColumns( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
234
+ data->owner_len, data->proc_name, data->proc_name_len, data->column_name, data->column_name_len );
235
+ #else
236
+ rc = SQLProcedureColumnsW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
237
+ data->owner_len, data->proc_name, data->proc_name_len, data->column_name, data->column_name_len );
238
+ #endif
239
+
240
+ data->stmt_res->is_executing = 0;
241
+
242
+ return rc;
243
+ }
244
+
245
+ /*
246
+ This function calls SQLProcedures cli call to get the list of stored procedures
247
+ and associated metadata of the stored procedure
248
+ */
249
+ int _ruby_ibm_db_SQLProcedures_helper(metadata_args *data) {
250
+ int rc = 0;
251
+
252
+ data->stmt_res->is_executing = 1;
253
+
254
+ #ifndef UNICODE_SUPPORT_VERSION
255
+ rc = SQLProcedures( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
256
+ data->owner_len, data->proc_name, data->proc_name_len );
257
+ #else
258
+ rc = SQLProceduresW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
259
+ data->owner_len, data->proc_name, data->proc_name_len );
260
+ #endif
261
+
262
+ data->stmt_res->is_executing = 0;
263
+
264
+ return rc;
265
+ }
266
+
267
+ /*
268
+ This function calls SQLSpecialColumns cli call to get the metadata related to the special columns
269
+ (Unique index or primary key column) and associated metadata
270
+ */
271
+ int _ruby_ibm_db_SQLSpecialColumns_helper(metadata_args *data) {
272
+ int rc = 0;
273
+
274
+ data->stmt_res->is_executing = 1;
275
+
276
+ #ifndef UNICODE_SUPPORT_VERSION
277
+ rc = SQLSpecialColumns( (SQLHSTMT) data->stmt_res->hstmt, SQL_BEST_ROWID, data->qualifier, data->qualifier_len,
278
+ data->owner, data->owner_len, data->table_name, data->table_name_len,
279
+ (SQLUSMALLINT)data->scope, SQL_NULLABLE );
280
+ #else
281
+ rc = SQLSpecialColumnsW( (SQLHSTMT) data->stmt_res->hstmt, SQL_BEST_ROWID, data->qualifier, data->qualifier_len,
282
+ data->owner, data->owner_len, data->table_name, data->table_name_len,
283
+ (SQLUSMALLINT)data->scope, SQL_NULLABLE );
284
+ #endif
285
+
286
+ data->stmt_res->is_executing = 0;
287
+
288
+ return rc;
289
+ }
290
+
291
+ /*
292
+ This function calls SQLStatistics cli call to get the index information for a given table.
293
+ */
294
+ int _ruby_ibm_db_SQLStatistics_helper(metadata_args *data) {
295
+ int rc = 0;
296
+
297
+ data->stmt_res->is_executing = 1;
298
+
299
+ #ifndef UNICODE_SUPPORT_VERSION
300
+ rc = SQLStatistics( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
301
+ data->owner_len, data->table_name, data->table_name_len, (SQLUSMALLINT)data->unique, SQL_QUICK );
302
+ #else
303
+ rc = SQLStatisticsW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
304
+ data->owner_len, data->table_name, data->table_name_len, (SQLUSMALLINT)data->unique, SQL_QUICK );
305
+ #endif
306
+
307
+ data->stmt_res->is_executing = 0;
308
+
309
+ return rc;
310
+ }
311
+
312
+ /*
313
+ This function calls SQLTablePrivileges cli call to retrieve list of tables and
314
+ the asscociated privileges for each table.
315
+ */
316
+ int _ruby_ibm_db_SQLTablePrivileges_helper(metadata_args *data) {
317
+ int rc = 0;
318
+
319
+ data->stmt_res->is_executing = 1;
320
+
321
+ #ifndef UNICODE_SUPPORT_VERSION
322
+ rc = SQLTablePrivileges( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
323
+ data->owner, data->owner_len, data->table_name, data->table_name_len );
324
+ #else
325
+ rc = SQLTablePrivilegesW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
326
+ data->owner, data->owner_len, data->table_name, data->table_name_len );
327
+ #endif
328
+
329
+ data->stmt_res->is_executing = 0;
330
+
331
+ return rc;
332
+ }
333
+
334
+ /*
335
+ This function calls SQLTables cli call to retrieve list of tables in the specified schema and
336
+ the asscociated metadata for each table.
337
+ */
338
+ int _ruby_ibm_db_SQLTables_helper(metadata_args *data) {
339
+ int rc = 0;
340
+
341
+ data->stmt_res->is_executing = 1;
342
+
343
+ #ifndef UNICODE_SUPPORT_VERSION
344
+ rc = SQLTables( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
345
+ data->owner_len, data->table_name, data->table_name_len, data->table_type, data->table_type_len );
346
+ #else
347
+ rc = SQLTablesW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
348
+ data->owner_len, data->table_name, data->table_name_len, data->table_type, data->table_type_len );
349
+ #endif
350
+
351
+ data->stmt_res->is_executing = 0;
352
+
353
+ return rc;
354
+ }
355
+
356
+ /*
357
+ This function calls SQLExecDirect cli call to execute a statement directly
358
+ */
359
+ int _ruby_ibm_db_SQLExecDirect_helper(exec_cum_prepare_args *data) {
360
+ int rc = 0;
361
+
362
+ data->stmt_res->is_executing = 1;
363
+
364
+ #ifndef UNICODE_SUPPORT_VERSION
365
+ rc = SQLExecDirect( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
366
+ #else
367
+ rc = SQLExecDirectW( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
368
+ #endif
369
+
370
+ data->stmt_res->is_executing = 0;
371
+
372
+ return rc;
373
+ }
374
+
375
+ /*
376
+ This function calls SQLPrepare cli call to prepare the given statement
377
+ */
378
+ int _ruby_ibm_db_SQLPrepare_helper(exec_cum_prepare_args *data) {
379
+ int rc = 0;
380
+
381
+ data->stmt_res->is_executing = 1;
382
+
383
+ #ifndef UNICODE_SUPPORT_VERSION
384
+ rc = SQLPrepare( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
385
+ #else
386
+ rc = SQLPrepareW( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
387
+ #endif
388
+
389
+ data->stmt_res->is_executing = 0;
390
+
391
+ return rc;
392
+ }
393
+
394
+ /*
395
+ This function calls SQLFreeStmt to end processing on the statement referenced by statement handle
396
+ */
397
+ int _ruby_ibm_db_SQLFreeStmt_helper(free_stmt_args *data) {
398
+ int rc = 0;
399
+
400
+ data->stmt_res->is_executing = 1;
401
+
402
+ SQLFreeStmt((SQLHSTMT)data->stmt_res->hstmt, data->option );
403
+
404
+ data->stmt_res->is_executing = 0;
405
+
406
+ return rc;
407
+ }
408
+
409
+ /*
410
+ This function calls SQLExecute cli call to execute the prepared
411
+ */
412
+ int _ruby_ibm_db_SQLExecute_helper(stmt_handle *stmt_res) {
413
+ int rc = 0;
414
+
415
+ stmt_res->is_executing = 1;
416
+
417
+ rc = SQLExecute( (SQLHSTMT) stmt_res->hstmt );
418
+
419
+ stmt_res->is_executing = 0;
420
+
421
+ return rc;
422
+ }
423
+
424
+ /*
425
+ This function calls SQLParamData cli call to read if there is still data to be sent
426
+ */
427
+ int _ruby_ibm_db_SQLParamData_helper(param_cum_put_data_args *data) {
428
+ int rc = 0;
429
+
430
+ data->stmt_res->is_executing = 1;
431
+
432
+ rc = SQLParamData( (SQLHSTMT) data->stmt_res->hstmt, (SQLPOINTER *) &(data->valuePtr) );
433
+
434
+ data->stmt_res->is_executing = 0;
435
+
436
+ return rc;
437
+ }
438
+
439
+ /*
440
+ This function calls SQLColAttributes cli call to get the specified attribute of the column in result set
441
+ */
442
+ int _ruby_ibm_db_SQLColAttributes_helper(col_attr_args *data) {
443
+ int rc = 0;
444
+
445
+ data->stmt_res->is_executing = 1;
446
+
447
+ rc = SQLColAttributes( (SQLHSTMT) data->stmt_res->hstmt, data->col_num,
448
+ data->FieldIdentifier, NULL, 0, NULL, &(data->num_attr) );
449
+
450
+ data->stmt_res->is_executing = 0;
451
+
452
+ return rc;
453
+ }
454
+
455
+ /*
456
+ This function calls SQLPutData cli call to supply parameter data value
457
+ */
458
+ int _ruby_ibm_db_SQLPutData_helper(param_cum_put_data_args *data) {
459
+ int rc = 0;
460
+
461
+ data->stmt_res->is_executing = 1;
462
+
463
+ rc = SQLPutData( (SQLHSTMT) data->stmt_res->hstmt, (SQLPOINTER)(((param_node*)(data->valuePtr))->svalue),
464
+ ((param_node*)(data->valuePtr))->ivalue );
465
+
466
+ data->stmt_res->is_executing = 0;
467
+
468
+ return rc;
469
+ }
470
+
471
+ /*
472
+ This function calls SQLGetData cli call to retrieve data for a single column
473
+ */
474
+ int _ruby_ibm_db_SQLGetData_helper(get_data_args *data) {
475
+ int rc = 0;
476
+
477
+ data->stmt_res->is_executing = 1;
478
+
479
+ rc = SQLGetData( (SQLHSTMT) data->stmt_res->hstmt, data->col_num, data->targetType, data->buff,
480
+ data->buff_length, data->out_length);
481
+
482
+ data->stmt_res->is_executing = 0;
483
+
484
+ return rc;
485
+ }
486
+
487
+ /*
488
+ This function calls SQLGetLength cli call to retrieve the length of the lob value
489
+ */
490
+ int _ruby_ibm_db_SQLGetLength_helper(get_length_args *data) {
491
+ int col_num = data->col_num;
492
+ int rc = 0;
493
+
494
+ data->stmt_res->is_executing = 1;
495
+
496
+ rc = SQLGetLength( (SQLHSTMT) *( data->new_hstmt ), data->stmt_res->column_info[col_num-1].loc_type,
497
+ data->stmt_res->column_info[col_num-1].lob_loc, data->sLength,
498
+ &(data->stmt_res->column_info[col_num-1].loc_ind) );
499
+
500
+ data->stmt_res->is_executing = 0;
501
+
502
+ return rc;
503
+ }
504
+
505
+ /*
506
+ This function calls SQLGetSubString cli call to retrieve portion of the lob value
507
+ */
508
+ int _ruby_ibm_db_SQLGetSubString_helper(get_subString_args *data) {
509
+ int col_num = data->col_num;
510
+ int rc = 0;
511
+
512
+ data->stmt_res->is_executing = 1;
513
+
514
+ rc = SQLGetSubString( (SQLHSTMT) *( data->new_hstmt ), data->stmt_res->column_info[col_num-1].loc_type,
515
+ data->stmt_res->column_info[col_num-1].lob_loc, 1, data->forLength, data->targetCType,
516
+ data->buffer, data->buff_length, data->out_length,
517
+ &(data->stmt_res->column_info[col_num-1].loc_ind) );
518
+
519
+ data->stmt_res->is_executing = 0;
520
+
521
+ return rc;
522
+ }
523
+
524
+ /*
525
+ This function calls SQLNextResult cli call to fetch the multiple result sets that might be returned by a stored Proc
526
+ */
527
+ int _ruby_ibm_db_SQLNextResult_helper(next_result_args *data) {
528
+ int rc = 0;
529
+
530
+ data->stmt_res->is_executing = 1;
531
+
532
+ rc = SQLNextResult( (SQLHSTMT) data->stmt_res->hstmt, (SQLHSTMT) *(data->new_hstmt) );
533
+
534
+ data->stmt_res->is_executing = 0;
535
+
536
+ return rc;
537
+ }
538
+
539
+ /*
540
+ This function calls SQLFetchScroll cli call to fetch the specified rowset of data from result
541
+ */
542
+ int _ruby_ibm_db_SQLFetchScroll_helper(fetch_data_args *data) {
543
+ int rc = 0;
544
+
545
+ data->stmt_res->is_executing = 1;
546
+
547
+ rc = SQLFetchScroll( (SQLHSTMT) data->stmt_res->hstmt, data->fetchOrientation, data->fetchOffset);
548
+
549
+ data->stmt_res->is_executing = 0;
550
+
551
+ return rc;
552
+ }
553
+
554
+ /*
555
+ This function calls SQLFetch cli call to advance the cursor to
556
+ the next row of the result set, and retrieves any bound columns
557
+ */
558
+ int _ruby_ibm_db_SQLFetch_helper(fetch_data_args *data) {
559
+ int rc = 0;
560
+
561
+ data->stmt_res->is_executing = 1;
562
+
563
+ rc = SQLFetch( (SQLHSTMT) data->stmt_res->hstmt );
564
+
565
+ data->stmt_res->is_executing = 0;
566
+
567
+ return rc;
568
+ }
569
+
570
+ /*
571
+ This function calls SQLNumResultCols cli call to fetch the number of fields contained in a result set
572
+ */
573
+ int _ruby_ibm_db_SQLNumResultCols_helper(row_col_count_args *data) {
574
+ int rc = 0;
575
+
576
+ data->stmt_res->is_executing = 1;
577
+
578
+ rc = SQLNumResultCols( (SQLHSTMT) data->stmt_res->hstmt, (SQLSMALLINT*) &(data->count) );
579
+
580
+ data->stmt_res->is_executing = 0;
581
+
582
+ return rc;
583
+ }
584
+
585
+ /*
586
+ This function calls SQLNumParams cli call to fetch the number of parameter markers in an SQL statement
587
+ */
588
+ int _ruby_ibm_db_SQLNumParams_helper(row_col_count_args *data) {
589
+ int rc = 0;
590
+
591
+ data->stmt_res->is_executing = 1;
592
+
593
+ rc = SQLNumParams( (SQLHSTMT) data->stmt_res->hstmt, (SQLSMALLINT*) &(data->count) );
594
+
595
+ data->stmt_res->is_executing = 0;
596
+
597
+ return rc;
598
+ }
599
+
600
+ /*
601
+ This function calls SQLRowCount cli call to fetch the number of rows affected by the SQL statement
602
+ */
603
+ int _ruby_ibm_db_SQLRowCount_helper(sql_row_count_args *data) {
604
+ int rc = 0;
605
+
606
+ data->stmt_res->is_executing = 1;
607
+
608
+ rc = SQLRowCount( (SQLHSTMT) data->stmt_res->hstmt, (SQLLEN*) &(data->count) );
609
+
610
+ data->stmt_res->is_executing = 0;
611
+
612
+ return rc;
613
+ }
614
+
615
+ /*
616
+ This function calls SQLGetInfo cli call to get general information about DBMS, which the app is connected to
617
+ */
618
+ int _ruby_ibm_db_SQLGetInfo_helper(get_info_args *data) {
619
+ #ifndef UNICODE_SUPPORT_VERSION
620
+ return SQLGetInfo( data->conn_res->hdbc, data->infoType, data->infoValue, data->buff_length, data->out_length);
621
+ #else
622
+ return SQLGetInfoW( data->conn_res->hdbc, data->infoType, data->infoValue, data->buff_length, data->out_length);
623
+ #endif
624
+ }
625
+
626
+ /*
627
+ This function calls SQLGetDiagRec cli call to get the current values of a diagnostic record that contains error
628
+ */
629
+ int _ruby_ibm_db_SQLGetDiagRec_helper(get_diagRec_args *data) {
630
+ #ifdef UNICODE_SUPPORT_VERSION
631
+ return SQLGetDiagRecW( data->hType, data->handle, data->recNum, data->SQLState, data->NativeErrorPtr,
632
+ data->msgText, data->buff_length, data->text_length_ptr );
633
+ #else
634
+ return SQLGetDiagRec(data->hType, data->handle, data->recNum, data->SQLState, data->NativeErrorPtr,
635
+ data->msgText, data->buff_length, data->text_length_ptr );
636
+ #endif
637
+ }
638
+
639
+ /*
640
+ This function calls SQLSetStmtAttr cli call to set attributes related to a statement
641
+ */
642
+ int _ruby_ibm_db_SQLSetStmtAttr_helper(set_handle_attr_args *data) {
643
+ #ifndef UNICODE_SUPPORT_VERSION
644
+ return SQLSetStmtAttr( (SQLHSTMT) *(data->handle), data->attribute, data->valuePtr, data->strLength );
645
+ #else
646
+ return SQLSetStmtAttrW( (SQLHSTMT) *(data->handle), data->attribute, data->valuePtr, data->strLength );
647
+ #endif
648
+ }
649
+
650
+ /*
651
+ This function calls SQLSetConnectAttr cli call to set attributes that govern aspects of connections
652
+ */
653
+ int _ruby_ibm_db_SQLSetConnectAttr_helper(set_handle_attr_args *data) {
654
+ #ifndef UNICODE_SUPPORT_VERSION
655
+ return SQLSetConnectAttr( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr, data->strLength );
656
+ #else
657
+ return SQLSetConnectAttrW( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr, data->strLength );
658
+ #endif
659
+ }
660
+
661
+ /*
662
+ This function calls SQLSetEnvAttr cli call to set an environment attribute
663
+ */
664
+ int _ruby_ibm_db_SQLSetEnvAttr_helper(set_handle_attr_args *data) {
665
+ return SQLSetEnvAttr( (SQLHENV) *(data->handle), data->attribute, data->valuePtr, data->strLength);
666
+ }
667
+
668
+ /*
669
+ This function calls SQLGetStmtAttr cli call to set an environment attribute
670
+
671
+ The unicode equivalent of SQLGetStmtAttr is not used because the attributes being retrieved currently are not of type char or binary (SQL_IS_INTEGER). If support for retrieving a string type is provided then use the SQLGetStmtAttrW function accordingly
672
+ In get_last_serial_id although we are retrieving a char type, it is converted back to an integer (atoi). The char to integer conversion function in unicode equivalent will be more complicated and is unnecessary for this case.
673
+
674
+ */
675
+ int _ruby_ibm_db_SQLGetStmtAttr_helper(get_handle_attr_args *data) {
676
+ return SQLGetStmtAttr( (SQLHSTMT) *(data->handle), data->attribute, data->valuePtr,
677
+ data->buff_length, data->out_length);
678
+ }
679
+
680
+ /*
681
+ This function calls SQLGetConnectAttr cli call to set an environment attribute
682
+ */
683
+ int _ruby_ibm_db_SQLGetConnectAttr_helper(get_handle_attr_args *data) {
684
+ #ifndef UNICODE_SUPPORT_VERSION
685
+ return SQLGetConnectAttr( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr,
686
+ data->buff_length, data->out_length);
687
+ #else
688
+ return SQLGetConnectAttrW( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr,
689
+ data->buff_length, data->out_length);
690
+ #endif
691
+ }
692
+
693
+ /*
694
+ This function calls SQLBindFileToParam cli call
695
+ */
696
+ int _ruby_ibm_db_SQLBindFileToParam_helper(stmt_handle *stmt_res, param_node *curr) {
697
+ int rc = 0;
698
+
699
+ stmt_res->is_executing = 1;
700
+
701
+ rc = SQLBindFileToParam( (SQLHSTMT)stmt_res->hstmt, curr->param_num,
702
+ curr->data_type, (SQLCHAR*)curr->svalue,
703
+ (SQLSMALLINT*)&(curr->ivalue), &(curr->file_options),
704
+ curr->ivalue, &(curr->bind_indicator) );
705
+
706
+ stmt_res->is_executing = 0;
707
+
708
+ return rc;
709
+ }
710
+
711
+ /*
712
+ This function calls SQLBindParameter cli call
713
+ */
714
+ int _ruby_ibm_db_SQLBindParameter_helper(bind_parameter_args *data) {
715
+ int rc = 0;
716
+
717
+ data->stmt_res->is_executing = 1;
718
+
719
+ rc = SQLBindParameter( (SQLHSTMT) data->stmt_res->hstmt, data->param_num, data->IOType, data->valueType,
720
+ data->paramType, data->colSize, data->decimalDigits, data->paramValPtr, data->buff_length,
721
+ data->out_length );
722
+
723
+ data->stmt_res->is_executing = 0;
724
+
725
+ return rc;
726
+ }
727
+
728
+ /*
729
+ Statement level thread unblock function. This fuction cancels a statement level SQL call issued when requested for,
730
+ allowing for a safe interrupt of the thread.
731
+ */
732
+ void _ruby_ibm_db_Statement_level_UBF(stmt_handle *stmt_res) {
733
+ int rc = 0;
734
+ if( stmt_res->is_executing == 1 ) {
735
+ rc = SQLCancel( (SQLHSTMT) stmt_res->hstmt );
736
+ }
737
+ return;
738
+ }