ibm_db 1.5.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,9 @@
1
1
  Change Log
2
2
  ==============
3
+ 2010/01/21 (IBM_DB adapter 2.0.0, driver 2.0.0) :
4
+ - Support for usage of parameterized SQL queries
5
+ - Exposed constant VERSION in the driver [Feature Request: #27231]
6
+
3
7
  2009/08/21 (IBM_DB adapter 1.5.0, driver 1.5.0) :
4
8
  - non-block enhancement in the ruby driver made for Ruby version 1.9. [support request #25023]
5
9
  - New API's getErrormsg and getErrorstate for retrieving error messages/state added
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2006, 2007, 2008, 2009 IBM Corporation
1
+ Copyright (c) 2006, 2007, 2008, 2009, 2010 IBM Corporation
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the "Software"),
@@ -0,0 +1,39 @@
1
+ +-------------------------------------------+-------------------------------------------+
2
+ | README for Parameterized Queries Support in Ruby-on-Rails/ Activerecord applications |
3
+ +-------------------------------------------+-------------------------------------------+
4
+
5
+ Enabling Usage of Parameterized Queries with Ruby-on-Rails / Activerecord applications
6
+ ======================================================================================
7
+ To enable usage of parameterized SQL queries with Ruby-on-Rails/ActiveRecord applications, in your connection configuration (database.yml), set "parameterized" to true. By default "parameterized" is false (if not specified). A sample database.yml file showing development section with parameterized queries enabled looks as below
8
+
9
+ development:
10
+ adapter: ibm_db
11
+ username: db2inst1
12
+ password: secret
13
+ database: devdb
14
+ #schema: db2inst1
15
+ #host: localhost
16
+ #port: 50000
17
+ #account: my_account
18
+ #app_user: my_app_user
19
+ #application: my_application
20
+ #workstation: my_workstation
21
+ parameterized: true
22
+
23
+ Similarly for the other sections (test/production) of the database.yml file set "parameterized" to true to enable usage of parameterized SQL queries
24
+
25
+ Supported Activerecord Versions
26
+ ===============================
27
+ Activerecord-2.3.3, Activerecord-2.3.4, Activerecord-2.3.5
28
+
29
+ Supported Operating Systems and Databases
30
+ =========================================
31
+ Refer the main README
32
+
33
+ Feedback
34
+ ========
35
+ Your feedback is very much appreciated and expected through Rubyforge:
36
+ - rubyibm project: http://rubyforge.org/projects/rubyibm/
37
+ - rubyibm forum: http://rubyforge.org/forum/?group_id=2361
38
+ - rubyibm bug reports: http://rubyforge.org/tracker/?group_id=2361
39
+ - IBM_DB developers: rubyibm-developers@rubyforge.org
data/README CHANGED
@@ -1,5 +1,5 @@
1
1
  =====================================================================
2
- README for the IBM_DB Adapter (1.5.0) and Driver (1.5.0) (2009/08/21)
2
+ README for the IBM_DB Adapter (2.0.0) and Driver (2.0.0) (2010/01/21)
3
3
  For ActiveRecord Version >= 1.15.5 (and Rails >= 1.2.5)
4
4
  =====================================================================
5
5
 
data/ext/ibm_db.c CHANGED
@@ -2,7 +2,7 @@
2
2
  +----------------------------------------------------------------------+
3
3
  | Licensed Materials - Property of IBM |
4
4
  | |
5
- | (C) Copyright IBM Corporation 2006, 2007,2008, 2009 |
5
+ | (C) Copyright IBM Corporation 2006, 2007,2008, 2009, 2010 |
6
6
  +----------------------------------------------------------------------+
7
7
  | Authors: Sushant Koduru, Lynh Nguyen, Kanchana Padmanabhan, |
8
8
  | Dan Scott, Helmut Tessarek, Sam Ruby, Kellen Bombardier, |
@@ -12,7 +12,7 @@
12
12
  +----------------------------------------------------------------------+
13
13
  */
14
14
 
15
- #define MODULE_RELEASE "1.5.0"
15
+ #define MODULE_RELEASE "2.0.0"
16
16
 
17
17
  #ifdef HAVE_CONFIG_H
18
18
  #include "config.h"
@@ -31,7 +31,7 @@ static struct _ibm_db_globals *ibm_db_globals;
31
31
  static void _ruby_ibm_db_check_sql_errors( void *conn_or_stmt, int resourceType, SQLHANDLE handle, SQLSMALLINT hType,
32
32
  int rc, int cpy_to_global, char* ret_str, int API, SQLSMALLINT recno,
33
33
  int release_gil );
34
- static VALUE _ruby_ibm_db_assign_options( void* handle, int type, long opt_key, VALUE data, char *error );
34
+ static VALUE _ruby_ibm_db_assign_options( void* handle, int type, long opt_key, VALUE data, VALUE *error );
35
35
  static void _ruby_ibm_db_clear_conn_err_cache();
36
36
  static void _ruby_ibm_db_clear_stmt_err_cache();
37
37
  static int _ruby_ibm_db_set_decfloat_rounding_mode_client(SQLHANDLE hdbc);
@@ -44,7 +44,7 @@ typedef struct _stmt_bind_data_array {
44
44
  stmt_handle *stmt_res;
45
45
  SQLSMALLINT num;
46
46
  int bind_params;
47
- char *error;
47
+ VALUE *error;
48
48
  }stmt_bind_array;
49
49
 
50
50
  /*
@@ -55,7 +55,8 @@ typedef struct _ibm_db_connect_helper_args_struct {
55
55
  connect_args *conn_args;
56
56
  int isPersistent;
57
57
  VALUE *options;
58
- char *error;
58
+ VALUE *error;
59
+ int literal_replacement;
59
60
  } connect_helper_args;
60
61
 
61
62
  /*
@@ -64,7 +65,7 @@ typedef struct _ibm_db_connect_helper_args_struct {
64
65
  typedef struct _ibm_db_result_args_struct {
65
66
  stmt_handle *stmt_res;
66
67
  VALUE column;
67
- char *error;
68
+ VALUE *error;
68
69
  } ibm_db_result_args;
69
70
 
70
71
  /*
@@ -75,7 +76,7 @@ typedef struct _ibm_db_fetch_helper_struct {
75
76
  VALUE row_number;
76
77
  int arg_count;
77
78
  int funcType;
78
- char *error;
79
+ VALUE *error;
79
80
  } ibm_db_fetch_helper_args;
80
81
 
81
82
  void ruby_init_ibm_db();
@@ -241,10 +242,10 @@ static void ruby_ibm_db_init_globals(struct _ibm_db_globals *ibm_db_globals)
241
242
  /* env handle */
242
243
  ibm_db_globals->bin_mode = 1;
243
244
 
244
- memset(ibm_db_globals->__ruby_conn_err_msg, 0, DB2_MAX_ERR_MSG_LEN);
245
- memset(ibm_db_globals->__ruby_stmt_err_msg, 0, DB2_MAX_ERR_MSG_LEN);
246
- memset(ibm_db_globals->__ruby_conn_err_state, 0, SQL_SQLSTATE_SIZE + 1);
247
- memset(ibm_db_globals->__ruby_stmt_err_state, 0, SQL_SQLSTATE_SIZE + 1);
245
+ memset(ibm_db_globals->__ruby_conn_err_msg, '\0', DB2_MAX_ERR_MSG_LEN);
246
+ memset(ibm_db_globals->__ruby_stmt_err_msg, '\0', DB2_MAX_ERR_MSG_LEN);
247
+ memset(ibm_db_globals->__ruby_conn_err_state, '\0', SQL_SQLSTATE_SIZE + 1);
248
+ memset(ibm_db_globals->__ruby_stmt_err_state, '\0', SQL_SQLSTATE_SIZE + 1);
248
249
  }
249
250
  /* */
250
251
 
@@ -268,18 +269,20 @@ char *estrndup(char *data, int max) {
268
269
  return dup;
269
270
  }
270
271
 
271
- char *strtolower(char *data, int max) {
272
- while (max--) {
273
- data[max] = tolower(data[max]);
272
+ void strtolower(char *data, int max) {
273
+ if( max > 0 ) {
274
+ while (max--) {
275
+ data[max] = tolower(data[max]);
276
+ }
274
277
  }
275
- return data;
276
278
  }
277
279
 
278
- char *strtoupper(char *data, int max) {
279
- while (max--) {
280
- data[max] = toupper(data[max]);
280
+ void strtoupper(char *data, int max) {
281
+ if( max > 0 ) {
282
+ while (max--) {
283
+ data[max] = toupper(data[max]);
284
+ }
281
285
  }
282
- return data;
283
286
  }
284
287
 
285
288
  /* static void _ruby_ibm_db_mark_conn_struct */
@@ -317,6 +320,7 @@ static void _ruby_ibm_db_free_conn_struct(conn_handle *handle)
317
320
  ruby_xfree( handle );
318
321
  }*/
319
322
  ruby_xfree( handle );
323
+ handle = NULL;
320
324
  }
321
325
  }
322
326
  /* */
@@ -344,7 +348,10 @@ static void _ruby_ibm_db_mark_row_struct(row_hash_struct *handle)
344
348
  /* static void _ruby_ibm_db_free_row_struct */
345
349
  static void _ruby_ibm_db_free_row_struct(row_hash_struct *handle)
346
350
  {
347
- ruby_xfree( handle );
351
+ if ( handle != NULL ) {
352
+ ruby_xfree( handle );
353
+ handle = NULL;
354
+ }
348
355
  }
349
356
  /* */
350
357
 
@@ -360,22 +367,28 @@ static void _ruby_ibm_db_free_result_struct(stmt_handle* handle)
360
367
  curr_ptr = handle->head_cache_list;
361
368
  prev_ptr = handle->head_cache_list;
362
369
 
363
- while (curr_ptr != NULL) {
370
+ while ( curr_ptr != NULL ) {
364
371
  curr_ptr = curr_ptr->next;
365
372
 
366
- if (prev_ptr->varname) {
373
+ if ( prev_ptr->varname != NULL ) {
367
374
  ruby_xfree( prev_ptr->varname );
375
+ prev_ptr->varname = NULL;
368
376
  }
369
377
 
370
- if ( prev_ptr->svalue ) {
378
+ if ( prev_ptr->svalue != NULL ) {
371
379
  ruby_xfree( prev_ptr->svalue );
380
+ prev_ptr->svalue = NULL;
372
381
  }
373
382
  ruby_xfree( prev_ptr );
374
383
 
375
384
  prev_ptr = curr_ptr;
376
385
  }
386
+ handle->head_cache_list = NULL;
387
+ handle->num_params = 0;
388
+ handle->current_node = NULL;
389
+
377
390
  /* free row data cache */
378
- if (handle->row_data) {
391
+ if ( handle->row_data ) {
379
392
  for (i=0; i<handle->num_columns;i++) {
380
393
  switch (handle->column_info[i].type) {
381
394
  case SQL_CHAR:
@@ -404,7 +417,10 @@ static void _ruby_ibm_db_free_result_struct(stmt_handle* handle)
404
417
  /* free column info cache */
405
418
  if ( handle->column_info ) {
406
419
  for (i=0; i<handle->num_columns; i++) {
407
- ruby_xfree( handle->column_info[i].name );
420
+ if ( handle->column_info[i].name != NULL ) {
421
+ ruby_xfree( handle->column_info[i].name );
422
+ handle->column_info[i].name = NULL;
423
+ }
408
424
  }
409
425
  ruby_xfree( handle->column_info );
410
426
  handle->column_info = NULL;
@@ -421,7 +437,7 @@ static stmt_handle *_ibm_db_new_stmt_struct(conn_handle* conn_res)
421
437
  stmt_handle *stmt_res;
422
438
 
423
439
  stmt_res = ALLOC( stmt_handle );
424
- memset( stmt_res, 0, sizeof(stmt_handle) );
440
+ memset( stmt_res, '\0', sizeof(stmt_handle) );
425
441
 
426
442
  /* Initialize stmt resource so parsing assigns updated options if needed */
427
443
  stmt_res->hdbc = conn_res->hdbc;
@@ -443,7 +459,8 @@ static stmt_handle *_ibm_db_new_stmt_struct(conn_handle* conn_res)
443
459
 
444
460
  stmt_res->row_data = NULL;
445
461
 
446
- stmt_res->is_executing = 0;
462
+ stmt_res->is_executing = 0;
463
+ stmt_res->is_freed = 0;
447
464
 
448
465
  stmt_res->ruby_stmt_err_msg = NULL;
449
466
  stmt_res->ruby_stmt_err_state = NULL;
@@ -456,31 +473,47 @@ static stmt_handle *_ibm_db_new_stmt_struct(conn_handle* conn_res)
456
473
  static void _ruby_ibm_db_mark_stmt_struct(stmt_handle *handle)
457
474
  {
458
475
  }
476
+
459
477
  /* */
460
478
 
461
- /* static _ruby_ibm_db_free_stmt_struct */
462
- static void _ruby_ibm_db_free_stmt_struct(stmt_handle *handle)
479
+ /* static _ruby_ibm_db_free_stmt_handle_and_resources */
480
+ static void _ruby_ibm_db_free_stmt_handle_and_resources(stmt_handle *handle)
463
481
  {
464
482
  int rc;
465
483
  if ( handle != NULL ) {
466
484
 
467
- rc = SQLFreeHandle( SQL_HANDLE_STMT, handle->hstmt );
485
+ if( !handle->is_freed ) {
486
+ rc = SQLFreeHandle( SQL_HANDLE_STMT, handle->hstmt );
468
487
 
469
- _ruby_ibm_db_free_result_struct( handle );
488
+ _ruby_ibm_db_free_result_struct( handle );
470
489
 
471
- if( handle->ruby_stmt_err_msg) {
472
- ruby_xfree( handle->ruby_stmt_err_msg );
473
- handle->ruby_stmt_err_msg = NULL;
474
- }
490
+ if( handle->ruby_stmt_err_msg != NULL ) {
491
+ ruby_xfree( handle->ruby_stmt_err_msg );
492
+ handle->ruby_stmt_err_msg = NULL;
493
+ }
475
494
 
476
- if( handle->ruby_stmt_err_state) {
477
- ruby_xfree( handle->ruby_stmt_err_state );
478
- handle->ruby_stmt_err_state = NULL;
495
+ if( handle->ruby_stmt_err_state != NULL ) {
496
+ ruby_xfree( handle->ruby_stmt_err_state );
497
+ handle->ruby_stmt_err_state = NULL;
498
+ }
499
+ handle->is_freed = 1; /* Indicates that the handle is freed */
479
500
  }
501
+ }
502
+ }
480
503
 
504
+ /* */
505
+
506
+ /* static _ruby_ibm_db_free_stmt_struct */
507
+ static void _ruby_ibm_db_free_stmt_struct(stmt_handle *handle)
508
+ {
509
+ int rc;
510
+ if ( handle != NULL ) {
511
+ _ruby_ibm_db_free_stmt_handle_and_resources( handle );
481
512
  ruby_xfree( handle );
513
+ handle = NULL;
482
514
  }
483
515
  }
516
+
484
517
  /* */
485
518
 
486
519
  /* allow direct access to hash object as object attributes */
@@ -514,7 +547,7 @@ void ruby_init_ibm_db()
514
547
  #endif
515
548
 
516
549
  ibm_db_globals = ALLOC(struct _ibm_db_globals);
517
- memset(ibm_db_globals, 0, sizeof(struct _ibm_db_globals));
550
+ memset(ibm_db_globals, '\0', sizeof(struct _ibm_db_globals));
518
551
 
519
552
  ruby_ibm_db_init_globals(ibm_db_globals);
520
553
 
@@ -592,6 +625,12 @@ void ruby_init_ibm_db()
592
625
  rb_define_const(mDB, "DB_CONN", INT2NUM(DB_CONN));
593
626
  /*Specifies resource Type passed is Statement Handle, for retrieving error message*/
594
627
  rb_define_const(mDB, "DB_STMT", INT2NUM(DB_STMT));
628
+ /*Specifies Quoted Literal replacement connection attribute is to be set*/
629
+ rb_define_const(mDB, "QUOTED_LITERAL_REPLACEMENT_ON", INT2NUM(SET_QUOTED_LITERAL_REPLACEMENT_ON));
630
+ /*Specifies Quoted Literal replacement connection attribute should not be set*/
631
+ rb_define_const(mDB, "QUOTED_LITERAL_REPLACEMENT_OFF", INT2NUM(SET_QUOTED_LITERAL_REPLACEMENT_OFF));
632
+ /*Specfies the version of the driver*/
633
+ rb_define_const(mDB, "VERSION",rb_str_new2(MODULE_RELEASE));
595
634
 
596
635
  rb_global_variable(&persistent_list);
597
636
 
@@ -699,7 +738,7 @@ static void _ruby_ibm_db_check_sql_errors( void *conn_or_stmt, int resourceType,
699
738
  memset(msg, '\0', SQL_MAX_MESSAGE_LENGTH + 1);
700
739
  memset(sqlstate, '\0', SQL_SQLSTATE_SIZE + 1);
701
740
 
702
- get_DiagRec_args = ALLOC_N(get_diagRec_args, sizeof(struct _ibm_db_get_diagRec_struct));
741
+ get_DiagRec_args = ALLOC(get_diagRec_args);
703
742
  memset(get_DiagRec_args,'\0',sizeof(struct _ibm_db_get_diagRec_struct));
704
743
 
705
744
  get_DiagRec_args->hType = hType;
@@ -762,14 +801,14 @@ static void _ruby_ibm_db_check_sql_errors( void *conn_or_stmt, int resourceType,
762
801
  }
763
802
 
764
803
  if( conn_res->ruby_error_msg == NULL ) {
765
- conn_res->ruby_error_msg = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN);
804
+ conn_res->ruby_error_msg = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1);
766
805
  }
767
806
 
768
807
  memset( conn_res->ruby_error_state,'\0', SQL_SQLSTATE_SIZE+1 );
769
- memset( conn_res->ruby_error_msg,'\0', DB2_MAX_ERR_MSG_LEN );
808
+ memset( conn_res->ruby_error_msg,'\0', DB2_MAX_ERR_MSG_LEN+1 );
770
809
 
771
810
  strncpy(conn_res->ruby_error_state, (char*)sqlstate, SQL_SQLSTATE_SIZE+1 );
772
- strncpy(conn_res->ruby_error_msg, (char*)errMsg, DB2_MAX_ERR_MSG_LEN );
811
+ strncpy(conn_res->ruby_error_msg, (char*)errMsg, DB2_MAX_ERR_MSG_LEN+1 );
773
812
 
774
813
  break;
775
814
 
@@ -786,14 +825,14 @@ static void _ruby_ibm_db_check_sql_errors( void *conn_or_stmt, int resourceType,
786
825
  }
787
826
 
788
827
  if( conn_res->ruby_error_msg == NULL ) {
789
- conn_res->ruby_error_msg = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN);
828
+ conn_res->ruby_error_msg = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1);
790
829
  }
791
830
 
792
831
  memset( conn_res->ruby_error_state,'\0', SQL_SQLSTATE_SIZE+1 );
793
- memset( conn_res->ruby_error_msg,'\0', DB2_MAX_ERR_MSG_LEN );
832
+ memset( conn_res->ruby_error_msg,'\0', DB2_MAX_ERR_MSG_LEN+1 );
794
833
 
795
834
  strncpy(conn_res->ruby_error_state, (char*)sqlstate, SQL_SQLSTATE_SIZE+1 );
796
- strncpy(conn_res->ruby_error_msg, (char*)errMsg, DB2_MAX_ERR_MSG_LEN );
835
+ strncpy(conn_res->ruby_error_msg, (char*)errMsg, DB2_MAX_ERR_MSG_LEN+1 );
797
836
 
798
837
  break;
799
838
 
@@ -807,14 +846,14 @@ static void _ruby_ibm_db_check_sql_errors( void *conn_or_stmt, int resourceType,
807
846
  }
808
847
 
809
848
  if( stmt_res->ruby_stmt_err_msg == NULL ) {
810
- stmt_res->ruby_stmt_err_msg = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN);
849
+ stmt_res->ruby_stmt_err_msg = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1);
811
850
  }
812
851
 
813
852
  memset( stmt_res->ruby_stmt_err_state, '\0', SQL_SQLSTATE_SIZE+1 );
814
- memset( stmt_res->ruby_stmt_err_msg, '\0', DB2_MAX_ERR_MSG_LEN );
853
+ memset( stmt_res->ruby_stmt_err_msg, '\0', DB2_MAX_ERR_MSG_LEN+1 );
815
854
 
816
855
  strncpy(stmt_res->ruby_stmt_err_state, (char*)sqlstate, SQL_SQLSTATE_SIZE+1 );
817
- strncpy(stmt_res->ruby_stmt_err_msg, (char*)errMsg, DB2_MAX_ERR_MSG_LEN );
856
+ strncpy(stmt_res->ruby_stmt_err_msg, (char*)errMsg, DB2_MAX_ERR_MSG_LEN+1 );
818
857
 
819
858
  break;
820
859
 
@@ -825,7 +864,7 @@ static void _ruby_ibm_db_check_sql_errors( void *conn_or_stmt, int resourceType,
825
864
  conn_errormsg and conn_error are removed
826
865
  */
827
866
  strncpy(IBM_DB_G(__ruby_stmt_err_state), (char*)sqlstate, SQL_SQLSTATE_SIZE+1);
828
- strncpy(IBM_DB_G(__ruby_stmt_err_msg), (char*)errMsg, DB2_MAX_ERR_MSG_LEN);
867
+ strncpy(IBM_DB_G(__ruby_stmt_err_msg), (char*)errMsg, DB2_MAX_ERR_MSG_LEN+1);
829
868
 
830
869
  break;
831
870
 
@@ -842,7 +881,7 @@ static void _ruby_ibm_db_check_sql_errors( void *conn_or_stmt, int resourceType,
842
881
  return;
843
882
  case DB_ERRMSG:
844
883
  if ( ret_str != NULL ) {
845
- strncpy(ret_str, (char*)msg, DB2_MAX_ERR_MSG_LEN);
884
+ strncpy(ret_str, (char*)msg, DB2_MAX_ERR_MSG_LEN+1);
846
885
  }
847
886
  return;
848
887
  default:
@@ -859,9 +898,9 @@ static void _ruby_ibm_db_check_sql_errors( void *conn_or_stmt, int resourceType,
859
898
  /* */
860
899
 
861
900
  /*
862
- static void _ruby_ibm_db_assign_options( void *handle, int type, long opt_key, VALUE data, char *error )
901
+ static void _ruby_ibm_db_assign_options( void *handle, int type, long opt_key, VALUE data, VALUE *error )
863
902
  */
864
- static VALUE _ruby_ibm_db_assign_options( void *handle, int type, long opt_key, VALUE data, char *error )
903
+ static VALUE _ruby_ibm_db_assign_options( void *handle, int type, long opt_key, VALUE data, VALUE *error )
865
904
  {
866
905
  int rc = 0;
867
906
  long option_num = 0;
@@ -884,7 +923,7 @@ static VALUE _ruby_ibm_db_assign_options( void *handle, int type, long opt_key,
884
923
  ((stmt_handle*)handle)->s_case_mode = CASE_NATURAL;
885
924
  break;
886
925
  default:
887
- sprintf(error,"ATTR_CASE attribute must be one of CASE_LOWER, CASE_UPPER, or CASE_NATURAL");
926
+ *error = rb_str_new2("ATTR_CASE attribute must be one of CASE_LOWER, CASE_UPPER, or CASE_NATURAL");
888
927
  return Qfalse;
889
928
  }
890
929
  } else if (type == SQL_HANDLE_DBC) {
@@ -899,15 +938,15 @@ static VALUE _ruby_ibm_db_assign_options( void *handle, int type, long opt_key,
899
938
  ((conn_handle*)handle)->c_case_mode = CASE_NATURAL;
900
939
  break;
901
940
  default:
902
- sprintf(error,"ATTR_CASE attribute must be one of CASE_LOWER, CASE_UPPER, or CASE_NATURAL");
941
+ *error = rb_str_new2("ATTR_CASE attribute must be one of CASE_LOWER, CASE_UPPER, or CASE_NATURAL");
903
942
  return Qfalse;
904
943
  }
905
944
  } else {
906
- sprintf(error,"Connection or statement handle must be passed in.");
945
+ *error = rb_str_new2("Connection or statement handle must be passed in");
907
946
  return Qfalse;
908
947
  }
909
948
  } else if (type == SQL_HANDLE_STMT) {
910
- handleAttr_args = ALLOC_N(set_handle_attr_args,sizeof(struct _ibm_db_set_handle_attr_struct));
949
+ handleAttr_args = ALLOC( set_handle_attr_args );
911
950
  memset(handleAttr_args,'\0',sizeof(struct _ibm_db_set_handle_attr_struct));
912
951
 
913
952
  handleAttr_args->handle = &((stmt_handle *)handle)->hstmt;
@@ -927,7 +966,13 @@ static VALUE _ruby_ibm_db_assign_options( void *handle, int type, long opt_key,
927
966
  if ( rc == SQL_ERROR ) {
928
967
  _ruby_ibm_db_check_sql_errors( handle, DB_STMT, (SQLHSTMT)((stmt_handle *)handle)->hstmt,
929
968
  SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 0 );
930
- sprintf(error,"Setting of statement attribute failed: %s", ((stmt_handle *)handle)->ruby_stmt_err_msg);
969
+ ruby_xfree( handleAttr_args );
970
+ handleAttr_args = NULL;
971
+ if( handle != NULL && ((stmt_handle *)handle)->ruby_stmt_err_msg != NULL ) {
972
+ *error = rb_str_cat2(rb_str_new2("Setting of statement attribute failed: "), ((stmt_handle *)handle)->ruby_stmt_err_msg);
973
+ } else {
974
+ *error = rb_str_new2("Setting of statement attribute failed: <error message could not be retrieved>");
975
+ }
931
976
  return Qfalse;
932
977
  }
933
978
  } else {
@@ -950,12 +995,18 @@ static VALUE _ruby_ibm_db_assign_options( void *handle, int type, long opt_key,
950
995
  if ( rc == SQL_ERROR ) {
951
996
  _ruby_ibm_db_check_sql_errors( handle, DB_STMT, (SQLHSTMT)((stmt_handle *)handle)->hstmt,
952
997
  SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 0 );
953
- sprintf(error,"Setting of statement attribute failed: %s", ((stmt_handle *)handle)->ruby_stmt_err_msg);
998
+ ruby_xfree( handleAttr_args );
999
+ handleAttr_args = NULL;
1000
+ if( handle != NULL && ((stmt_handle *)handle)->ruby_stmt_err_msg != NULL ) {
1001
+ *error = rb_str_cat2(rb_str_new2("Setting of statement attribute failed: "), ((stmt_handle *)handle)->ruby_stmt_err_msg);
1002
+ } else {
1003
+ *error = rb_str_new2("Setting of statement attribute failed: <error message could not be retrieved>");
1004
+ }
954
1005
  return Qfalse;
955
1006
  }
956
1007
  }
957
1008
  } else if (type == SQL_HANDLE_DBC) {
958
- handleAttr_args = ALLOC_N(set_handle_attr_args,sizeof(struct _ibm_db_set_handle_attr_struct));
1009
+ handleAttr_args = ALLOC( set_handle_attr_args );
959
1010
  memset(handleAttr_args,'\0',sizeof(struct _ibm_db_set_handle_attr_struct));
960
1011
 
961
1012
  handleAttr_args->handle = &((conn_handle*)handle)->hdbc;
@@ -975,7 +1026,13 @@ static VALUE _ruby_ibm_db_assign_options( void *handle, int type, long opt_key,
975
1026
  if ( rc == SQL_ERROR ) {
976
1027
  _ruby_ibm_db_check_sql_errors( handle, DB_CONN, (SQLHDBC)((conn_handle *)handle)->hdbc,
977
1028
  SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
978
- sprintf(error,"Setting of connection attribute failed: %s", ((conn_handle *)handle)->ruby_error_msg);
1029
+ ruby_xfree( handleAttr_args );
1030
+ handleAttr_args = NULL;
1031
+ if( handle != NULL && ((conn_handle *)handle)->ruby_error_msg != NULL ) {
1032
+ *error = rb_str_cat2(rb_str_new2("Setting of connection attribute failed: "), ((conn_handle *)handle)->ruby_error_msg);
1033
+ } else {
1034
+ *error = rb_str_new2("Setting of connection attribute failed: <error message could not be retrieved>");
1035
+ }
979
1036
  return Qfalse;
980
1037
  }
981
1038
  } else {
@@ -996,12 +1053,18 @@ static VALUE _ruby_ibm_db_assign_options( void *handle, int type, long opt_key,
996
1053
  if ( rc == SQL_ERROR ) {
997
1054
  _ruby_ibm_db_check_sql_errors( handle, DB_CONN, (SQLHDBC)((conn_handle *)handle)->hdbc,
998
1055
  SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0);
999
- sprintf(error,"Setting of connection attribute failed: %s", ((conn_handle *)handle)->ruby_error_msg);
1056
+ ruby_xfree( handleAttr_args );
1057
+ handleAttr_args = NULL;
1058
+ if( handle != NULL && ((conn_handle *)handle)->ruby_error_msg != NULL ) {
1059
+ *error = rb_str_cat2(rb_str_new2("Setting of connection attribute failed: "), ((conn_handle *)handle)->ruby_error_msg);
1060
+ } else {
1061
+ *error = rb_str_new2("Setting of connection attribute failed: <error message could not be retrieved>");
1062
+ }
1000
1063
  return Qfalse;
1001
1064
  }
1002
1065
  }
1003
1066
  } else {
1004
- sprintf(error,"Connection or statement handle must be passed in.");
1067
+ *error = rb_str_new2("Connection or statement handle must be passed in");
1005
1068
  return Qfalse;
1006
1069
  }
1007
1070
 
@@ -1015,9 +1078,9 @@ static VALUE _ruby_ibm_db_assign_options( void *handle, int type, long opt_key,
1015
1078
  }
1016
1079
  /* */
1017
1080
 
1018
- /* static int _ruby_ibm_db_parse_options( VALUE options, int type, void *handle)
1081
+ /* static int _ruby_ibm_db_parse_options( VALUE options, int type, void *handle, VALUE *error)
1019
1082
  */
1020
- static int _ruby_ibm_db_parse_options ( VALUE options, int type, void *handle, char *error )
1083
+ static int _ruby_ibm_db_parse_options ( VALUE options, int type, void *handle, VALUE *error )
1021
1084
  {
1022
1085
  int numOpts = 0, i = 0;
1023
1086
  VALUE keys;
@@ -1061,12 +1124,12 @@ static int _ruby_ibm_db_parse_options ( VALUE options, int type, void *handle, c
1061
1124
  static int _ruby_ibm_db_get_result_set_info(stmt_handle *stmt_res)
1062
1125
  {
1063
1126
  int rc = -1, i;
1064
- SQLCHAR *tmp_name;
1127
+ SQLCHAR tmp_name[BUFSIZ];
1065
1128
 
1066
1129
  row_col_count_args *result_cols_args = NULL;
1067
1130
  describecol_args *describecolargs = NULL;
1068
1131
 
1069
- result_cols_args = ALLOC_N(row_col_count_args,sizeof(struct _ibm_db_row_col_count_struct));
1132
+ result_cols_args = ALLOC( row_col_count_args );
1070
1133
  memset(result_cols_args,'\0',sizeof(struct _ibm_db_row_col_count_struct));
1071
1134
 
1072
1135
  result_cols_args->stmt_res = stmt_res;
@@ -1077,6 +1140,7 @@ static int _ruby_ibm_db_get_result_set_info(stmt_handle *stmt_res)
1077
1140
  if ( rc == SQL_ERROR || result_cols_args->count == 0) {
1078
1141
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, (SQLHSTMT)stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 0 );
1079
1142
  ruby_xfree( result_cols_args );
1143
+ result_cols_args = NULL;
1080
1144
  return -1;
1081
1145
  }
1082
1146
  stmt_res->num_columns = result_cols_args->count;
@@ -1084,7 +1148,7 @@ static int _ruby_ibm_db_get_result_set_info(stmt_handle *stmt_res)
1084
1148
  stmt_res->column_info = ALLOC_N(ibm_db_result_set_info, result_cols_args->count);
1085
1149
  memset(stmt_res->column_info, 0, sizeof(ibm_db_result_set_info)*(result_cols_args->count));
1086
1150
 
1087
- describecolargs = ALLOC_N(describecol_args,sizeof(struct _ibm_db_describecol_args_struct));
1151
+ describecolargs = ALLOC( describecol_args );
1088
1152
  memset(describecolargs,'\0',sizeof(struct _ibm_db_describecol_args_struct));
1089
1153
 
1090
1154
  describecolargs->stmt_res = stmt_res;
@@ -1095,7 +1159,7 @@ static int _ruby_ibm_db_get_result_set_info(stmt_handle *stmt_res)
1095
1159
  stmt_res->column_info[i].loc_ind = 0;
1096
1160
  stmt_res->column_info[i].loc_type = 0;
1097
1161
 
1098
- stmt_res->column_info[i].name = (SQLCHAR*)ALLOC_N(char, BUFSIZ);
1162
+ stmt_res->column_info[i].name = tmp_name;
1099
1163
  memset(stmt_res->column_info[i].name, '\0', BUFSIZ);
1100
1164
 
1101
1165
  describecolargs->col_no = i + 1;
@@ -1108,14 +1172,16 @@ static int _ruby_ibm_db_get_result_set_info(stmt_handle *stmt_res)
1108
1172
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, (SQLHSTMT)stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 0 );
1109
1173
  ruby_xfree( result_cols_args );
1110
1174
  ruby_xfree( describecolargs );
1175
+ ruby_xfree( stmt_res->column_info );
1176
+ result_cols_args = NULL;
1177
+ describecolargs = NULL;
1178
+ stmt_res->column_info = NULL;
1111
1179
  return -1;
1112
1180
  }
1113
1181
  if ( describecolargs->name_length <= 0 ) {
1114
- ruby_xfree( stmt_res->column_info[i].name );
1115
1182
  stmt_res->column_info[i].name = (SQLCHAR *)estrdup("");
1116
1183
  } else if ( describecolargs->name_length >= BUFSIZ ) {
1117
1184
  /* column name is longer than BUFSIZ, free the previously allocate memory and reallocate new*/
1118
- ruby_xfree( stmt_res->column_info[i].name );
1119
1185
 
1120
1186
  stmt_res->column_info[i].name = (SQLCHAR*)ALLOC_N(char, describecolargs->name_length+1);
1121
1187
  describecolargs->buff_length = describecolargs->name_length + 1;
@@ -1126,12 +1192,14 @@ static int _ruby_ibm_db_get_result_set_info(stmt_handle *stmt_res)
1126
1192
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, (SQLHSTMT)stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 0 );
1127
1193
  ruby_xfree( describecolargs );
1128
1194
  ruby_xfree( result_cols_args );
1195
+ ruby_xfree( stmt_res->column_info );
1196
+ result_cols_args = NULL;
1197
+ describecolargs = NULL;
1198
+ stmt_res->column_info = NULL;
1129
1199
  return -1;
1130
1200
  }
1131
1201
  } else {
1132
- tmp_name = stmt_res->column_info[i].name;
1133
- stmt_res->column_info[i].name = (SQLCHAR*) estrndup( (char *)tmp_name, describecolargs->name_length );
1134
- ruby_xfree( tmp_name );
1202
+ stmt_res->column_info[i].name = (SQLCHAR*) estrdup( (char *)tmp_name );
1135
1203
  }
1136
1204
  }
1137
1205
 
@@ -1161,9 +1229,9 @@ static int _ruby_ibm_db_bind_column_helper(stmt_handle *stmt_res)
1161
1229
  bind_col_args *bindCol_args = NULL;
1162
1230
 
1163
1231
  stmt_res->row_data = ALLOC_N(ibm_db_row_type, stmt_res->num_columns);
1164
- memset(stmt_res->row_data,0,sizeof(ibm_db_row_type)*stmt_res->num_columns);
1232
+ memset(stmt_res->row_data,'\0',sizeof(ibm_db_row_type)*stmt_res->num_columns);
1165
1233
 
1166
- bindCol_args = ALLOC_N(bind_col_args,sizeof(struct _ibm_db_bind_col_struct));
1234
+ bindCol_args = ALLOC( bind_col_args );
1167
1235
  memset(bindCol_args,'\0',sizeof(struct _ibm_db_bind_col_struct));
1168
1236
 
1169
1237
  bindCol_args->stmt_res = stmt_res;
@@ -1381,8 +1449,8 @@ static int _ruby_ibm_db_bind_column_helper(stmt_handle *stmt_res)
1381
1449
  */
1382
1450
  static void _ruby_ibm_db_clear_stmt_err_cache()
1383
1451
  {
1384
- memset(IBM_DB_G(__ruby_stmt_err_msg), 0, DB2_MAX_ERR_MSG_LEN);
1385
- memset(IBM_DB_G(__ruby_stmt_err_state), 0, SQL_SQLSTATE_SIZE + 1);
1452
+ memset(IBM_DB_G(__ruby_stmt_err_msg), '\0', DB2_MAX_ERR_MSG_LEN);
1453
+ memset(IBM_DB_G(__ruby_stmt_err_state), '\0', SQL_SQLSTATE_SIZE + 1);
1386
1454
  }
1387
1455
 
1388
1456
  /* static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data )
@@ -1397,7 +1465,7 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1397
1465
  connect_args *conn_args = data->conn_args;
1398
1466
  VALUE *options = data->options;
1399
1467
  int isPersistent = data->isPersistent;
1400
- char *error = data->error;
1468
+ VALUE *error = data->error;
1401
1469
 
1402
1470
  int rc = 0;
1403
1471
  int reused = 0;
@@ -1412,7 +1480,7 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1412
1480
 
1413
1481
  conn_alive = 1;
1414
1482
 
1415
- handleAttr_args = ALLOC_N(set_handle_attr_args,sizeof(struct _ibm_db_set_handle_attr_struct));
1483
+ handleAttr_args = ALLOC( set_handle_attr_args );
1416
1484
  memset(handleAttr_args,'\0',sizeof(struct _ibm_db_set_handle_attr_struct));
1417
1485
 
1418
1486
  do {
@@ -1427,7 +1495,7 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1427
1495
  Data_Get_Struct(entry, conn_handle, conn_res);
1428
1496
  #ifndef PASE /* i5/OS server mode is persistant */
1429
1497
  /* Need to reinitialize connection? */
1430
- get_handleAttr_args = ALLOC_N(get_handle_attr_args,sizeof(struct _ibm_db_get_handle_attr_struct));
1498
+ get_handleAttr_args = ALLOC( get_handle_attr_args );
1431
1499
  memset(get_handleAttr_args,'\0',sizeof(struct _ibm_db_get_handle_attr_struct));
1432
1500
 
1433
1501
  get_handleAttr_args->handle = &( conn_res->hdbc );
@@ -1439,6 +1507,7 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1439
1507
  rc = _ruby_ibm_db_SQLGetConnectAttr_helper( get_handleAttr_args );
1440
1508
 
1441
1509
  ruby_xfree( get_handleAttr_args );
1510
+ get_handleAttr_args = NULL;
1442
1511
 
1443
1512
  if ( (rc == SQL_SUCCESS) && conn_alive ) {
1444
1513
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
@@ -1453,9 +1522,12 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1453
1522
 
1454
1523
  if ( conn_res == NULL ) {
1455
1524
  conn_res = ALLOC(conn_handle);
1456
- memset(conn_res, 0, sizeof(conn_handle));
1525
+ memset(conn_res, '\0', sizeof(conn_handle));
1457
1526
  }
1458
1527
 
1528
+ /* handle not active as of yet */
1529
+ conn_res->handle_active = 0;
1530
+
1459
1531
  /* We need to set this early, in case we get an error below,
1460
1532
  so we know how to free the connection */
1461
1533
  conn_res->flag_pconnect = isPersistent;
@@ -1469,7 +1541,12 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1469
1541
  if (rc != SQL_SUCCESS) {
1470
1542
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->henv, SQL_HANDLE_ENV, rc, 1, NULL, -1, 1, 0 );
1471
1543
  ruby_xfree( handleAttr_args );
1472
- sprintf(error,"Allocation of environment handle failed:%s", conn_res->ruby_error_msg);
1544
+ handleAttr_args = NULL;
1545
+ if( conn_res != NULL && conn_res->ruby_error_msg != NULL ) {
1546
+ *error = rb_str_cat2(rb_str_new2("Allocation of environment handle failed: "), conn_res->ruby_error_msg);
1547
+ } else {
1548
+ *error = rb_str_new2("Allocation of environment handle failed: <error message could not be retrieved>");
1549
+ }
1473
1550
  return Qnil;
1474
1551
  break;
1475
1552
  }
@@ -1490,8 +1567,14 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1490
1567
 
1491
1568
  if (rc != SQL_SUCCESS) {
1492
1569
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->henv, SQL_HANDLE_ENV, rc, 1, NULL, -1, 1, 0 );
1493
- sprintf(error, "Setting of Environemnt Attribute during connection failed: %s",conn_res->ruby_error_msg);
1570
+ if( conn_res != NULL && conn_res->ruby_error_msg != NULL ) {
1571
+ *error = rb_str_cat2(rb_str_new2("Setting of Environemnt Attribute during connection failed: "),conn_res->ruby_error_msg);
1572
+ } else {
1573
+ *error = rb_str_new2("Setting of Environemnt Attribute during connection failed: <error message could not be retrieved>");
1574
+ }
1494
1575
  ruby_xfree( handleAttr_args );
1576
+ handleAttr_args = NULL;
1577
+ rc = SQLFreeHandle(SQL_HANDLE_ENV, conn_res->henv );
1495
1578
  _ruby_ibm_db_free_conn_struct( conn_res );
1496
1579
  return Qnil;
1497
1580
  break;
@@ -1503,8 +1586,14 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1503
1586
  rc = SQLAllocHandle( SQL_HANDLE_DBC, conn_res->henv, &(conn_res->hdbc) );
1504
1587
  if (rc != SQL_SUCCESS) {
1505
1588
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->henv, SQL_HANDLE_ENV, rc, 1, NULL, -1, 1, 0 );
1506
- sprintf(error, "Allocation of connection handle failed: %s",conn_res->ruby_error_msg);
1589
+ if( conn_res != NULL && conn_res->ruby_error_msg != NULL ) {
1590
+ *error = rb_str_cat2(rb_str_new2("Allocation of connection handle failed: "),conn_res->ruby_error_msg);
1591
+ } else {
1592
+ *error = rb_str_new2("Allocation of connection handle failed: <error message could not be retrieved>");
1593
+ }
1507
1594
  ruby_xfree( handleAttr_args );
1595
+ handleAttr_args = NULL;
1596
+ rc = SQLFreeHandle(SQL_HANDLE_ENV, conn_res->henv );
1508
1597
  _ruby_ibm_db_free_conn_struct( conn_res );
1509
1598
  return Qnil;
1510
1599
  break;
@@ -1554,14 +1643,14 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1554
1643
 
1555
1644
  conn_res->errorType = 1;
1556
1645
 
1557
- /* handle not active as of yet */
1558
- conn_res->handle_active = 0;
1559
-
1560
1646
  /* Set Options */
1561
1647
  if ( !NIL_P(*options) ) {
1562
1648
  rc = _ruby_ibm_db_parse_options( *options, SQL_HANDLE_DBC, conn_res, error );
1563
1649
  if (rc != SQL_SUCCESS) {
1564
1650
  ruby_xfree( handleAttr_args );
1651
+ handleAttr_args = NULL;
1652
+ rc = SQLFreeHandle(SQL_HANDLE_DBC, conn_res->hdbc );
1653
+ rc = SQLFreeHandle(SQL_HANDLE_ENV, conn_res->henv );
1565
1654
  _ruby_ibm_db_free_conn_struct( conn_res );
1566
1655
  return Qnil;
1567
1656
  }
@@ -1582,8 +1671,13 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1582
1671
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
1583
1672
  SQLFreeHandle( SQL_HANDLE_DBC, conn_res->hdbc );
1584
1673
  SQLFreeHandle( SQL_HANDLE_ENV, conn_res->henv );
1585
- sprintf(error, "Connection failed: %s",conn_res->ruby_error_msg);
1674
+ if( conn_res != NULL && conn_res->ruby_error_msg != NULL ) {
1675
+ *error = rb_str_cat2(rb_str_new2("Connection failed: "),conn_res->ruby_error_msg);
1676
+ } else {
1677
+ *error = rb_str_new2("Connection failed: <error message could not be retrieved>");
1678
+ }
1586
1679
  ruby_xfree( handleAttr_args );
1680
+ handleAttr_args = NULL;
1587
1681
  _ruby_ibm_db_free_conn_struct( conn_res );
1588
1682
  return Qnil;
1589
1683
  break;
@@ -1604,7 +1698,7 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1604
1698
  server = ALLOC_N(char, 2048);
1605
1699
  memset(server, 0, sizeof(server));
1606
1700
 
1607
- getInfo_args = ALLOC_N(get_info_args,sizeof(struct _ibm_db_get_info_struct));
1701
+ getInfo_args = ALLOC( get_info_args );
1608
1702
  memset(getInfo_args,'\0',sizeof(struct _ibm_db_get_info_struct));
1609
1703
 
1610
1704
  getInfo_args->conn_res = conn_res;
@@ -1624,6 +1718,10 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1624
1718
 
1625
1719
  ruby_xfree( getInfo_args );
1626
1720
  ruby_xfree( server );
1721
+ getInfo_args = NULL;
1722
+ server = NULL;
1723
+
1724
+ rc = SQL_SUCCESS; /*Setting rc to SQL_SUCCESS, because the below block may or may not be executed*/
1627
1725
 
1628
1726
  /* Set SQL_ATTR_REPLACE_QUOTED_LITERALS connection attribute to
1629
1727
  * enable CLI numeric literal feature. This is equivalent to
@@ -1634,7 +1732,7 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1634
1732
  */
1635
1733
  #ifndef PASE
1636
1734
  /* Only enable this feature if we are not connected to an Informix data server */
1637
- if (!is_informix) {
1735
+ if (!is_informix && data->literal_replacement == SET_QUOTED_LITERAL_REPLACEMENT_ON ) {
1638
1736
  handleAttr_args->handle = &( conn_res->hdbc );
1639
1737
  handleAttr_args->strLength = SQL_IS_INTEGER;
1640
1738
  handleAttr_args->attribute = SQL_ATTR_REPLACE_QUOTED_LITERALS;
@@ -1648,7 +1746,7 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1648
1746
  }
1649
1747
  #else
1650
1748
  /* Only enable this feature if we are not connected to an Informix data server */
1651
- if (!is_informix) {
1749
+ if (!is_informix && data->literal_replacement == SET_QUOTED_LITERAL_REPLACEMENT_ON ) {
1652
1750
  handleAttr_args->handle = &( conn_res->hdbc );
1653
1751
  handleAttr_args->strLength = SQL_IS_INTEGER;
1654
1752
  handleAttr_args->attribute = SQL_ATTR_REPLACE_QUOTED_LITERALS;
@@ -1682,15 +1780,18 @@ static VALUE _ruby_ibm_db_connect_helper2( connect_helper_args *data ) {
1682
1780
  rb_hash_aset(persistent_list, rb_str_new2(hKey), entry);
1683
1781
  }
1684
1782
  ruby_xfree( hKey );
1783
+ hKey = NULL;
1685
1784
  }
1686
1785
 
1687
1786
  if ( rc < SQL_SUCCESS ) {
1688
1787
  if (conn_res != NULL && conn_res->handle_active) {
1689
1788
  rc = SQLFreeHandle( SQL_HANDLE_DBC, conn_res->hdbc);
1789
+ rc = SQLFreeHandle(SQL_HANDLE_ENV, conn_res->henv );
1690
1790
  }
1691
1791
 
1692
1792
  /* free memory */
1693
1793
  if (conn_res != NULL) {
1794
+ conn_res->handle_active = 0;
1694
1795
  _ruby_ibm_db_free_conn_struct(conn_res);
1695
1796
  }
1696
1797
 
@@ -1718,28 +1819,34 @@ static VALUE _ruby_ibm_db_connect_helper( int argc, VALUE *argv, int isPersisten
1718
1819
  connect_helper_args *helper_args = NULL;
1719
1820
 
1720
1821
  VALUE r_db, r_uid, r_passwd, options,return_value;
1822
+ VALUE r_literal_replacement = Qnil;
1721
1823
 
1722
- char error[DB2_MAX_ERR_MSG_LEN + 28];
1824
+ VALUE error = Qnil;
1723
1825
 
1724
- rb_scan_args(argc, argv, "31", &r_db, &r_uid, &r_passwd, &options);
1826
+ rb_scan_args(argc, argv, "32", &r_db, &r_uid, &r_passwd, &options, &r_literal_replacement );
1725
1827
 
1726
- memset( error,'\0',DB2_MAX_ERR_MSG_LEN + 28 );
1727
1828
  /* Allocate the mwmory for necessary components */
1728
1829
 
1729
- conn_args = ALLOC_N(connect_args, sizeof(struct _ibm_db_connect_args_struct));
1830
+ conn_args = ALLOC( connect_args );
1730
1831
  memset(conn_args,'\0',sizeof(struct _ibm_db_connect_args_struct));
1731
1832
 
1732
1833
  conn_args->database = rb_str2cstr(r_db, &(conn_args->database_len));
1733
1834
  conn_args->uid = rb_str2cstr(r_uid, &(conn_args->uid_len));
1734
1835
  conn_args->password = rb_str2cstr(r_passwd, &(conn_args->password_len));
1735
1836
 
1736
- helper_args = ALLOC_N(connect_helper_args, sizeof(struct _ibm_db_connect_helper_args_struct));
1837
+ helper_args = ALLOC( connect_helper_args );
1737
1838
  memset(helper_args,'\0',sizeof(struct _ibm_db_connect_helper_args_struct));
1738
1839
 
1739
- helper_args->conn_args = conn_args;
1740
- helper_args->isPersistent = isPersistent;
1741
- helper_args->options = &options;
1742
- helper_args->error = error;
1840
+ helper_args->conn_args = conn_args;
1841
+ helper_args->isPersistent = isPersistent;
1842
+ helper_args->options = &options;
1843
+ helper_args->error = &error;
1844
+
1845
+ if( !NIL_P(r_literal_replacement) ) {
1846
+ helper_args->literal_replacement = NUM2INT(r_literal_replacement);
1847
+ } else {
1848
+ helper_args->literal_replacement = SET_QUOTED_LITERAL_REPLACEMENT_ON; /*QUOTED LITERAL replacemnt is ON by default*/
1849
+ }
1743
1850
 
1744
1851
  /* Call the function where the actual logic is being run*/
1745
1852
  #ifdef GIL_RELEASE_VERSION
@@ -1751,7 +1858,7 @@ static VALUE _ruby_ibm_db_connect_helper( int argc, VALUE *argv, int isPersisten
1751
1858
 
1752
1859
  /* Free the memory allocated */
1753
1860
  if(conn_args != NULL) {
1754
- /* Memory to structure elements is not allocated explicitly hence it is automatically freed by Ruby
1861
+ /* Memory to structure elements of helper_args is not allocated explicitly hence it is automatically freed by Ruby.
1755
1862
  Dont try to explicitly free it, else a double free exception is thrown and the application will crash
1756
1863
  with memory dump.
1757
1864
  */
@@ -1766,7 +1873,7 @@ static VALUE _ruby_ibm_db_connect_helper( int argc, VALUE *argv, int isPersisten
1766
1873
  }
1767
1874
 
1768
1875
  if( return_value == Qnil ){
1769
- rb_throw( error, Qnil );
1876
+ rb_throw( RSTRING_PTR(error), Qnil );
1770
1877
  }
1771
1878
  return return_value;
1772
1879
  }
@@ -1788,7 +1895,7 @@ static int _ruby_ibm_db_set_decfloat_rounding_mode_client_helper(_rounding_mode
1788
1895
 
1789
1896
  SQLCHAR *stmt = (SQLCHAR *)"values current decfloat rounding mode";
1790
1897
 
1791
- exec_direct_args = ALLOC_N(exec_cum_prepare_args,sizeof(struct _ibm_db_exec_direct_args_struct));
1898
+ exec_direct_args = ALLOC( exec_cum_prepare_args );
1792
1899
  memset(exec_direct_args,'\0',sizeof(struct _ibm_db_exec_direct_args_struct));
1793
1900
 
1794
1901
  exec_direct_args->stmt_string = stmt;
@@ -1799,15 +1906,15 @@ static int _ruby_ibm_db_set_decfloat_rounding_mode_client_helper(_rounding_mode
1799
1906
 
1800
1907
  if ( rc == SQL_ERROR ) {
1801
1908
  if( conn_res->ruby_error_msg == NULL){
1802
- conn_res->ruby_error_msg = ALLOC_N( char, DB2_MAX_ERR_MSG_LEN );
1909
+ conn_res->ruby_error_msg = ALLOC_N( char, DB2_MAX_ERR_MSG_LEN+1 );
1803
1910
  }
1804
- memset(conn_res->ruby_error_msg, '\0', DB2_MAX_ERR_MSG_LEN );
1911
+ memset(conn_res->ruby_error_msg, '\0', DB2_MAX_ERR_MSG_LEN+1 );
1805
1912
 
1806
1913
  _ruby_ibm_db_check_sql_errors( conn_res , DB_CONN, (SQLHSTMT) rnd_mode->stmt_res->hstmt,
1807
1914
  SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 0 );
1808
1915
  } else {
1809
1916
 
1810
- bindCol_args = ALLOC_N(bind_col_args,sizeof(struct _ibm_db_bind_col_struct));
1917
+ bindCol_args = ALLOC( bind_col_args );
1811
1918
  memset(bindCol_args,'\0',sizeof(struct _ibm_db_bind_col_struct));
1812
1919
 
1813
1920
  bindCol_args->stmt_res = rnd_mode->stmt_res;
@@ -1821,16 +1928,16 @@ static int _ruby_ibm_db_set_decfloat_rounding_mode_client_helper(_rounding_mode
1821
1928
 
1822
1929
  if ( rc == SQL_ERROR ) {
1823
1930
  if( conn_res->ruby_error_msg == NULL){
1824
- conn_res->ruby_error_msg = ALLOC_N( char, DB2_MAX_ERR_MSG_LEN );
1931
+ conn_res->ruby_error_msg = ALLOC_N( char, DB2_MAX_ERR_MSG_LEN+1 );
1825
1932
  }
1826
- memset(conn_res->ruby_error_msg, '\0', DB2_MAX_ERR_MSG_LEN );
1933
+ memset(conn_res->ruby_error_msg, '\0', DB2_MAX_ERR_MSG_LEN+1 );
1827
1934
 
1828
1935
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, (SQLHSTMT)rnd_mode->stmt_res->hstmt,
1829
1936
  SQL_HANDLE_STMT, rc, 1, NULL ,-1, 1, 0);
1830
1937
 
1831
1938
  } else {
1832
1939
 
1833
- fetch_args = ALLOC_N(fetch_data_args,sizeof(struct _ibm_db_fetch_data_struct));
1940
+ fetch_args = ALLOC( fetch_data_args );
1834
1941
  memset(fetch_args,'\0',sizeof(struct _ibm_db_fetch_data_struct));
1835
1942
 
1836
1943
  fetch_args->stmt_res = rnd_mode->stmt_res;
@@ -1839,9 +1946,9 @@ static int _ruby_ibm_db_set_decfloat_rounding_mode_client_helper(_rounding_mode
1839
1946
 
1840
1947
  if ( rc == SQL_ERROR ) {
1841
1948
  if( conn_res->ruby_error_msg == NULL){
1842
- conn_res->ruby_error_msg = ALLOC_N( char, DB2_MAX_ERR_MSG_LEN );
1949
+ conn_res->ruby_error_msg = ALLOC_N( char, DB2_MAX_ERR_MSG_LEN+1 );
1843
1950
  }
1844
- memset(conn_res->ruby_error_msg, '\0', DB2_MAX_ERR_MSG_LEN );
1951
+ memset(conn_res->ruby_error_msg, '\0', DB2_MAX_ERR_MSG_LEN+1 );
1845
1952
 
1846
1953
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, (SQLHSTMT) rnd_mode->stmt_res->hstmt,
1847
1954
  SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 0 );
@@ -1892,7 +1999,7 @@ static int _ruby_ibm_db_set_decfloat_rounding_mode_client( set_handle_attr_args
1892
1999
 
1893
2000
  SQLHANDLE hdbc = *(data->handle);
1894
2001
 
1895
- rnd_mode = ALLOC_N(_rounding_mode,sizeof(struct _rounding_mode_struct));
2002
+ rnd_mode = ALLOC( _rounding_mode );
1896
2003
  memset(rnd_mode,'\0',sizeof(struct _rounding_mode_struct));
1897
2004
 
1898
2005
  stmt_res = _ibm_db_new_stmt_struct(conn_res);
@@ -1903,12 +2010,20 @@ static int _ruby_ibm_db_set_decfloat_rounding_mode_client( set_handle_attr_args
1903
2010
  if (rc == SQL_ERROR) {
1904
2011
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, hdbc, SQL_HANDLE_DBC, rc, 1,
1905
2012
  NULL, -1, 1, 0 );
2013
+ ruby_xfree( rnd_mode );
2014
+ ruby_xfree( stmt_res );
2015
+ rnd_mode = NULL;
2016
+ stmt_res = NULL;
1906
2017
  return rc;
1907
2018
  }
1908
2019
 
2020
+ rnd_mode->stmt_res = stmt_res;
2021
+
1909
2022
  _ruby_ibm_db_set_decfloat_rounding_mode_client_helper(rnd_mode, conn_res);
1910
2023
 
1911
2024
  _ruby_ibm_db_free_stmt_struct( rnd_mode->stmt_res );
2025
+ rnd_mode->stmt_res = NULL;
2026
+ stmt_res = NULL;
1912
2027
 
1913
2028
  data->strLength = SQL_NTS;
1914
2029
  data->attribute = SQL_ATTR_DECFLOAT_ROUNDING_MODE;
@@ -1921,6 +2036,9 @@ static int _ruby_ibm_db_set_decfloat_rounding_mode_client( set_handle_attr_args
1921
2036
 
1922
2037
  rc = _ruby_ibm_db_SQLSetConnectAttr_helper( data );
1923
2038
 
2039
+ ruby_xfree( rnd_mode );
2040
+ rnd_mode = NULL;
2041
+
1924
2042
  return rc;
1925
2043
  }
1926
2044
  #endif
@@ -1933,8 +2051,8 @@ static int _ruby_ibm_db_set_decfloat_rounding_mode_client( set_handle_attr_args
1933
2051
  static void _ruby_ibm_db_clear_conn_err_cache()
1934
2052
  {
1935
2053
  /* Clear out the cached conn messages */
1936
- memset(IBM_DB_G(__ruby_conn_err_msg), 0, DB2_MAX_ERR_MSG_LEN);
1937
- memset(IBM_DB_G(__ruby_conn_err_state), 0, SQL_SQLSTATE_SIZE + 1);
2054
+ memset(IBM_DB_G(__ruby_conn_err_msg), '\0', DB2_MAX_ERR_MSG_LEN);
2055
+ memset(IBM_DB_G(__ruby_conn_err_state), '\0', SQL_SQLSTATE_SIZE + 1);
1938
2056
  }
1939
2057
  /* */
1940
2058
 
@@ -1942,7 +2060,7 @@ static void _ruby_ibm_db_clear_conn_err_cache()
1942
2060
  *
1943
2061
  * ===Description
1944
2062
  *
1945
- * resource IBM_DB.connect ( string database, string username, string password [, array options] )
2063
+ * resource IBM_DB.connect ( string database, string username, string password [, array options, int set_replace_quoted_literal] )
1946
2064
  *
1947
2065
  * Creates a new connection to an IBM DB2 Universal Database, IBM Cloudscape, or Apache Derby database.
1948
2066
  * ==Parameters
@@ -1983,6 +2101,12 @@ static void _ruby_ibm_db_clear_conn_err_cache()
1983
2101
  * Passing the SQL_CURSOR_KEYSET_DRIVEN value specifies a scrollable cursor for a statement resource.
1984
2102
  * This mode enables random access to rows in a result set, but currently is supported
1985
2103
  * only by IBM DB2 Universal Database.
2104
+ * ====<em>set_replace_quoted_literal</em>
2105
+ * This variable indicates if the CLI Connection attribute SQL_ATTR_REPLACE_QUOTED_LITERAL is to be set or not
2106
+ * To turn it ON pass IBM_DB::SET_QUOTED_LITERAL_REPLACEMENT_ON
2107
+ * To turn it OFF pass IBM_DB::SET_QUOTED_LITERAL_REPLACEMENT_OFF
2108
+ *
2109
+ * Default Setting: - IBM_DB::SET_QUOTED_LITERAL_REPLACEMENT_ON
1986
2110
  *
1987
2111
  * ==Return Values
1988
2112
  * Returns a connection handle resource if the connection attempt is successful.
@@ -2001,7 +2125,7 @@ VALUE ibm_db_connect(int argc, VALUE *argv, VALUE self)
2001
2125
  * IBM_DB.pconnect -- Returns a persistent connection to a database
2002
2126
  *
2003
2127
  * ===Description
2004
- * resource IBM_DB.pconnect ( string database, string username, string password [, array options] )
2128
+ * resource IBM_DB.pconnect ( string database, string username, string password [, array options, int set_replace_quoted_literal] )
2005
2129
  *
2006
2130
  * Returns a persistent connection to an IBM DB2 Universal Database, IBM Cloudscape,
2007
2131
  * or Apache Derby database.
@@ -2039,6 +2163,12 @@ VALUE ibm_db_connect(int argc, VALUE *argv, VALUE self)
2039
2163
  * Passing the SQL_CURSOR_KEYSET_DRIVEN value specifies a scrollable cursor for a statement resource.
2040
2164
  * This mode enables random access to rows in a result set, but currently is supported only
2041
2165
  * by IBM DB2 Universal Database.
2166
+ * ====<em>set_replace_quoted_literal</em>
2167
+ * This variable indicates if the CLI Connection attribute SQL_ATTR_REPLACE_QUOTED_LITERAL is to be set or not
2168
+ * To turn it ON pass IBM_DB::SET_QUOTED_LITERAL_REPLACEMENT_ON
2169
+ * To turn it OFF pass IBM_DB::SET_QUOTED_LITERAL_REPLACEMENT_OFF
2170
+ *
2171
+ * Default Setting: - IBM_DB::SET_QUOTED_LITERAL_REPLACEMENT_ON
2042
2172
  *
2043
2173
  * ===Return Values
2044
2174
  *
@@ -2112,7 +2242,7 @@ VALUE ibm_db_autocommit(int argc, VALUE *argv, VALUE self)
2112
2242
  if (argc == 2) {
2113
2243
  autocommit = FIX2INT(value);
2114
2244
  if(autocommit != (conn_res->auto_commit)) {
2115
- handleAttr_args = ALLOC_N(set_handle_attr_args,sizeof(struct _ibm_db_set_handle_attr_struct));
2245
+ handleAttr_args = ALLOC( set_handle_attr_args );
2116
2246
  memset(handleAttr_args,'\0',sizeof(struct _ibm_db_set_handle_attr_struct));
2117
2247
 
2118
2248
  handleAttr_args->handle = &( conn_res->hdbc );
@@ -2166,7 +2296,7 @@ static void _ruby_ibm_db_add_param_cache( stmt_handle *stmt_res, int param_no, c
2166
2296
  if ( curr == NULL || curr->param_num != param_no ) {
2167
2297
  /* Allocate memory and make new node to be added */
2168
2298
  tmp_curr = ALLOC(param_node);
2169
- memset(tmp_curr, 0, sizeof(param_node));
2299
+ memset(tmp_curr, '\0', sizeof(param_node));
2170
2300
 
2171
2301
  /* assign values */
2172
2302
  tmp_curr->data_type = data_type;
@@ -2177,6 +2307,8 @@ static void _ruby_ibm_db_add_param_cache( stmt_handle *stmt_res, int param_no, c
2177
2307
  tmp_curr->file_options = SQL_FILE_READ;
2178
2308
  tmp_curr->param_type = param_type;
2179
2309
  tmp_curr->size = size;
2310
+ tmp_curr->varname = NULL;
2311
+ tmp_curr->svalue = NULL;
2180
2312
 
2181
2313
  /* Set this flag in stmt_res if a FILE INPUT is present */
2182
2314
  if ( param_type == PARAM_FILE) {
@@ -2209,6 +2341,16 @@ static void _ruby_ibm_db_add_param_cache( stmt_handle *stmt_res, int param_no, c
2209
2341
  curr->param_type = param_type;
2210
2342
  curr->size = size;
2211
2343
 
2344
+ if( curr->varname != NULL ) {
2345
+ ruby_xfree( curr->varname );
2346
+ }
2347
+ curr->varname = NULL;
2348
+
2349
+ if( curr->svalue != NULL ) {
2350
+ ruby_xfree( curr->svalue );
2351
+ }
2352
+ curr->svalue = NULL;
2353
+
2212
2354
  /* Set this flag in stmt_res if a FILE INPUT is present */
2213
2355
  if ( param_type == PARAM_FILE) {
2214
2356
  stmt_res->file_param = 1;
@@ -2218,7 +2360,6 @@ static void _ruby_ibm_db_add_param_cache( stmt_handle *stmt_res, int param_no, c
2218
2360
  /* Var lengths can be variable and different in both cases. */
2219
2361
  /* This shouldn't happen often anyway */
2220
2362
  if ( varname != NULL) {
2221
- ruby_xfree( curr->varname );
2222
2363
  curr->varname = estrndup(varname, varname_len);
2223
2364
  }
2224
2365
  }
@@ -2233,7 +2374,6 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
2233
2374
  int rc = 0;
2234
2375
  VALUE return_value = Qtrue;
2235
2376
 
2236
- char error[DB2_MAX_ERR_MSG_LEN + 13];
2237
2377
 
2238
2378
  /* Check for Param options */
2239
2379
  switch (argc) {
@@ -2250,8 +2390,7 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
2250
2390
 
2251
2391
  if ( rc == SQL_ERROR ) {
2252
2392
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 1 );
2253
- sprintf(error, "Describe Param Failed: %s", stmt_res->ruby_stmt_err_msg );
2254
- rb_warn( error );
2393
+ rb_warn("Describe Param Failed: %s", stmt_res->ruby_stmt_err_msg );
2255
2394
  return_value = Qfalse;
2256
2395
  break;
2257
2396
  }
@@ -2272,8 +2411,7 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
2272
2411
 
2273
2412
  if ( rc == SQL_ERROR ) {
2274
2413
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 1 );
2275
- sprintf(error, "Describe Param Failed: %s", stmt_res->ruby_stmt_err_msg );
2276
- rb_warn( error );
2414
+ rb_warn("Describe Param Failed: %s", stmt_res->ruby_stmt_err_msg );
2277
2415
  return_value = Qfalse;
2278
2416
  break;
2279
2417
  }
@@ -2294,8 +2432,7 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
2294
2432
 
2295
2433
  if ( rc == SQL_ERROR ) {
2296
2434
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 1 );
2297
- sprintf(error, "Describe Param Failed: %s", stmt_res->ruby_stmt_err_msg );
2298
- rb_warn( error );
2435
+ rb_warn("Describe Param Failed: %s", stmt_res->ruby_stmt_err_msg );
2299
2436
  return_value = Qfalse;
2300
2437
  break;
2301
2438
  }
@@ -2317,8 +2454,7 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
2317
2454
 
2318
2455
  if ( rc == SQL_ERROR ) {
2319
2456
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 1 );
2320
- sprintf(error, "Describe Param Failed: %s", stmt_res->ruby_stmt_err_msg );
2321
- rb_warn( error );
2457
+ rb_warn("Describe Param Failed: %s", stmt_res->ruby_stmt_err_msg );
2322
2458
  return_value = Qfalse;
2323
2459
  break;
2324
2460
  }
@@ -2445,7 +2581,7 @@ VALUE ibm_db_bind_param(int argc, VALUE *argv, VALUE self)
2445
2581
  if (!NIL_P(stmt)) {
2446
2582
  Data_Get_Struct(stmt, stmt_handle, stmt_res);
2447
2583
 
2448
- desc_param_args = ALLOC_N(describeparam_args,sizeof(struct _ibm_db_describeparam_args_struct));
2584
+ desc_param_args = ALLOC( describeparam_args );
2449
2585
  memset(desc_param_args,'\0',sizeof(struct _ibm_db_describeparam_args_struct));
2450
2586
 
2451
2587
  desc_param_args->param_no = NUM2INT(r_param_no);
@@ -2515,7 +2651,7 @@ VALUE ibm_db_close(int argc, VALUE *argv, VALUE self)
2515
2651
  if ( conn_res->handle_active && !conn_res->flag_pconnect ) {
2516
2652
  /* Disconnect from DB. If stmt is allocated, it is freed automatically */
2517
2653
  if (conn_res->auto_commit == 0) {
2518
- end_X_args = ALLOC_N(end_tran_args,sizeof(struct _ibm_db_end_tran_args_struct));
2654
+ end_X_args = ALLOC( end_tran_args );
2519
2655
  memset(end_X_args,'\0',sizeof(struct _ibm_db_end_tran_args_struct));
2520
2656
 
2521
2657
  end_X_args->hdbc = &(conn_res->hdbc);
@@ -2561,6 +2697,8 @@ VALUE ibm_db_close(int argc, VALUE *argv, VALUE self)
2561
2697
 
2562
2698
  connection = Qnil;
2563
2699
 
2700
+ rc = SQLFreeHandle(SQL_HANDLE_ENV, conn_res->henv );
2701
+
2564
2702
  return_value = Qtrue;
2565
2703
  }
2566
2704
  }
@@ -2638,7 +2776,7 @@ VALUE ibm_db_column_privileges(int argc, VALUE *argv, VALUE self)
2638
2776
  rb_scan_args(argc, argv, "14", &connection,
2639
2777
  &r_qualifier, &r_owner, &r_table_name, &r_column_name);
2640
2778
 
2641
- col_privileges_args = ALLOC_N(metadata_args,sizeof(struct _ibm_db_metadata_args_struct));
2779
+ col_privileges_args = ALLOC( metadata_args );
2642
2780
  memset(col_privileges_args,'\0',sizeof(struct _ibm_db_metadata_args_struct));
2643
2781
 
2644
2782
  col_privileges_args->qualifier = NULL;
@@ -2688,6 +2826,7 @@ VALUE ibm_db_column_privileges(int argc, VALUE *argv, VALUE self)
2688
2826
  NULL, -1, 1, 1 );
2689
2827
 
2690
2828
  _ruby_ibm_db_free_stmt_struct( stmt_res );
2829
+ stmt_res = NULL;
2691
2830
 
2692
2831
  return_value = Qfalse;
2693
2832
  } else {
@@ -2778,7 +2917,7 @@ VALUE ibm_db_columns(int argc, VALUE *argv, VALUE self)
2778
2917
  rb_scan_args(argc, argv, "14", &connection,
2779
2918
  &r_qualifier, &r_owner, &r_table_name, &r_column_name);
2780
2919
 
2781
- col_metadata_args = ALLOC_N(metadata_args,sizeof(struct _ibm_db_metadata_args_struct));
2920
+ col_metadata_args = ALLOC( metadata_args );
2782
2921
  memset(col_metadata_args,'\0',sizeof(struct _ibm_db_metadata_args_struct));
2783
2922
 
2784
2923
  col_metadata_args->qualifier = NULL;
@@ -2798,6 +2937,8 @@ VALUE ibm_db_columns(int argc, VALUE *argv, VALUE self)
2798
2937
  rc = SQLAllocHandle(SQL_HANDLE_STMT, conn_res->hdbc, &(stmt_res->hstmt));
2799
2938
  if (rc == SQL_ERROR) {
2800
2939
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 1 );
2940
+ ruby_xfree( stmt_res );
2941
+ stmt_res = NULL;
2801
2942
  return_value = Qfalse;
2802
2943
  } else {
2803
2944
  if (!NIL_P(r_qualifier)) {
@@ -2827,6 +2968,7 @@ VALUE ibm_db_columns(int argc, VALUE *argv, VALUE self)
2827
2968
  NULL, -1, 1, 1 );
2828
2969
 
2829
2970
  _ruby_ibm_db_free_stmt_struct( stmt_res );
2971
+ stmt_res = NULL;
2830
2972
 
2831
2973
  return_value = Qfalse;
2832
2974
  } else {
@@ -2914,7 +3056,7 @@ VALUE ibm_db_foreign_keys(int argc, VALUE *argv, VALUE self)
2914
3056
  rb_scan_args(argc, argv, "4", &connection,
2915
3057
  &r_qualifier, &r_owner, &r_table_name);
2916
3058
 
2917
- col_metadata_args = ALLOC_N(metadata_args,sizeof(struct _ibm_db_metadata_args_struct));
3059
+ col_metadata_args = ALLOC( metadata_args );
2918
3060
  memset(col_metadata_args,'\0',sizeof(struct _ibm_db_metadata_args_struct));
2919
3061
 
2920
3062
  col_metadata_args->qualifier = NULL;
@@ -2934,6 +3076,8 @@ VALUE ibm_db_foreign_keys(int argc, VALUE *argv, VALUE self)
2934
3076
  rc = SQLAllocHandle(SQL_HANDLE_STMT, conn_res->hdbc, &(stmt_res->hstmt));
2935
3077
  if (rc == SQL_ERROR) {
2936
3078
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 1 );
3079
+ ruby_xfree( stmt_res );
3080
+ stmt_res = NULL;
2937
3081
  return_value = Qfalse;
2938
3082
  } else {
2939
3083
  if (!NIL_P(r_qualifier)) {
@@ -2961,6 +3105,7 @@ VALUE ibm_db_foreign_keys(int argc, VALUE *argv, VALUE self)
2961
3105
  NULL, -1, 1, 1 );
2962
3106
 
2963
3107
  _ruby_ibm_db_free_stmt_struct( stmt_res );
3108
+ stmt_res = NULL;
2964
3109
 
2965
3110
  return_value = Qfalse;
2966
3111
  } else {
@@ -3039,7 +3184,7 @@ VALUE ibm_db_primary_keys(int argc, VALUE *argv, VALUE self)
3039
3184
  rb_scan_args(argc, argv, "4", &connection,
3040
3185
  &r_qualifier, &r_owner, &r_table_name);
3041
3186
 
3042
- col_metadata_args = ALLOC_N(metadata_args,sizeof(struct _ibm_db_metadata_args_struct));
3187
+ col_metadata_args = ALLOC( metadata_args );
3043
3188
  memset(col_metadata_args,'\0',sizeof(struct _ibm_db_metadata_args_struct));
3044
3189
 
3045
3190
  col_metadata_args->qualifier = NULL;
@@ -3059,6 +3204,8 @@ VALUE ibm_db_primary_keys(int argc, VALUE *argv, VALUE self)
3059
3204
  rc = SQLAllocHandle(SQL_HANDLE_STMT, conn_res->hdbc, &(stmt_res->hstmt));
3060
3205
  if (rc == SQL_ERROR) {
3061
3206
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 1 );
3207
+ ruby_xfree( stmt_res );
3208
+ stmt_res = NULL;
3062
3209
  return_value = Qfalse;
3063
3210
  } else {
3064
3211
  if (!NIL_P(r_qualifier)) {
@@ -3085,6 +3232,7 @@ VALUE ibm_db_primary_keys(int argc, VALUE *argv, VALUE self)
3085
3232
  NULL, -1, 1, 1 );
3086
3233
 
3087
3234
  _ruby_ibm_db_free_stmt_struct( stmt_res );
3235
+ stmt_res = NULL;
3088
3236
 
3089
3237
  return_value = Qfalse;
3090
3238
  } else {
@@ -3184,7 +3332,7 @@ VALUE ibm_db_procedure_columns(int argc, VALUE *argv, VALUE self)
3184
3332
  rb_scan_args(argc, argv, "5", &connection,
3185
3333
  &r_qualifier, &r_owner, &r_proc_name, &r_column_name);
3186
3334
 
3187
- col_metadata_args = ALLOC_N(metadata_args,sizeof(struct _ibm_db_metadata_args_struct));
3335
+ col_metadata_args = ALLOC( metadata_args );
3188
3336
  memset(col_metadata_args,'\0',sizeof(struct _ibm_db_metadata_args_struct));
3189
3337
 
3190
3338
  col_metadata_args->qualifier = NULL;
@@ -3204,6 +3352,8 @@ VALUE ibm_db_procedure_columns(int argc, VALUE *argv, VALUE self)
3204
3352
  rc = SQLAllocHandle(SQL_HANDLE_STMT, conn_res->hdbc, &(stmt_res->hstmt));
3205
3353
  if (rc == SQL_ERROR) {
3206
3354
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 1 );
3355
+ ruby_xfree( stmt_res );
3356
+ stmt_res = NULL;
3207
3357
  return_value = Qfalse;
3208
3358
  } else {
3209
3359
  if (!NIL_P(r_qualifier)) {
@@ -3233,6 +3383,7 @@ VALUE ibm_db_procedure_columns(int argc, VALUE *argv, VALUE self)
3233
3383
  NULL, -1, 1, 1 );
3234
3384
 
3235
3385
  _ruby_ibm_db_free_stmt_struct( stmt_res );
3386
+ stmt_res = NULL;
3236
3387
 
3237
3388
  return_value = Qfalse;
3238
3389
  } else {
@@ -3311,7 +3462,7 @@ VALUE ibm_db_procedures(int argc, VALUE *argv, VALUE self)
3311
3462
  rb_scan_args(argc, argv, "4", &connection,
3312
3463
  &r_qualifier, &r_owner, &r_proc_name);
3313
3464
 
3314
- proc_metadata_args = ALLOC_N(metadata_args,sizeof(struct _ibm_db_metadata_args_struct));
3465
+ proc_metadata_args = ALLOC( metadata_args );
3315
3466
  memset(proc_metadata_args,'\0',sizeof(struct _ibm_db_metadata_args_struct));
3316
3467
 
3317
3468
  proc_metadata_args->qualifier = NULL;
@@ -3330,6 +3481,8 @@ VALUE ibm_db_procedures(int argc, VALUE *argv, VALUE self)
3330
3481
  rc = SQLAllocHandle(SQL_HANDLE_STMT, conn_res->hdbc, &(stmt_res->hstmt));
3331
3482
  if (rc == SQL_ERROR) {
3332
3483
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 1 );
3484
+ ruby_xfree( stmt_res );
3485
+ stmt_res = NULL;
3333
3486
  return_value = Qfalse;
3334
3487
  } else {
3335
3488
  if (!NIL_P(r_qualifier)) {
@@ -3355,6 +3508,9 @@ VALUE ibm_db_procedures(int argc, VALUE *argv, VALUE self)
3355
3508
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1,
3356
3509
  NULL, -1, 1, 1 );
3357
3510
 
3511
+ _ruby_ibm_db_free_stmt_struct( stmt_res );
3512
+ stmt_res = NULL;
3513
+
3358
3514
  return_value = Qfalse;
3359
3515
  } else {
3360
3516
  return_value = Data_Wrap_Struct(le_stmt_struct,
@@ -3449,7 +3605,7 @@ VALUE ibm_db_special_columns(int argc, VALUE *argv, VALUE self)
3449
3605
  rb_scan_args(argc, argv, "5", &connection, &r_qualifier,
3450
3606
  &r_owner, &r_table_name, &r_scope);
3451
3607
 
3452
- col_metadata_args = ALLOC_N(metadata_args,sizeof(struct _ibm_db_metadata_args_struct));
3608
+ col_metadata_args = ALLOC( metadata_args );
3453
3609
  memset(col_metadata_args,'\0',sizeof(struct _ibm_db_metadata_args_struct));
3454
3610
 
3455
3611
  col_metadata_args->qualifier = NULL;
@@ -3470,6 +3626,8 @@ VALUE ibm_db_special_columns(int argc, VALUE *argv, VALUE self)
3470
3626
  rc = SQLAllocHandle(SQL_HANDLE_STMT, conn_res->hdbc, &(stmt_res->hstmt));
3471
3627
  if (rc == SQL_ERROR) {
3472
3628
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 1 );
3629
+ ruby_xfree( stmt_res );
3630
+ stmt_res = NULL;
3473
3631
  return_value = Qfalse;
3474
3632
  } else {
3475
3633
  if (!NIL_P(r_qualifier)) {
@@ -3499,6 +3657,7 @@ VALUE ibm_db_special_columns(int argc, VALUE *argv, VALUE self)
3499
3657
  NULL, -1, 1, 1 );
3500
3658
 
3501
3659
  _ruby_ibm_db_free_stmt_struct( stmt_res );
3660
+ stmt_res = NULL;
3502
3661
 
3503
3662
  return_value = Qfalse;
3504
3663
  } else {
@@ -3610,7 +3769,7 @@ VALUE ibm_db_statistics(int argc, VALUE *argv, VALUE self)
3610
3769
 
3611
3770
  metadata_args *col_metadata_args = NULL;
3612
3771
 
3613
- col_metadata_args = ALLOC_N(metadata_args,sizeof(struct _ibm_db_metadata_args_struct));
3772
+ col_metadata_args = ALLOC( metadata_args );
3614
3773
  memset(col_metadata_args,'\0',sizeof(struct _ibm_db_metadata_args_struct));
3615
3774
 
3616
3775
  col_metadata_args->qualifier = NULL;
@@ -3633,6 +3792,8 @@ VALUE ibm_db_statistics(int argc, VALUE *argv, VALUE self)
3633
3792
  rc = SQLAllocHandle(SQL_HANDLE_STMT, conn_res->hdbc, &(stmt_res->hstmt));
3634
3793
  if (rc == SQL_ERROR) {
3635
3794
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 1 );
3795
+ ruby_xfree( stmt_res );
3796
+ stmt_res = NULL;
3636
3797
  return_value = Qfalse;
3637
3798
  } else {
3638
3799
  if (!NIL_P(r_qualifier)) {
@@ -3661,6 +3822,9 @@ VALUE ibm_db_statistics(int argc, VALUE *argv, VALUE self)
3661
3822
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1,
3662
3823
  NULL, -1, 1, 1 );
3663
3824
 
3825
+ _ruby_ibm_db_free_stmt_struct( stmt_res );
3826
+ stmt_res = NULL;
3827
+
3664
3828
  return_value = Qfalse;
3665
3829
  } else {
3666
3830
  return_value = Data_Wrap_Struct(le_stmt_struct,
@@ -3741,7 +3905,7 @@ VALUE ibm_db_table_privileges(int argc, VALUE *argv, VALUE self)
3741
3905
  rb_scan_args(argc, argv, "13", &connection, &r_qualifier,
3742
3906
  &r_owner, &r_table_name);
3743
3907
 
3744
- table_privileges_args = ALLOC_N(metadata_args,sizeof(struct _ibm_db_metadata_args_struct));
3908
+ table_privileges_args = ALLOC( metadata_args );
3745
3909
  memset(table_privileges_args,'\0',sizeof(struct _ibm_db_metadata_args_struct));
3746
3910
 
3747
3911
  table_privileges_args->qualifier = NULL;
@@ -3760,6 +3924,8 @@ VALUE ibm_db_table_privileges(int argc, VALUE *argv, VALUE self)
3760
3924
  rc = SQLAllocHandle(SQL_HANDLE_STMT, conn_res->hdbc, &(stmt_res->hstmt));
3761
3925
  if (rc == SQL_ERROR) {
3762
3926
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 1 );
3927
+ ruby_xfree( stmt_res );
3928
+ stmt_res = NULL;
3763
3929
  return_value = Qfalse;
3764
3930
  } else {
3765
3931
  if (!NIL_P(r_qualifier)) {
@@ -3786,6 +3952,9 @@ VALUE ibm_db_table_privileges(int argc, VALUE *argv, VALUE self)
3786
3952
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1,
3787
3953
  NULL, -1, 1, 1 );
3788
3954
 
3955
+ _ruby_ibm_db_free_stmt_struct( stmt_res );
3956
+ stmt_res = NULL;
3957
+
3789
3958
  return_value = Qfalse;
3790
3959
  } else {
3791
3960
  return_value = Data_Wrap_Struct(le_stmt_struct,
@@ -3867,7 +4036,7 @@ VALUE ibm_db_tables(int argc, VALUE *argv, VALUE self)
3867
4036
  rb_scan_args(argc, argv, "14", &connection,
3868
4037
  &r_qualifier, &r_owner, &r_table_name, &r_table_type);
3869
4038
 
3870
- table_metadata_args = ALLOC_N(metadata_args,sizeof(struct _ibm_db_metadata_args_struct));
4039
+ table_metadata_args = ALLOC( metadata_args );
3871
4040
  memset(table_metadata_args,'\0',sizeof(struct _ibm_db_metadata_args_struct));
3872
4041
 
3873
4042
  table_metadata_args->qualifier = NULL;
@@ -3888,6 +4057,8 @@ VALUE ibm_db_tables(int argc, VALUE *argv, VALUE self)
3888
4057
  rc = SQLAllocHandle(SQL_HANDLE_STMT, conn_res->hdbc, &(stmt_res->hstmt));
3889
4058
  if (rc == SQL_ERROR) {
3890
4059
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 1 );
4060
+ ruby_xfree( stmt_res );
4061
+ stmt_res = NULL;
3891
4062
  return_value = Qfalse;
3892
4063
  } else {
3893
4064
  if (!NIL_P(r_qualifier)) {
@@ -3917,6 +4088,9 @@ VALUE ibm_db_tables(int argc, VALUE *argv, VALUE self)
3917
4088
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1,
3918
4089
  NULL, -1, 1, 1 );
3919
4090
 
4091
+ _ruby_ibm_db_free_stmt_struct( stmt_res );
4092
+ stmt_res = NULL;
4093
+
3920
4094
  return_value = Qfalse;
3921
4095
  } else {
3922
4096
  return_value = Data_Wrap_Struct(le_stmt_struct,
@@ -3977,7 +4151,7 @@ VALUE ibm_db_commit(int argc, VALUE *argv, VALUE self)
3977
4151
  return Qfalse;
3978
4152
  }
3979
4153
 
3980
- end_X_args = ALLOC_N(end_tran_args,sizeof(struct _ibm_db_end_tran_args_struct));
4154
+ end_X_args = ALLOC( end_tran_args );
3981
4155
  memset(end_X_args,'\0',sizeof(struct _ibm_db_end_tran_args_struct));
3982
4156
 
3983
4157
  end_X_args->hdbc = &(conn_res->hdbc);
@@ -4016,19 +4190,20 @@ static int _ruby_ibm_db_do_prepare(conn_handle *conn_res, VALUE stmt, stmt_handl
4016
4190
  VALUE options)
4017
4191
  {
4018
4192
  int rc;
4019
- char error[100];
4193
+
4194
+ VALUE error = Qnil;
4020
4195
 
4021
4196
  exec_cum_prepare_args *prepare_args = NULL;
4022
4197
 
4023
4198
  /* get the string and its length */
4024
4199
  if ( !NIL_P(stmt) ) {
4025
- prepare_args = ALLOC_N(exec_cum_prepare_args,sizeof(struct _ibm_db_exec_direct_args_struct));
4200
+ prepare_args = ALLOC( exec_cum_prepare_args );
4026
4201
  memset(prepare_args,'\0',sizeof(struct _ibm_db_exec_direct_args_struct));
4027
4202
 
4028
4203
  prepare_args->stmt_string = (SQLCHAR*)rb_str2cstr(stmt, &(prepare_args->stmt_string_len));
4029
4204
  } else {
4030
- ruby_xfree( stmt_res );
4031
4205
  rb_warn("Supplied parameter is invalid");
4206
+ stmt_res->is_freed = 1; /* At this point there is no handle allocated or resource used hence is_freed is set to 1*/
4032
4207
  return SQL_ERROR;
4033
4208
  }
4034
4209
 
@@ -4041,11 +4216,11 @@ static int _ruby_ibm_db_do_prepare(conn_handle *conn_res, VALUE stmt, stmt_handl
4041
4216
  } else {
4042
4217
 
4043
4218
  if ( !NIL_P(options) ) {
4044
- rc = _ruby_ibm_db_parse_options( options, SQL_HANDLE_STMT, stmt_res, error );
4219
+ rc = _ruby_ibm_db_parse_options( options, SQL_HANDLE_STMT, stmt_res, &error );
4045
4220
  if ( rc == SQL_ERROR ) {
4046
4221
  ruby_xfree( prepare_args );
4047
- _ruby_ibm_db_free_stmt_struct( stmt_res );
4048
- rb_warn( error );
4222
+ prepare_args = NULL;
4223
+ rb_warn( RSTRING_PTR(error) );
4049
4224
  return rc;
4050
4225
  }
4051
4226
  }
@@ -4127,7 +4302,7 @@ VALUE ibm_db_exec(int argc, VALUE *argv, VALUE self)
4127
4302
  exec_cum_prepare_args *exec_direct_args = NULL;
4128
4303
 
4129
4304
  int rc;
4130
- char error[100];
4305
+ VALUE error = Qnil;
4131
4306
 
4132
4307
  /* This function basically is a wrap of the _ruby_ibm_db_do_prepare and _ruby_ibm_db_execute_stmt */
4133
4308
  /* After completing statement execution, it returns the statement resource */
@@ -4142,7 +4317,7 @@ VALUE ibm_db_exec(int argc, VALUE *argv, VALUE self)
4142
4317
  }
4143
4318
 
4144
4319
  if (!NIL_P(stmt)) {
4145
- exec_direct_args = ALLOC_N(exec_cum_prepare_args,sizeof(struct _ibm_db_exec_direct_args_struct));
4320
+ exec_direct_args = ALLOC( exec_cum_prepare_args );
4146
4321
  memset(exec_direct_args,'\0',sizeof(struct _ibm_db_exec_direct_args_struct));
4147
4322
 
4148
4323
  exec_direct_args->stmt_string = (SQLCHAR*)rb_str2cstr(stmt, &(exec_direct_args->stmt_string_len));
@@ -4161,15 +4336,19 @@ VALUE ibm_db_exec(int argc, VALUE *argv, VALUE self)
4161
4336
  rc = SQLAllocHandle(SQL_HANDLE_STMT, conn_res->hdbc, &(stmt_res->hstmt));
4162
4337
  if ( rc < SQL_SUCCESS ) {
4163
4338
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 1 );
4339
+ ruby_xfree( stmt_res );
4340
+ stmt_res = NULL;
4164
4341
  return_value = Qfalse;
4165
4342
  } else {
4166
4343
 
4167
4344
  if (!NIL_P(options)) {
4168
- rc = _ruby_ibm_db_parse_options( options, SQL_HANDLE_STMT, stmt_res, error );
4345
+ rc = _ruby_ibm_db_parse_options( options, SQL_HANDLE_STMT, stmt_res, &error );
4169
4346
  if ( rc == SQL_ERROR ) {
4170
4347
  _ruby_ibm_db_free_stmt_struct( stmt_res );
4348
+ stmt_res = NULL;
4171
4349
  ruby_xfree( exec_direct_args );
4172
- rb_warn( error );
4350
+ exec_direct_args = NULL;
4351
+ rb_warn( RSTRING_PTR(error) );
4173
4352
  return Qfalse;
4174
4353
  }
4175
4354
  }
@@ -4189,6 +4368,7 @@ VALUE ibm_db_exec(int argc, VALUE *argv, VALUE self)
4189
4368
  SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 1 );
4190
4369
 
4191
4370
  _ruby_ibm_db_free_stmt_struct( stmt_res );
4371
+ stmt_res = NULL;
4192
4372
 
4193
4373
  return_value = Qfalse;
4194
4374
  } else {
@@ -4229,10 +4409,8 @@ VALUE ibm_db_exec(int argc, VALUE *argv, VALUE self)
4229
4409
  */
4230
4410
  VALUE ibm_db_free_result(int argc, VALUE *argv, VALUE self)
4231
4411
  {
4232
- VALUE stmt = Qnil;
4233
- int rc = 0;
4234
-
4235
- char error[DB2_MAX_ERR_MSG_LEN + 16];
4412
+ VALUE stmt = Qnil;
4413
+ int rc = 0;
4236
4414
 
4237
4415
  stmt_handle *stmt_res = NULL;
4238
4416
  free_stmt_args *freeStmt_args = NULL;
@@ -4242,7 +4420,7 @@ VALUE ibm_db_free_result(int argc, VALUE *argv, VALUE self)
4242
4420
  if (!NIL_P(stmt)) {
4243
4421
  Data_Get_Struct(stmt, stmt_handle, stmt_res);
4244
4422
  if ( stmt_res->hstmt ) {
4245
- freeStmt_args = ALLOC_N(free_stmt_args, sizeof( struct _ibm_db_free_stmt_struct ) );
4423
+ freeStmt_args = ALLOC( free_stmt_args );
4246
4424
  memset(freeStmt_args, '\0', sizeof( struct _ibm_db_free_stmt_struct ) );
4247
4425
 
4248
4426
  freeStmt_args->stmt_res = stmt_res;
@@ -4256,15 +4434,15 @@ VALUE ibm_db_free_result(int argc, VALUE *argv, VALUE self)
4256
4434
  #endif
4257
4435
 
4258
4436
  ruby_xfree( freeStmt_args );
4437
+ freeStmt_args = NULL;
4259
4438
 
4260
4439
  if ( rc == SQL_ERROR ) {
4261
4440
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 1 );
4262
- sprintf(error, "Statement Free Failed: %s", stmt_res->ruby_stmt_err_msg);
4263
- rb_warn( error );
4441
+ rb_warn( "Statement Free Failed: %s", stmt_res->ruby_stmt_err_msg);
4264
4442
  return Qfalse;
4265
4443
  }
4266
4444
  }
4267
- _ruby_ibm_db_free_result_struct(stmt_res);
4445
+ _ruby_ibm_db_free_result_struct( stmt_res );
4268
4446
  } else {
4269
4447
  rb_warn("Supplied parameter is invalid");
4270
4448
  return Qfalse;
@@ -4331,7 +4509,6 @@ VALUE ibm_db_prepare(int argc, VALUE *argv, VALUE self)
4331
4509
  stmt_handle *stmt_res;
4332
4510
 
4333
4511
  int rc;
4334
- char error[DB2_MAX_ERR_MSG_LEN + 16];
4335
4512
 
4336
4513
  rb_scan_args(argc, argv, "21", &connection, &stmt, &options);
4337
4514
 
@@ -4357,9 +4534,9 @@ VALUE ibm_db_prepare(int argc, VALUE *argv, VALUE self)
4357
4534
 
4358
4535
  if ( rc < SQL_SUCCESS ) {
4359
4536
  _ruby_ibm_db_free_stmt_struct(stmt_res);
4537
+ stmt_res = NULL;
4360
4538
 
4361
- sprintf(error, "Statement Prepare Failed: %s", conn_res->ruby_error_msg);
4362
- rb_warn( error );
4539
+ rb_warn("Statement Prepare Failed: %s", conn_res->ruby_error_msg);
4363
4540
 
4364
4541
  return_value = Qfalse;
4365
4542
  } else {
@@ -4381,7 +4558,7 @@ static param_node* build_list( stmt_handle *stmt_res, int param_no, SQLSMALLINT
4381
4558
 
4382
4559
  /* Allocate memory and make new node to be added */
4383
4560
  tmp_curr = ALLOC(param_node);
4384
- memset(tmp_curr,0,sizeof(param_node));
4561
+ memset(tmp_curr,'\0',sizeof(param_node));
4385
4562
  /* assign values */
4386
4563
  tmp_curr->data_type = data_type;
4387
4564
  tmp_curr->param_size = precision;
@@ -4390,6 +4567,8 @@ static param_node* build_list( stmt_handle *stmt_res, int param_no, SQLSMALLINT
4390
4567
  tmp_curr->param_num = param_no;
4391
4568
  tmp_curr->file_options = SQL_FILE_READ;
4392
4569
  tmp_curr->param_type = SQL_PARAM_INPUT;
4570
+ tmp_curr->varname = NULL;
4571
+ tmp_curr->svalue = NULL;
4393
4572
 
4394
4573
  while ( curr != NULL ) {
4395
4574
  prev = curr;
@@ -4417,12 +4596,13 @@ static int _ruby_ibm_db_bind_parameter_helper(stmt_handle *stmt_res, param_node
4417
4596
  int origlen = 0;
4418
4597
  int is_known_type = 1;
4419
4598
 
4599
+ SQLCHAR *tmp_str;
4420
4600
  SQLSMALLINT valueType;
4421
4601
  SQLPOINTER paramValuePtr;
4422
4602
 
4423
4603
  bind_parameter_args *bindParameter_args = NULL;
4424
4604
 
4425
- bindParameter_args = ALLOC_N(bind_parameter_args,sizeof(struct _ibm_db_bind_parameter_struct));
4605
+ bindParameter_args = ALLOC( bind_parameter_args );
4426
4606
  memset(bindParameter_args,'\0',sizeof(struct _ibm_db_bind_parameter_struct));
4427
4607
 
4428
4608
  bindParameter_args->stmt_res = stmt_res;
@@ -4434,7 +4614,11 @@ static int _ruby_ibm_db_bind_parameter_helper(stmt_handle *stmt_res, param_node
4434
4614
 
4435
4615
  switch(TYPE(*bind_data)) {
4436
4616
  case T_BIGNUM:
4437
- curr->svalue = rb_str2cstr( rb_big2str(*bind_data,10), &curr->ivalue );
4617
+ tmp_str = (SQLCHAR *) rb_str2cstr( rb_big2str(*bind_data,10), (long*)&curr->ivalue );
4618
+
4619
+ curr->svalue = (SQLCHAR *) ALLOC_N(char, curr->ivalue+1);
4620
+ memset(curr->svalue, '\0', curr->ivalue+1);
4621
+ memcpy(curr->svalue, tmp_str, curr->ivalue);
4438
4622
 
4439
4623
  bindParameter_args->valueType = SQL_C_CHAR;
4440
4624
  bindParameter_args->paramValPtr = curr->svalue;
@@ -4450,7 +4634,7 @@ static int _ruby_ibm_db_bind_parameter_helper(stmt_handle *stmt_res, param_node
4450
4634
  if(curr->data_type == SQL_BIGINT) {
4451
4635
  valueType = SQL_C_DEFAULT;
4452
4636
  } else {
4453
- valueType = SQL_C_LONG;
4637
+ valueType = SQL_C_SBIGINT;
4454
4638
  }
4455
4639
 
4456
4640
  bindParameter_args->valueType = valueType;
@@ -4467,7 +4651,7 @@ static int _ruby_ibm_db_bind_parameter_helper(stmt_handle *stmt_res, param_node
4467
4651
  case T_FALSE:
4468
4652
  curr->ivalue = 0;
4469
4653
 
4470
- bindParameter_args->valueType = SQL_C_LONG;
4654
+ bindParameter_args->valueType = SQL_C_SBIGINT;
4471
4655
  bindParameter_args->paramValPtr = &curr->ivalue;
4472
4656
  bindParameter_args->buff_length = 0;
4473
4657
  bindParameter_args->out_length = NULL;
@@ -4480,7 +4664,7 @@ static int _ruby_ibm_db_bind_parameter_helper(stmt_handle *stmt_res, param_node
4480
4664
  case T_TRUE:
4481
4665
  curr->ivalue = 1;
4482
4666
 
4483
- bindParameter_args->valueType = SQL_C_LONG;
4667
+ bindParameter_args->valueType = SQL_C_SBIGINT;
4484
4668
  bindParameter_args->paramValPtr = &curr->ivalue;
4485
4669
  bindParameter_args->buff_length = 0;
4486
4670
  bindParameter_args->out_length = NULL;
@@ -4504,7 +4688,7 @@ static int _ruby_ibm_db_bind_parameter_helper(stmt_handle *stmt_res, param_node
4504
4688
  break;
4505
4689
 
4506
4690
  case T_STRING:
4507
- curr->svalue = rb_str2cstr( *bind_data, &curr->ivalue );
4691
+ tmp_str = (SQLCHAR *) rb_str2cstr( *bind_data, (long*) &curr->ivalue );
4508
4692
  origlen = curr->ivalue;
4509
4693
  /*
4510
4694
  * An extra parameter is given by the client to pick the size of the string
@@ -4520,11 +4704,15 @@ static int _ruby_ibm_db_bind_parameter_helper(stmt_handle *stmt_res, param_node
4520
4704
  curr->ivalue = curr->param_size;
4521
4705
  }
4522
4706
  }
4523
- curr->svalue = memcpy(ALLOC_N(char, curr->ivalue+1), curr->svalue, origlen);
4707
+ curr->svalue = (SQLCHAR *) ALLOC_N(char, curr->ivalue+1);
4708
+ memset(curr->svalue, '\0', origlen);
4709
+ memcpy(curr->svalue, tmp_str, origlen);
4524
4710
  curr->svalue[origlen] = '\0';
4525
4711
  }
4526
4712
  else {
4527
- curr->svalue = memcpy(ALLOC_N(char, curr->ivalue+1), curr->svalue, curr->ivalue);
4713
+ curr->svalue = (SQLCHAR *) ALLOC_N(char, curr->ivalue+1);
4714
+ memset(curr->svalue, '\0', origlen);
4715
+ memcpy(curr->svalue, tmp_str, curr->ivalue);
4528
4716
  curr->svalue[curr->ivalue] = '\0';
4529
4717
  }
4530
4718
 
@@ -4639,7 +4827,7 @@ static int _ruby_ibm_db_bind_data( stmt_handle *stmt_res, param_node *curr, VALU
4639
4827
  return SQL_ERROR;
4640
4828
  }
4641
4829
  curr->bind_indicator = 0;
4642
- curr->svalue = rb_str2cstr(*bind_data, &curr->ivalue);
4830
+ curr->svalue = (SQLCHAR *) rb_str2cstr(*bind_data, (long*) &curr->ivalue);
4643
4831
 
4644
4832
  /* Bind file name string */
4645
4833
  rc = _ruby_ibm_db_SQLBindFileToParam_helper(stmt_res, curr);
@@ -4656,9 +4844,9 @@ static int _ruby_ibm_db_bind_data( stmt_handle *stmt_res, param_node *curr, VALU
4656
4844
  return rc;
4657
4845
  }
4658
4846
  /*
4659
- static int _ruby_ibm_db_bind_param_list(stmt_handle *stmt_res)
4847
+ static int _ruby_ibm_db_bind_param_list(stmt_handle *stmt_res, VALUE *error)
4660
4848
  */
4661
- static int _ruby_ibm_db_bind_param_list(stmt_handle *stmt_res, char *error ) {
4849
+ static int _ruby_ibm_db_bind_param_list(stmt_handle *stmt_res, VALUE *error ) {
4662
4850
  int rc;
4663
4851
  VALUE bind_data; /* Data value from symbol table */
4664
4852
  param_node *curr = NULL; /* To traverse the list */
@@ -4674,7 +4862,11 @@ static int _ruby_ibm_db_bind_param_list(stmt_handle *stmt_res, char *error ) {
4674
4862
  rc = _ruby_ibm_db_bind_data( stmt_res, curr, &bind_data);
4675
4863
 
4676
4864
  if ( rc == SQL_ERROR ) {
4677
- sprintf(error, "Binding Error 1: %s", stmt_res->ruby_stmt_err_msg );
4865
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
4866
+ *error = rb_str_cat2(rb_str_new2("Binding Error 1: "), stmt_res->ruby_stmt_err_msg );
4867
+ } else {
4868
+ *error = rb_str_new2("Binding Error 1: <error message could not be retrieved>");
4869
+ }
4678
4870
  return rc;
4679
4871
  }
4680
4872
  curr = curr->next;
@@ -4684,10 +4876,10 @@ static int _ruby_ibm_db_bind_param_list(stmt_handle *stmt_res, char *error ) {
4684
4876
  }
4685
4877
  /* */
4686
4878
 
4687
- /* static int _ruby_ibm_db_execute_helper2(stmt_res, data, int bind_cmp_list, int bind_params, char *error )
4879
+ /* static int _ruby_ibm_db_execute_helper2(stmt_res, data, int bind_cmp_list, int bind_params, VALUE *error )
4688
4880
  */
4689
4881
  static int _ruby_ibm_db_execute_helper2(stmt_handle *stmt_res, VALUE *data, int bind_cmp_list,
4690
- int bind_params, char *error )
4882
+ int bind_params, VALUE *error )
4691
4883
  {
4692
4884
  int rc = SQL_SUCCESS;
4693
4885
  param_node *curr = NULL; /* To traverse the list */
@@ -4714,7 +4906,7 @@ static int _ruby_ibm_db_execute_helper2(stmt_handle *stmt_res, VALUE *data, int
4714
4906
  parameter and then bind it.
4715
4907
  */
4716
4908
 
4717
- desc_param_args = ALLOC_N(describeparam_args,sizeof(struct _ibm_db_describeparam_args_struct));
4909
+ desc_param_args = ALLOC( describeparam_args );
4718
4910
  memset(desc_param_args,'\0',sizeof(struct _ibm_db_describeparam_args_struct));
4719
4911
 
4720
4912
  desc_param_args->param_no = ++stmt_res->num_params;
@@ -4729,7 +4921,11 @@ static int _ruby_ibm_db_execute_helper2(stmt_handle *stmt_res, VALUE *data, int
4729
4921
 
4730
4922
  if ( rc == SQL_ERROR ) {
4731
4923
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 0 );
4732
- sprintf(error, "Describe Param Failed: %s", stmt_res->ruby_stmt_err_msg );
4924
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
4925
+ *error = rb_str_cat2(rb_str_new2("Describe Param Failed: "), stmt_res->ruby_stmt_err_msg );
4926
+ } else {
4927
+ *error = rb_str_new2("Describe Param Failed: <error message could not be retrieved>");
4928
+ }
4733
4929
 
4734
4930
  if(desc_param_args != NULL) {
4735
4931
  ruby_xfree( desc_param_args );
@@ -4750,7 +4946,11 @@ static int _ruby_ibm_db_execute_helper2(stmt_handle *stmt_res, VALUE *data, int
4750
4946
  rc = _ruby_ibm_db_bind_data( stmt_res, curr, data );
4751
4947
 
4752
4948
  if ( rc == SQL_ERROR ) {
4753
- sprintf(error, "Binding Error 2: %s", stmt_res->ruby_stmt_err_msg );
4949
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
4950
+ *error = rb_str_cat2(rb_str_new2("Binding Error 2: "), stmt_res->ruby_stmt_err_msg );
4951
+ } else {
4952
+ *error = rb_str_new2("Binding Error 2: <error message could not be retrieved>");
4953
+ }
4754
4954
  return rc;
4755
4955
  }
4756
4956
  } else {
@@ -4765,7 +4965,11 @@ static int _ruby_ibm_db_execute_helper2(stmt_handle *stmt_res, VALUE *data, int
4765
4965
  rc = _ruby_ibm_db_bind_data( stmt_res, curr, data);
4766
4966
 
4767
4967
  if ( rc == SQL_ERROR ) {
4768
- sprintf(error, "Binding Error 2: %s", stmt_res->ruby_stmt_err_msg );
4968
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
4969
+ *error = rb_str_cat2(rb_str_new2("Binding Error 2: "), stmt_res->ruby_stmt_err_msg );
4970
+ } else {
4971
+ *error = rb_str_new2("Binding Error 2: <error message could not be retrieved>");
4972
+ }
4769
4973
  return rc;
4770
4974
  }
4771
4975
  stmt_res->current_node = curr->next;
@@ -4798,13 +5002,14 @@ void var_assign(char *name, VALUE value) {
4798
5002
  strcat(statement, expr);
4799
5003
  rb_eval_string( statement );
4800
5004
  ruby_xfree( statement );
5005
+ statement = NULL;
4801
5006
  #endif
4802
5007
  }
4803
5008
 
4804
5009
  /*
4805
- static VALUE _ruby_ibm_db_desc_and_bind_param_list(stmt_bind_array *bind_array)
5010
+ static VALUE _ruby_ibm_db_desc_and_bind_param_list(stmt_bind_array *bind_array, VALUE *error)
4806
5011
  */
4807
- static VALUE _ruby_ibm_db_desc_and_bind_param_list(stmt_bind_array *bind_array, char *error ) {
5012
+ static VALUE _ruby_ibm_db_desc_and_bind_param_list(stmt_bind_array *bind_array, VALUE *error ) {
4808
5013
  int rc, numOpts, i = 0;
4809
5014
 
4810
5015
  VALUE data;
@@ -4817,13 +5022,11 @@ static VALUE _ruby_ibm_db_desc_and_bind_param_list(stmt_bind_array *bind_array,
4817
5022
 
4818
5023
  if (numOpts > bind_array->num) {
4819
5024
  /* More are passed in -- Warning - Use the max number present */
4820
- sprintf(error, "%d params bound not matching %d required", numOpts, bind_array->num);
4821
- rb_warn(error);
4822
- memset( error, '\0', DB2_MAX_ERR_MSG_LEN + 23 );
5025
+ rb_warn("Number of params passed in are more than bound parameters");
4823
5026
  numOpts = bind_array->num;
4824
5027
  } else if (numOpts < bind_array->num) {
4825
5028
  /* If there are less params passed in, than are present -- Error */
4826
- sprintf(error, "%d params bound not matching %d required", numOpts, bind_array->num);
5029
+ *error = rb_str_new2("Number of params passed in are less than bound parameters");
4827
5030
  return Qnil;
4828
5031
  }
4829
5032
 
@@ -4852,7 +5055,7 @@ static VALUE _ruby_ibm_db_execute_helper(stmt_bind_array *bind_array) {
4852
5055
  VALUE ret_value = Qtrue;
4853
5056
  stmt_handle *stmt_res = NULL;
4854
5057
 
4855
- char *error = NULL;
5058
+ VALUE *error;
4856
5059
  int rc = 0;
4857
5060
 
4858
5061
  SQLSMALLINT num = 0;
@@ -4865,7 +5068,7 @@ static VALUE _ruby_ibm_db_execute_helper(stmt_bind_array *bind_array) {
4865
5068
 
4866
5069
  /* Free any cursors that might have been allocated in a previous call to SQLExecute */
4867
5070
 
4868
- freeStmt_args = ALLOC_N(free_stmt_args, sizeof( struct _ibm_db_free_stmt_struct ) );
5071
+ freeStmt_args = ALLOC( free_stmt_args );
4869
5072
  memset(freeStmt_args, '\0', sizeof( struct _ibm_db_free_stmt_struct ) );
4870
5073
 
4871
5074
  freeStmt_args->stmt_res = stmt_res;
@@ -4874,8 +5077,9 @@ static VALUE _ruby_ibm_db_execute_helper(stmt_bind_array *bind_array) {
4874
5077
  _ruby_ibm_db_SQLFreeStmt_helper( freeStmt_args );
4875
5078
 
4876
5079
  ruby_xfree( freeStmt_args );
5080
+ freeStmt_args = NULL;
4877
5081
 
4878
- num_params_args = ALLOC_N(row_col_count_args,sizeof(struct _ibm_db_row_col_count_struct));
5082
+ num_params_args = ALLOC( row_col_count_args );
4879
5083
  memset(num_params_args,'\0',sizeof(struct _ibm_db_row_col_count_struct));
4880
5084
 
4881
5085
  num_params_args->stmt_res = stmt_res;
@@ -4886,13 +5090,19 @@ static VALUE _ruby_ibm_db_execute_helper(stmt_bind_array *bind_array) {
4886
5090
  if ( rc == SQL_ERROR ) {
4887
5091
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 0 );
4888
5092
  ruby_xfree( num_params_args );
4889
- sprintf(error, "Execute Failed due to: %s", stmt_res->ruby_stmt_err_msg );
5093
+ num_params_args = NULL;
5094
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
5095
+ *error = rb_str_cat2(rb_str_new2("Execute Failed due to: "), stmt_res->ruby_stmt_err_msg );
5096
+ } else {
5097
+ *error = rb_str_new2("Execute Failed due to: <error message could not be retrieved>");
5098
+ }
4890
5099
  return Qnil;
4891
5100
  }
4892
5101
 
4893
5102
  num = num_params_args->count;
4894
5103
 
4895
5104
  ruby_xfree( num_params_args );
5105
+ num_params_args = NULL;
4896
5106
 
4897
5107
  if ( num != 0 ) {
4898
5108
 
@@ -4903,7 +5113,7 @@ static VALUE _ruby_ibm_db_execute_helper(stmt_bind_array *bind_array) {
4903
5113
  /* Make sure IBM_DB.bind_param has been called */
4904
5114
  /* If the param list is NULL -- ERROR */
4905
5115
  if (TYPE( *(bind_array->parameters_array) ) != T_ARRAY) {
4906
- sprintf(error, "Param is not an array");
5116
+ *error = rb_str_new2("Param is not an array");
4907
5117
  return Qnil;
4908
5118
  }
4909
5119
 
@@ -4913,7 +5123,7 @@ static VALUE _ruby_ibm_db_execute_helper(stmt_bind_array *bind_array) {
4913
5123
  return Qnil;
4914
5124
  }
4915
5125
  if(ret_value == Qfalse) {
4916
- return Qfalse;
5126
+ return Qfalse;
4917
5127
  }
4918
5128
 
4919
5129
  } else {
@@ -4921,17 +5131,17 @@ static VALUE _ruby_ibm_db_execute_helper(stmt_bind_array *bind_array) {
4921
5131
  /* No additional params passed in. Use values already bound. */
4922
5132
  if ( num > stmt_res->num_params ) {
4923
5133
  /* More parameters than we expected */
4924
- sprintf(error, "%d params bound not matching %d required", stmt_res->num_params, num);
5134
+ *error = rb_str_new2("Number of params passed are more than bound parameters");
4925
5135
  return Qnil;
4926
5136
  } else if ( num < stmt_res->num_params ) {
4927
5137
  /* Fewer parameters than we expected */
4928
- sprintf(error, "%d params bound not matching %d required", stmt_res->num_params, num);
5138
+ *error = rb_str_new2("Number of params passed are less than bound parameters");
4929
5139
  return Qnil;
4930
5140
  }
4931
5141
 
4932
5142
  /* Param cache node list is empty -- No params bound */
4933
5143
  if ( stmt_res->head_cache_list == NULL ) {
4934
- sprintf(error, "Parameters not bound");
5144
+ *error = rb_str_new2("Parameters not bound");
4935
5145
  return Qnil;
4936
5146
  } else {
4937
5147
  /* The 1 denotes that you work with the whole list */
@@ -4951,13 +5161,17 @@ static VALUE _ruby_ibm_db_execute_helper(stmt_bind_array *bind_array) {
4951
5161
 
4952
5162
  if ( rc == SQL_ERROR ) {
4953
5163
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 0 );
4954
- sprintf(error, "Statement Execute Failed: %s", stmt_res->ruby_stmt_err_msg );
5164
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
5165
+ *error = rb_str_cat2(rb_str_new2("Statement Execute Failed: "), stmt_res->ruby_stmt_err_msg );
5166
+ } else {
5167
+ *error = rb_str_new2("Statement Execute Failed: <error message could not be retrieved>");
5168
+ }
4955
5169
  return Qnil;
4956
5170
  }
4957
5171
 
4958
5172
  if ( rc == SQL_NEED_DATA ) {
4959
5173
 
4960
- put_param_data_args = ALLOC_N(param_cum_put_data_args,sizeof(struct _ibm_db_param_and_put_data_struct));
5174
+ put_param_data_args = ALLOC( param_cum_put_data_args );
4961
5175
  memset(put_param_data_args,'\0',sizeof(struct _ibm_db_param_and_put_data_struct));
4962
5176
 
4963
5177
  put_param_data_args->stmt_res = stmt_res;
@@ -4969,7 +5183,11 @@ static VALUE _ruby_ibm_db_execute_helper(stmt_bind_array *bind_array) {
4969
5183
 
4970
5184
  if ( rc == SQL_ERROR ) {
4971
5185
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 0 );
4972
- sprintf(error, "Sending data failed: %s", stmt_res->ruby_stmt_err_msg );
5186
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
5187
+ *error = rb_str_cat2(rb_str_new2("Sending data failed: "), stmt_res->ruby_stmt_err_msg );
5188
+ } else {
5189
+ *error = rb_str_new2("Sending data failed: <error message could not be retrieved>");
5190
+ }
4973
5191
 
4974
5192
  if (put_param_data_args != NULL) {
4975
5193
  ruby_xfree( put_param_data_args );
@@ -5022,7 +5240,7 @@ VALUE ibm_db_execute(int argc, VALUE *argv, VALUE self)
5022
5240
  /* This is used to loop over the param cache */
5023
5241
  param_node *tmp_curr, *prev_ptr, *curr_ptr;
5024
5242
 
5025
- char error[DB2_MAX_ERR_MSG_LEN + 23];
5243
+ VALUE error = Qnil;
5026
5244
 
5027
5245
  rb_scan_args(argc, argv, "11", &stmt, &parameters_array);
5028
5246
 
@@ -5039,14 +5257,14 @@ VALUE ibm_db_execute(int argc, VALUE *argv, VALUE self)
5039
5257
  /* This ensures that each call to IBM_DB.execute start from scratch */
5040
5258
  stmt_res->current_node = stmt_res->head_cache_list;
5041
5259
 
5042
- bind_array = ALLOC_N(stmt_bind_array,sizeof(struct _stmt_bind_data_array));
5260
+ bind_array = ALLOC( stmt_bind_array );
5043
5261
  memset(bind_array,'\0',sizeof(struct _stmt_bind_data_array));
5044
5262
 
5045
5263
  bind_array->parameters_array = &parameters_array;
5046
5264
  bind_array->stmt_res = stmt_res;
5047
5265
  bind_array->bind_params = 0;
5048
5266
  bind_array->num = 0;
5049
- bind_array->error = error;
5267
+ bind_array->error = &error;
5050
5268
 
5051
5269
  #ifdef GIL_RELEASE_VERSION
5052
5270
  ret_value = rb_thread_blocking_region( (void *)_ruby_ibm_db_execute_helper, bind_array,
@@ -5056,8 +5274,9 @@ VALUE ibm_db_execute(int argc, VALUE *argv, VALUE self)
5056
5274
  #endif
5057
5275
 
5058
5276
  if( ret_value == Qnil || ret_value == Qfalse ) {
5059
- rb_warn( error, Qnil );
5277
+ rb_warn( RSTRING_PTR(error) );
5060
5278
  ruby_xfree( bind_array );
5279
+ bind_array = NULL;
5061
5280
  return Qfalse;
5062
5281
  }
5063
5282
 
@@ -5071,8 +5290,14 @@ VALUE ibm_db_execute(int argc, VALUE *argv, VALUE self)
5071
5290
  curr_ptr = curr_ptr->next;
5072
5291
 
5073
5292
  /* Free Values */
5074
- if ( prev_ptr->svalue) {
5293
+ if ( prev_ptr->svalue != NULL ) {
5075
5294
  ruby_xfree( prev_ptr->svalue );
5295
+ prev_ptr->svalue = NULL;
5296
+ }
5297
+
5298
+ if ( prev_ptr->varname != NULL ) {
5299
+ ruby_xfree( prev_ptr->varname );
5300
+ prev_ptr->varname = NULL;
5076
5301
  }
5077
5302
 
5078
5303
  ruby_xfree( prev_ptr );
@@ -5082,6 +5307,7 @@ VALUE ibm_db_execute(int argc, VALUE *argv, VALUE self)
5082
5307
 
5083
5308
  stmt_res->head_cache_list = NULL;
5084
5309
  stmt_res->num_params = 0;
5310
+ stmt_res->current_node = NULL;
5085
5311
  } else {
5086
5312
  /* Bind the IN/OUT Params back into the active symbol table */
5087
5313
  tmp_curr = stmt_res->head_cache_list;
@@ -5105,7 +5331,7 @@ VALUE ibm_db_execute(int argc, VALUE *argv, VALUE self)
5105
5331
  var_assign(tmp_curr->varname, rb_float_new(tmp_curr->fvalue));
5106
5332
  break;
5107
5333
  default:
5108
- var_assign(tmp_curr->varname, rb_str_new2(tmp_curr->svalue));
5334
+ var_assign(tmp_curr->varname, rb_str_new2((char *)tmp_curr->svalue));
5109
5335
  break;
5110
5336
  }
5111
5337
 
@@ -5162,6 +5388,7 @@ VALUE ibm_db_execute(int argc, VALUE *argv, VALUE self)
5162
5388
  VALUE ibm_db_conn_errormsg(int argc, VALUE *argv, VALUE self)
5163
5389
  {
5164
5390
  VALUE connection = Qnil;
5391
+ VALUE ret_val = Qnil;
5165
5392
  conn_handle *conn_res = NULL;
5166
5393
  char *return_str = NULL; /* This variable is used by _ruby_ibm_db_check_sql_errors to return err strings */
5167
5394
 
@@ -5177,8 +5404,8 @@ VALUE ibm_db_conn_errormsg(int argc, VALUE *argv, VALUE self)
5177
5404
  return Qnil;
5178
5405
  }
5179
5406
 
5180
- return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN);
5181
- memset(return_str, 0, DB2_MAX_ERR_MSG_LEN);
5407
+ return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1);
5408
+ memset(return_str, '\0', DB2_MAX_ERR_MSG_LEN+1);
5182
5409
 
5183
5410
  _ruby_ibm_db_check_sql_errors(conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, -1, 0, return_str, DB_ERRMSG, conn_res->errormsg_recno_tracker, 1 );
5184
5411
 
@@ -5187,7 +5414,10 @@ VALUE ibm_db_conn_errormsg(int argc, VALUE *argv, VALUE self)
5187
5414
 
5188
5415
  conn_res->errormsg_recno_tracker++;
5189
5416
 
5190
- return rb_str_new2(return_str);
5417
+ ret_val = rb_str_new2(return_str);
5418
+ ruby_xfree( return_str );
5419
+
5420
+ return ret_val;
5191
5421
  } else {
5192
5422
  return rb_str_new2(IBM_DB_G(__ruby_conn_err_msg));
5193
5423
  }
@@ -5219,6 +5449,7 @@ VALUE ibm_db_conn_errormsg(int argc, VALUE *argv, VALUE self)
5219
5449
  VALUE ibm_db_stmt_errormsg(int argc, VALUE *argv, VALUE self)
5220
5450
  {
5221
5451
  VALUE stmt = Qnil;
5452
+ VALUE ret_val = Qnil;
5222
5453
  stmt_handle *stmt_res = NULL;
5223
5454
  char *return_str = NULL; /* This variable is used by _ruby_ibm_db_check_sql_errors to return err strings */
5224
5455
 
@@ -5229,8 +5460,8 @@ VALUE ibm_db_stmt_errormsg(int argc, VALUE *argv, VALUE self)
5229
5460
  if (!NIL_P(stmt)) {
5230
5461
  Data_Get_Struct(stmt, stmt_handle, stmt_res);
5231
5462
 
5232
- return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN);
5233
- memset(return_str, 0, DB2_MAX_ERR_MSG_LEN);
5463
+ return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1);
5464
+ memset(return_str, '\0', DB2_MAX_ERR_MSG_LEN+1);
5234
5465
 
5235
5466
  _ruby_ibm_db_check_sql_errors(stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, -1, 0,
5236
5467
  return_str, DB_ERRMSG, stmt_res->errormsg_recno_tracker, 1);
@@ -5240,7 +5471,10 @@ VALUE ibm_db_stmt_errormsg(int argc, VALUE *argv, VALUE self)
5240
5471
 
5241
5472
  stmt_res->errormsg_recno_tracker++;
5242
5473
 
5243
- return rb_str_new2(return_str);
5474
+ ret_val = rb_str_new2(return_str);
5475
+ ruby_xfree( return_str );
5476
+
5477
+ return ret_val;
5244
5478
  } else {
5245
5479
  return rb_str_new2(IBM_DB_G(__ruby_stmt_err_msg));
5246
5480
  }
@@ -5280,6 +5514,7 @@ VALUE ibm_db_stmt_errormsg(int argc, VALUE *argv, VALUE self)
5280
5514
  VALUE ibm_db_conn_error(int argc, VALUE *argv, VALUE self)
5281
5515
  {
5282
5516
  VALUE connection = Qnil;
5517
+ VALUE ret_val = Qnil;
5283
5518
  conn_handle *conn_res = NULL;
5284
5519
 
5285
5520
  char *return_str = NULL; /* This variable is used by _ruby_ibm_db_check_sql_errors to return err strings */
@@ -5297,7 +5532,7 @@ VALUE ibm_db_conn_error(int argc, VALUE *argv, VALUE self)
5297
5532
  }
5298
5533
 
5299
5534
  return_str = ALLOC_N(char, SQL_SQLSTATE_SIZE + 1);
5300
- memset(return_str, 0, SQL_SQLSTATE_SIZE + 1);
5535
+ memset(return_str, '\0', SQL_SQLSTATE_SIZE + 1);
5301
5536
 
5302
5537
  _ruby_ibm_db_check_sql_errors(conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, -1, 0,
5303
5538
  return_str, DB_ERR_STATE, conn_res->error_recno_tracker, 1);
@@ -5308,7 +5543,10 @@ VALUE ibm_db_conn_error(int argc, VALUE *argv, VALUE self)
5308
5543
 
5309
5544
  conn_res->error_recno_tracker++;
5310
5545
 
5311
- return rb_str_new2(return_str);
5546
+ ret_val = rb_str_new2(return_str);
5547
+ ruby_xfree( return_str );
5548
+
5549
+ return ret_val;
5312
5550
  } else {
5313
5551
  return rb_str_new2(IBM_DB_G(__ruby_conn_err_state));
5314
5552
  }
@@ -5342,6 +5580,7 @@ VALUE ibm_db_conn_error(int argc, VALUE *argv, VALUE self)
5342
5580
  VALUE ibm_db_stmt_error(int argc, VALUE *argv, VALUE self)
5343
5581
  {
5344
5582
  VALUE stmt = Qnil;
5583
+ VALUE ret_val = Qnil;
5345
5584
  stmt_handle *stmt_res = NULL;
5346
5585
  char *return_str = NULL; /* This variable is used by _ruby_ibm_db_check_sql_errors to return err strings */
5347
5586
 
@@ -5352,8 +5591,8 @@ VALUE ibm_db_stmt_error(int argc, VALUE *argv, VALUE self)
5352
5591
  if (!NIL_P(stmt)) {
5353
5592
  Data_Get_Struct(stmt, stmt_handle, stmt_res);
5354
5593
 
5355
- return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN);
5356
- memset(return_str, 0, DB2_MAX_ERR_MSG_LEN);
5594
+ return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1);
5595
+ memset(return_str, '\0', DB2_MAX_ERR_MSG_LEN+1);
5357
5596
 
5358
5597
  _ruby_ibm_db_check_sql_errors(stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, -1, 0,
5359
5598
  return_str, DB_ERR_STATE, stmt_res->error_recno_tracker, 1 );
@@ -5364,7 +5603,10 @@ VALUE ibm_db_stmt_error(int argc, VALUE *argv, VALUE self)
5364
5603
 
5365
5604
  stmt_res->error_recno_tracker++;
5366
5605
 
5367
- return rb_str_new2(return_str);
5606
+ ret_val = rb_str_new2(return_str);
5607
+ ruby_xfree( return_str );
5608
+
5609
+ return ret_val;
5368
5610
  } else {
5369
5611
  return rb_str_new2(IBM_DB_G(__ruby_stmt_err_state));
5370
5612
  }
@@ -5435,8 +5677,8 @@ VALUE ibm_db_getErrormsg(int argc, VALUE *argv, VALUE self)
5435
5677
  return_value = rb_str_new2( conn_res->ruby_error_msg );
5436
5678
  } else {
5437
5679
 
5438
- return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN);
5439
- memset(return_str, 0, DB2_MAX_ERR_MSG_LEN);
5680
+ return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1);
5681
+ memset(return_str, '\0', DB2_MAX_ERR_MSG_LEN+1);
5440
5682
 
5441
5683
  _ruby_ibm_db_check_sql_errors(conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, -1, 0, return_str,
5442
5684
  DB_ERRMSG, conn_res->errormsg_recno_tracker, 1 );
@@ -5446,6 +5688,7 @@ VALUE ibm_db_getErrormsg(int argc, VALUE *argv, VALUE self)
5446
5688
  }
5447
5689
 
5448
5690
  return_value = rb_str_new2(return_str);
5691
+ ruby_xfree( return_str );
5449
5692
  }
5450
5693
  conn_res->errormsg_recno_tracker++;
5451
5694
  }
@@ -5455,8 +5698,8 @@ VALUE ibm_db_getErrormsg(int argc, VALUE *argv, VALUE self)
5455
5698
  if( stmt_res->errormsg_recno_tracker == 1 && stmt_res->ruby_stmt_err_msg != NULL ) {
5456
5699
  return_value = rb_str_new2( stmt_res->ruby_stmt_err_msg );
5457
5700
  } else {
5458
- return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN);
5459
- memset(return_str, 0, DB2_MAX_ERR_MSG_LEN);
5701
+ return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1);
5702
+ memset(return_str, '\0', DB2_MAX_ERR_MSG_LEN+1);
5460
5703
 
5461
5704
  _ruby_ibm_db_check_sql_errors(stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, -1, 0,
5462
5705
  return_str, DB_ERRMSG, stmt_res->errormsg_recno_tracker, 1);
@@ -5466,6 +5709,7 @@ VALUE ibm_db_getErrormsg(int argc, VALUE *argv, VALUE self)
5466
5709
  }
5467
5710
 
5468
5711
  return_value = rb_str_new2(return_str);
5712
+ ruby_xfree( return_str );
5469
5713
  }
5470
5714
  stmt_res->errormsg_recno_tracker++;
5471
5715
  } /*End of Resource Type check */
@@ -5545,8 +5789,8 @@ VALUE ibm_db_getErrorstate(int argc, VALUE *argv, VALUE self)
5545
5789
  return_value = rb_str_new2( conn_res->ruby_error_state );
5546
5790
  } else {
5547
5791
 
5548
- return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN);
5549
- memset(return_str, 0, DB2_MAX_ERR_MSG_LEN);
5792
+ return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1);
5793
+ memset(return_str, '\0', DB2_MAX_ERR_MSG_LEN+1);
5550
5794
 
5551
5795
  _ruby_ibm_db_check_sql_errors(conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, -1, 0, return_str,
5552
5796
  DB_ERRMSG, conn_res->error_recno_tracker, 1 );
@@ -5556,6 +5800,7 @@ VALUE ibm_db_getErrorstate(int argc, VALUE *argv, VALUE self)
5556
5800
  }
5557
5801
 
5558
5802
  return_value = rb_str_new2(return_str);
5803
+ ruby_xfree( return_str );
5559
5804
  }
5560
5805
  conn_res->error_recno_tracker++;
5561
5806
  }
@@ -5565,8 +5810,8 @@ VALUE ibm_db_getErrorstate(int argc, VALUE *argv, VALUE self)
5565
5810
  if( stmt_res->error_recno_tracker == 1 && stmt_res->ruby_stmt_err_state != NULL ) {
5566
5811
  return_value = rb_str_new2( stmt_res->ruby_stmt_err_state );
5567
5812
  } else {
5568
- return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN);
5569
- memset(return_str, 0, DB2_MAX_ERR_MSG_LEN);
5813
+ return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1);
5814
+ memset(return_str, '\0', DB2_MAX_ERR_MSG_LEN+1);
5570
5815
 
5571
5816
  _ruby_ibm_db_check_sql_errors(stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, -1, 0,
5572
5817
  return_str, DB_ERRMSG, stmt_res->error_recno_tracker, 1);
@@ -5576,6 +5821,7 @@ VALUE ibm_db_getErrorstate(int argc, VALUE *argv, VALUE self)
5576
5821
  }
5577
5822
 
5578
5823
  return_value = rb_str_new2(return_str);
5824
+ ruby_xfree( return_str );
5579
5825
  }
5580
5826
  stmt_res->error_recno_tracker++;
5581
5827
  } /*End of Resource Type check */
@@ -5630,9 +5876,9 @@ VALUE ibm_db_next_result(int argc, VALUE *argv, VALUE self)
5630
5876
 
5631
5877
  if ( rc < SQL_SUCCESS ) {
5632
5878
  if ( stmt_res->ruby_stmt_err_msg == NULL ) {
5633
- stmt_res->ruby_stmt_err_msg = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN );
5879
+ stmt_res->ruby_stmt_err_msg = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1 );
5634
5880
  }
5635
- memset( stmt_res->ruby_stmt_err_msg, '\0', DB2_MAX_ERR_MSG_LEN );
5881
+ memset( stmt_res->ruby_stmt_err_msg, '\0', DB2_MAX_ERR_MSG_LEN+1 );
5636
5882
 
5637
5883
  _ruby_ibm_db_check_sql_errors( stmt_res , DB_STMT, stmt_res->hdbc, SQL_HANDLE_DBC, rc, 0,
5638
5884
  stmt_res->ruby_stmt_err_msg, 1, 1, 1 );
@@ -5640,7 +5886,7 @@ VALUE ibm_db_next_result(int argc, VALUE *argv, VALUE self)
5640
5886
  ret_value = Qfalse;
5641
5887
  } else {
5642
5888
 
5643
- nextresultparams = ALLOC_N(next_result_args,sizeof(struct _ibm_db_next_result_args_struct));
5889
+ nextresultparams = ALLOC( next_result_args );
5644
5890
  memset(nextresultparams,'\0',sizeof(struct _ibm_db_next_result_args_struct));
5645
5891
 
5646
5892
  nextresultparams->stmt_res = stmt_res;
@@ -5666,7 +5912,7 @@ VALUE ibm_db_next_result(int argc, VALUE *argv, VALUE self)
5666
5912
  /* Initialize stmt resource members with default values. */
5667
5913
  /* Parsing will update options if needed */
5668
5914
  new_stmt_res = ALLOC(stmt_handle);
5669
- memset(new_stmt_res, 0, sizeof(stmt_handle));
5915
+ memset(new_stmt_res, '\0', sizeof(stmt_handle));
5670
5916
 
5671
5917
  new_stmt_res->s_bin_mode = stmt_res->s_bin_mode;
5672
5918
  new_stmt_res->cursor_type = stmt_res->cursor_type;
@@ -5680,6 +5926,7 @@ VALUE ibm_db_next_result(int argc, VALUE *argv, VALUE self)
5680
5926
  new_stmt_res->row_data = NULL;
5681
5927
  new_stmt_res->hstmt = new_hstmt;
5682
5928
  new_stmt_res->hdbc = stmt_res->hdbc;
5929
+ new_stmt_res->is_freed = 0;
5683
5930
 
5684
5931
  ret_value = Data_Wrap_Struct(le_stmt_struct,
5685
5932
  _ruby_ibm_db_mark_stmt_struct, _ruby_ibm_db_free_stmt_struct,
@@ -5729,14 +5976,12 @@ VALUE ibm_db_num_fields(int argc, VALUE *argv, VALUE self)
5729
5976
 
5730
5977
  row_col_count_args *result_cols_args = NULL;
5731
5978
 
5732
- char error[DB2_MAX_ERR_MSG_LEN + 15];
5733
-
5734
5979
  rb_scan_args(argc, argv, "1", &stmt);
5735
5980
 
5736
5981
  if (!NIL_P(stmt)) {
5737
5982
  Data_Get_Struct(stmt, stmt_handle, stmt_res);
5738
5983
 
5739
- result_cols_args = ALLOC_N(row_col_count_args,sizeof(struct _ibm_db_row_col_count_struct));
5984
+ result_cols_args = ALLOC( row_col_count_args );
5740
5985
  memset(result_cols_args,'\0',sizeof(struct _ibm_db_row_col_count_struct));
5741
5986
 
5742
5987
  result_cols_args->stmt_res = stmt_res;
@@ -5751,9 +5996,7 @@ VALUE ibm_db_num_fields(int argc, VALUE *argv, VALUE self)
5751
5996
 
5752
5997
  if ( rc == SQL_ERROR ) {
5753
5998
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 1 );
5754
- sprintf(error, "Failed to retrieve the number of fields: %s", stmt_res->ruby_stmt_err_msg );
5755
-
5756
- rb_warn( error );
5999
+ rb_warn("Failed to retrieve the number of fields: %s", stmt_res->ruby_stmt_err_msg );
5757
6000
  ret_val = Qfalse;
5758
6001
  } else {
5759
6002
  ret_val = INT2NUM(result_cols_args->count);
@@ -5813,17 +6056,15 @@ VALUE ibm_db_num_rows(int argc, VALUE *argv, VALUE self)
5813
6056
  stmt_handle *stmt_res;
5814
6057
  int rc = 0;
5815
6058
 
5816
- row_col_count_args *row_count_args = NULL;
5817
-
5818
- char error[DB2_MAX_ERR_MSG_LEN + 10 ];
6059
+ sql_row_count_args *row_count_args = NULL;
5819
6060
 
5820
6061
  rb_scan_args(argc, argv, "1", &stmt);
5821
6062
 
5822
6063
  if (!NIL_P(stmt)) {
5823
6064
  Data_Get_Struct(stmt, stmt_handle, stmt_res);
5824
6065
 
5825
- row_count_args = ALLOC_N(row_col_count_args,sizeof(struct _ibm_db_row_col_count_struct));
5826
- memset(row_count_args,'\0',sizeof(struct _ibm_db_row_col_count_struct));
6066
+ row_count_args = ALLOC( sql_row_count_args );
6067
+ memset(row_count_args,'\0',sizeof(struct _ibm_db_row_count_struct));
5827
6068
 
5828
6069
  row_count_args->stmt_res = stmt_res;
5829
6070
  row_count_args->count = 0;
@@ -5837,9 +6078,7 @@ VALUE ibm_db_num_rows(int argc, VALUE *argv, VALUE self)
5837
6078
 
5838
6079
  if ( rc == SQL_ERROR ) {
5839
6080
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 1 );
5840
- sprintf(error, "Retrieval of number of rows failed: %s", stmt_res->ruby_stmt_err_msg );
5841
-
5842
- rb_warn( error );
6081
+ rb_warn("Retrieval of number of rows failed: %s", stmt_res->ruby_stmt_err_msg );
5843
6082
  ret_val = Qfalse;
5844
6083
  } else {
5845
6084
  ret_val = INT2NUM( row_count_args->count );
@@ -6011,7 +6250,7 @@ VALUE ibm_db_field_display_size(int argc, VALUE *argv, VALUE self)
6011
6250
  ret_val = Qfalse;
6012
6251
  } else {
6013
6252
 
6014
- colattr_args = ALLOC_N( col_attr_args,sizeof(struct _ibm_db_col_attr_struct) );
6253
+ colattr_args = ALLOC( col_attr_args );
6015
6254
  memset( colattr_args,'\0',sizeof(struct _ibm_db_col_attr_struct) );
6016
6255
 
6017
6256
  colattr_args->stmt_res = stmt_res;
@@ -6357,7 +6596,7 @@ VALUE ibm_db_field_width(int argc, VALUE *argv, VALUE self)
6357
6596
  ret_val = Qfalse;
6358
6597
  } else {
6359
6598
 
6360
- colattr_args = ALLOC_N( col_attr_args,sizeof(struct _ibm_db_col_attr_struct) );
6599
+ colattr_args = ALLOC( col_attr_args );
6361
6600
  memset( colattr_args,'\0',sizeof(struct _ibm_db_col_attr_struct) );
6362
6601
 
6363
6602
  colattr_args->stmt_res = stmt_res;
@@ -6464,7 +6703,7 @@ VALUE ibm_db_rollback(int argc, VALUE *argv, VALUE self)
6464
6703
  return Qfalse;
6465
6704
  }
6466
6705
 
6467
- end_X_args = ALLOC_N(end_tran_args,sizeof(struct _ibm_db_end_tran_args_struct));
6706
+ end_X_args = ALLOC( end_tran_args );
6468
6707
  memset(end_X_args,'\0',sizeof(struct _ibm_db_end_tran_args_struct));
6469
6708
 
6470
6709
  end_X_args->hdbc = &(conn_res->hdbc);
@@ -6497,7 +6736,7 @@ VALUE ibm_db_rollback(int argc, VALUE *argv, VALUE self)
6497
6736
  /* */
6498
6737
 
6499
6738
  /*
6500
- * IBM_DB.free_stmt -- Frees resources associated with the indicated statement resource
6739
+ * IBM_DB.free_stmt -- Frees the indicated statement handle and any resources associated with it
6501
6740
  *
6502
6741
  * ===Description
6503
6742
  * bool IBM_DB.free_stmt ( resource stmt )
@@ -6514,10 +6753,22 @@ VALUE ibm_db_rollback(int argc, VALUE *argv, VALUE self)
6514
6753
  *
6515
6754
  * Returns TRUE on success or FALSE on failure.
6516
6755
  *
6517
- * ===DEPRECATED
6518
6756
  */
6519
6757
  VALUE ibm_db_free_stmt(int argc, VALUE *argv, VALUE self)
6520
6758
  {
6759
+ VALUE stmt = Qnil;
6760
+ stmt_handle *stmt_res = NULL;
6761
+
6762
+ rb_scan_args(argc, argv, "1", &stmt);
6763
+
6764
+ if (!NIL_P(stmt)) {
6765
+ Data_Get_Struct(stmt, stmt_handle, stmt_res);
6766
+
6767
+ _ruby_ibm_db_free_stmt_handle_and_resources( stmt_res );
6768
+
6769
+ } else {
6770
+ rb_warn("Statement resource passed for freeing is not valid");
6771
+ }
6521
6772
  return Qtrue;
6522
6773
  }
6523
6774
  /* */
@@ -6528,7 +6779,7 @@ static RETCODE _ruby_ibm_db_get_data(stmt_handle *stmt_res, int col_num, short c
6528
6779
  RETCODE rc = SQL_SUCCESS;
6529
6780
  get_data_args *getData_args;
6530
6781
 
6531
- getData_args = ALLOC_N(get_data_args, sizeof(struct _ibm_db_get_data_args_struct) );
6782
+ getData_args = ALLOC( get_data_args );
6532
6783
  memset(getData_args,'\0',sizeof(struct _ibm_db_get_data_args_struct));
6533
6784
 
6534
6785
  getData_args->stmt_res = stmt_res;
@@ -6565,16 +6816,16 @@ static RETCODE _ruby_ibm_db_get_length(stmt_handle* stmt_res, SQLUSMALLINT col_n
6565
6816
 
6566
6817
  if ( rc < SQL_SUCCESS ) {
6567
6818
  if( stmt_res->ruby_stmt_err_msg == NULL ) {
6568
- stmt_res->ruby_stmt_err_msg = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN );
6819
+ stmt_res->ruby_stmt_err_msg = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1 );
6569
6820
  }
6570
- memset( stmt_res->ruby_stmt_err_msg, '\0', DB2_MAX_ERR_MSG_LEN );
6821
+ memset( stmt_res->ruby_stmt_err_msg, '\0', DB2_MAX_ERR_MSG_LEN+1 );
6571
6822
 
6572
6823
  _ruby_ibm_db_check_sql_errors( stmt_res , DB_STMT, stmt_res->hdbc, SQL_HANDLE_DBC, rc, 0,
6573
6824
  stmt_res->ruby_stmt_err_msg, 1, 1, 0 );
6574
6825
  return SQL_ERROR;
6575
6826
  }
6576
6827
 
6577
- getLength_args = ALLOC_N(get_length_args, sizeof(struct _ibm_db_get_data_length_struct) );
6828
+ getLength_args = ALLOC( get_length_args );
6578
6829
  memset(getLength_args,'\0',sizeof(struct _ibm_db_get_data_length_struct));
6579
6830
 
6580
6831
  getLength_args->new_hstmt = &( new_hstmt);
@@ -6611,9 +6862,9 @@ static RETCODE _ruby_ibm_db_get_data2(stmt_handle *stmt_res, SQLUSMALLINT col_nu
6611
6862
 
6612
6863
  if ( rc < SQL_SUCCESS ) {
6613
6864
  if( stmt_res->ruby_stmt_err_msg == NULL ) {
6614
- stmt_res->ruby_stmt_err_msg = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN );
6865
+ stmt_res->ruby_stmt_err_msg = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN+1 );
6615
6866
  }
6616
- memset( stmt_res->ruby_stmt_err_msg, '\0', DB2_MAX_ERR_MSG_LEN );
6867
+ memset( stmt_res->ruby_stmt_err_msg, '\0', DB2_MAX_ERR_MSG_LEN+1 );
6617
6868
 
6618
6869
  _ruby_ibm_db_check_sql_errors( stmt_res , DB_STMT, stmt_res->hdbc, SQL_HANDLE_DBC, rc, 0,
6619
6870
  stmt_res->ruby_stmt_err_msg, 1, 1, 0 );
@@ -6621,7 +6872,7 @@ static RETCODE _ruby_ibm_db_get_data2(stmt_handle *stmt_res, SQLUSMALLINT col_nu
6621
6872
  return SQL_ERROR;
6622
6873
  }
6623
6874
 
6624
- getSubString_args = ALLOC_N(get_subString_args, sizeof(struct _ibm_db_get_data_subString_struct) );
6875
+ getSubString_args = ALLOC( get_subString_args );
6625
6876
  memset(getSubString_args,'\0', sizeof(struct _ibm_db_get_data_subString_struct) );
6626
6877
 
6627
6878
  getSubString_args->new_hstmt = &new_hstmt;
@@ -6698,17 +6949,17 @@ static VALUE _ruby_ibm_db_result_helper(ibm_db_result_args *data) {
6698
6949
  /* get column header info*/
6699
6950
  if ( stmt_res->column_info == NULL ) {
6700
6951
  if (_ruby_ibm_db_get_result_set_info(stmt_res)<0) {
6701
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
6702
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
6703
- sprintf(data->error, "Column information cannot be retrieved: %s", stmt_res->ruby_stmt_err_msg );
6952
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
6953
+ *(data->error) = rb_str_cat2(rb_str_new2("Column information cannot be retrieved: "), stmt_res->ruby_stmt_err_msg );
6954
+ } else {
6955
+ *(data->error) = rb_str_new2("Column information cannot be retrieved: <error message could not be retrieved>");
6956
+ }
6704
6957
  return Qnil;
6705
6958
  }
6706
6959
  }
6707
6960
 
6708
6961
  if(col_num < 0 || col_num >= stmt_res->num_columns) {
6709
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
6710
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
6711
- sprintf(data->error, "Column ordinal out of range" );
6962
+ *(data->error) = rb_str_new2("Column ordinal out of range" );
6712
6963
  return Qnil;
6713
6964
  }
6714
6965
 
@@ -6733,9 +6984,7 @@ static VALUE _ruby_ibm_db_result_helper(ibm_db_result_args *data) {
6733
6984
  in_length = stmt_res->column_info[col_num].size+1;
6734
6985
  out_ptr = (SQLPOINTER)ALLOC_N(char,in_length);
6735
6986
  if ( out_ptr == NULL ) {
6736
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
6737
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
6738
- sprintf(data->error, "Failed to Allocate Memory" );
6987
+ rb_warn( "Failed to Allocate Memory while trying to retrieve the result" );
6739
6988
  return Qnil;
6740
6989
  }
6741
6990
  rc = _ruby_ibm_db_get_data(stmt_res, col_num+1, SQL_C_CHAR, out_ptr, in_length, &out_length);
@@ -6748,6 +6997,7 @@ static VALUE _ruby_ibm_db_result_helper(ibm_db_result_args *data) {
6748
6997
  } else {
6749
6998
  return_value = rb_str_new2((char*)out_ptr);
6750
6999
  ruby_xfree( out_ptr );
7000
+ out_ptr = NULL;
6751
7001
  return return_value;
6752
7002
  }
6753
7003
  break;
@@ -6789,9 +7039,7 @@ static VALUE _ruby_ibm_db_result_helper(ibm_db_result_args *data) {
6789
7039
  }
6790
7040
  out_char_ptr = (char*)ALLOC_N(char,in_length+1);
6791
7041
  if ( out_char_ptr == NULL ) {
6792
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
6793
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
6794
- sprintf(data->error, "Failed to Allocate Memory for LOB Data" );
7042
+ rb_warn( "Failed to Allocate Memory for LOB Data" );
6795
7043
  return Qnil;
6796
7044
  }
6797
7045
  rc = _ruby_ibm_db_get_data2(stmt_res, col_num+1, SQL_C_CHAR, (void*)out_char_ptr, in_length, in_length+1, &out_length);
@@ -6799,7 +7047,11 @@ static VALUE _ruby_ibm_db_result_helper(ibm_db_result_args *data) {
6799
7047
  return Qfalse;
6800
7048
  }
6801
7049
 
6802
- return rb_str_new2(out_char_ptr);
7050
+ return_value = rb_str_new2(out_char_ptr);
7051
+ ruby_xfree( out_char_ptr );
7052
+ out_char_ptr = NULL;
7053
+
7054
+ return return_value;
6803
7055
  break;
6804
7056
 
6805
7057
  case SQL_BLOB:
@@ -6830,16 +7082,18 @@ static VALUE _ruby_ibm_db_result_helper(ibm_db_result_args *data) {
6830
7082
  case BINARY:
6831
7083
  out_ptr = (SQLPOINTER)ALLOC_N(char,in_length);
6832
7084
  if ( out_ptr == NULL ) {
6833
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
6834
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
6835
- sprintf(data->error, "Failed to Allocate Memory for LOB Data" );
7085
+ rb_warn( "Failed to Allocate Memory for LOB Data" );
6836
7086
  return Qnil;
6837
7087
  }
6838
7088
  rc = _ruby_ibm_db_get_data2(stmt_res, col_num+1, lob_bind_type, (char *)out_ptr, in_length, in_length, &out_length);
6839
7089
  if (rc == SQL_ERROR) {
6840
7090
  return Qfalse;
6841
7091
  }
6842
- return rb_str_new((char*)out_ptr,out_length);
7092
+ return_value = rb_str_new((char*)out_ptr,out_length);
7093
+ ruby_xfree( out_ptr );
7094
+ out_ptr = NULL;
7095
+
7096
+ return return_value;
6843
7097
  default:
6844
7098
  break;
6845
7099
  }
@@ -6855,16 +7109,18 @@ static VALUE _ruby_ibm_db_result_helper(ibm_db_result_args *data) {
6855
7109
  }
6856
7110
  out_ptr = (SQLPOINTER)ALLOC_N(char, in_length);
6857
7111
  if ( out_ptr == NULL ) {
6858
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
6859
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
6860
- sprintf(data->error, "Failed to Allocate Memory for LOB Data" );
7112
+ rb_warn( "Failed to Allocate Memory for LOB Data" );
6861
7113
  return Qnil;
6862
7114
  }
6863
7115
  rc = _ruby_ibm_db_get_data2(stmt_res, col_num+1, SQL_C_BINARY, (SQLPOINTER)out_ptr, in_length, in_length, &out_length);
6864
7116
  if (rc == SQL_ERROR) {
6865
7117
  return Qfalse;
6866
7118
  }
6867
- return rb_str_new((char*)out_ptr,out_length);
7119
+ return_value = rb_str_new((char*)out_ptr,out_length);
7120
+ ruby_xfree( out_ptr );
7121
+ out_ptr = NULL;
7122
+
7123
+ return return_value;
6868
7124
 
6869
7125
  default:
6870
7126
  break;
@@ -6900,14 +7156,14 @@ VALUE ibm_db_result(int argc, VALUE *argv, VALUE self)
6900
7156
  VALUE ret_val = Qfalse;
6901
7157
  VALUE stmt = Qnil;
6902
7158
 
6903
- char *error = NULL;
7159
+ VALUE error = Qnil;
6904
7160
 
6905
- result_args = ALLOC_N(ibm_db_result_args,sizeof(struct _ibm_db_result_args_struct));
7161
+ result_args = ALLOC( ibm_db_result_args );
6906
7162
  memset(result_args,'\0',sizeof(struct _ibm_db_result_args_struct));
6907
7163
 
6908
7164
  result_args->stmt_res = NULL;
6909
7165
  result_args->column = Qnil;
6910
- result_args->error = NULL;
7166
+ result_args->error = &error;
6911
7167
 
6912
7168
  rb_scan_args(argc, argv, "2", &stmt, &(result_args->column) );
6913
7169
 
@@ -6921,8 +7177,6 @@ VALUE ibm_db_result(int argc, VALUE *argv, VALUE self)
6921
7177
  ret_val = _ruby_ibm_db_result_helper( result_args );
6922
7178
  #endif
6923
7179
 
6924
- error = result_args->error;
6925
-
6926
7180
  } else {
6927
7181
  rb_warn("Invalid Statement resource specified");
6928
7182
  ret_val = Qnil;
@@ -6934,9 +7188,8 @@ VALUE ibm_db_result(int argc, VALUE *argv, VALUE self)
6934
7188
  result_args = NULL;
6935
7189
  }
6936
7190
 
6937
- if( error != NULL && ret_val == Qnil) {
6938
- rb_warn( error );
6939
- ruby_xfree( error );
7191
+ if( error != Qnil && ret_val == Qnil) {
7192
+ rb_warn( RSTRING_PTR(error) );
6940
7193
  ret_val = Qnil;
6941
7194
  }
6942
7195
 
@@ -6976,9 +7229,11 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
6976
7229
  /* get column header info*/
6977
7230
  if ( stmt_res->column_info == NULL ) {
6978
7231
  if (_ruby_ibm_db_get_result_set_info(stmt_res)<0) {
6979
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
6980
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
6981
- sprintf(data->error, "Column information cannot be retrieved: %s", stmt_res->ruby_stmt_err_msg );
7232
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
7233
+ *(data->error) = rb_str_cat2(rb_str_new2("Column information cannot be retrieved: "), stmt_res->ruby_stmt_err_msg );
7234
+ } else {
7235
+ *(data->error) = rb_str_new2("Column information cannot be retrieved: <error message could not be retrieved>");
7236
+ }
6982
7237
  return Qnil;
6983
7238
  }
6984
7239
  }
@@ -6987,16 +7242,18 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
6987
7242
  if ( stmt_res->row_data == NULL ) {
6988
7243
  rc = _ruby_ibm_db_bind_column_helper(stmt_res);
6989
7244
  if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO ) {
6990
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
6991
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
6992
- sprintf(data->error, "Column binding cannot be done: %s", stmt_res->ruby_stmt_err_msg );
7245
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
7246
+ *(data->error) = rb_str_cat2(rb_str_new2("Column binding cannot be done: "), stmt_res->ruby_stmt_err_msg );
7247
+ } else {
7248
+ *(data->error) = rb_str_new2("Column binding cannot be done: <error message could not be retrieved>");
7249
+ }
6993
7250
  return Qnil;
6994
7251
  }
6995
7252
  }
6996
7253
 
6997
7254
  /* check if row_number is present */
6998
7255
  if (data->arg_count == 2 && row_number > 0) {
6999
- fetch_args = ALLOC_N(fetch_data_args,sizeof(struct _ibm_db_fetch_data_struct));
7256
+ fetch_args = ALLOC( fetch_data_args );
7000
7257
  memset(fetch_args,'\0',sizeof(struct _ibm_db_fetch_data_struct));
7001
7258
 
7002
7259
  fetch_args->stmt_res = stmt_res;
@@ -7034,13 +7291,11 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
7034
7291
  }
7035
7292
  #endif /*PASE*/
7036
7293
  } else if (data->arg_count == 2 && row_number < 0) {
7037
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
7038
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
7039
- sprintf(data->error, "Requested row number must be a positive value");
7294
+ *(data->error) = rb_str_new2("Requested row number must be a positive value");
7040
7295
  return Qnil;
7041
7296
  } else {
7042
7297
  /*row_number is NULL or 0; just fetch next row*/
7043
- fetch_args = ALLOC_N(fetch_data_args,sizeof(struct _ibm_db_fetch_data_struct));
7298
+ fetch_args = ALLOC( fetch_data_args );
7044
7299
  memset(fetch_args,'\0',sizeof(struct _ibm_db_fetch_data_struct));
7045
7300
 
7046
7301
  fetch_args->stmt_res = stmt_res;
@@ -7058,9 +7313,11 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
7058
7313
  return Qfalse;
7059
7314
  } else if ( rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
7060
7315
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 0 );
7061
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
7062
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
7063
- sprintf(data->error, "Fetch Failure: %s", stmt_res->ruby_stmt_err_msg );
7316
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
7317
+ *(data->error) = rb_str_cat2(rb_str_new2("Fetch Failure: "), stmt_res->ruby_stmt_err_msg );
7318
+ } else {
7319
+ *(data->error) = rb_str_new2("Fetch Failure: <error message could not be retrieved>");
7320
+ }
7064
7321
  return Qnil;
7065
7322
  }
7066
7323
  /* copy the data over return_value */
@@ -7077,10 +7334,10 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
7077
7334
 
7078
7335
  switch(stmt_res->s_case_mode) {
7079
7336
  case CASE_LOWER:
7080
- stmt_res->column_info[i].name = (SQLCHAR*)strtolower((char*)stmt_res->column_info[i].name, strlen((char*)stmt_res->column_info[i].name));
7337
+ strtolower((char*)stmt_res->column_info[i].name, strlen((char*)stmt_res->column_info[i].name));
7081
7338
  break;
7082
7339
  case CASE_UPPER:
7083
- stmt_res->column_info[i].name = (SQLCHAR*)strtoupper((char*)stmt_res->column_info[i].name, strlen((char*)stmt_res->column_info[i].name));
7340
+ strtoupper((char*)stmt_res->column_info[i].name, strlen((char*)stmt_res->column_info[i].name));
7084
7341
  break;
7085
7342
  case CASE_NATURAL:
7086
7343
  default:
@@ -7105,20 +7362,18 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
7105
7362
  /* i5/OS will xlate from EBCIDIC to ASCII (via SQLGetData) */
7106
7363
  tmp_length = stmt_res->column_info[i].size;
7107
7364
  out_ptr = (SQLPOINTER)ALLOC_N(char, tmp_length+1);
7108
- memset(out_ptr,0,tmp_length+1);
7109
7365
  if ( out_ptr == NULL ) {
7110
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
7111
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
7112
- sprintf(data->error, "Failed to allocate Memory");
7366
+ rb_warn( "Failed to allocate Memory");
7113
7367
  return Qnil;
7114
7368
  }
7369
+ memset(out_ptr,'\0',tmp_length+1);
7115
7370
  rc = _ruby_ibm_db_get_data(stmt_res, i+1, SQL_C_CHAR, out_ptr, tmp_length+1, &out_length);
7116
7371
  if ( rc == SQL_ERROR ) {
7117
7372
  ruby_xfree( out_ptr );
7373
+ out_ptr = NULL;
7118
7374
  return Qfalse;
7119
7375
  }
7120
7376
  if (out_length == SQL_NULL_DATA) {
7121
- ruby_xfree( out_ptr );
7122
7377
  if ( op & FETCH_ASSOC ) {
7123
7378
  rb_hash_aset(return_value, rb_str_new2((char*)stmt_res->column_info[i].name), Qnil);
7124
7379
  }
@@ -7134,6 +7389,8 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
7134
7389
  rb_ary_store(return_value, i, rb_str_new2((char *)out_ptr));
7135
7390
  }
7136
7391
  }
7392
+ ruby_xfree( out_ptr );
7393
+ out_ptr = NULL;
7137
7394
  break;
7138
7395
  #endif /* PASE */
7139
7396
  case SQL_TYPE_DATE:
@@ -7268,7 +7525,9 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
7268
7525
  rc = _ruby_ibm_db_get_data2(stmt_res, i+1, lob_bind_type, (char *)out_ptr, tmp_length, tmp_length, &out_length);
7269
7526
  if (rc == SQL_ERROR) {
7270
7527
  ruby_xfree( out_ptr );
7528
+ out_ptr = NULL;
7271
7529
  out_length = 0;
7530
+ return Qfalse;
7272
7531
  }
7273
7532
 
7274
7533
  if ( op & FETCH_ASSOC ) {
@@ -7279,6 +7538,10 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
7279
7538
  } else if ( op == FETCH_BOTH ) {
7280
7539
  rb_hash_aset(return_value, INT2NUM(i), rb_str_new((char*)out_ptr, out_length));
7281
7540
  }
7541
+
7542
+ ruby_xfree( out_ptr );
7543
+ out_ptr = NULL;
7544
+ out_length = 0;
7282
7545
  break;
7283
7546
  default:
7284
7547
  break;
@@ -7299,9 +7562,11 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
7299
7562
  rc = _ruby_ibm_db_get_data(stmt_res, i+1, SQL_C_BINARY, NULL, 0, (SQLINTEGER *)&tmp_length);
7300
7563
 
7301
7564
  if ( rc == SQL_ERROR ) {
7302
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
7303
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
7304
- sprintf(data->error, "Failed to Determine XML Size: %s", stmt_res->ruby_stmt_err_msg );
7565
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
7566
+ *(data->error) = rb_str_cat2(rb_str_new2("Failed to Determine XML Size: "), stmt_res->ruby_stmt_err_msg );
7567
+ } else {
7568
+ *(data->error) = rb_str_new2("Failed to Determine XML Size: <error message could not be retrieved>");
7569
+ }
7305
7570
  return Qnil;
7306
7571
  }
7307
7572
 
@@ -7318,14 +7583,13 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
7318
7583
  out_ptr = (SQLPOINTER)ALLOC_N(char, tmp_length);
7319
7584
 
7320
7585
  if ( out_ptr == NULL ) {
7321
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
7322
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
7323
- sprintf(data->error,"Failed to Allocate Memory for XML Data");
7586
+ rb_warn( "Failed to Allocate Memory for XML Data" );
7324
7587
  return Qnil;
7325
7588
  }
7326
7589
  rc = _ruby_ibm_db_get_data(stmt_res, i+1, SQL_C_BINARY, out_ptr, tmp_length, &out_length);
7327
7590
  if (rc == SQL_ERROR) {
7328
7591
  ruby_xfree( out_ptr );
7592
+ out_ptr = NULL;
7329
7593
  return Qfalse;
7330
7594
  }
7331
7595
 
@@ -7337,6 +7601,8 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
7337
7601
  } else if ( op == FETCH_BOTH ) {
7338
7602
  rb_hash_aset(return_value, INT2NUM(i), rb_str_new((char *)out_ptr, out_length));
7339
7603
  }
7604
+ ruby_xfree( out_ptr );
7605
+ out_ptr = NULL;
7340
7606
  }
7341
7607
  break;
7342
7608
 
@@ -7365,16 +7631,16 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
7365
7631
  out_ptr = (SQLPOINTER)ALLOC_N(char, tmp_length+1);
7366
7632
 
7367
7633
  if ( out_ptr == NULL ) {
7368
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
7369
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
7370
- sprintf(data->error,"Failed to Allocate Memory for LOB Data");
7634
+ rb_warn( "Failed to Allocate Memory for LOB Data" );
7371
7635
  return Qnil;
7372
7636
  }
7373
7637
 
7374
7638
  rc = _ruby_ibm_db_get_data2(stmt_res, i+1, SQL_C_CHAR, out_ptr, tmp_length, tmp_length+1, &out_length);
7375
7639
  if (rc == SQL_ERROR) {
7376
7640
  ruby_xfree( out_ptr );
7641
+ out_ptr = NULL;
7377
7642
  out_length = 0;
7643
+ return Qfalse;
7378
7644
  } else {
7379
7645
  out_ptr[tmp_length] = '\0';
7380
7646
  }
@@ -7387,6 +7653,8 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
7387
7653
  } else if ( op == FETCH_BOTH ) {
7388
7654
  rb_hash_aset(return_value, INT2NUM(i), rb_str_new((char*)out_ptr, out_length));
7389
7655
  }
7656
+ ruby_xfree( out_ptr );
7657
+ out_ptr = NULL;
7390
7658
  }
7391
7659
  break;
7392
7660
 
@@ -7418,14 +7686,16 @@ static int _ruby_ibm_db_fetch_row_helper( ibm_db_fetch_helper_args *data) {
7418
7686
  /* get column header info*/
7419
7687
  if ( stmt_res->column_info == NULL ) {
7420
7688
  if (_ruby_ibm_db_get_result_set_info(stmt_res)<0) {
7421
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
7422
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
7423
- sprintf(data->error, "Column information cannot be retrieved: %s", stmt_res->ruby_stmt_err_msg );
7689
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
7690
+ *(data->error) = rb_str_cat2(rb_str_new2("Column information cannot be retrieved: "), stmt_res->ruby_stmt_err_msg );
7691
+ } else {
7692
+ *(data->error) = rb_str_new2("Column information cannot be retrieved: <error message could not be retrieved>");
7693
+ }
7424
7694
  return Qnil;
7425
7695
  }
7426
7696
  }
7427
7697
 
7428
- fetch_args = ALLOC_N(fetch_data_args,sizeof(struct _ibm_db_fetch_data_struct));
7698
+ fetch_args = ALLOC( fetch_data_args );
7429
7699
  memset(fetch_args,'\0',sizeof(struct _ibm_db_fetch_data_struct));
7430
7700
 
7431
7701
  fetch_args->stmt_res = stmt_res;
@@ -7452,9 +7722,7 @@ static int _ruby_ibm_db_fetch_row_helper( ibm_db_fetch_helper_args *data) {
7452
7722
  }
7453
7723
  #endif /*PASE*/
7454
7724
  } else if (data->arg_count == 2 && row_number < 0) {
7455
- data->error = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN + 30 );
7456
- memset(data->error, '\0', DB2_MAX_ERR_MSG_LEN + 30 );
7457
- sprintf(data->error, "Requested row number must be a positive value");
7725
+ *(data->error) = rb_str_new2("Requested row number must be a positive value");
7458
7726
  return Qnil;
7459
7727
  } else {
7460
7728
  /*row_number is NULL or 0; just fetch next row*/
@@ -7513,11 +7781,9 @@ VALUE ibm_db_fetch_row(int argc, VALUE *argv, VALUE self)
7513
7781
  VALUE stmt = Qnil;
7514
7782
  VALUE ret_val = Qnil;
7515
7783
 
7516
- char *error = NULL;
7784
+ VALUE error = Qnil;
7517
7785
  stmt_handle *stmt_res = NULL;
7518
7786
 
7519
- char diagnose_msg[DB2_MAX_ERR_MSG_LEN + 30];
7520
-
7521
7787
  ibm_db_fetch_helper_args *helper_args = NULL;
7522
7788
 
7523
7789
  rb_scan_args(argc, argv, "11", &stmt, &row_number);
@@ -7529,13 +7795,13 @@ VALUE ibm_db_fetch_row(int argc, VALUE *argv, VALUE self)
7529
7795
  return Qfalse;
7530
7796
  }
7531
7797
 
7532
- helper_args = ALLOC_N(ibm_db_fetch_helper_args,sizeof(struct _ibm_db_fetch_helper_struct));
7798
+ helper_args = ALLOC( ibm_db_fetch_helper_args );
7533
7799
  memset(helper_args,'\0',sizeof(struct _ibm_db_fetch_helper_struct));
7534
7800
 
7535
7801
  helper_args->stmt_res = stmt_res;
7536
7802
  helper_args->row_number = row_number;
7537
7803
  helper_args->arg_count = argc;
7538
- helper_args->error = NULL;
7804
+ helper_args->error = &error;
7539
7805
 
7540
7806
  #ifdef GIL_RELEASE_VERSION
7541
7807
  ret_val = rb_thread_blocking_region( (void *)_ruby_ibm_db_fetch_row_helper, helper_args,
@@ -7544,18 +7810,14 @@ VALUE ibm_db_fetch_row(int argc, VALUE *argv, VALUE self)
7544
7810
  ret_val = _ruby_ibm_db_fetch_row_helper( helper_args );
7545
7811
  #endif
7546
7812
 
7547
- error = helper_args->error;
7548
-
7549
7813
  /*Free Memory Allocated*/
7550
7814
  if ( helper_args != NULL) {
7551
7815
  ruby_xfree( helper_args );
7552
7816
  helper_args = NULL;
7553
7817
  }
7554
7818
 
7555
- if( error != NULL && ret_val == Qnil ) {
7556
- sprintf(diagnose_msg, "%s", error );
7557
- ruby_xfree( error );
7558
- rb_throw(diagnose_msg,Qnil);
7819
+ if( error != Qnil && ret_val == Qnil ) {
7820
+ rb_throw( RSTRING_PTR(error),Qnil );
7559
7821
  }
7560
7822
 
7561
7823
  return ret_val;
@@ -7590,8 +7852,7 @@ VALUE ibm_db_fetch_assoc(int argc, VALUE *argv, VALUE self) {
7590
7852
  VALUE stmt = Qnil;
7591
7853
  VALUE ret_val = Qnil;
7592
7854
 
7593
- char *error = NULL;
7594
- char diagnose_msg[DB2_MAX_ERR_MSG_LEN + 30];
7855
+ VALUE error = Qnil;
7595
7856
 
7596
7857
  stmt_handle *stmt_res = NULL;
7597
7858
 
@@ -7606,13 +7867,13 @@ VALUE ibm_db_fetch_assoc(int argc, VALUE *argv, VALUE self) {
7606
7867
  return Qfalse;
7607
7868
  }
7608
7869
 
7609
- helper_args = ALLOC_N(ibm_db_fetch_helper_args,sizeof(struct _ibm_db_fetch_helper_struct));
7870
+ helper_args = ALLOC( ibm_db_fetch_helper_args );
7610
7871
  memset(helper_args,'\0',sizeof(struct _ibm_db_fetch_helper_struct));
7611
7872
 
7612
7873
  helper_args->stmt_res = stmt_res;
7613
7874
  helper_args->row_number = row_number;
7614
7875
  helper_args->arg_count = argc;
7615
- helper_args->error = NULL;
7876
+ helper_args->error = &error;
7616
7877
  helper_args->funcType = FETCH_ASSOC;
7617
7878
 
7618
7879
  #ifdef GIL_RELEASE_VERSION
@@ -7622,18 +7883,14 @@ VALUE ibm_db_fetch_assoc(int argc, VALUE *argv, VALUE self) {
7622
7883
  ret_val = _ruby_ibm_db_bind_fetch_helper( helper_args );
7623
7884
  #endif
7624
7885
 
7625
- error = helper_args->error;
7626
-
7627
7886
  /*Free Memory Allocated*/
7628
7887
  if ( helper_args != NULL) {
7629
7888
  ruby_xfree( helper_args );
7630
7889
  helper_args = NULL;
7631
7890
  }
7632
7891
 
7633
- if( error != NULL && ret_val == Qnil ) {
7634
- sprintf(diagnose_msg, "%s", error );
7635
- ruby_xfree( error );
7636
- rb_throw( error, Qnil );
7892
+ if( error != Qnil && ret_val == Qnil ) {
7893
+ rb_throw( RSTRING_PTR(error), Qnil );
7637
7894
  }
7638
7895
 
7639
7896
  return ret_val;
@@ -7674,12 +7931,11 @@ VALUE ibm_db_fetch_assoc(int argc, VALUE *argv, VALUE self) {
7674
7931
  */
7675
7932
  VALUE ibm_db_fetch_object(int argc, VALUE *argv, VALUE self)
7676
7933
  {
7677
- VALUE row_number = Qnil;
7678
- VALUE stmt = Qnil;
7679
- VALUE ret_val = Qnil;
7934
+ VALUE row_number = Qnil;
7935
+ VALUE stmt = Qnil;
7936
+ VALUE ret_val = Qnil;
7680
7937
 
7681
- char *error = NULL;
7682
- char diagnose_msg[DB2_MAX_ERR_MSG_LEN + 30];
7938
+ VALUE error = Qnil;
7683
7939
 
7684
7940
  stmt_handle *stmt_res = NULL;
7685
7941
 
@@ -7698,13 +7954,13 @@ VALUE ibm_db_fetch_object(int argc, VALUE *argv, VALUE self)
7698
7954
 
7699
7955
  row_res = ALLOC(row_hash_struct);
7700
7956
 
7701
- helper_args = ALLOC_N(ibm_db_fetch_helper_args,sizeof(struct _ibm_db_fetch_helper_struct));
7957
+ helper_args = ALLOC( ibm_db_fetch_helper_args );
7702
7958
  memset(helper_args,'\0',sizeof(struct _ibm_db_fetch_helper_struct));
7703
7959
 
7704
7960
  helper_args->stmt_res = stmt_res;
7705
7961
  helper_args->row_number = row_number;
7706
7962
  helper_args->arg_count = argc;
7707
- helper_args->error = NULL;
7963
+ helper_args->error = &error;
7708
7964
  helper_args->funcType = FETCH_ASSOC;
7709
7965
 
7710
7966
  #ifdef GIL_RELEASE_VERSION
@@ -7714,18 +7970,14 @@ VALUE ibm_db_fetch_object(int argc, VALUE *argv, VALUE self)
7714
7970
  row_res->hash = _ruby_ibm_db_bind_fetch_helper( helper_args );
7715
7971
  #endif
7716
7972
 
7717
- error = helper_args->error;
7718
-
7719
7973
  /*Free Memory Allocated*/
7720
7974
  if ( helper_args != NULL) {
7721
7975
  ruby_xfree( helper_args );
7722
7976
  helper_args = NULL;
7723
7977
  }
7724
7978
 
7725
- if( error != NULL && ret_val == Qnil ) {
7726
- sprintf(diagnose_msg, "%s", error );
7727
- ruby_xfree( error );
7728
- rb_throw( error, Qnil );
7979
+ if( error != Qnil && ret_val == Qnil ) {
7980
+ rb_throw( RSTRING_PTR(error), Qnil );
7729
7981
  }
7730
7982
 
7731
7983
  if (RTEST(row_res->hash)) {
@@ -7734,6 +7986,7 @@ VALUE ibm_db_fetch_object(int argc, VALUE *argv, VALUE self)
7734
7986
  row_res);
7735
7987
  } else {
7736
7988
  ruby_xfree( row_res );
7989
+ row_res = NULL;
7737
7990
  return Qfalse;
7738
7991
  }
7739
7992
  }
@@ -7769,11 +8022,9 @@ VALUE ibm_db_fetch_array(int argc, VALUE *argv, VALUE self)
7769
8022
  VALUE stmt = Qnil;
7770
8023
  VALUE ret_val = Qnil;
7771
8024
 
7772
- char *error = NULL;
8025
+ VALUE error = Qnil;
7773
8026
  stmt_handle *stmt_res = NULL;
7774
8027
 
7775
- char diagnose_msg[DB2_MAX_ERR_MSG_LEN + 30];
7776
-
7777
8028
  ibm_db_fetch_helper_args *helper_args = NULL;
7778
8029
 
7779
8030
  rb_scan_args(argc, argv, "11", &stmt, &row_number);
@@ -7785,13 +8036,13 @@ VALUE ibm_db_fetch_array(int argc, VALUE *argv, VALUE self)
7785
8036
  return Qfalse;
7786
8037
  }
7787
8038
 
7788
- helper_args = ALLOC_N(ibm_db_fetch_helper_args,sizeof(struct _ibm_db_fetch_helper_struct));
8039
+ helper_args = ALLOC( ibm_db_fetch_helper_args );
7789
8040
  memset(helper_args,'\0',sizeof(struct _ibm_db_fetch_helper_struct));
7790
8041
 
7791
8042
  helper_args->stmt_res = stmt_res;
7792
8043
  helper_args->row_number = row_number;
7793
8044
  helper_args->arg_count = argc;
7794
- helper_args->error = NULL;
8045
+ helper_args->error = &error;
7795
8046
  helper_args->funcType = FETCH_INDEX;
7796
8047
 
7797
8048
  #ifdef GIL_RELEASE_VERSION
@@ -7801,18 +8052,14 @@ VALUE ibm_db_fetch_array(int argc, VALUE *argv, VALUE self)
7801
8052
  ret_val = _ruby_ibm_db_bind_fetch_helper( helper_args );
7802
8053
  #endif
7803
8054
 
7804
- error = helper_args->error;
7805
-
7806
8055
  /*Free Memory Allocated*/
7807
8056
  if ( helper_args != NULL) {
7808
8057
  ruby_xfree( helper_args );
7809
8058
  helper_args = NULL;
7810
8059
  }
7811
8060
 
7812
- if( error != NULL && ret_val == Qnil ) {
7813
- sprintf(diagnose_msg, "%s", error );
7814
- ruby_xfree( error );
7815
- rb_throw( error, Qnil );
8061
+ if( error != Qnil && ret_val == Qnil ) {
8062
+ rb_throw( RSTRING_PTR(error), Qnil );
7816
8063
  }
7817
8064
 
7818
8065
  return ret_val;
@@ -7851,11 +8098,9 @@ VALUE ibm_db_fetch_both(int argc, VALUE *argv, VALUE self)
7851
8098
  VALUE stmt = Qnil;
7852
8099
  VALUE ret_val = Qnil;
7853
8100
 
7854
- char *error = NULL;
8101
+ VALUE error = Qnil;
7855
8102
  stmt_handle *stmt_res = NULL;
7856
8103
 
7857
- char diagnose_msg[DB2_MAX_ERR_MSG_LEN + 30];
7858
-
7859
8104
  ibm_db_fetch_helper_args *helper_args = NULL;
7860
8105
 
7861
8106
  rb_scan_args(argc, argv, "11", &stmt, &row_number);
@@ -7867,13 +8112,13 @@ VALUE ibm_db_fetch_both(int argc, VALUE *argv, VALUE self)
7867
8112
  return Qfalse;
7868
8113
  }
7869
8114
 
7870
- helper_args = ALLOC_N(ibm_db_fetch_helper_args,sizeof(struct _ibm_db_fetch_helper_struct));
8115
+ helper_args = ALLOC( ibm_db_fetch_helper_args );
7871
8116
  memset(helper_args,'\0',sizeof(struct _ibm_db_fetch_helper_struct));
7872
8117
 
7873
8118
  helper_args->stmt_res = stmt_res;
7874
8119
  helper_args->row_number = row_number;
7875
8120
  helper_args->arg_count = argc;
7876
- helper_args->error = NULL;
8121
+ helper_args->error = &error;
7877
8122
  helper_args->funcType = FETCH_BOTH;
7878
8123
 
7879
8124
  #ifdef GIL_RELEASE_VERSION
@@ -7883,18 +8128,14 @@ VALUE ibm_db_fetch_both(int argc, VALUE *argv, VALUE self)
7883
8128
  ret_val = _ruby_ibm_db_bind_fetch_helper( helper_args );
7884
8129
  #endif
7885
8130
 
7886
- error = helper_args->error;
7887
-
7888
8131
  /*Free Memory Allocated*/
7889
8132
  if ( helper_args != NULL) {
7890
8133
  ruby_xfree( helper_args );
7891
8134
  helper_args = NULL;
7892
8135
  }
7893
8136
 
7894
- if( error != NULL && ret_val == Qnil ) {
7895
- sprintf(diagnose_msg, "%s", error );
7896
- ruby_xfree( error );
7897
- rb_throw( error, Qnil );
8137
+ if( error != Qnil && ret_val == Qnil ) {
8138
+ rb_throw( RSTRING_PTR(error), Qnil );
7898
8139
  }
7899
8140
 
7900
8141
  return ret_val;
@@ -7936,7 +8177,7 @@ VALUE ibm_db_set_option(int argc, VALUE *argv, VALUE self)
7936
8177
  int rc = 0;
7937
8178
  long type = 0;
7938
8179
 
7939
- char error[DB2_MAX_ERR_MSG_LEN];
8180
+ VALUE error = Qnil;
7940
8181
 
7941
8182
  rb_scan_args(argc, argv, "3", &conn_or_stmt, &r_options, &r_type);
7942
8183
 
@@ -7947,9 +8188,9 @@ VALUE ibm_db_set_option(int argc, VALUE *argv, VALUE self)
7947
8188
  Data_Get_Struct(conn_or_stmt, conn_handle, conn_res);
7948
8189
 
7949
8190
  if ( !NIL_P(r_options) ) {
7950
- rc = _ruby_ibm_db_parse_options( r_options, SQL_HANDLE_DBC, conn_res, error );
8191
+ rc = _ruby_ibm_db_parse_options( r_options, SQL_HANDLE_DBC, conn_res, &error );
7951
8192
  if (rc == SQL_ERROR) {
7952
- rb_warn( error );
8193
+ rb_warn( RSTRING_PTR(error) );
7953
8194
  return Qfalse;
7954
8195
  }
7955
8196
  }
@@ -7957,9 +8198,9 @@ VALUE ibm_db_set_option(int argc, VALUE *argv, VALUE self)
7957
8198
  Data_Get_Struct( conn_or_stmt, stmt_handle, stmt_res );
7958
8199
 
7959
8200
  if ( !NIL_P(r_options) ) {
7960
- rc = _ruby_ibm_db_parse_options( r_options, SQL_HANDLE_STMT, stmt_res, error );
8201
+ rc = _ruby_ibm_db_parse_options( r_options, SQL_HANDLE_STMT, stmt_res, &error );
7961
8202
  if (rc == SQL_ERROR) {
7962
- rb_warn( error );
8203
+ rb_warn( RSTRING_PTR(error) );
7963
8204
  return Qfalse;
7964
8205
  }
7965
8206
  }
@@ -7994,12 +8235,11 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
7994
8235
  getInfo_args->infoValue = (SQLPOINTER)buffer255;
7995
8236
  getInfo_args->buff_length = sizeof( buffer255 );
7996
8237
 
7997
- memset(buffer255, 0, sizeof(buffer255));
8238
+ memset(buffer255, '\0', sizeof(buffer255));
7998
8239
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
7999
8240
 
8000
8241
  if ( rc == SQL_ERROR ) {
8001
8242
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8002
- ruby_xfree( getInfo_args );
8003
8243
  return Qfalse;
8004
8244
  } else {
8005
8245
  rb_iv_set(return_value, "@DBMS_NAME", rb_str_new2(buffer255));
@@ -8010,12 +8250,11 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8010
8250
  getInfo_args->infoValue = (SQLPOINTER)buffer11;
8011
8251
  getInfo_args->buff_length = sizeof( buffer11 );
8012
8252
 
8013
- memset(buffer11, 0, sizeof(buffer11));
8253
+ memset(buffer11, '\0', sizeof(buffer11));
8014
8254
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8015
8255
 
8016
8256
  if ( rc == SQL_ERROR ) {
8017
8257
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8018
- ruby_xfree( getInfo_args );
8019
8258
  return Qfalse;
8020
8259
  } else {
8021
8260
  rb_iv_set(return_value, "@DBMS_VER", rb_str_new2(buffer11));
@@ -8033,7 +8272,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8033
8272
 
8034
8273
  if ( rc == SQL_ERROR ) {
8035
8274
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8036
- ruby_xfree( getInfo_args );
8037
8275
  return Qfalse;
8038
8276
  } else {
8039
8277
  rb_iv_set(return_value, "@DB_CODEPAGE", INT2NUM(bufferint32));
@@ -8045,12 +8283,11 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8045
8283
  getInfo_args->infoValue = (SQLPOINTER)buffer255;
8046
8284
  getInfo_args->buff_length = sizeof( buffer255 );
8047
8285
 
8048
- memset(buffer255, 0, sizeof(buffer255));
8286
+ memset(buffer255, '\0', sizeof(buffer255));
8049
8287
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8050
8288
 
8051
8289
  if ( rc == SQL_ERROR ) {
8052
8290
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8053
- ruby_xfree( getInfo_args );
8054
8291
  return Qfalse;
8055
8292
  } else {
8056
8293
  rb_iv_set(return_value, "@DB_NAME", rb_str_new2(buffer255));
@@ -8062,12 +8299,11 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8062
8299
  getInfo_args->infoValue = (SQLPOINTER)buffer255;
8063
8300
  getInfo_args->buff_length = sizeof( buffer255 );
8064
8301
 
8065
- memset(buffer255, 0, sizeof(buffer255));
8302
+ memset(buffer255, '\0', sizeof(buffer255));
8066
8303
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8067
8304
 
8068
8305
  if ( rc == SQL_ERROR ) {
8069
8306
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8070
- ruby_xfree( getInfo_args );
8071
8307
  return Qfalse;
8072
8308
  } else {
8073
8309
  rb_iv_set(return_value, "@INST_NAME", rb_str_new2(buffer255));
@@ -8078,12 +8314,11 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8078
8314
  getInfo_args->infoValue = (SQLPOINTER)buffer255;
8079
8315
  getInfo_args->buff_length = sizeof( buffer255 );
8080
8316
 
8081
- memset(buffer255, 0, sizeof(buffer255));
8317
+ memset(buffer255, '\0', sizeof(buffer255));
8082
8318
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8083
8319
 
8084
8320
  if ( rc == SQL_ERROR ) {
8085
8321
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8086
- ruby_xfree( getInfo_args );
8087
8322
  return Qfalse;
8088
8323
  } else {
8089
8324
  rb_iv_set(return_value, "@SPECIAL_CHARS", rb_str_new2(buffer255));
@@ -8095,12 +8330,11 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8095
8330
  getInfo_args->infoValue = (SQLPOINTER)buffer2k;
8096
8331
  getInfo_args->buff_length = sizeof( buffer2k );
8097
8332
 
8098
- memset(buffer2k, 0, sizeof(buffer2k));
8333
+ memset(buffer2k, '\0', sizeof(buffer2k));
8099
8334
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8100
8335
 
8101
8336
  if ( rc == SQL_ERROR ) {
8102
8337
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8103
- ruby_xfree( getInfo_args );
8104
8338
  return Qfalse;
8105
8339
  } else {
8106
8340
  char *keyword, *last;
@@ -8130,7 +8364,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8130
8364
 
8131
8365
  if ( rc == SQL_ERROR ) {
8132
8366
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8133
- ruby_xfree( getInfo_args );
8134
8367
  return Qfalse;
8135
8368
  } else {
8136
8369
  if( bitmask & SQL_TXN_READ_UNCOMMITTED ) {
@@ -8163,7 +8396,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8163
8396
 
8164
8397
  if ( rc == SQL_ERROR ) {
8165
8398
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8166
- ruby_xfree( getInfo_args );
8167
8399
  return Qfalse;
8168
8400
  } else {
8169
8401
  VALUE array;
@@ -8200,7 +8432,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8200
8432
 
8201
8433
  if ( rc == SQL_ERROR ) {
8202
8434
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8203
- ruby_xfree( getInfo_args);
8204
8435
  return Qfalse;
8205
8436
  } else {
8206
8437
  switch (bufferint32) {
@@ -8227,12 +8458,11 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8227
8458
  getInfo_args->infoValue = (SQLPOINTER)buffer11;
8228
8459
  getInfo_args->buff_length = sizeof( buffer11 );
8229
8460
 
8230
- memset(buffer11, 0, sizeof(buffer11));
8461
+ memset(buffer11, '\0', sizeof(buffer11));
8231
8462
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8232
8463
 
8233
8464
  if ( rc == SQL_ERROR ) {
8234
8465
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8235
- ruby_xfree( getInfo_args );
8236
8466
  return Qfalse;
8237
8467
  } else {
8238
8468
  if( strcmp((char *)buffer11, "Y") == 0 ) {
@@ -8247,12 +8477,11 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8247
8477
  getInfo_args->infoValue = (SQLPOINTER)buffer11;
8248
8478
  getInfo_args->buff_length = sizeof( buffer11 );
8249
8479
 
8250
- memset(buffer11, 0, sizeof(buffer11));
8480
+ memset(buffer11, '\0', sizeof(buffer11));
8251
8481
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8252
8482
 
8253
8483
  if ( rc == SQL_ERROR ) {
8254
8484
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8255
- ruby_xfree( getInfo_args );
8256
8485
  return Qfalse;
8257
8486
  } else {
8258
8487
  rb_iv_set(return_value, "@IDENTIFIER_QUOTE_CHAR", rb_str_new2(buffer11));
@@ -8263,12 +8492,11 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8263
8492
  getInfo_args->infoValue = (SQLPOINTER)buffer11;
8264
8493
  getInfo_args->buff_length = sizeof( buffer11 );
8265
8494
 
8266
- memset(buffer11, 0, sizeof(buffer11));
8495
+ memset(buffer11, '\0', sizeof(buffer11));
8267
8496
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8268
8497
 
8269
8498
  if ( rc == SQL_ERROR ) {
8270
8499
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8271
- ruby_xfree( getInfo_args );
8272
8500
  return Qfalse;
8273
8501
  } else {
8274
8502
  if( strcmp(buffer11, "Y") == 0 ) {
@@ -8288,7 +8516,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8288
8516
 
8289
8517
  if ( rc == SQL_ERROR ) {
8290
8518
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8291
- ruby_xfree( getInfo_args );
8292
8519
  return Qfalse;
8293
8520
  } else {
8294
8521
  rb_iv_set(return_value, "@MAX_COL_NAME_LEN", INT2NUM(bufferint16));
@@ -8304,7 +8531,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8304
8531
 
8305
8532
  if ( rc == SQL_ERROR ) {
8306
8533
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8307
- ruby_xfree( getInfo_args );
8308
8534
  return Qfalse;
8309
8535
  } else {
8310
8536
  rb_iv_set(return_value, "@MAX_ROW_SIZE", INT2NUM(bufferint32));
@@ -8321,7 +8547,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8321
8547
 
8322
8548
  if ( rc == SQL_ERROR ) {
8323
8549
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8324
- ruby_xfree( getInfo_args );
8325
8550
  return Qfalse;
8326
8551
  } else {
8327
8552
  rb_iv_set(return_value, "@MAX_IDENTIFIER_LEN", INT2NUM(bufferint16));
@@ -8337,7 +8562,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8337
8562
 
8338
8563
  if ( rc == SQL_ERROR ) {
8339
8564
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8340
- ruby_xfree( getInfo_args );
8341
8565
  return Qfalse;
8342
8566
  } else {
8343
8567
  rb_iv_set(return_value, "@MAX_INDEX_SIZE", INT2NUM(bufferint32));
@@ -8353,7 +8577,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8353
8577
 
8354
8578
  if ( rc == SQL_ERROR ) {
8355
8579
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8356
- ruby_xfree( getInfo_args );
8357
8580
  return Qfalse;
8358
8581
  } else {
8359
8582
  rb_iv_set(return_value, "@MAX_PROC_NAME_LEN", INT2NUM(bufferint16));
@@ -8369,7 +8592,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8369
8592
 
8370
8593
  if ( rc == SQL_ERROR ) {
8371
8594
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8372
- ruby_xfree( getInfo_args );
8373
8595
  return Qfalse;
8374
8596
  } else {
8375
8597
  rb_iv_set(return_value, "@MAX_SCHEMA_NAME_LEN", INT2NUM(bufferint16));
@@ -8385,7 +8607,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8385
8607
 
8386
8608
  if ( rc == SQL_ERROR ) {
8387
8609
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8388
- ruby_xfree( getInfo_args );
8389
8610
  return Qfalse;
8390
8611
  } else {
8391
8612
  rb_iv_set(return_value, "@MAX_STATEMENT_LEN", INT2NUM(bufferint32));
@@ -8401,7 +8622,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8401
8622
 
8402
8623
  if ( rc == SQL_ERROR ) {
8403
8624
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8404
- ruby_xfree( getInfo_args );
8405
8625
  return Qfalse;
8406
8626
  } else {
8407
8627
  rb_iv_set(return_value, "@MAX_TABLE_NAME_LEN", INT2NUM(bufferint16));
@@ -8417,7 +8637,6 @@ static VALUE ibm_db_server_info_helper( get_info_args *getInfo_args ) {
8417
8637
 
8418
8638
  if ( rc == SQL_ERROR ) {
8419
8639
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8420
- ruby_xfree( getInfo_args );
8421
8640
  return Qfalse;
8422
8641
  } else {
8423
8642
  VALUE rv = Qnil;
@@ -8526,7 +8745,7 @@ VALUE ibm_db_server_info(int argc, VALUE *argv, VALUE self)
8526
8745
  return Qfalse;
8527
8746
  }
8528
8747
 
8529
- getInfo_args = ALLOC_N(get_info_args,sizeof(struct _ibm_db_get_info_struct));
8748
+ getInfo_args = ALLOC( get_info_args );
8530
8749
  memset(getInfo_args,'\0',sizeof(struct _ibm_db_get_info_struct));
8531
8750
 
8532
8751
  getInfo_args->conn_res = conn_res;
@@ -8573,12 +8792,11 @@ static VALUE ibm_db_client_info_helper( get_info_args *getInfo_args) {
8573
8792
  getInfo_args->infoValue = (SQLPOINTER)buffer255;
8574
8793
  getInfo_args->buff_length = sizeof( buffer255 );
8575
8794
 
8576
- memset(buffer255, 0, sizeof(buffer255));
8795
+ memset(buffer255, '\0', sizeof(buffer255));
8577
8796
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8578
8797
 
8579
8798
  if ( rc == SQL_ERROR ) {
8580
8799
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8581
- ruby_xfree( getInfo_args );
8582
8800
  return Qfalse;
8583
8801
  } else {
8584
8802
  rb_iv_set(return_value, "@DRIVER_NAME", rb_str_new2(buffer255));
@@ -8589,12 +8807,11 @@ static VALUE ibm_db_client_info_helper( get_info_args *getInfo_args) {
8589
8807
  getInfo_args->infoValue = (SQLPOINTER)buffer255;
8590
8808
  getInfo_args->buff_length = sizeof( buffer255 );
8591
8809
 
8592
- memset(buffer255, 0, sizeof(buffer255));
8810
+ memset(buffer255, '\0', sizeof(buffer255));
8593
8811
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8594
8812
 
8595
8813
  if ( rc == SQL_ERROR ) {
8596
8814
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8597
- ruby_xfree( getInfo_args );
8598
8815
  return Qfalse;
8599
8816
  } else {
8600
8817
  rb_iv_set(return_value, "@DRIVER_VER", rb_str_new2(buffer255));
@@ -8605,12 +8822,11 @@ static VALUE ibm_db_client_info_helper( get_info_args *getInfo_args) {
8605
8822
  getInfo_args->infoValue = (SQLPOINTER)buffer255;
8606
8823
  getInfo_args->buff_length = sizeof( buffer255 );
8607
8824
 
8608
- memset(buffer255, 0, sizeof(buffer255));
8825
+ memset(buffer255, '\0', sizeof(buffer255));
8609
8826
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8610
8827
 
8611
8828
  if ( rc == SQL_ERROR ) {
8612
8829
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8613
- ruby_xfree( getInfo_args );
8614
8830
  return Qfalse;
8615
8831
  } else {
8616
8832
  rb_iv_set(return_value, "@DATA_SOURCE_NAME", rb_str_new2(buffer255));
@@ -8621,12 +8837,11 @@ static VALUE ibm_db_client_info_helper( get_info_args *getInfo_args) {
8621
8837
  getInfo_args->infoValue = (SQLPOINTER)buffer255;
8622
8838
  getInfo_args->buff_length = sizeof( buffer255 );
8623
8839
 
8624
- memset(buffer255, 0, sizeof(buffer255));
8840
+ memset(buffer255, '\0', sizeof(buffer255));
8625
8841
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8626
8842
 
8627
8843
  if ( rc == SQL_ERROR ) {
8628
8844
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8629
- ruby_xfree( getInfo_args );
8630
8845
  return Qfalse;
8631
8846
  } else {
8632
8847
  rb_iv_set(return_value, "@DRIVER_ODBC_VER", rb_str_new2(buffer255));
@@ -8638,12 +8853,11 @@ static VALUE ibm_db_client_info_helper( get_info_args *getInfo_args) {
8638
8853
  getInfo_args->infoValue = (SQLPOINTER)buffer255;
8639
8854
  getInfo_args->buff_length = sizeof( buffer255 );
8640
8855
 
8641
- memset(buffer255, 0, sizeof(buffer255));
8856
+ memset(buffer255, '\0', sizeof(buffer255));
8642
8857
  rc = _ruby_ibm_db_SQLGetInfo_helper( getInfo_args );
8643
8858
 
8644
8859
  if ( rc == SQL_ERROR ) {
8645
8860
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8646
- ruby_xfree( getInfo_args );
8647
8861
  return Qfalse;
8648
8862
  } else {
8649
8863
  rb_iv_set(return_value, "@ODBC_VER", rb_str_new2(buffer255));
@@ -8660,7 +8874,6 @@ static VALUE ibm_db_client_info_helper( get_info_args *getInfo_args) {
8660
8874
 
8661
8875
  if ( rc == SQL_ERROR ) {
8662
8876
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8663
- ruby_xfree( getInfo_args );
8664
8877
  return Qfalse;
8665
8878
  } else {
8666
8879
  switch (bufferint16) {
@@ -8690,7 +8903,6 @@ static VALUE ibm_db_client_info_helper( get_info_args *getInfo_args) {
8690
8903
 
8691
8904
  if ( rc == SQL_ERROR ) {
8692
8905
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8693
- ruby_xfree( getInfo_args );
8694
8906
  return Qfalse;
8695
8907
  } else {
8696
8908
  rb_iv_set(return_value, "@APPL_CODEPAGE", INT2NUM(bufferint32));
@@ -8706,7 +8918,6 @@ static VALUE ibm_db_client_info_helper( get_info_args *getInfo_args) {
8706
8918
 
8707
8919
  if ( rc == SQL_ERROR ) {
8708
8920
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 0 );
8709
- ruby_xfree( getInfo_args );
8710
8921
  return Qfalse;
8711
8922
  } else {
8712
8923
  rb_iv_set(return_value, "@CONN_CODEPAGE", INT2NUM(bufferint32));
@@ -8774,7 +8985,7 @@ VALUE ibm_db_client_info(int argc, VALUE *argv, VALUE self)
8774
8985
  return Qfalse;
8775
8986
  }
8776
8987
 
8777
- getInfo_args = ALLOC_N(get_info_args,sizeof(struct _ibm_db_get_info_struct));
8988
+ getInfo_args = ALLOC( get_info_args );
8778
8989
  memset(getInfo_args,'\0',sizeof(struct _ibm_db_get_info_struct));
8779
8990
 
8780
8991
  getInfo_args->conn_res = conn_res;
@@ -8834,7 +9045,7 @@ VALUE ibm_db_active(int argc, VALUE *argv, VALUE self)
8834
9045
  if (!NIL_P(connection)) {
8835
9046
  Data_Get_Struct(connection, conn_handle, conn_res);
8836
9047
  #ifndef PASE
8837
- get_handleAttr_args = ALLOC_N(get_handle_attr_args,sizeof(struct _ibm_db_get_handle_attr_struct));
9048
+ get_handleAttr_args = ALLOC( get_handle_attr_args );
8838
9049
  memset(get_handleAttr_args,'\0',sizeof(struct _ibm_db_get_handle_attr_struct));
8839
9050
 
8840
9051
  get_handleAttr_args->handle = &( conn_res->hdbc );
@@ -8846,6 +9057,7 @@ VALUE ibm_db_active(int argc, VALUE *argv, VALUE self)
8846
9057
  rc = _ruby_ibm_db_SQLGetConnectAttr_helper( get_handleAttr_args );
8847
9058
 
8848
9059
  ruby_xfree( get_handleAttr_args );
9060
+ get_handleAttr_args = NULL;
8849
9061
 
8850
9062
  if ( rc == SQL_ERROR ) {
8851
9063
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 1 );
@@ -8896,6 +9108,7 @@ VALUE ibm_db_get_option(int argc, VALUE *argv, VALUE self)
8896
9108
  VALUE conn_or_stmt = Qnil;
8897
9109
  VALUE option = Qnil;
8898
9110
  VALUE r_type = Qnil;
9111
+ VALUE ret_val = Qnil;
8899
9112
 
8900
9113
  SQLCHAR *value = NULL;
8901
9114
  SQLINTEGER value_int = 0;
@@ -8927,8 +9140,9 @@ VALUE ibm_db_get_option(int argc, VALUE *argv, VALUE self)
8927
9140
  op_integer=(SQLINTEGER)FIX2INT(option);
8928
9141
  /* ACCTSTR_LEN is the largest possible length of the options to retrieve */
8929
9142
  value = (SQLCHAR *)ALLOC_N(char, ACCTSTR_LEN + 1);
9143
+ memset(value,'\0', ACCTSTR_LEN + 1);
8930
9144
 
8931
- get_handleAttr_args = ALLOC_N(get_handle_attr_args,sizeof(struct _ibm_db_get_handle_attr_struct));
9145
+ get_handleAttr_args = ALLOC( get_handle_attr_args );
8932
9146
  memset(get_handleAttr_args,'\0',sizeof(struct _ibm_db_get_handle_attr_struct));
8933
9147
 
8934
9148
  get_handleAttr_args->handle = &( conn_res->hdbc );
@@ -8940,12 +9154,17 @@ VALUE ibm_db_get_option(int argc, VALUE *argv, VALUE self)
8940
9154
  rc = _ruby_ibm_db_SQLGetConnectAttr_helper( get_handleAttr_args );
8941
9155
 
8942
9156
  ruby_xfree( get_handleAttr_args );
9157
+ get_handleAttr_args = NULL;
8943
9158
 
8944
9159
  if (rc == SQL_ERROR) {
8945
9160
  _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, -1, 1, 1 );
8946
- return Qfalse;
9161
+ ret_val = Qfalse;
9162
+ } else {
9163
+ ret_val = rb_str_new2((char *)value);
8947
9164
  }
8948
- return rb_str_new2((char *)value);
9165
+ ruby_xfree( value );
9166
+ value = NULL;
9167
+ return ret_val;
8949
9168
  } else {
8950
9169
  rb_warn("No options specified");
8951
9170
  return Qfalse;
@@ -8959,7 +9178,7 @@ VALUE ibm_db_get_option(int argc, VALUE *argv, VALUE self)
8959
9178
  op_integer=(SQLINTEGER)FIX2INT(option);
8960
9179
  /* Checking that the option to get is the cursor type because that is what we support here */
8961
9180
  if (op_integer == SQL_ATTR_CURSOR_TYPE) {
8962
- get_handleAttr_args = ALLOC_N(get_handle_attr_args,sizeof(struct _ibm_db_get_handle_attr_struct));
9181
+ get_handleAttr_args = ALLOC( get_handle_attr_args );
8963
9182
  memset(get_handleAttr_args,'\0',sizeof(struct _ibm_db_get_handle_attr_struct));
8964
9183
 
8965
9184
  get_handleAttr_args->handle = &( stmt_res->hstmt );
@@ -8971,6 +9190,7 @@ VALUE ibm_db_get_option(int argc, VALUE *argv, VALUE self)
8971
9190
  rc = _ruby_ibm_db_SQLGetStmtAttr_helper( get_handleAttr_args );
8972
9191
 
8973
9192
  ruby_xfree( get_handleAttr_args );
9193
+ get_handleAttr_args = NULL;
8974
9194
 
8975
9195
  if (rc == SQL_ERROR) {
8976
9196
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 1 );
@@ -9017,7 +9237,9 @@ VALUE ibm_db_get_option(int argc, VALUE *argv, VALUE self)
9017
9237
  */
9018
9238
  VALUE ibm_db_get_last_serial_value(int argc, VALUE *argv, VALUE self)
9019
9239
  {
9020
- VALUE stmt = Qnil;
9240
+ VALUE stmt = Qnil;
9241
+ VALUE ret_val = Qnil;
9242
+
9021
9243
  char *value = NULL;
9022
9244
 
9023
9245
  stmt_handle *stmt_res;
@@ -9034,7 +9256,7 @@ VALUE ibm_db_get_last_serial_value(int argc, VALUE *argv, VALUE self)
9034
9256
  /* We allocate a buffer of size 31 as per recommendations from the CLI IDS team */
9035
9257
  value = (char *) ALLOC_N(char, 31);
9036
9258
 
9037
- get_handleAttr_args = ALLOC_N(get_handle_attr_args,sizeof(struct _ibm_db_get_handle_attr_struct));
9259
+ get_handleAttr_args = ALLOC( get_handle_attr_args );
9038
9260
  memset(get_handleAttr_args,'\0',sizeof(struct _ibm_db_get_handle_attr_struct));
9039
9261
 
9040
9262
  get_handleAttr_args->handle = &( stmt_res->hstmt );
@@ -9046,12 +9268,17 @@ VALUE ibm_db_get_last_serial_value(int argc, VALUE *argv, VALUE self)
9046
9268
  rc = _ruby_ibm_db_SQLGetStmtAttr_helper( get_handleAttr_args );
9047
9269
 
9048
9270
  ruby_xfree( get_handleAttr_args );
9271
+ get_handleAttr_args = NULL;
9049
9272
 
9050
9273
  if ( rc == SQL_ERROR ) {
9051
9274
  _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, (SQLHSTMT)stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1, 1 );
9052
9275
  return Qfalse;
9053
9276
  }
9054
- return INT2NUM(atoi( value ));
9277
+ ret_val = INT2NUM(atoi( value ));
9278
+ ruby_xfree( value );
9279
+ value = NULL;
9280
+
9281
+ return ret_val;
9055
9282
  }
9056
9283
  else {
9057
9284
  rb_warn("Supplied statement handle is invalid");