ibm_db 2.6.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,851 +1,866 @@
1
- /*
2
- +----------------------------------------------------------------------+
3
- | Licensed Materials - Property of IBM |
4
- | |
5
- | (C) Copyright IBM Corporation 2009 - 2015 |
6
- +----------------------------------------------------------------------+
7
- | Authors: Praveen Devarao, Arvind Gupta |
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.h"
25
-
26
- #include "ruby_ibm_db_cli.h"
27
-
28
- /*
29
- This function connects to the database using either SQLConnect or SQLDriverConnect CLI API
30
- depending on whether it is a cataloged or an uncataloged connection.
31
- */
32
- int _ruby_ibm_db_SQLConnect_helper(connect_args *data) {
33
- if(data->ctlg_conn == 1) {
34
- #ifndef UNICODE_SUPPORT_VERSION
35
- return SQLConnect( (SQLHDBC)*(data->hdbc), (SQLCHAR *)data->database,
36
- (SQLSMALLINT)data->database_len, (SQLCHAR *)data->uid, (SQLSMALLINT)data->uid_len,
37
- (SQLCHAR *)data->password, (SQLSMALLINT)data->password_len );
38
- #else
39
- return SQLConnectW( (SQLHDBC)*(data->hdbc), data->database,
40
- data->database_len, data->uid, data->uid_len,
41
- data->password, data->password_len );
42
- #endif
43
- } else {
44
- #ifndef UNICODE_SUPPORT_VERSION
45
- return SQLDriverConnect( (SQLHDBC) *(data->hdbc), (SQLHWND)NULL,
46
- (SQLCHAR*)data->database, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );
47
- #else
48
- return SQLDriverConnectW( (SQLHDBC) *(data->hdbc), (SQLHWND)NULL,
49
- data->database, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );
50
- #endif
51
- }
52
- }
53
-
54
- /*
55
- This function issues SQLDisconnect to disconnect from the Dataserver
56
- */
57
- int _ruby_ibm_db_SQLDisconnect_helper(SQLHANDLE *hdbc) {
58
- return SQLDisconnect( (SQLHDBC) *hdbc );
59
- }
60
-
61
- /*
62
- Connection level Unblock function. This function is called when a thread interruput is issued while executing a
63
- connection level SQL call
64
- */
65
- void _ruby_ibm_db_Connection_level_UBF(void *data) {
66
- return;
67
- }
68
-
69
- /*
70
- This function will commit and end the inprogress transaction by issuing a SQLCommit
71
- */
72
- int _ruby_ibm_db_SQLEndTran(end_tran_args *endtran_args) {
73
- int rc = 0;
74
- rc = SQLEndTran( endtran_args->handleType, *(endtran_args->hdbc), endtran_args->completionType );
75
- endtran_args->rc = rc;
76
- return rc;
77
- }
78
-
79
- /*
80
- This function call the SQLDescribeParam cli call to get the description of the parameter in the sql specified
81
- */
82
- int _ruby_ibm_db_SQLDescribeParam_helper(describeparam_args *data) {
83
- int rc = 0;
84
- data->stmt_res->is_executing = 1;
85
-
86
- rc = SQLDescribeParam( (SQLHSTMT) data->stmt_res->hstmt, (SQLUSMALLINT)data->param_no, &(data->sql_data_type),
87
- &(data->sql_precision), &(data->sql_scale), &(data->sql_nullable) );
88
-
89
- data->stmt_res->is_executing = 0;
90
- data->rc = rc;
91
- return rc;
92
- }
93
-
94
- /*
95
- This function call the SQLDescribeCol cli call to get the description of the parameter in the sql specified
96
- */
97
- int _ruby_ibm_db_SQLDescribeCol_helper(describecol_args *data) {
98
- int i = data->col_no - 1;
99
- int rc = 0;
100
-
101
- data->stmt_res->is_executing = 1;
102
-
103
- #ifdef UNICODE_SUPPORT_VERSION
104
- rc = SQLDescribeColW( (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
- #else
109
- rc = SQLDescribeCol( (SQLHSTMT)data->stmt_res->hstmt, (SQLSMALLINT)(data->col_no),
110
- data->stmt_res->column_info[i].name, data->buff_length, &(data->name_length),
111
- &(data->stmt_res->column_info[i].type), &(data->stmt_res->column_info[i].size),
112
- &(data->stmt_res->column_info[i].scale), &(data->stmt_res->column_info[i].nullable) );
113
- #endif
114
-
115
- data->stmt_res->is_executing = 0;
116
-
117
- return rc;
118
- }
119
-
120
- /*
121
- This function call the SQLBindCol cli call to get the description of the parameter in the sql specified
122
- */
123
- int _ruby_ibm_db_SQLBindCol_helper(bind_col_args *data) {
124
- int rc = 0;
125
- data->stmt_res->is_executing = 1;
126
-
127
- rc = SQLBindCol( (SQLHSTMT) data->stmt_res->hstmt, (SQLUSMALLINT)(data->col_num),
128
- data->TargetType, data->TargetValuePtr, data->buff_length,
129
- data->out_length );
130
-
131
- data->stmt_res->is_executing = 0;
132
- return rc;
133
- }
134
-
135
- /*
136
- This function calls SQLColumnPrivileges cli call to get the list of columns and the associated privileges
137
- */
138
- int _ruby_ibm_db_SQLColumnPrivileges_helper(metadata_args *data) {
139
- int rc = 0;
140
-
141
- data->stmt_res->is_executing = 1;
142
-
143
- #ifndef UNICODE_SUPPORT_VERSION
144
- rc = SQLColumnPrivileges( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
145
- data->owner, data->owner_len, data->table_name, data->table_name_len,
146
- data->column_name, data->column_name_len );
147
- #else
148
- rc = SQLColumnPrivilegesW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
149
- data->owner, data->owner_len, data->table_name, data->table_name_len,
150
- data->column_name, data->column_name_len );
151
- #endif
152
-
153
- data->stmt_res->is_executing = 0;
154
- data->rc=rc;
155
- return rc;
156
-
157
- }
158
-
159
- /*
160
- This function calls SQLColumns cli call to get the list of columns and the associated metadata of the table
161
- */
162
- int _ruby_ibm_db_SQLColumns_helper(metadata_args *data) {
163
- int rc = 0;
164
-
165
- data->stmt_res->is_executing = 1;
166
-
167
- #ifndef UNICODE_SUPPORT_VERSION
168
- rc = SQLColumns( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
169
- data->owner, data->owner_len, data->table_name, data->table_name_len,
170
- data->column_name, data->column_name_len );
171
- #else
172
- rc = SQLColumnsW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
173
- data->owner, data->owner_len, data->table_name, data->table_name_len,
174
- data->column_name, data->column_name_len );
175
- #endif
176
-
177
- data->stmt_res->is_executing = 0;
178
- data->rc = rc;
179
- return rc;
180
- }
181
-
182
- /*
183
- This function calls SQLPrimaryKeys cli call to get the list of primay key columns and the associated metadata
184
- */
185
- int _ruby_ibm_db_SQLPrimaryKeys_helper(metadata_args *data) {
186
- int rc = 0;
187
-
188
- data->stmt_res->is_executing = 1;
189
-
190
- #ifndef UNICODE_SUPPORT_VERSION
191
- rc = SQLPrimaryKeys( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
192
- data->owner, data->owner_len, data->table_name, data->table_name_len );
193
- #else
194
- rc = SQLPrimaryKeysW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
195
- data->owner, data->owner_len, data->table_name, data->table_name_len );
196
- #endif
197
-
198
- data->stmt_res->is_executing = 0;
199
- data->rc = rc;
200
- return rc;
201
- }
202
-
203
- /*
204
- This function calls SQLForeignKeys cli call to get the list of foreign key columns and the associated metadata
205
- */
206
- int _ruby_ibm_db_SQLForeignKeys_helper(metadata_args *data) {
207
- int rc = 0;
208
-
209
- data->stmt_res->is_executing = 1;
210
-
211
- #ifndef UNICODE_SUPPORT_VERSION
212
- rc = SQLForeignKeys( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
213
- data->owner, data->owner_len, data->table_name , data->table_name_len, NULL, SQL_NTS,
214
- NULL, SQL_NTS, NULL, SQL_NTS );
215
- #else
216
- rc = SQLForeignKeysW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
217
- data->owner, data->owner_len, data->table_name , data->table_name_len, NULL, SQL_NTS,
218
- NULL, SQL_NTS, NULL, SQL_NTS );
219
- #endif
220
-
221
- data->stmt_res->is_executing = 0;
222
- data->rc = rc;
223
- return rc;
224
- }
225
-
226
- /*
227
- This function calls SQLProcedureColumns cli call to get the list of parameters
228
- and associated metadata of the stored procedure
229
- */
230
- int _ruby_ibm_db_SQLProcedureColumns_helper(metadata_args *data) {
231
- int rc = 0;
232
-
233
- data->stmt_res->is_executing = 1;
234
-
235
- #ifndef UNICODE_SUPPORT_VERSION
236
- rc = SQLProcedureColumns( (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
- #else
239
- rc = SQLProcedureColumnsW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
240
- data->owner_len, data->proc_name, data->proc_name_len, data->column_name, data->column_name_len );
241
- #endif
242
-
243
- data->stmt_res->is_executing = 0;
244
- data->rc = rc;
245
- return rc;
246
- }
247
-
248
- /*
249
- This function calls SQLProcedures cli call to get the list of stored procedures
250
- and associated metadata of the stored procedure
251
- */
252
- int _ruby_ibm_db_SQLProcedures_helper(metadata_args *data) {
253
- int rc = 0;
254
-
255
- data->stmt_res->is_executing = 1;
256
-
257
- #ifndef UNICODE_SUPPORT_VERSION
258
- rc = SQLProcedures( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
259
- data->owner_len, data->proc_name, data->proc_name_len );
260
- #else
261
- rc = SQLProceduresW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
262
- data->owner_len, data->proc_name, data->proc_name_len );
263
- #endif
264
-
265
- data->stmt_res->is_executing = 0;
266
- data->rc = rc;
267
- return rc;
268
- }
269
-
270
- /*
271
- This function calls SQLSpecialColumns cli call to get the metadata related to the special columns
272
- (Unique index or primary key column) and associated metadata
273
- */
274
- int _ruby_ibm_db_SQLSpecialColumns_helper(metadata_args *data) {
275
- int rc = 0;
276
-
277
- data->stmt_res->is_executing = 1;
278
-
279
- #ifndef UNICODE_SUPPORT_VERSION
280
- rc = SQLSpecialColumns( (SQLHSTMT) data->stmt_res->hstmt, SQL_BEST_ROWID, data->qualifier, data->qualifier_len,
281
- data->owner, data->owner_len, data->table_name, data->table_name_len,
282
- (SQLUSMALLINT)data->scope, SQL_NULLABLE );
283
- #else
284
- rc = SQLSpecialColumnsW( (SQLHSTMT) data->stmt_res->hstmt, SQL_BEST_ROWID, data->qualifier, data->qualifier_len,
285
- data->owner, data->owner_len, data->table_name, data->table_name_len,
286
- (SQLUSMALLINT)data->scope, SQL_NULLABLE );
287
- #endif
288
-
289
- data->stmt_res->is_executing = 0;
290
- data->rc = rc;
291
- return rc;
292
- }
293
-
294
- /*
295
- This function calls SQLStatistics cli call to get the index information for a given table.
296
- */
297
- int _ruby_ibm_db_SQLStatistics_helper(metadata_args *data) {
298
- int rc = 0;
299
-
300
- data->stmt_res->is_executing = 1;
301
-
302
- #ifndef UNICODE_SUPPORT_VERSION
303
- rc = SQLStatistics( (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
- #else
306
- rc = SQLStatisticsW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
307
- data->owner_len, data->table_name, data->table_name_len, (SQLUSMALLINT)data->unique, SQL_QUICK );
308
- #endif
309
-
310
- data->stmt_res->is_executing = 0;
311
- data->rc= rc;
312
- return rc;
313
- }
314
-
315
- /*
316
- This function calls SQLTablePrivileges cli call to retrieve list of tables and
317
- the asscociated privileges for each table.
318
- */
319
- int _ruby_ibm_db_SQLTablePrivileges_helper(metadata_args *data) {
320
- int rc = 0;
321
-
322
- data->stmt_res->is_executing = 1;
323
-
324
- #ifndef UNICODE_SUPPORT_VERSION
325
- rc = SQLTablePrivileges( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
326
- data->owner, data->owner_len, data->table_name, data->table_name_len );
327
- #else
328
- rc = SQLTablePrivilegesW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
329
- data->owner, data->owner_len, data->table_name, data->table_name_len );
330
- #endif
331
-
332
- data->stmt_res->is_executing = 0;
333
- data->rc = rc;
334
- return rc;
335
- }
336
-
337
- /*
338
- This function calls SQLTables cli call to retrieve list of tables in the specified schema and
339
- the asscociated metadata for each table.
340
- */
341
- int _ruby_ibm_db_SQLTables_helper(metadata_args *data) {
342
- int rc = 0;
343
-
344
- data->stmt_res->is_executing = 1;
345
-
346
- #ifndef UNICODE_SUPPORT_VERSION
347
- rc = SQLTables( (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
- #else
350
- rc = SQLTablesW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
351
- data->owner_len, data->table_name, data->table_name_len, data->table_type, data->table_type_len );
352
- #endif
353
-
354
- data->stmt_res->is_executing = 0;
355
- data->rc = rc;
356
- return rc;
357
- }
358
-
359
- /*
360
- This function calls SQLExecDirect cli call to execute a statement directly
361
- */
362
- int _ruby_ibm_db_SQLExecDirect_helper(exec_cum_prepare_args *data) {
363
- int rc = 0;
364
-
365
- data->stmt_res->is_executing = 1;
366
-
367
- #ifndef UNICODE_SUPPORT_VERSION
368
- rc = SQLExecDirect( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
369
- #else
370
- rc = SQLExecDirectW( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
371
- #endif
372
-
373
- data->stmt_res->is_executing = 0;
374
- data->rc=rc;
375
- return rc;
376
- }
377
-
378
- /*
379
- This function calls SQLCreateDb cli call
380
- */
381
- int _ruby_ibm_db_SQLCreateDB_helper(create_drop_db_args *data) {
382
- int rc = 0;
383
- #ifndef UNICODE_SUPPORT_VERSION
384
- #ifdef _WIN32
385
- HINSTANCE cliLib = NULL;
386
- FARPROC sqlcreatedb;
387
- cliLib = DLOPEN( LIBDB2 );
388
- sqlcreatedb = DLSYM( cliLib, "SQLCreateDb" );
389
- #elif _AIX
390
- void *cliLib = NULL;
391
- typedef int (*sqlcreatedbType)( SQLHDBC, SQLCHAR *, SQLINTEGER, SQLCHAR *, SQLINTEGER, SQLCHAR *, SQLINTEGER );
392
- sqlcreatedbType sqlcreatedb;
393
- /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
394
- cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
395
- sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDb" );
396
- #else
397
- void *cliLib = NULL;
398
- typedef int (*sqlcreatedbType)( SQLHDBC, SQLCHAR *, SQLINTEGER, SQLCHAR *, SQLINTEGER, SQLCHAR *, SQLINTEGER );
399
- sqlcreatedbType sqlcreatedb;
400
- cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
401
- sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDb" );
402
- #endif
403
- #else
404
- #ifdef _WIN32
405
- HINSTANCE cliLib = NULL;
406
- FARPROC sqlcreatedb;
407
- cliLib = DLOPEN( LIBDB2 );
408
- sqlcreatedb = DLSYM( cliLib, "SQLCreateDbW" );
409
- #elif _AIX
410
- void *cliLib = NULL;
411
- typedef int (*sqlcreatedbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER );
412
- sqlcreatedbType sqlcreatedb;
413
- /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
414
- cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
415
- sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDbW" );
416
- #else
417
- void *cliLib = NULL;
418
- typedef int (*sqlcreatedbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER );
419
- sqlcreatedbType sqlcreatedb;
420
- cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
421
- sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDbW" );
422
- #endif
423
- #endif
424
-
425
- rc = (*sqlcreatedb)( (SQLHSTMT) data->conn_res->hdbc, data->dbName, (SQLINTEGER)data->dbName_string_len,
426
- data->codeSet, (SQLINTEGER)data->codeSet_string_len,
427
- data->mode, (SQLINTEGER)data->mode_string_len );
428
- data->rc =rc;
429
- DLCLOSE( cliLib );
430
- return rc;
431
- }
432
-
433
- /*
434
- This function calls SQLDropDb cli call
435
- */
436
- int _ruby_ibm_db_SQLDropDB_helper(create_drop_db_args *data) {
437
- int rc = 0;
438
- #ifndef UNICODE_SUPPORT_VERSION
439
- #ifdef _WIN32
440
- HINSTANCE cliLib = NULL;
441
- FARPROC sqldropdb;
442
- cliLib = DLOPEN( LIBDB2 );
443
- sqldropdb = DLSYM( cliLib, "SQLDropDb" );
444
- #elif _AIX
445
- void *cliLib = NULL;
446
- typedef int (*sqldropdbType)( SQLHDBC, SQLCHAR *, SQLINTEGER);
447
- sqldropdbType sqldropdb;
448
- /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
449
- cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
450
- sqldropdb = (sqldropdbType) DLSYM( cliLib, "SQLDropDb" );
451
- #else
452
- void *cliLib = NULL;
453
- typedef int (*sqldropdbType)( SQLHDBC, SQLCHAR *, SQLINTEGER);
454
- sqldropdbType sqldropdb;
455
- cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
456
- sqldropdb = (sqldropdbType) DLSYM( cliLib, "SQLDropDb" );
457
- #endif
458
- #else
459
- #ifdef _WIN32
460
- HINSTANCE cliLib = NULL;
461
- FARPROC sqldropdb;
462
- cliLib = DLOPEN( LIBDB2 );
463
- sqldropdb = DLSYM( cliLib, "SQLDropDbW" );
464
- #elif _AIX
465
- void *cliLib = NULL;
466
- typedef int (*sqldropdbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER);
467
- sqldropdbType sqldropdb;
468
- /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
469
- cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
470
- sqldropdb = (sqldropdbType) DLSYM( cliLib, "SQLDropDbW" );
471
- #else
472
- void *cliLib = NULL;
473
- typedef int (*sqldropdbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER);
474
- sqldropdbType sqldropdb;
475
- cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
476
- sqldropdb = (sqldropdbType) DLSYM( cliLib, "SQLDropDbW" );
477
- #endif
478
- #endif
479
-
480
- rc = (*sqldropdb)( (SQLHSTMT) data->conn_res->hdbc, data->dbName, (SQLINTEGER)data->dbName_string_len );
481
-
482
- DLCLOSE( cliLib );
483
- return rc;
484
- }
485
-
486
- /*
487
- This function calls SQLPrepare cli call to prepare the given statement
488
- */
489
- int _ruby_ibm_db_SQLPrepare_helper(exec_cum_prepare_args *data) {
490
- int rc = 0;
491
-
492
- data->stmt_res->is_executing = 1;
493
-
494
- #ifndef UNICODE_SUPPORT_VERSION
495
- rc = SQLPrepare( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
496
- #else
497
- rc = SQLPrepareW( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
498
- #endif
499
-
500
- data->stmt_res->is_executing = 0;
501
-
502
- return rc;
503
- }
504
-
505
- /*
506
- This function calls SQLFreeStmt to end processing on the statement referenced by statement handle
507
- */
508
- int _ruby_ibm_db_SQLFreeStmt_helper(free_stmt_args *data) {
509
- int rc = 0;
510
-
511
- data->stmt_res->is_executing = 1;
512
-
513
- rc = SQLFreeStmt((SQLHSTMT)data->stmt_res->hstmt, data->option );
514
-
515
- data->stmt_res->is_executing = 0;
516
- data->rc = rc;
517
- return rc;
518
- }
519
-
520
- /*
521
- This function calls SQLExecute cli call to execute the prepared
522
- */
523
- int _ruby_ibm_db_SQLExecute_helper(stmt_handle *stmt_res) {
524
- int rc = 0;
525
-
526
- stmt_res->is_executing = 1;
527
-
528
- rc = SQLExecute( (SQLHSTMT) stmt_res->hstmt );
529
-
530
- stmt_res->is_executing = 0;
531
-
532
- return rc;
533
- }
534
-
535
- /*
536
- This function calls SQLParamData cli call to read if there is still data to be sent
537
- */
538
- int _ruby_ibm_db_SQLParamData_helper(param_cum_put_data_args *data) {
539
- int rc = 0;
540
-
541
- data->stmt_res->is_executing = 1;
542
-
543
- rc = SQLParamData( (SQLHSTMT) data->stmt_res->hstmt, (SQLPOINTER *) &(data->valuePtr) );
544
-
545
- data->stmt_res->is_executing = 0;
546
-
547
- return rc;
548
- }
549
-
550
- /*
551
- This function calls SQLColAttributes cli call to get the specified attribute of the column in result set
552
- */
553
- int _ruby_ibm_db_SQLColAttributes_helper(col_attr_args *data) {
554
- int rc = 0;
555
-
556
- data->stmt_res->is_executing = 1;
557
-
558
- rc = SQLColAttributes( (SQLHSTMT) data->stmt_res->hstmt, data->col_num,
559
- data->FieldIdentifier, NULL, 0, NULL, &(data->num_attr) );
560
-
561
- data->stmt_res->is_executing = 0;
562
- data->rc = rc;
563
- return rc;
564
- }
565
-
566
- /*
567
- This function calls SQLPutData cli call to supply parameter data value
568
- */
569
- int _ruby_ibm_db_SQLPutData_helper(param_cum_put_data_args *data) {
570
- int rc = 0;
571
-
572
- data->stmt_res->is_executing = 1;
573
-
574
- rc = SQLPutData( (SQLHSTMT) data->stmt_res->hstmt, (SQLPOINTER)(((param_node*)(data->valuePtr))->svalue),
575
- ((param_node*)(data->valuePtr))->ivalue );
576
-
577
- data->stmt_res->is_executing = 0;
578
-
579
- return rc;
580
- }
581
-
582
- /*
583
- This function calls SQLGetData cli call to retrieve data for a single column
584
- */
585
- int _ruby_ibm_db_SQLGetData_helper(get_data_args *data) {
586
- int rc = 0;
587
-
588
- data->stmt_res->is_executing = 1;
589
-
590
- rc = SQLGetData( (SQLHSTMT) data->stmt_res->hstmt, data->col_num, data->targetType, data->buff,
591
- data->buff_length, data->out_length);
592
-
593
- data->stmt_res->is_executing = 0;
594
-
595
- return rc;
596
- }
597
-
598
- /*
599
- This function calls SQLGetLength cli call to retrieve the length of the lob value
600
- */
601
- int _ruby_ibm_db_SQLGetLength_helper(get_length_args *data) {
602
- int col_num = data->col_num;
603
- int rc = 0;
604
-
605
- data->stmt_res->is_executing = 1;
606
-
607
- rc = SQLGetLength( (SQLHSTMT) *( data->new_hstmt ), data->stmt_res->column_info[col_num-1].loc_type,
608
- data->stmt_res->column_info[col_num-1].lob_loc, data->sLength,
609
- &(data->stmt_res->column_info[col_num-1].loc_ind) );
610
-
611
- data->stmt_res->is_executing = 0;
612
-
613
- return rc;
614
- }
615
-
616
- /*
617
- This function calls SQLGetSubString cli call to retrieve portion of the lob value
618
- */
619
- int _ruby_ibm_db_SQLGetSubString_helper(get_subString_args *data) {
620
- int col_num = data->col_num;
621
- int rc = 0;
622
-
623
- data->stmt_res->is_executing = 1;
624
-
625
- rc = SQLGetSubString( (SQLHSTMT) *( data->new_hstmt ), data->stmt_res->column_info[col_num-1].loc_type,
626
- data->stmt_res->column_info[col_num-1].lob_loc, 1, data->forLength, data->targetCType,
627
- data->buffer, data->buff_length, data->out_length,
628
- &(data->stmt_res->column_info[col_num-1].loc_ind) );
629
-
630
- data->stmt_res->is_executing = 0;
631
-
632
- return rc;
633
- }
634
-
635
- /*
636
- This function calls SQLNextResult cli call to fetch the multiple result sets that might be returned by a stored Proc
637
- */
638
- int _ruby_ibm_db_SQLNextResult_helper(next_result_args *data) {
639
- int rc = 0;
640
-
641
- data->stmt_res->is_executing = 1;
642
-
643
- rc = SQLNextResult( (SQLHSTMT) data->stmt_res->hstmt, (SQLHSTMT) *(data->new_hstmt) );
644
-
645
- data->stmt_res->is_executing = 0;
646
- data->rc = rc;
647
- return rc;
648
- }
649
-
650
- /*
651
- This function calls SQLFetchScroll cli call to fetch the specified rowset of data from result
652
- */
653
- int _ruby_ibm_db_SQLFetchScroll_helper(fetch_data_args *data) {
654
- int rc = 0;
655
-
656
- data->stmt_res->is_executing = 1;
657
-
658
- rc = SQLFetchScroll( (SQLHSTMT) data->stmt_res->hstmt, data->fetchOrientation, data->fetchOffset);
659
-
660
- data->stmt_res->is_executing = 0;
661
-
662
- return rc;
663
- }
664
-
665
- /*
666
- This function calls SQLFetch cli call to advance the cursor to
667
- the next row of the result set, and retrieves any bound columns
668
- */
669
- int _ruby_ibm_db_SQLFetch_helper(fetch_data_args *data) {
670
- int rc = 0;
671
-
672
- data->stmt_res->is_executing = 1;
673
-
674
- rc = SQLFetch( (SQLHSTMT) data->stmt_res->hstmt );
675
-
676
- data->stmt_res->is_executing = 0;
677
-
678
- return rc;
679
- }
680
-
681
- /*
682
- This function calls SQLNumResultCols cli call to fetch the number of fields contained in a result set
683
- */
684
- int _ruby_ibm_db_SQLNumResultCols_helper(row_col_count_args *data) {
685
- int rc = 0;
686
-
687
- data->stmt_res->is_executing = 1;
688
-
689
- rc = SQLNumResultCols( (SQLHSTMT) data->stmt_res->hstmt, (SQLSMALLINT*) &(data->count) );
690
-
691
- data->stmt_res->is_executing = 0;
692
- data->rc = rc;
693
- return rc;
694
- }
695
-
696
- /*
697
- This function calls SQLNumParams cli call to fetch the number of parameter markers in an SQL statement
698
- */
699
- int _ruby_ibm_db_SQLNumParams_helper(row_col_count_args *data) {
700
- int rc = 0;
701
-
702
- data->stmt_res->is_executing = 1;
703
-
704
- rc = SQLNumParams( (SQLHSTMT) data->stmt_res->hstmt, (SQLSMALLINT*) &(data->count) );
705
-
706
- data->stmt_res->is_executing = 0;
707
-
708
- return rc;
709
- }
710
-
711
- /*
712
- This function calls SQLRowCount cli call to fetch the number of rows affected by the SQL statement
713
- */
714
- int _ruby_ibm_db_SQLRowCount_helper(sql_row_count_args *data) {
715
- int rc = 0;
716
-
717
- data->stmt_res->is_executing = 1;
718
-
719
- rc = SQLRowCount( (SQLHSTMT) data->stmt_res->hstmt, (SQLLEN*) &(data->count) );
720
-
721
- data->stmt_res->is_executing = 0;
722
-
723
- return rc;
724
- }
725
-
726
- /*
727
- This function calls SQLGetInfo cli call to get general information about DBMS, which the app is connected to
728
- */
729
- int _ruby_ibm_db_SQLGetInfo_helper(get_info_args *data) {
730
- #ifndef UNICODE_SUPPORT_VERSION
731
- return SQLGetInfo( data->conn_res->hdbc, data->infoType, data->infoValue, data->buff_length, data->out_length);
732
- #else
733
- return SQLGetInfoW( data->conn_res->hdbc, data->infoType, data->infoValue, data->buff_length, data->out_length);
734
- #endif
735
- }
736
-
737
- /*
738
- This function calls SQLGetDiagRec cli call to get the current values of a diagnostic record that contains error
739
- */
740
- int _ruby_ibm_db_SQLGetDiagRec_helper(get_diagRec_args *data) {
741
- #ifdef UNICODE_SUPPORT_VERSION
742
- int rc= SQLGetDiagRecW( data->hType, data->handle, data->recNum, data->SQLState, data->NativeErrorPtr,
743
- data->msgText, data->buff_length, data->text_length_ptr );
744
- data->return_code=rc;
745
- return rc;
746
- #else
747
- return SQLGetDiagRec(data->hType, data->handle, data->recNum, data->SQLState, data->NativeErrorPtr,
748
- data->msgText, data->buff_length, data->text_length_ptr );
749
- #endif
750
- }
751
-
752
- /*
753
- This function calls SQLSetStmtAttr cli call to set attributes related to a statement
754
- */
755
- int _ruby_ibm_db_SQLSetStmtAttr_helper(set_handle_attr_args *data) {
756
- #ifndef UNICODE_SUPPORT_VERSION
757
- return SQLSetStmtAttr( (SQLHSTMT) *(data->handle), data->attribute, data->valuePtr, data->strLength );
758
- #else
759
- return SQLSetStmtAttrW( (SQLHSTMT) *(data->handle), data->attribute, data->valuePtr, data->strLength );
760
- #endif
761
- }
762
-
763
- /*
764
- This function calls SQLSetConnectAttr cli call to set attributes that govern aspects of connections
765
- */
766
- int _ruby_ibm_db_SQLSetConnectAttr_helper(set_handle_attr_args *data) {
767
- #ifndef UNICODE_SUPPORT_VERSION
768
- return SQLSetConnectAttr( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr, data->strLength );
769
- #else
770
- return SQLSetConnectAttrW( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr, data->strLength );
771
- #endif
772
- }
773
-
774
- /*
775
- This function calls SQLSetEnvAttr cli call to set an environment attribute
776
- */
777
- int _ruby_ibm_db_SQLSetEnvAttr_helper(set_handle_attr_args *data) {
778
- return SQLSetEnvAttr( (SQLHENV) *(data->handle), data->attribute, data->valuePtr, data->strLength);
779
- }
780
-
781
- /*
782
- This function calls SQLGetStmtAttr cli call to set an environment attribute
783
-
784
- 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
785
- 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.
786
-
787
- */
788
- int _ruby_ibm_db_SQLGetStmtAttr_helper(get_handle_attr_args *data) {
789
- return SQLGetStmtAttr( (SQLHSTMT) *(data->handle), data->attribute, data->valuePtr,
790
- data->buff_length, data->out_length);
791
- }
792
-
793
- /*
794
- This function calls SQLGetConnectAttr cli call to set an environment attribute
795
- */
796
- int _ruby_ibm_db_SQLGetConnectAttr_helper(get_handle_attr_args *data) {
797
- #ifndef UNICODE_SUPPORT_VERSION
798
- return SQLGetConnectAttr( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr,
799
- data->buff_length, data->out_length);
800
- #else
801
- return SQLGetConnectAttrW( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr,
802
- data->buff_length, data->out_length);
803
- #endif
804
- }
805
-
806
- /*
807
- This function calls SQLBindFileToParam cli call
808
- */
809
- int _ruby_ibm_db_SQLBindFileToParam_helper(stmt_handle *stmt_res, param_node *curr) {
810
- int rc = 0;
811
-
812
- stmt_res->is_executing = 1;
813
-
814
- rc = SQLBindFileToParam( (SQLHSTMT)stmt_res->hstmt, curr->param_num,
815
- curr->data_type, (SQLCHAR*)curr->svalue,
816
- (SQLSMALLINT*)&(curr->ivalue), &(curr->file_options),
817
- curr->ivalue, &(curr->bind_indicator) );
818
-
819
- stmt_res->is_executing = 0;
820
-
821
- return rc;
822
- }
823
-
824
- /*
825
- This function calls SQLBindParameter cli call
826
- */
827
- int _ruby_ibm_db_SQLBindParameter_helper(bind_parameter_args *data) {
828
- int rc = 0;
829
-
830
- data->stmt_res->is_executing = 1;
831
-
832
- rc = SQLBindParameter( (SQLHSTMT) data->stmt_res->hstmt, data->param_num, data->IOType, data->valueType,
833
- data->paramType, data->colSize, data->decimalDigits, data->paramValPtr, data->buff_length,
834
- data->out_length );
835
-
836
- data->stmt_res->is_executing = 0;
837
-
838
- return rc;
839
- }
840
-
841
- /*
842
- Statement level thread unblock function. This fuction cancels a statement level SQL call issued when requested for,
843
- allowing for a safe interrupt of the thread.
844
- */
845
- void _ruby_ibm_db_Statement_level_UBF(stmt_handle *stmt_res) {
846
- int rc = 0;
847
- if( stmt_res->is_executing == 1 ) {
848
- rc = SQLCancel( (SQLHSTMT) stmt_res->hstmt );
849
- }
850
- return;
851
- }
1
+ /*
2
+ +----------------------------------------------------------------------+
3
+ | Licensed Materials - Property of IBM |
4
+ | |
5
+ | (C) Copyright IBM Corporation 2009 - 2015 |
6
+ +----------------------------------------------------------------------+
7
+ | Authors: Praveen Devarao, Arvind Gupta |
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.h"
25
+
26
+ #include "ruby_ibm_db_cli.h"
27
+
28
+ /*
29
+ This function connects to the database using either SQLConnect or SQLDriverConnect CLI API
30
+ depending on whether it is a cataloged or an uncataloged connection.
31
+ */
32
+ int _ruby_ibm_db_SQLConnect_helper(connect_args *data) {
33
+ if(data->ctlg_conn == 1) {
34
+ #ifndef UNICODE_SUPPORT_VERSION
35
+ return SQLConnect( (SQLHDBC)*(data->hdbc), (SQLCHAR *)data->database,
36
+ (SQLSMALLINT)data->database_len, (SQLCHAR *)data->uid, (SQLSMALLINT)data->uid_len,
37
+ (SQLCHAR *)data->password, (SQLSMALLINT)data->password_len );
38
+ #else
39
+ return SQLConnectW( (SQLHDBC)*(data->hdbc), data->database,
40
+ data->database_len, data->uid, data->uid_len,
41
+ data->password, data->password_len );
42
+ #endif
43
+ } else {
44
+ #ifndef UNICODE_SUPPORT_VERSION
45
+ return SQLDriverConnect( (SQLHDBC) *(data->hdbc), (SQLHWND)NULL,
46
+ (SQLCHAR*)data->database, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );
47
+ #else
48
+ return SQLDriverConnectW( (SQLHDBC) *(data->hdbc), (SQLHWND)NULL,
49
+ data->database, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );
50
+ #endif
51
+ }
52
+ }
53
+
54
+ /*
55
+ This function issues SQLDisconnect to disconnect from the Dataserver
56
+ */
57
+ int _ruby_ibm_db_SQLDisconnect_helper(SQLHANDLE *hdbc) {
58
+ return SQLDisconnect( (SQLHDBC) *hdbc );
59
+ }
60
+
61
+ /*
62
+ Connection level Unblock function. This function is called when a thread interruput is issued while executing a
63
+ connection level SQL call
64
+ */
65
+ void _ruby_ibm_db_Connection_level_UBF(void *data) {
66
+ return;
67
+ }
68
+
69
+ /*
70
+ This function will commit and end the inprogress transaction by issuing a SQLCommit
71
+ */
72
+ int _ruby_ibm_db_SQLEndTran(end_tran_args *endtran_args) {
73
+ int rc = 0;
74
+ rc = SQLEndTran( endtran_args->handleType, *(endtran_args->hdbc), endtran_args->completionType );
75
+ endtran_args->rc = rc;
76
+ return rc;
77
+ }
78
+
79
+ /*
80
+ This function call the SQLDescribeParam cli call to get the description of the parameter in the sql specified
81
+ */
82
+ int _ruby_ibm_db_SQLDescribeParam_helper(describeparam_args *data) {
83
+ int rc = 0;
84
+ data->stmt_res->is_executing = 1;
85
+
86
+ rc = SQLDescribeParam( (SQLHSTMT) data->stmt_res->hstmt, (SQLUSMALLINT)data->param_no, &(data->sql_data_type),
87
+ &(data->sql_precision), &(data->sql_scale), &(data->sql_nullable) );
88
+
89
+ data->stmt_res->is_executing = 0;
90
+ data->rc = rc;
91
+ return rc;
92
+ }
93
+
94
+ /*
95
+ This function call the SQLDescribeCol cli call to get the description of the parameter in the sql specified
96
+ */
97
+ int _ruby_ibm_db_SQLDescribeCol_helper(describecol_args *data) {
98
+ int i = data->col_no - 1;
99
+ int rc = 0;
100
+
101
+ data->stmt_res->is_executing = 1;
102
+
103
+ #ifdef UNICODE_SUPPORT_VERSION
104
+ rc = SQLDescribeColW( (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
+ #else
109
+ rc = SQLDescribeCol( (SQLHSTMT)data->stmt_res->hstmt, (SQLSMALLINT)(data->col_no),
110
+ data->stmt_res->column_info[i].name, data->buff_length, &(data->name_length),
111
+ &(data->stmt_res->column_info[i].type), &(data->stmt_res->column_info[i].size),
112
+ &(data->stmt_res->column_info[i].scale), &(data->stmt_res->column_info[i].nullable) );
113
+ #endif
114
+
115
+ data->stmt_res->is_executing = 0;
116
+
117
+ return rc;
118
+ }
119
+
120
+ /*
121
+ This function call the SQLBindCol cli call to get the description of the parameter in the sql specified
122
+ */
123
+ int _ruby_ibm_db_SQLBindCol_helper(bind_col_args *data) {
124
+ int rc = 0;
125
+ data->stmt_res->is_executing = 1;
126
+
127
+ rc = SQLBindCol( (SQLHSTMT) data->stmt_res->hstmt, (SQLUSMALLINT)(data->col_num),
128
+ data->TargetType, data->TargetValuePtr, data->buff_length,
129
+ data->out_length );
130
+
131
+ data->stmt_res->is_executing = 0;
132
+ return rc;
133
+ }
134
+
135
+ /*
136
+ This function calls SQLColumnPrivileges cli call to get the list of columns and the associated privileges
137
+ */
138
+ int _ruby_ibm_db_SQLColumnPrivileges_helper(metadata_args *data) {
139
+ int rc = 0;
140
+
141
+ data->stmt_res->is_executing = 1;
142
+
143
+ #ifndef UNICODE_SUPPORT_VERSION
144
+ rc = SQLColumnPrivileges( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
145
+ data->owner, data->owner_len, data->table_name, data->table_name_len,
146
+ data->column_name, data->column_name_len );
147
+ #else
148
+ rc = SQLColumnPrivilegesW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
149
+ data->owner, data->owner_len, data->table_name, data->table_name_len,
150
+ data->column_name, data->column_name_len );
151
+ #endif
152
+
153
+ data->stmt_res->is_executing = 0;
154
+ data->rc=rc;
155
+ return rc;
156
+
157
+ }
158
+
159
+ /*
160
+ This function calls SQLColumns cli call to get the list of columns and the associated metadata of the table
161
+ */
162
+ int _ruby_ibm_db_SQLColumns_helper(metadata_args *data) {
163
+ int rc = 0;
164
+
165
+ data->stmt_res->is_executing = 1;
166
+
167
+ #ifndef UNICODE_SUPPORT_VERSION
168
+ rc = SQLColumns( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
169
+ data->owner, data->owner_len, data->table_name, data->table_name_len,
170
+ data->column_name, data->column_name_len );
171
+ #else
172
+ rc = SQLColumnsW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
173
+ data->owner, data->owner_len, data->table_name, data->table_name_len,
174
+ data->column_name, data->column_name_len );
175
+ #endif
176
+
177
+ data->stmt_res->is_executing = 0;
178
+ data->rc = rc;
179
+ return rc;
180
+ }
181
+
182
+ /*
183
+ This function calls SQLPrimaryKeys cli call to get the list of primay key columns and the associated metadata
184
+ */
185
+ int _ruby_ibm_db_SQLPrimaryKeys_helper(metadata_args *data) {
186
+ int rc = 0;
187
+
188
+ data->stmt_res->is_executing = 1;
189
+
190
+ #ifndef UNICODE_SUPPORT_VERSION
191
+ rc = SQLPrimaryKeys( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
192
+ data->owner, data->owner_len, data->table_name, data->table_name_len );
193
+ #else
194
+ rc = SQLPrimaryKeysW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
195
+ data->owner, data->owner_len, data->table_name, data->table_name_len );
196
+ #endif
197
+
198
+ data->stmt_res->is_executing = 0;
199
+ data->rc = rc;
200
+ return rc;
201
+ }
202
+
203
+ /*
204
+ This function calls SQLForeignKeys cli call to get the list of foreign key columns and the associated metadata
205
+ */
206
+ int _ruby_ibm_db_SQLForeignKeys_helper(metadata_args *data) {
207
+ int rc = 0;
208
+
209
+ data->stmt_res->is_executing = 1;
210
+
211
+ if(!NIL_P(data->table_type))
212
+ {
213
+ #ifndef UNICODE_SUPPORT_VERSION
214
+ rc = SQLForeignKeys( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
215
+ data->owner, data->owner_len, NULL , SQL_NTS, NULL, SQL_NTS,
216
+ NULL, SQL_NTS, data->table_name, data->table_name_len );
217
+ #else
218
+ rc = SQLForeignKeysW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
219
+ data->owner, data->owner_len, NULL , SQL_NTS, NULL, SQL_NTS,
220
+ NULL, SQL_NTS, data->table_name, data->table_name_len );
221
+ #endif
222
+ }
223
+ else
224
+ {
225
+ #ifndef UNICODE_SUPPORT_VERSION
226
+ rc = SQLForeignKeys( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
227
+ data->owner, data->owner_len, data->table_name , data->table_name_len, NULL, SQL_NTS,
228
+ NULL, SQL_NTS, NULL, SQL_NTS );
229
+ #else
230
+ rc = SQLForeignKeysW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
231
+ data->owner, data->owner_len, data->table_name , data->table_name_len, NULL, SQL_NTS,
232
+ NULL, SQL_NTS, NULL, SQL_NTS );
233
+ #endif
234
+ }
235
+
236
+ data->stmt_res->is_executing = 0;
237
+ data->rc = rc;
238
+ return rc;
239
+ }
240
+
241
+ /*
242
+ This function calls SQLProcedureColumns cli call to get the list of parameters
243
+ and associated metadata of the stored procedure
244
+ */
245
+ int _ruby_ibm_db_SQLProcedureColumns_helper(metadata_args *data) {
246
+ int rc = 0;
247
+
248
+ data->stmt_res->is_executing = 1;
249
+
250
+ #ifndef UNICODE_SUPPORT_VERSION
251
+ rc = SQLProcedureColumns( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
252
+ data->owner_len, data->proc_name, data->proc_name_len, data->column_name, data->column_name_len );
253
+ #else
254
+ rc = SQLProcedureColumnsW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
255
+ data->owner_len, data->proc_name, data->proc_name_len, data->column_name, data->column_name_len );
256
+ #endif
257
+
258
+ data->stmt_res->is_executing = 0;
259
+ data->rc = rc;
260
+ return rc;
261
+ }
262
+
263
+ /*
264
+ This function calls SQLProcedures cli call to get the list of stored procedures
265
+ and associated metadata of the stored procedure
266
+ */
267
+ int _ruby_ibm_db_SQLProcedures_helper(metadata_args *data) {
268
+ int rc = 0;
269
+
270
+ data->stmt_res->is_executing = 1;
271
+
272
+ #ifndef UNICODE_SUPPORT_VERSION
273
+ rc = SQLProcedures( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
274
+ data->owner_len, data->proc_name, data->proc_name_len );
275
+ #else
276
+ rc = SQLProceduresW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
277
+ data->owner_len, data->proc_name, data->proc_name_len );
278
+ #endif
279
+
280
+ data->stmt_res->is_executing = 0;
281
+ data->rc = rc;
282
+ return rc;
283
+ }
284
+
285
+ /*
286
+ This function calls SQLSpecialColumns cli call to get the metadata related to the special columns
287
+ (Unique index or primary key column) and associated metadata
288
+ */
289
+ int _ruby_ibm_db_SQLSpecialColumns_helper(metadata_args *data) {
290
+ int rc = 0;
291
+
292
+ data->stmt_res->is_executing = 1;
293
+
294
+ #ifndef UNICODE_SUPPORT_VERSION
295
+ rc = SQLSpecialColumns( (SQLHSTMT) data->stmt_res->hstmt, SQL_BEST_ROWID, data->qualifier, data->qualifier_len,
296
+ data->owner, data->owner_len, data->table_name, data->table_name_len,
297
+ (SQLUSMALLINT)data->scope, SQL_NULLABLE );
298
+ #else
299
+ rc = SQLSpecialColumnsW( (SQLHSTMT) data->stmt_res->hstmt, SQL_BEST_ROWID, data->qualifier, data->qualifier_len,
300
+ data->owner, data->owner_len, data->table_name, data->table_name_len,
301
+ (SQLUSMALLINT)data->scope, SQL_NULLABLE );
302
+ #endif
303
+
304
+ data->stmt_res->is_executing = 0;
305
+ data->rc = rc;
306
+ return rc;
307
+ }
308
+
309
+ /*
310
+ This function calls SQLStatistics cli call to get the index information for a given table.
311
+ */
312
+ int _ruby_ibm_db_SQLStatistics_helper(metadata_args *data) {
313
+ int rc = 0;
314
+
315
+ data->stmt_res->is_executing = 1;
316
+
317
+ #ifndef UNICODE_SUPPORT_VERSION
318
+ rc = SQLStatistics( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
319
+ data->owner_len, data->table_name, data->table_name_len, (SQLUSMALLINT)data->unique, SQL_QUICK );
320
+ #else
321
+ rc = SQLStatisticsW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
322
+ data->owner_len, data->table_name, data->table_name_len, (SQLUSMALLINT)data->unique, SQL_QUICK );
323
+ #endif
324
+
325
+ data->stmt_res->is_executing = 0;
326
+ data->rc= rc;
327
+ return rc;
328
+ }
329
+
330
+ /*
331
+ This function calls SQLTablePrivileges cli call to retrieve list of tables and
332
+ the asscociated privileges for each table.
333
+ */
334
+ int _ruby_ibm_db_SQLTablePrivileges_helper(metadata_args *data) {
335
+ int rc = 0;
336
+
337
+ data->stmt_res->is_executing = 1;
338
+
339
+ #ifndef UNICODE_SUPPORT_VERSION
340
+ rc = SQLTablePrivileges( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
341
+ data->owner, data->owner_len, data->table_name, data->table_name_len );
342
+ #else
343
+ rc = SQLTablePrivilegesW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len,
344
+ data->owner, data->owner_len, data->table_name, data->table_name_len );
345
+ #endif
346
+
347
+ data->stmt_res->is_executing = 0;
348
+ data->rc = rc;
349
+ return rc;
350
+ }
351
+
352
+ /*
353
+ This function calls SQLTables cli call to retrieve list of tables in the specified schema and
354
+ the asscociated metadata for each table.
355
+ */
356
+ int _ruby_ibm_db_SQLTables_helper(metadata_args *data) {
357
+ int rc = 0;
358
+
359
+ data->stmt_res->is_executing = 1;
360
+
361
+ #ifndef UNICODE_SUPPORT_VERSION
362
+ rc = SQLTables( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
363
+ data->owner_len, data->table_name, data->table_name_len, data->table_type, data->table_type_len );
364
+ #else
365
+ rc = SQLTablesW( (SQLHSTMT) data->stmt_res->hstmt, data->qualifier, data->qualifier_len, data->owner,
366
+ data->owner_len, data->table_name, data->table_name_len, data->table_type, data->table_type_len );
367
+ #endif
368
+
369
+ data->stmt_res->is_executing = 0;
370
+ data->rc = rc;
371
+ return rc;
372
+ }
373
+
374
+ /*
375
+ This function calls SQLExecDirect cli call to execute a statement directly
376
+ */
377
+ int _ruby_ibm_db_SQLExecDirect_helper(exec_cum_prepare_args *data) {
378
+ int rc = 0;
379
+
380
+ data->stmt_res->is_executing = 1;
381
+
382
+ #ifndef UNICODE_SUPPORT_VERSION
383
+ rc = SQLExecDirect( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
384
+ #else
385
+ rc = SQLExecDirectW( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
386
+ #endif
387
+
388
+ data->stmt_res->is_executing = 0;
389
+ data->rc=rc;
390
+ return rc;
391
+ }
392
+
393
+ /*
394
+ This function calls SQLCreateDb cli call
395
+ */
396
+ int _ruby_ibm_db_SQLCreateDB_helper(create_drop_db_args *data) {
397
+ int rc = 0;
398
+ #ifndef UNICODE_SUPPORT_VERSION
399
+ #ifdef _WIN32
400
+ HINSTANCE cliLib = NULL;
401
+ FARPROC sqlcreatedb;
402
+ cliLib = DLOPEN( LIBDB2 );
403
+ sqlcreatedb = DLSYM( cliLib, "SQLCreateDb" );
404
+ #elif _AIX
405
+ void *cliLib = NULL;
406
+ typedef int (*sqlcreatedbType)( SQLHDBC, SQLCHAR *, SQLINTEGER, SQLCHAR *, SQLINTEGER, SQLCHAR *, SQLINTEGER );
407
+ sqlcreatedbType sqlcreatedb;
408
+ /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
409
+ cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
410
+ sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDb" );
411
+ #else
412
+ void *cliLib = NULL;
413
+ typedef int (*sqlcreatedbType)( SQLHDBC, SQLCHAR *, SQLINTEGER, SQLCHAR *, SQLINTEGER, SQLCHAR *, SQLINTEGER );
414
+ sqlcreatedbType sqlcreatedb;
415
+ cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
416
+ sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDb" );
417
+ #endif
418
+ #else
419
+ #ifdef _WIN32
420
+ HINSTANCE cliLib = NULL;
421
+ FARPROC sqlcreatedb;
422
+ cliLib = DLOPEN( LIBDB2 );
423
+ sqlcreatedb = DLSYM( cliLib, "SQLCreateDbW" );
424
+ #elif _AIX
425
+ void *cliLib = NULL;
426
+ typedef int (*sqlcreatedbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER );
427
+ sqlcreatedbType sqlcreatedb;
428
+ /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
429
+ cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
430
+ sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDbW" );
431
+ #else
432
+ void *cliLib = NULL;
433
+ typedef int (*sqlcreatedbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER );
434
+ sqlcreatedbType sqlcreatedb;
435
+ cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
436
+ sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDbW" );
437
+ #endif
438
+ #endif
439
+
440
+ rc = (*sqlcreatedb)( (SQLHSTMT) data->conn_res->hdbc, data->dbName, (SQLINTEGER)data->dbName_string_len,
441
+ data->codeSet, (SQLINTEGER)data->codeSet_string_len,
442
+ data->mode, (SQLINTEGER)data->mode_string_len );
443
+ data->rc =rc;
444
+ DLCLOSE( cliLib );
445
+ return rc;
446
+ }
447
+
448
+ /*
449
+ This function calls SQLDropDb cli call
450
+ */
451
+ int _ruby_ibm_db_SQLDropDB_helper(create_drop_db_args *data) {
452
+ int rc = 0;
453
+ #ifndef UNICODE_SUPPORT_VERSION
454
+ #ifdef _WIN32
455
+ HINSTANCE cliLib = NULL;
456
+ FARPROC sqldropdb;
457
+ cliLib = DLOPEN( LIBDB2 );
458
+ sqldropdb = DLSYM( cliLib, "SQLDropDb" );
459
+ #elif _AIX
460
+ void *cliLib = NULL;
461
+ typedef int (*sqldropdbType)( SQLHDBC, SQLCHAR *, SQLINTEGER);
462
+ sqldropdbType sqldropdb;
463
+ /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
464
+ cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
465
+ sqldropdb = (sqldropdbType) DLSYM( cliLib, "SQLDropDb" );
466
+ #else
467
+ void *cliLib = NULL;
468
+ typedef int (*sqldropdbType)( SQLHDBC, SQLCHAR *, SQLINTEGER);
469
+ sqldropdbType sqldropdb;
470
+ cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
471
+ sqldropdb = (sqldropdbType) DLSYM( cliLib, "SQLDropDb" );
472
+ #endif
473
+ #else
474
+ #ifdef _WIN32
475
+ HINSTANCE cliLib = NULL;
476
+ FARPROC sqldropdb;
477
+ cliLib = DLOPEN( LIBDB2 );
478
+ sqldropdb = DLSYM( cliLib, "SQLDropDbW" );
479
+ #elif _AIX
480
+ void *cliLib = NULL;
481
+ typedef int (*sqldropdbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER);
482
+ sqldropdbType sqldropdb;
483
+ /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
484
+ cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
485
+ sqldropdb = (sqldropdbType) DLSYM( cliLib, "SQLDropDbW" );
486
+ #else
487
+ void *cliLib = NULL;
488
+ typedef int (*sqldropdbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER);
489
+ sqldropdbType sqldropdb;
490
+ cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
491
+ sqldropdb = (sqldropdbType) DLSYM( cliLib, "SQLDropDbW" );
492
+ #endif
493
+ #endif
494
+
495
+ rc = (*sqldropdb)( (SQLHSTMT) data->conn_res->hdbc, data->dbName, (SQLINTEGER)data->dbName_string_len );
496
+
497
+ DLCLOSE( cliLib );
498
+ return rc;
499
+ }
500
+
501
+ /*
502
+ This function calls SQLPrepare cli call to prepare the given statement
503
+ */
504
+ int _ruby_ibm_db_SQLPrepare_helper(exec_cum_prepare_args *data) {
505
+ int rc = 0;
506
+
507
+ data->stmt_res->is_executing = 1;
508
+
509
+ #ifndef UNICODE_SUPPORT_VERSION
510
+ rc = SQLPrepare( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
511
+ #else
512
+ rc = SQLPrepareW( (SQLHSTMT) data->stmt_res->hstmt, data->stmt_string, (SQLINTEGER)data->stmt_string_len );
513
+ #endif
514
+
515
+ data->stmt_res->is_executing = 0;
516
+
517
+ return rc;
518
+ }
519
+
520
+ /*
521
+ This function calls SQLFreeStmt to end processing on the statement referenced by statement handle
522
+ */
523
+ int _ruby_ibm_db_SQLFreeStmt_helper(free_stmt_args *data) {
524
+ int rc = 0;
525
+
526
+ data->stmt_res->is_executing = 1;
527
+
528
+ rc = SQLFreeStmt((SQLHSTMT)data->stmt_res->hstmt, data->option );
529
+
530
+ data->stmt_res->is_executing = 0;
531
+ data->rc = rc;
532
+ return rc;
533
+ }
534
+
535
+ /*
536
+ This function calls SQLExecute cli call to execute the prepared
537
+ */
538
+ int _ruby_ibm_db_SQLExecute_helper(stmt_handle *stmt_res) {
539
+ int rc = 0;
540
+
541
+ stmt_res->is_executing = 1;
542
+
543
+ rc = SQLExecute( (SQLHSTMT) stmt_res->hstmt );
544
+
545
+ stmt_res->is_executing = 0;
546
+
547
+ return rc;
548
+ }
549
+
550
+ /*
551
+ This function calls SQLParamData cli call to read if there is still data to be sent
552
+ */
553
+ int _ruby_ibm_db_SQLParamData_helper(param_cum_put_data_args *data) {
554
+ int rc = 0;
555
+
556
+ data->stmt_res->is_executing = 1;
557
+
558
+ rc = SQLParamData( (SQLHSTMT) data->stmt_res->hstmt, (SQLPOINTER *) &(data->valuePtr) );
559
+
560
+ data->stmt_res->is_executing = 0;
561
+
562
+ return rc;
563
+ }
564
+
565
+ /*
566
+ This function calls SQLColAttributes cli call to get the specified attribute of the column in result set
567
+ */
568
+ int _ruby_ibm_db_SQLColAttributes_helper(col_attr_args *data) {
569
+ int rc = 0;
570
+
571
+ data->stmt_res->is_executing = 1;
572
+
573
+ rc = SQLColAttributes( (SQLHSTMT) data->stmt_res->hstmt, data->col_num,
574
+ data->FieldIdentifier, NULL, 0, NULL, &(data->num_attr) );
575
+
576
+ data->stmt_res->is_executing = 0;
577
+ data->rc = rc;
578
+ return rc;
579
+ }
580
+
581
+ /*
582
+ This function calls SQLPutData cli call to supply parameter data value
583
+ */
584
+ int _ruby_ibm_db_SQLPutData_helper(param_cum_put_data_args *data) {
585
+ int rc = 0;
586
+
587
+ data->stmt_res->is_executing = 1;
588
+
589
+ rc = SQLPutData( (SQLHSTMT) data->stmt_res->hstmt, (SQLPOINTER)(((param_node*)(data->valuePtr))->svalue),
590
+ ((param_node*)(data->valuePtr))->ivalue );
591
+
592
+ data->stmt_res->is_executing = 0;
593
+
594
+ return rc;
595
+ }
596
+
597
+ /*
598
+ This function calls SQLGetData cli call to retrieve data for a single column
599
+ */
600
+ int _ruby_ibm_db_SQLGetData_helper(get_data_args *data) {
601
+ int rc = 0;
602
+
603
+ data->stmt_res->is_executing = 1;
604
+
605
+ rc = SQLGetData( (SQLHSTMT) data->stmt_res->hstmt, data->col_num, data->targetType, data->buff,
606
+ data->buff_length, data->out_length);
607
+
608
+ data->stmt_res->is_executing = 0;
609
+
610
+ return rc;
611
+ }
612
+
613
+ /*
614
+ This function calls SQLGetLength cli call to retrieve the length of the lob value
615
+ */
616
+ int _ruby_ibm_db_SQLGetLength_helper(get_length_args *data) {
617
+ int col_num = data->col_num;
618
+ int rc = 0;
619
+
620
+ data->stmt_res->is_executing = 1;
621
+
622
+ rc = SQLGetLength( (SQLHSTMT) *( data->new_hstmt ), data->stmt_res->column_info[col_num-1].loc_type,
623
+ data->stmt_res->column_info[col_num-1].lob_loc, data->sLength,
624
+ &(data->stmt_res->column_info[col_num-1].loc_ind) );
625
+
626
+ data->stmt_res->is_executing = 0;
627
+
628
+ return rc;
629
+ }
630
+
631
+ /*
632
+ This function calls SQLGetSubString cli call to retrieve portion of the lob value
633
+ */
634
+ int _ruby_ibm_db_SQLGetSubString_helper(get_subString_args *data) {
635
+ int col_num = data->col_num;
636
+ int rc = 0;
637
+
638
+ data->stmt_res->is_executing = 1;
639
+
640
+ rc = SQLGetSubString( (SQLHSTMT) *( data->new_hstmt ), data->stmt_res->column_info[col_num-1].loc_type,
641
+ data->stmt_res->column_info[col_num-1].lob_loc, 1, data->forLength, data->targetCType,
642
+ data->buffer, data->buff_length, data->out_length,
643
+ &(data->stmt_res->column_info[col_num-1].loc_ind) );
644
+
645
+ data->stmt_res->is_executing = 0;
646
+
647
+ return rc;
648
+ }
649
+
650
+ /*
651
+ This function calls SQLNextResult cli call to fetch the multiple result sets that might be returned by a stored Proc
652
+ */
653
+ int _ruby_ibm_db_SQLNextResult_helper(next_result_args *data) {
654
+ int rc = 0;
655
+
656
+ data->stmt_res->is_executing = 1;
657
+
658
+ rc = SQLNextResult( (SQLHSTMT) data->stmt_res->hstmt, (SQLHSTMT) *(data->new_hstmt) );
659
+
660
+ data->stmt_res->is_executing = 0;
661
+ data->rc = rc;
662
+ return rc;
663
+ }
664
+
665
+ /*
666
+ This function calls SQLFetchScroll cli call to fetch the specified rowset of data from result
667
+ */
668
+ int _ruby_ibm_db_SQLFetchScroll_helper(fetch_data_args *data) {
669
+ int rc = 0;
670
+
671
+ data->stmt_res->is_executing = 1;
672
+
673
+ rc = SQLFetchScroll( (SQLHSTMT) data->stmt_res->hstmt, data->fetchOrientation, data->fetchOffset);
674
+
675
+ data->stmt_res->is_executing = 0;
676
+
677
+ return rc;
678
+ }
679
+
680
+ /*
681
+ This function calls SQLFetch cli call to advance the cursor to
682
+ the next row of the result set, and retrieves any bound columns
683
+ */
684
+ int _ruby_ibm_db_SQLFetch_helper(fetch_data_args *data) {
685
+ int rc = 0;
686
+
687
+ data->stmt_res->is_executing = 1;
688
+
689
+ rc = SQLFetch( (SQLHSTMT) data->stmt_res->hstmt );
690
+
691
+ data->stmt_res->is_executing = 0;
692
+
693
+ return rc;
694
+ }
695
+
696
+ /*
697
+ This function calls SQLNumResultCols cli call to fetch the number of fields contained in a result set
698
+ */
699
+ int _ruby_ibm_db_SQLNumResultCols_helper(row_col_count_args *data) {
700
+ int rc = 0;
701
+
702
+ data->stmt_res->is_executing = 1;
703
+
704
+ rc = SQLNumResultCols( (SQLHSTMT) data->stmt_res->hstmt, (SQLSMALLINT*) &(data->count) );
705
+
706
+ data->stmt_res->is_executing = 0;
707
+ data->rc = rc;
708
+ return rc;
709
+ }
710
+
711
+ /*
712
+ This function calls SQLNumParams cli call to fetch the number of parameter markers in an SQL statement
713
+ */
714
+ int _ruby_ibm_db_SQLNumParams_helper(row_col_count_args *data) {
715
+ int rc = 0;
716
+
717
+ data->stmt_res->is_executing = 1;
718
+
719
+ rc = SQLNumParams( (SQLHSTMT) data->stmt_res->hstmt, (SQLSMALLINT*) &(data->count) );
720
+
721
+ data->stmt_res->is_executing = 0;
722
+
723
+ return rc;
724
+ }
725
+
726
+ /*
727
+ This function calls SQLRowCount cli call to fetch the number of rows affected by the SQL statement
728
+ */
729
+ int _ruby_ibm_db_SQLRowCount_helper(sql_row_count_args *data) {
730
+ int rc = 0;
731
+
732
+ data->stmt_res->is_executing = 1;
733
+
734
+ rc = SQLRowCount( (SQLHSTMT) data->stmt_res->hstmt, (SQLLEN*) &(data->count) );
735
+
736
+ data->stmt_res->is_executing = 0;
737
+
738
+ return rc;
739
+ }
740
+
741
+ /*
742
+ This function calls SQLGetInfo cli call to get general information about DBMS, which the app is connected to
743
+ */
744
+ int _ruby_ibm_db_SQLGetInfo_helper(get_info_args *data) {
745
+ #ifndef UNICODE_SUPPORT_VERSION
746
+ return SQLGetInfo( data->conn_res->hdbc, data->infoType, data->infoValue, data->buff_length, data->out_length);
747
+ #else
748
+ return SQLGetInfoW( data->conn_res->hdbc, data->infoType, data->infoValue, data->buff_length, data->out_length);
749
+ #endif
750
+ }
751
+
752
+ /*
753
+ This function calls SQLGetDiagRec cli call to get the current values of a diagnostic record that contains error
754
+ */
755
+ int _ruby_ibm_db_SQLGetDiagRec_helper(get_diagRec_args *data) {
756
+ #ifdef UNICODE_SUPPORT_VERSION
757
+ int rc= SQLGetDiagRecW( data->hType, data->handle, data->recNum, data->SQLState, data->NativeErrorPtr,
758
+ data->msgText, data->buff_length, data->text_length_ptr );
759
+ data->return_code=rc;
760
+ return rc;
761
+ #else
762
+ return SQLGetDiagRec(data->hType, data->handle, data->recNum, data->SQLState, data->NativeErrorPtr,
763
+ data->msgText, data->buff_length, data->text_length_ptr );
764
+ #endif
765
+ }
766
+
767
+ /*
768
+ This function calls SQLSetStmtAttr cli call to set attributes related to a statement
769
+ */
770
+ int _ruby_ibm_db_SQLSetStmtAttr_helper(set_handle_attr_args *data) {
771
+ #ifndef UNICODE_SUPPORT_VERSION
772
+ return SQLSetStmtAttr( (SQLHSTMT) *(data->handle), data->attribute, data->valuePtr, data->strLength );
773
+ #else
774
+ return SQLSetStmtAttrW( (SQLHSTMT) *(data->handle), data->attribute, data->valuePtr, data->strLength );
775
+ #endif
776
+ }
777
+
778
+ /*
779
+ This function calls SQLSetConnectAttr cli call to set attributes that govern aspects of connections
780
+ */
781
+ int _ruby_ibm_db_SQLSetConnectAttr_helper(set_handle_attr_args *data) {
782
+ #ifndef UNICODE_SUPPORT_VERSION
783
+ return SQLSetConnectAttr( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr, data->strLength );
784
+ #else
785
+ return SQLSetConnectAttrW( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr, data->strLength );
786
+ #endif
787
+ }
788
+
789
+ /*
790
+ This function calls SQLSetEnvAttr cli call to set an environment attribute
791
+ */
792
+ int _ruby_ibm_db_SQLSetEnvAttr_helper(set_handle_attr_args *data) {
793
+ return SQLSetEnvAttr( (SQLHENV) *(data->handle), data->attribute, data->valuePtr, data->strLength);
794
+ }
795
+
796
+ /*
797
+ This function calls SQLGetStmtAttr cli call to set an environment attribute
798
+
799
+ 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
800
+ 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.
801
+
802
+ */
803
+ int _ruby_ibm_db_SQLGetStmtAttr_helper(get_handle_attr_args *data) {
804
+ return SQLGetStmtAttr( (SQLHSTMT) *(data->handle), data->attribute, data->valuePtr,
805
+ data->buff_length, data->out_length);
806
+ }
807
+
808
+ /*
809
+ This function calls SQLGetConnectAttr cli call to set an environment attribute
810
+ */
811
+ int _ruby_ibm_db_SQLGetConnectAttr_helper(get_handle_attr_args *data) {
812
+ #ifndef UNICODE_SUPPORT_VERSION
813
+ return SQLGetConnectAttr( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr,
814
+ data->buff_length, data->out_length);
815
+ #else
816
+ return SQLGetConnectAttrW( (SQLHDBC) *(data->handle), data->attribute, data->valuePtr,
817
+ data->buff_length, data->out_length);
818
+ #endif
819
+ }
820
+
821
+ /*
822
+ This function calls SQLBindFileToParam cli call
823
+ */
824
+ int _ruby_ibm_db_SQLBindFileToParam_helper(stmt_handle *stmt_res, param_node *curr) {
825
+ int rc = 0;
826
+
827
+ stmt_res->is_executing = 1;
828
+
829
+ rc = SQLBindFileToParam( (SQLHSTMT)stmt_res->hstmt, curr->param_num,
830
+ curr->data_type, (SQLCHAR*)curr->svalue,
831
+ (SQLSMALLINT*)&(curr->ivalue), &(curr->file_options),
832
+ curr->ivalue, &(curr->bind_indicator) );
833
+
834
+ stmt_res->is_executing = 0;
835
+
836
+ return rc;
837
+ }
838
+
839
+ /*
840
+ This function calls SQLBindParameter cli call
841
+ */
842
+ int _ruby_ibm_db_SQLBindParameter_helper(bind_parameter_args *data) {
843
+ int rc = 0;
844
+
845
+ data->stmt_res->is_executing = 1;
846
+
847
+ rc = SQLBindParameter( (SQLHSTMT) data->stmt_res->hstmt, data->param_num, data->IOType, data->valueType,
848
+ data->paramType, data->colSize, data->decimalDigits, data->paramValPtr, data->buff_length,
849
+ data->out_length );
850
+
851
+ data->stmt_res->is_executing = 0;
852
+
853
+ return rc;
854
+ }
855
+
856
+ /*
857
+ Statement level thread unblock function. This fuction cancels a statement level SQL call issued when requested for,
858
+ allowing for a safe interrupt of the thread.
859
+ */
860
+ void _ruby_ibm_db_Statement_level_UBF(stmt_handle *stmt_res) {
861
+ int rc = 0;
862
+ if( stmt_res->is_executing == 1 ) {
863
+ rc = SQLCancel( (SQLHSTMT) stmt_res->hstmt );
864
+ }
865
+ return;
866
+ }