db2 2.6.2 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/CHANGES +17 -0
  2. data/README +79 -141
  3. data/ext/Makefile.nt32 +3 -3
  4. data/ext/Makefile.nt32.191 +212 -0
  5. data/ext/extconf.rb +75 -14
  6. data/ext/ibm_db.c +504 -47
  7. data/ext/ruby_ibm_db.h +4 -1
  8. data/ext/ruby_ibm_db_cli.c +108 -1
  9. data/ext/ruby_ibm_db_cli.h +54 -1
  10. data/lib/active_record/connection_adapters/ibm_db_adapter.rb +423 -124
  11. data/lib/active_record/connection_adapters/ibm_db_pstmt.rb +1 -1
  12. data/test/cases/adapter_test.rb +169 -164
  13. data/test/cases/associations/belongs_to_associations_test.rb +268 -43
  14. data/test/cases/associations/cascaded_eager_loading_test.rb +31 -33
  15. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +90 -156
  16. data/test/cases/associations/join_model_test.rb +100 -150
  17. data/test/cases/attribute_methods_test.rb +259 -58
  18. data/test/cases/base_test.rb +785 -138
  19. data/test/cases/calculations_test.rb +128 -8
  20. data/test/cases/migration_test.rb +680 -286
  21. data/test/cases/persistence_test.rb +642 -0
  22. data/test/cases/query_cache_test.rb +257 -0
  23. data/test/cases/relations_test.rb +1182 -0
  24. data/test/cases/schema_dumper_test.rb +41 -17
  25. data/test/cases/transaction_callbacks_test.rb +300 -0
  26. data/test/cases/validations/uniqueness_validation_test.rb +38 -22
  27. data/test/cases/xml_serialization_test.rb +408 -0
  28. data/test/config.yml +154 -0
  29. data/test/connections/native_ibm_db/connection.rb +2 -0
  30. data/test/models/warehouse_thing.rb +4 -4
  31. data/test/schema/i5/ibm_db_specific_schema.rb +3 -1
  32. data/test/schema/ids/ibm_db_specific_schema.rb +3 -1
  33. data/test/schema/luw/ibm_db_specific_schema.rb +2 -0
  34. data/test/schema/schema.rb +196 -92
  35. data/test/schema/zOS/ibm_db_specific_schema.rb +3 -1
  36. metadata +73 -68
  37. data/.gitignore +0 -1
  38. data/test/cases/associations/eager_test.rb +0 -862
  39. data/test/cases/associations/has_many_through_associations_test.rb +0 -461
  40. data/test/cases/finder_test.rb +0 -1088
  41. data/test/cases/fixtures_test.rb +0 -684
@@ -3,19 +3,81 @@
3
3
  # +----------------------------------------------------------------------+
4
4
  # | Licensed Materials - Property of IBM |
5
5
  # | |
6
- # | (C) Copyright IBM Corporation 2006, 2007,2008 |
6
+ # | (C) Copyright IBM Corporation 2006 - 2012 |
7
7
  # +----------------------------------------------------------------------+
8
8
 
9
+ WIN = RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
10
+
11
+ # use ENV['IBM_DB_HOME'] or latest db2 you can find
12
+ IBM_DB_HOME = ENV['IBM_DB_HOME']
13
+
14
+ machine_bits = ['ibm'].pack('p').size * 8
15
+
16
+ is64Bit = true
17
+
18
+ module Kernel
19
+ def suppress_warnings
20
+ origVerbosity = $VERBOSE
21
+ $VERBOSE = nil
22
+ result = yield
23
+ $VERBOSE = origVerbosity
24
+ return result
25
+ end
26
+ end
27
+
28
+ if machine_bits == 64
29
+ is64Bit = true
30
+ puts "Detected 64-bit Ruby\n "
31
+ else
32
+ is64Bit = false
33
+ puts "Detected 32-bit Ruby\n "
34
+ end
35
+
36
+ if(IBM_DB_HOME == nil || IBM_DB_HOME == '')
37
+ IBM_DB_INCLUDE = ENV['IBM_DB_INCLUDE']
38
+ IBM_DB_LIB = ENV['IBM_DB_LIB']
39
+
40
+ if( ( (IBM_DB_INCLUDE.nil?) || (IBM_DB_LIB.nil?) ) ||
41
+ ( IBM_DB_INCLUDE == '' || IBM_DB_LIB == '' )
42
+ )
43
+ puts "Environment variable IBM_DB_HOME is not set. Set it to your DB2/IBM_Data_Server_Driver installation directory and retry gem install.\n "
44
+ exit 1
45
+ end
46
+ else
47
+ IBM_DB_INCLUDE = "#{IBM_DB_HOME}/include"
48
+
49
+ if(is64Bit)
50
+ IBM_DB_LIB="#{IBM_DB_HOME}/lib64"
51
+ else
52
+ IBM_DB_LIB="#{IBM_DB_HOME}/lib32"
53
+ end
54
+ end
55
+
56
+ if( !(File.directory?(IBM_DB_LIB)) )
57
+ suppress_warnings{IBM_DB_LIB = "#{IBM_DB_HOME}/lib"}
58
+ if( !(File.directory?(IBM_DB_LIB)) )
59
+ puts "Cannot find #{IBM_DB_LIB} directory. Check if you have set the IBM_DB_HOME environment variable's value correctly\n "
60
+ exit 1
61
+ end
62
+ notifyString = "Detected usage of IBM Data Server Driver package. Ensure you have downloaded "
63
+
64
+ if(is64Bit)
65
+ notifyString = notifyString + "64-bit package "
66
+ else
67
+ notifyString = notifyString + "32-bit package "
68
+ end
69
+ notifyString = notifyString + "of IBM_Data_Server_Driver and retry the 'gem install ibm_db' command\n "
70
+
71
+ puts notifyString
72
+ end
73
+
74
+ if( !(File.directory?(IBM_DB_INCLUDE)) )
75
+ puts " #{IBM_DB_HOME}/include folder not found. Check if you have set the IBM_DB_HOME environment variable's value correctly\n "
76
+ exit 1
77
+ end
78
+
9
79
  require 'mkmf'
10
- WIN = RUBY_PLATFORM =~ /mswin/
11
-
12
- # use ENV['DB2DIR'] or latest db2 you can find
13
- # (we need to revisit default when db2 10.x comes out)
14
- IBM_DB_INCLUDE = (ENV['IBM_DB_INCLUDE'] or
15
- (Dir['/opt/*/db2/*/include'].sort_by {|f| File.basename(f)}).last )
16
- IBM_DB_LIB = (ENV['IBM_DB_LIB'] or
17
- (Dir['/opt/*/db2/*/lib32'].sort_by {|f| File.basename(f)}).last )
18
-
80
+
19
81
  dir_config('IBM_DB',IBM_DB_INCLUDE,IBM_DB_LIB)
20
82
 
21
83
  def crash(str)
@@ -30,18 +92,17 @@ end
30
92
 
31
93
  unless (have_library(WIN ? 'db2cli' : 'db2','SQLConnect') or find_library(WIN ? 'db2cli' : 'db2','SQLConnect', IBM_DB_LIB))
32
94
  crash(<<EOL)
33
- Unable to locate DB2 libraries.
95
+ Unable to locate libdb2.so/a under #{IBM_DB_LIB}
34
96
 
35
97
  Follow the steps below and retry
36
98
 
37
99
  Step 1: - Install IBM DB2 Universal Database Server/Client
38
100
 
39
- step 2: - Set the environment variables IBM_DB_INCLUDE and IBM_DB_LIB as below
101
+ step 2: - Set the environment variable IBM_DB_HOME as below
40
102
 
41
103
  (assuming bash shell)
42
104
 
43
- export IBM_DB_INCLUDE=DB2HOME/include (eg. /home/db2inst1/sqllib/include or /opt/ibm/db2/v9.5/include)
44
- export IBM_DB_LIB=DB2HOME/lib (eg. /home/db2inst1/sqllib/lib or /opt/ibm/db2/V9.5/lib32)
105
+ export IBM_DB_HOME=<DB2/IBM_Data_Server_Driver installation directory> #(Eg: export IBM_DB_HOME=/opt/ibm/db2/v10)
45
106
 
46
107
  step 3: - Retry gem install
47
108
 
@@ -12,7 +12,7 @@
12
12
  +----------------------------------------------------------------------+
13
13
  */
14
14
 
15
- #define MODULE_RELEASE "2.5.6"
15
+ #define MODULE_RELEASE "2.5.10"
16
16
 
17
17
  #ifdef HAVE_CONFIG_H
18
18
  #include "config.h"
@@ -42,6 +42,7 @@ static void _ruby_ibm_db_clear_stmt_err_cache();
42
42
  static int _ruby_ibm_db_set_decfloat_rounding_mode_client(SQLHANDLE hdbc);
43
43
  static char *_ruby_ibm_db_instance_name;
44
44
  static int is_systemi, is_informix; /* 1 == TRUE; 0 == FALSE; */
45
+ static int createDbSupported, dropDbSupported; /*1 == TRUE; 0 == FALSE*/
45
46
 
46
47
  /* Strucure holding the necessary data to be passed to bind the list of elements passed to the execute function*/
47
48
  typedef struct _stmt_bind_data_array {
@@ -188,6 +189,9 @@ void Init_ibm_db(void) {
188
189
  mDB = rb_define_module("IBM_DB");
189
190
 
190
191
  rb_define_module_function(mDB, "connect", ibm_db_connect, -1);
192
+ rb_define_module_function(mDB, "createDB", ibm_db_createDB, -1);
193
+ rb_define_module_function(mDB, "dropDB", ibm_db_dropDB, -1);
194
+ rb_define_module_function(mDB, "createDBNX", ibm_db_createDBNX, -1);
191
195
  rb_define_module_function(mDB, "commit", ibm_db_commit, -1);
192
196
  rb_define_module_function(mDB, "pconnect", ibm_db_pconnect, -1);
193
197
  rb_define_module_function(mDB, "autocommit", ibm_db_autocommit, -1);
@@ -326,6 +330,54 @@ static void ruby_ibm_db_load_necessary_libs() {
326
330
  rb_eval_string("require \'bigdecimal\'");
327
331
  }
328
332
 
333
+ #ifdef _WIN32
334
+ static void ruby_ibm_db_check_sqlcreatedb(HINSTANCE cliLib) {
335
+ FARPROC sqlcreatedb;
336
+ sqlcreatedb = DLSYM( cliLib, "SQLCreateDbW" );
337
+ #else
338
+ static void ruby_ibm_db_check_sqlcreatedb(void *cliLib) {
339
+ typedef int (*sqlcreatedbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER );
340
+ sqlcreatedbType sqlcreatedb;
341
+ sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDbW" );
342
+ #endif
343
+ if ( sqlcreatedb == NULL ) {
344
+ createDbSupported = 0;
345
+ dropDbSupported = 0;
346
+ } else {
347
+ createDbSupported = 1;
348
+ dropDbSupported = 1;
349
+ }
350
+ }
351
+ /*Check if specific functions are supported or not based on CLI being used
352
+ * For Eg: SQLCreateDB and SQLDropDB is supported only from V97fp3 onwards. In this function we open the CLI library
353
+ * using DLOpen and check if the function is defined. If yes then we allow the user to use the function,
354
+ * else throw a warning saying this is not supported
355
+ */
356
+ static void ruby_ibm_db_check_if_cli_func_supported() {
357
+ #ifdef _WIN32
358
+ HINSTANCE cliLib = NULL;
359
+ #else
360
+ void *cliLib = NULL;
361
+ #endif
362
+
363
+ #ifdef _WIN32
364
+ cliLib = DLOPEN( LIBDB2 );
365
+ #elif _AIX
366
+ /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
367
+ cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
368
+ #else
369
+ cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
370
+ #endif
371
+ if ( !cliLib ) {
372
+ rb_warn("Could not load CLI library to check functionality support");
373
+ createDbSupported = 0;
374
+ dropDbSupported = 0;
375
+ return;
376
+ }
377
+ ruby_ibm_db_check_sqlcreatedb(cliLib);
378
+ DLCLOSE( cliLib );
379
+ }
380
+
329
381
  static void ruby_ibm_db_init_globals(struct _ibm_db_globals *ibm_db_globals)
330
382
  {
331
383
  /* env handle */
@@ -848,6 +900,8 @@ void ruby_init_ibm_db()
848
900
  rb_attr(le_server_info, rb_intern("NON_NULLABLE_COLUMNS"), 1, 0, 0);
849
901
 
850
902
  ruby_ibm_db_load_necessary_libs();
903
+
904
+ ruby_ibm_db_check_if_cli_func_supported();
851
905
  }
852
906
  /* */
853
907
 
@@ -932,7 +986,7 @@ static void _ruby_ibm_db_check_sql_errors( void *conn_or_stmt, int resourceType,
932
986
 
933
987
  if( release_gil == 1 ){
934
988
 
935
- #ifdef GIL_RELEASE_VERSION
989
+ #ifdef UNICODE_SUPPORT_VERSION
936
990
  return_code = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLGetDiagRec_helper, get_DiagRec_args,
937
991
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
938
992
  #else
@@ -1042,6 +1096,7 @@ static void _ruby_ibm_db_check_sql_errors( void *conn_or_stmt, int resourceType,
1042
1096
  strncpy(conn_res->ruby_error_msg, (char*)errMsg, length );
1043
1097
  #endif
1044
1098
  conn_res->ruby_error_msg_len = length;
1099
+ conn_res->sqlcode = sqlcode;
1045
1100
  break;
1046
1101
 
1047
1102
  case SQL_HANDLE_STMT:
@@ -1082,6 +1137,7 @@ static void _ruby_ibm_db_check_sql_errors( void *conn_or_stmt, int resourceType,
1082
1137
  strncpy(conn_res->ruby_error_msg, (char*)errMsg, length );
1083
1138
  #endif
1084
1139
  conn_res->ruby_error_msg_len = length;
1140
+ conn_res->sqlcode = sqlcode;
1085
1141
  break;
1086
1142
 
1087
1143
  case DB_STMT:
@@ -1119,6 +1175,7 @@ static void _ruby_ibm_db_check_sql_errors( void *conn_or_stmt, int resourceType,
1119
1175
  strncpy(stmt_res->ruby_stmt_err_msg, (char*)errMsg, length );
1120
1176
  #endif
1121
1177
  stmt_res->ruby_stmt_err_msg_len = length;
1178
+ stmt_res->sqlcode = sqlcode;
1122
1179
  break;
1123
1180
 
1124
1181
  } /*End of switch( resourceType )*/
@@ -1683,6 +1740,13 @@ static int _ruby_ibm_db_bind_column_helper(stmt_handle *stmt_res)
1683
1740
  */
1684
1741
  bindCol_args->buff_length = bindCol_args->buff_length * 2;
1685
1742
  }
1743
+
1744
+ if( column_type == SQL_CHAR || column_type == SQL_VARCHAR ) {
1745
+ /* Multiply the size by 4 to handle cases where client and server code pages are different.
1746
+ * 4 bytes should be able to cover any codeset character known*/
1747
+ bindCol_args->buff_length = bindCol_args->buff_length * 4;
1748
+ }
1749
+
1686
1750
  row_data->str_val = ALLOC_N(char, bindCol_args->buff_length);
1687
1751
  #endif
1688
1752
  bindCol_args->TargetValuePtr = row_data->str_val;
@@ -2435,7 +2499,7 @@ static VALUE _ruby_ibm_db_connect_helper( int argc, VALUE *argv, int isPersisten
2435
2499
  }
2436
2500
 
2437
2501
  /* Call the function where the actual logic is being run*/
2438
- #ifdef GIL_RELEASE_VERSION
2502
+ #ifdef UNICODE_SUPPORT_VERSION
2439
2503
  return_value = rb_thread_blocking_region( (void *)_ruby_ibm_db_connect_helper2, helper_args,
2440
2504
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
2441
2505
  #else
@@ -2776,6 +2840,366 @@ VALUE ibm_db_pconnect(int argc, VALUE *argv, VALUE self)
2776
2840
 
2777
2841
  return _ruby_ibm_db_connect_helper( argc, argv, 1);
2778
2842
  }
2843
+ /*
2844
+ * CreateDB helper
2845
+ */
2846
+ VALUE ruby_ibm_db_createDb_helper(VALUE connection, VALUE dbName, VALUE codeSet, VALUE mode, int createNX) {
2847
+
2848
+ VALUE return_value = Qfalse;
2849
+ #ifdef UNICODE_SUPPORT_VERSION
2850
+ VALUE dbName_utf16 = Qnil;
2851
+ VALUE codeSet_utf16 = Qnil;
2852
+ VALUE mode_utf16 = Qnil;
2853
+ #endif
2854
+
2855
+ int rc;
2856
+
2857
+ create_drop_db_args *create_db_args = NULL;
2858
+ conn_handle *conn_res;
2859
+
2860
+ if (!NIL_P(connection)) {
2861
+ Data_Get_Struct(connection, conn_handle, conn_res);
2862
+
2863
+ if( 0 == createDbSupported ) {
2864
+ rb_warn("Create Database not supported: This function is only supported from DB2 Client v97fp4 version and onwards");
2865
+ return Qfalse;
2866
+ }
2867
+
2868
+ if (!conn_res->handle_active) {
2869
+ rb_warn("Connection is not active");
2870
+ return Qfalse;
2871
+ }
2872
+
2873
+ if (!NIL_P(dbName)) {
2874
+ create_db_args = ALLOC( create_drop_db_args );
2875
+ memset(create_db_args,'\0',sizeof(struct _ibm_db_create_drop_db_args_struct));
2876
+
2877
+ #ifdef UNICODE_SUPPORT_VERSION
2878
+ dbName_utf16 = _ruby_ibm_db_export_str_to_utf16(dbName);
2879
+
2880
+ create_db_args->dbName = (SQLWCHAR*)RSTRING_PTR(dbName_utf16);
2881
+ create_db_args->dbName_string_len = RSTRING_LEN(dbName_utf16)/sizeof(SQLWCHAR); /*RSTRING_LEN returns number of bytes*/
2882
+
2883
+ if(!NIL_P(codeSet)){
2884
+ codeSet_utf16 = _ruby_ibm_db_export_str_to_utf16(codeSet);
2885
+ create_db_args->codeSet = (SQLWCHAR*)RSTRING_PTR(codeSet_utf16);
2886
+ create_db_args->codeSet_string_len = RSTRING_LEN(codeSet_utf16)/sizeof(SQLWCHAR); /*RSTRING_LEN returns number of bytes*/
2887
+ } else {
2888
+ create_db_args->codeSet = NULL;
2889
+ }
2890
+
2891
+ if(!NIL_P(mode)) {
2892
+ mode_utf16 = _ruby_ibm_db_export_str_to_utf16(mode);
2893
+ create_db_args->mode = (SQLWCHAR*)RSTRING_PTR(mode_utf16);
2894
+ create_db_args->mode_string_len = RSTRING_LEN(mode_utf16)/sizeof(SQLWCHAR); /*RSTRING_LEN returns number of bytes*/
2895
+ } else {
2896
+ create_db_args->mode = NULL;
2897
+ }
2898
+ #else
2899
+ create_db_args->dbName = (SQLCHAR*)rb_str2cstr(dbName, &(create_db_args->dbName_string_len));
2900
+ if(!NIL_P(codeSet)){
2901
+ create_db_args->codeSet = (SQLCHAR*)rb_str2cstr(codeSet, &(create_db_args->codeSet_string_len));
2902
+ } else {
2903
+ create_db_args->codeSet = NULL;
2904
+ }
2905
+ if(!NIL_P(mode)) {
2906
+ create_db_args->mode = (SQLCHAR*)rb_str2cstr(mode, &(create_db_args->mode_string_len));
2907
+ } else {
2908
+ create_db_args->mode = NULL;
2909
+ }
2910
+ #endif
2911
+ } else {
2912
+ rb_warn("Invalid Parameter: Database Name cannot be nil");
2913
+ return Qfalse;
2914
+ }
2915
+
2916
+ create_db_args->conn_res = conn_res;
2917
+
2918
+ _ruby_ibm_db_clear_conn_err_cache();
2919
+
2920
+ #ifdef UNICODE_SUPPORT_VERSION
2921
+ rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLCreateDB_helper, create_db_args,
2922
+ (void *)_ruby_ibm_db_Connection_level_UBF, NULL );
2923
+ #else
2924
+ rc = _ruby_ibm_db_SQLCreateDB_helper( create_db_args );
2925
+ #endif
2926
+
2927
+ if ( rc == SQL_ERROR ) {
2928
+ conn_res->error_recno_tracker = 1;
2929
+ conn_res->errormsg_recno_tracker = 1;
2930
+ _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, NULL, -1, 1, 0 );
2931
+ if(conn_res->sqlcode == -1005 && 1 == createNX) {
2932
+ return_value = Qtrue; /*Return true if database already exists and Create if not existing called*/
2933
+ /*Clear the error messages*/
2934
+ #ifdef UNICODE_SUPPORT_VERSION
2935
+ memset( conn_res->ruby_error_state, '\0', (SQL_SQLSTATE_SIZE + 1) * sizeof(SQLWCHAR) );
2936
+ memset( conn_res->ruby_error_msg, '\0', (DB2_MAX_ERR_MSG_LEN + 1) * sizeof(SQLWCHAR) );
2937
+ #else
2938
+ memset( conn_res->ruby_error_state, '\0', SQL_SQLSTATE_SIZE + 1 );
2939
+ memset( conn_res->ruby_error_msg, '\0', DB2_MAX_ERR_MSG_LEN + 1 );
2940
+ #endif
2941
+ } else {
2942
+ return_value = Qfalse;
2943
+ }
2944
+ } else {
2945
+ return_value = Qtrue;
2946
+ }
2947
+ }
2948
+
2949
+ /*Free memory allocated*/
2950
+ if( create_db_args != NULL ) {
2951
+ ruby_xfree( create_db_args );
2952
+ create_db_args = NULL;
2953
+ }
2954
+
2955
+ return return_value;
2956
+ }
2957
+ /* */
2958
+ /*
2959
+ * IBM_DB.createDB -- Creates a Database
2960
+ *
2961
+ * ===Description
2962
+ * bool IBM_DB.createDB ( resource connection , string dbName [, String codeSet, String mode] )
2963
+ *
2964
+ * Creates a database with the specified name. Returns true if operation successful else false
2965
+ *
2966
+ * ===Parameters
2967
+ *
2968
+ * connection
2969
+ * A valid database connection resource variable as returned from IBM_DB.connect() or IBM_DB.pconnect() with parameter ATTACH=true specified.
2970
+ * IBM_DB.connect('DRIVER={IBM DB2 ODBC DRIVER};ATTACH=true;HOSTNAME=myhost;PORT=1234;PROTOCOL=TCPIP;UID=user;PWD=secret;','','')
2971
+ * Note: Database is not specified. In this case we connect to the instance only.
2972
+ *
2973
+ * dbName
2974
+ * Name of the database that is to be created.
2975
+ *
2976
+ * codeSet
2977
+ * Database code set information.
2978
+ * Note: If the value of the codeSet argument is not specified,
2979
+ * the database is created in the Unicode code page for DB2 data servers and in the UTF-8 code page for IDS data servers
2980
+ *
2981
+ * mode
2982
+ * Database logging mode.
2983
+ * Note: This value is applicable only to IDS data servers
2984
+ *
2985
+ * ===Return Values
2986
+ *
2987
+ * Returns TRUE on success or FALSE on failure.
2988
+ */
2989
+ VALUE ibm_db_createDB(int argc, VALUE *argv, VALUE self)
2990
+ {
2991
+ VALUE connection = Qnil;
2992
+ VALUE dbName = Qnil;
2993
+ VALUE codeSet = Qnil;
2994
+ VALUE mode = Qnil;
2995
+
2996
+ rb_scan_args(argc, argv, "22", &connection, &dbName, &codeSet, &mode);
2997
+
2998
+ return ruby_ibm_db_createDb_helper(connection, dbName, codeSet, mode, 0);
2999
+ }
3000
+ /*
3001
+ * DropDb helper
3002
+ */
3003
+ VALUE ruby_ibm_db_dropDb_helper(VALUE connection, VALUE dbName) {
3004
+ #ifdef UNICODE_SUPPORT_VERSION
3005
+ VALUE dbName_utf16 = Qnil;
3006
+ #endif
3007
+
3008
+ VALUE return_value = Qfalse;
3009
+
3010
+ int rc;
3011
+
3012
+ create_drop_db_args *drop_db_args = NULL;
3013
+ conn_handle *conn_res = NULL;
3014
+
3015
+ if (!NIL_P(connection)) {
3016
+ Data_Get_Struct(connection, conn_handle, conn_res);
3017
+
3018
+ if( 0 == dropDbSupported ) {
3019
+ rb_warn("Drop Database not supported: This function is only supported from DB2 Client v97fp4 version and onwards");
3020
+ return Qfalse;
3021
+ }
3022
+
3023
+ if (!conn_res->handle_active) {
3024
+ rb_warn("Connection is not active");
3025
+ return Qfalse;
3026
+ }
3027
+
3028
+ if (!NIL_P(dbName)) {
3029
+ drop_db_args = ALLOC( create_drop_db_args );
3030
+ memset(drop_db_args,'\0',sizeof(struct _ibm_db_create_drop_db_args_struct));
3031
+
3032
+ #ifdef UNICODE_SUPPORT_VERSION
3033
+ dbName_utf16 = _ruby_ibm_db_export_str_to_utf16(dbName);
3034
+
3035
+ drop_db_args->dbName = (SQLWCHAR*)RSTRING_PTR(dbName_utf16);
3036
+ drop_db_args->dbName_string_len = RSTRING_LEN(dbName_utf16)/sizeof(SQLWCHAR); /*RSTRING_LEN returns number of bytes*/
3037
+ #else
3038
+ drop_db_args->dbName = (SQLCHAR*)rb_str2cstr(dbName, &(drop_db_args->dbName_string_len));
3039
+ #endif
3040
+ } else {
3041
+ rb_warn("Invalid Parameter: Database Name cannot be nil");
3042
+ return Qfalse;
3043
+ }
3044
+
3045
+ drop_db_args->conn_res = conn_res;
3046
+
3047
+ _ruby_ibm_db_clear_conn_err_cache();
3048
+
3049
+ #ifdef UNICODE_SUPPORT_VERSION
3050
+ rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLDropDB_helper, drop_db_args,
3051
+ (void *)_ruby_ibm_db_Connection_level_UBF, NULL );
3052
+ #else
3053
+ rc = _ruby_ibm_db_SQLDropDB_helper( drop_db_args );
3054
+ #endif
3055
+
3056
+ if ( rc == SQL_ERROR ) {
3057
+ conn_res->error_recno_tracker = 1;
3058
+ conn_res->errormsg_recno_tracker = 1;
3059
+ _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, NULL, -1, 1, 0 );
3060
+ return_value = Qfalse;
3061
+ } else {
3062
+ return_value = Qtrue;
3063
+ }
3064
+ }
3065
+
3066
+ /*Free memory allocated*/
3067
+ if( drop_db_args != NULL ) {
3068
+ ruby_xfree( drop_db_args );
3069
+ drop_db_args = NULL;
3070
+ }
3071
+
3072
+ return return_value;
3073
+ }
3074
+ /* */
3075
+ /*
3076
+ * IBM_DB.dropDB -- Drops the mentioned Database
3077
+ *
3078
+ * ===Description
3079
+ * bool IBM_DB.dropDB ( resource connection , string dbName [, String codeSet, String mode] )
3080
+ *
3081
+ * Drops a database with the specified name. Returns true if operation successful else false
3082
+ *
3083
+ * ===Parameters
3084
+ *
3085
+ * connection
3086
+ * A valid database connection resource variable as returned from IBM_DB.connect() or IBM_DB.pconnect() with parameter ATTACH=true specified.
3087
+ * IBM_DB.connect('DRIVER={IBM DB2 ODBC DRIVER};ATTACH=true;HOSTNAME=myhost;PORT=1234;PROTOCOL=TCPIP;UID=user;PWD=secret;','','')
3088
+ * Note: Database is not specified. In this case we connect to the instance only.
3089
+ * dbName
3090
+ * Name of the database that is to be created.
3091
+ *
3092
+ * ===Return Values
3093
+ *
3094
+ * Returns TRUE on success or FALSE on failure.
3095
+ */
3096
+ VALUE ibm_db_dropDB(int argc, VALUE *argv, VALUE self)
3097
+ {
3098
+ VALUE connection = Qnil;
3099
+ VALUE dbName = Qnil;
3100
+
3101
+ rb_scan_args(argc, argv, "2", &connection, &dbName);
3102
+
3103
+ return ruby_ibm_db_dropDb_helper(connection, dbName);
3104
+ }
3105
+ /* */
3106
+ /*
3107
+ * IBM_DB.recreateDB -- Recreates an Existing database
3108
+ *
3109
+ * ===Description
3110
+ * bool IBM_DB.recreateDB ( resource connection , string dbName [, String codeSet, String mode] )
3111
+ *
3112
+ * Recreates a database with the specified name. This method will drop an existing database and then re-create it.
3113
+ * If database doesnot exist the method will return false.
3114
+ * Returns true if operation successful else false
3115
+ *
3116
+ * ===Parameters
3117
+ *
3118
+ * connection
3119
+ * A valid database connection resource variable as returned from IBM_DB.connect() or IBM_DB.pconnect() with parameter ATTACH=true specified.
3120
+ * IBM_DB.connect('DRIVER={IBM DB2 ODBC DRIVER};ATTACH=true;HOSTNAME=myhost;PORT=1234;PROTOCOL=TCPIP;UID=user;PWD=secret;','','')
3121
+ * Note: Database is not specified. In this case we connect to the instance only.
3122
+ *
3123
+ * dbName
3124
+ * Name of the database that is to be created.
3125
+ *
3126
+ * codeSet
3127
+ * Database code set information.
3128
+ * Note: If the value of the codeSet argument is not specified,
3129
+ * the database is created in the Unicode code page for DB2 data servers and in the UTF-8 code page for IDS data servers
3130
+ *
3131
+ * mode
3132
+ * Database logging mode.
3133
+ * Note: This value is applicable only to IDS data servers
3134
+ *
3135
+ * ===Return Values
3136
+ *
3137
+ * Returns TRUE on success or FALSE on failure.
3138
+ */
3139
+ /*VALUE ibm_db_recreateDB(int argc, VALUE *argv, VALUE self)
3140
+ {
3141
+ VALUE connection = Qnil;
3142
+ VALUE dbName = Qnil;
3143
+ VALUE codeSet = Qnil;
3144
+ VALUE mode = Qnil;
3145
+ VALUE return_value = Qnil;
3146
+
3147
+ rb_scan_args(argc, argv, "22", &connection, &dbName, &codeSet, &mode);
3148
+
3149
+ return_value = ruby_ibm_db_dropDb_helper(connection, dbName);
3150
+
3151
+ if(return_value == Qfalse) {
3152
+ return Qfalse;
3153
+ }
3154
+
3155
+ return ruby_ibm_db_createDb_helper(connection, dbName, codeSet, mode);
3156
+ }*/
3157
+ /* */
3158
+ /*
3159
+ * IBM_DB.createDBNX -- creates a database if it does not exist aleady
3160
+ *
3161
+ * ===Description
3162
+ * bool IBM_DB.createDBNX ( resource connection , string dbName [, String codeSet, String mode] )
3163
+ *
3164
+ * Creates a database with the specified name, if it does not exist already. This method will drop an existing database and then re-create it.
3165
+ * If database doesnot exist the method will return false.
3166
+ * Returns true if operation successful else false
3167
+ *
3168
+ * ===Parameters
3169
+ *
3170
+ * connection
3171
+ * A valid database connection resource variable as returned from IBM_DB.connect() or IBM_DB.pconnect() with parameter ATTACH=true specified.
3172
+ * IBM_DB.connect('DRIVER={IBM DB2 ODBC DRIVER};ATTACH=true;HOSTNAME=myhost;PORT=1234;PROTOCOL=TCPIP;UID=user;PWD=secret;','','')
3173
+ * Note: Database is not specified. In this case we connect to the instance only.
3174
+ *
3175
+ * dbName
3176
+ * Name of the database that is to be created.
3177
+ *
3178
+ * codeSet
3179
+ * Database code set information.
3180
+ * Note: If the value of the codeSet argument is not specified,
3181
+ * the database is created in the Unicode code page for DB2 data servers and in the UTF-8 code page for IDS data servers
3182
+ *
3183
+ * mode
3184
+ * Database logging mode.
3185
+ * Note: This value is applicable only to IDS data servers
3186
+ *
3187
+ * ===Return Values
3188
+ *
3189
+ * Returns TRUE on success or FALSE on failure.
3190
+ */
3191
+ VALUE ibm_db_createDBNX(int argc, VALUE *argv, VALUE self)
3192
+ {
3193
+ VALUE connection = Qnil;
3194
+ VALUE dbName = Qnil;
3195
+ VALUE codeSet = Qnil;
3196
+ VALUE mode = Qnil;
3197
+ VALUE return_value = Qnil;
3198
+
3199
+ rb_scan_args(argc, argv, "22", &connection, &dbName, &codeSet, &mode);
3200
+
3201
+ return ruby_ibm_db_createDb_helper(connection, dbName, codeSet, mode, 1);
3202
+ }
2779
3203
  /* */
2780
3204
 
2781
3205
  /*
@@ -2984,7 +3408,7 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
2984
3408
  case 3:
2985
3409
  param_type = SQL_PARAM_INPUT;
2986
3410
 
2987
- #ifdef GIL_RELEASE_VERSION
3411
+ #ifdef UNICODE_SUPPORT_VERSION
2988
3412
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLDescribeParam_helper, data,
2989
3413
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res);
2990
3414
  #else
@@ -3004,7 +3428,7 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
3004
3428
 
3005
3429
  case 4:
3006
3430
 
3007
- #ifdef GIL_RELEASE_VERSION
3431
+ #ifdef UNICODE_SUPPORT_VERSION
3008
3432
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLDescribeParam_helper, data,
3009
3433
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res);
3010
3434
  #else
@@ -3024,7 +3448,7 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
3024
3448
 
3025
3449
  case 5:
3026
3450
 
3027
- #ifdef GIL_RELEASE_VERSION
3451
+ #ifdef UNICODE_SUPPORT_VERSION
3028
3452
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLDescribeParam_helper, data,
3029
3453
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
3030
3454
  #else
@@ -3045,7 +3469,7 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
3045
3469
 
3046
3470
  case 6:
3047
3471
 
3048
- #ifdef GIL_RELEASE_VERSION
3472
+ #ifdef UNICODE_SUPPORT_VERSION
3049
3473
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLDescribeParam_helper, data,
3050
3474
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
3051
3475
  #else
@@ -3277,7 +3701,7 @@ VALUE ibm_db_close(int argc, VALUE *argv, VALUE self)
3277
3701
  end_X_args->handleType = SQL_HANDLE_DBC;
3278
3702
  end_X_args->completionType = SQL_ROLLBACK; /*Remeber you are rolling back the transaction*/
3279
3703
 
3280
- #ifdef GIL_RELEASE_VERSION
3704
+ #ifdef UNICODE_SUPPORT_VERSION
3281
3705
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLEndTran, end_X_args,
3282
3706
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
3283
3707
  #else
@@ -3295,7 +3719,7 @@ VALUE ibm_db_close(int argc, VALUE *argv, VALUE self)
3295
3719
  }
3296
3720
  }
3297
3721
 
3298
- #ifdef GIL_RELEASE_VERSION
3722
+ #ifdef UNICODE_SUPPORT_VERSION
3299
3723
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLDisconnect_helper, &(conn_res->hdbc),
3300
3724
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
3301
3725
  #else
@@ -3472,7 +3896,7 @@ VALUE ibm_db_column_privileges(int argc, VALUE *argv, VALUE self)
3472
3896
  }
3473
3897
  col_privileges_args->stmt_res = stmt_res;
3474
3898
 
3475
- #ifdef GIL_RELEASE_VERSION
3899
+ #ifdef UNICODE_SUPPORT_VERSION
3476
3900
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLColumnPrivileges_helper, col_privileges_args,
3477
3901
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
3478
3902
  #else
@@ -3652,7 +4076,7 @@ VALUE ibm_db_columns(int argc, VALUE *argv, VALUE self)
3652
4076
  }
3653
4077
  col_metadata_args->stmt_res = stmt_res;
3654
4078
 
3655
- #ifdef GIL_RELEASE_VERSION
4079
+ #ifdef UNICODE_SUPPORT_VERSION
3656
4080
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLColumns_helper, col_metadata_args,
3657
4081
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
3658
4082
  #else
@@ -3818,7 +4242,7 @@ VALUE ibm_db_foreign_keys(int argc, VALUE *argv, VALUE self)
3818
4242
 
3819
4243
  col_metadata_args->stmt_res = stmt_res;
3820
4244
 
3821
- #ifdef GIL_RELEASE_VERSION
4245
+ #ifdef UNICODE_SUPPORT_VERSION
3822
4246
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLForeignKeys_helper, col_metadata_args,
3823
4247
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
3824
4248
  #else
@@ -3974,7 +4398,7 @@ VALUE ibm_db_primary_keys(int argc, VALUE *argv, VALUE self)
3974
4398
  }
3975
4399
  col_metadata_args->stmt_res = stmt_res;
3976
4400
 
3977
- #ifdef GIL_RELEASE_VERSION
4401
+ #ifdef UNICODE_SUPPORT_VERSION
3978
4402
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLPrimaryKeys_helper, col_metadata_args,
3979
4403
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
3980
4404
  #else
@@ -4165,7 +4589,7 @@ VALUE ibm_db_procedure_columns(int argc, VALUE *argv, VALUE self)
4165
4589
  }
4166
4590
  col_metadata_args->stmt_res = stmt_res;
4167
4591
 
4168
- #ifdef GIL_RELEASE_VERSION
4592
+ #ifdef UNICODE_SUPPORT_VERSION
4169
4593
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLProcedureColumns_helper, col_metadata_args,
4170
4594
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res);
4171
4595
  #else
@@ -4322,7 +4746,7 @@ VALUE ibm_db_procedures(int argc, VALUE *argv, VALUE self)
4322
4746
  }
4323
4747
  proc_metadata_args->stmt_res = stmt_res;
4324
4748
 
4325
- #ifdef GIL_RELEASE_VERSION
4749
+ #ifdef UNICODE_SUPPORT_VERSION
4326
4750
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLProcedures_helper, proc_metadata_args,
4327
4751
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res);
4328
4752
  #else
@@ -4499,7 +4923,7 @@ VALUE ibm_db_special_columns(int argc, VALUE *argv, VALUE self)
4499
4923
  }
4500
4924
  col_metadata_args->stmt_res = stmt_res;
4501
4925
 
4502
- #ifdef GIL_RELEASE_VERSION
4926
+ #ifdef UNICODE_SUPPORT_VERSION
4503
4927
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLSpecialColumns_helper, col_metadata_args,
4504
4928
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res);
4505
4929
  #else
@@ -4694,7 +5118,7 @@ VALUE ibm_db_statistics(int argc, VALUE *argv, VALUE self)
4694
5118
  }
4695
5119
  col_metadata_args->stmt_res = stmt_res;
4696
5120
 
4697
- #ifdef GIL_RELEASE_VERSION
5121
+ #ifdef UNICODE_SUPPORT_VERSION
4698
5122
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLStatistics_helper, col_metadata_args,
4699
5123
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
4700
5124
  #else
@@ -4853,7 +5277,7 @@ VALUE ibm_db_table_privileges(int argc, VALUE *argv, VALUE self)
4853
5277
 
4854
5278
  table_privileges_args->stmt_res = stmt_res;
4855
5279
 
4856
- #ifdef GIL_RELEASE_VERSION
5280
+ #ifdef UNICODE_SUPPORT_VERSION
4857
5281
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLTablePrivileges_helper, table_privileges_args,
4858
5282
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
4859
5283
  #else
@@ -5027,7 +5451,7 @@ VALUE ibm_db_tables(int argc, VALUE *argv, VALUE self)
5027
5451
 
5028
5452
  table_metadata_args->stmt_res = stmt_res;
5029
5453
 
5030
- #ifdef GIL_RELEASE_VERSION
5454
+ #ifdef UNICODE_SUPPORT_VERSION
5031
5455
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLTables_helper, table_metadata_args,
5032
5456
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
5033
5457
  #else
@@ -5109,7 +5533,7 @@ VALUE ibm_db_commit(int argc, VALUE *argv, VALUE self)
5109
5533
  end_X_args->handleType = SQL_HANDLE_DBC;
5110
5534
  end_X_args->completionType = SQL_COMMIT; /*Remeber you are Commiting the transaction*/
5111
5535
 
5112
- #ifdef GIL_RELEASE_VERSION
5536
+ #ifdef UNICODE_SUPPORT_VERSION
5113
5537
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLEndTran, end_X_args,
5114
5538
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
5115
5539
  #else
@@ -5189,7 +5613,7 @@ static int _ruby_ibm_db_do_prepare(conn_handle *conn_res, VALUE stmt, stmt_handl
5189
5613
  prepare_args->stmt_res = stmt_res;
5190
5614
 
5191
5615
  /* Prepare the stmt. The cursor type requested has already been set in _ruby_ibm_db_assign_options */
5192
- #ifdef GIL_RELEASE_VERSION
5616
+ #ifdef UNICODE_SUPPORT_VERSION
5193
5617
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLPrepare_helper, prepare_args,
5194
5618
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
5195
5619
  #else
@@ -5197,7 +5621,7 @@ static int _ruby_ibm_db_do_prepare(conn_handle *conn_res, VALUE stmt, stmt_handl
5197
5621
  #endif
5198
5622
 
5199
5623
  if ( rc == SQL_ERROR ) {
5200
- _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 0,
5624
+ _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1,
5201
5625
  NULL, NULL, -1, 1, 1 );
5202
5626
  }
5203
5627
  }
@@ -5327,7 +5751,7 @@ VALUE ibm_db_exec(int argc, VALUE *argv, VALUE self)
5327
5751
 
5328
5752
  exec_direct_args->stmt_res = stmt_res;
5329
5753
 
5330
- #ifdef GIL_RELEASE_VERSION
5754
+ #ifdef UNICODE_SUPPORT_VERSION
5331
5755
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLExecDirect_helper, exec_direct_args,
5332
5756
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
5333
5757
  #else
@@ -5402,7 +5826,7 @@ VALUE ibm_db_free_result(int argc, VALUE *argv, VALUE self)
5402
5826
  freeStmt_args->stmt_res = stmt_res;
5403
5827
  freeStmt_args->option = SQL_CLOSE;
5404
5828
 
5405
- #ifdef GIL_RELEASE_VERSION
5829
+ #ifdef UNICODE_SUPPORT_VERSION
5406
5830
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLFreeStmt_helper, freeStmt_args,
5407
5831
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
5408
5832
  #else
@@ -6381,7 +6805,8 @@ static VALUE _ruby_ibm_db_execute_helper(stmt_bind_array *bind_array) {
6381
6805
 
6382
6806
  put_param_data_args->stmt_res = stmt_res;
6383
6807
 
6384
- while ( _ruby_ibm_db_SQLParamData_helper( put_param_data_args ) == SQL_NEED_DATA ) {
6808
+ rc = _ruby_ibm_db_SQLParamData_helper( put_param_data_args );
6809
+ while ( rc == SQL_NEED_DATA ) {
6385
6810
 
6386
6811
  /* passing data value for a parameter */
6387
6812
  rc = _ruby_ibm_db_SQLPutData_helper(put_param_data_args);
@@ -6412,13 +6837,37 @@ static VALUE _ruby_ibm_db_execute_helper(stmt_bind_array *bind_array) {
6412
6837
 
6413
6838
  return Qnil;
6414
6839
  }
6840
+ rc = _ruby_ibm_db_SQLParamData_helper( put_param_data_args );
6415
6841
  }
6416
6842
 
6417
6843
  if (put_param_data_args != NULL) {
6418
6844
  ruby_xfree( put_param_data_args );
6419
6845
  put_param_data_args = NULL;
6420
6846
  }
6847
+
6848
+ if ( rc == SQL_ERROR ) {
6849
+ _ruby_ibm_db_check_sql_errors( stmt_res, DB_STMT, stmt_res->hstmt, SQL_HANDLE_STMT, rc, 1, NULL, NULL, -1, 1, 0 );
6850
+ if( stmt_res != NULL && stmt_res->ruby_stmt_err_msg != NULL ) {
6851
+ #ifdef UNICODE_SUPPORT_VERSION
6852
+ *error = rb_str_concat( _ruby_ibm_db_export_char_to_utf8_rstr( "Sending data failed: "),
6853
+ _ruby_ibm_db_export_sqlwchar_to_utf8_rstr( stmt_res->ruby_stmt_err_msg,
6854
+ stmt_res->ruby_stmt_err_msg_len )
6855
+ );
6856
+ #else
6857
+ *error = rb_str_cat2(rb_str_new2("Sending data failed: "), stmt_res->ruby_stmt_err_msg );
6858
+ #endif
6859
+ } else {
6860
+ #ifdef UNICODE_SUPPORT_VERSION
6861
+ *error = _ruby_ibm_db_export_char_to_utf8_rstr("Sending data failed: <error message could not be retrieved>");
6862
+ #else
6863
+ *error = rb_str_new2("Sending data failed: <error message could not be retrieved>");
6864
+ #endif
6865
+ }
6866
+
6867
+ return Qnil;
6868
+ }
6421
6869
  }
6870
+
6422
6871
  return Qtrue;
6423
6872
  }
6424
6873
  /*
@@ -6482,7 +6931,7 @@ VALUE ibm_db_execute(int argc, VALUE *argv, VALUE self)
6482
6931
  bind_array->num = 0;
6483
6932
  bind_array->error = &error;
6484
6933
 
6485
- #ifdef GIL_RELEASE_VERSION
6934
+ #ifdef UNICODE_SUPPORT_VERSION
6486
6935
  ret_value = rb_thread_blocking_region( (void *)_ruby_ibm_db_execute_helper, bind_array,
6487
6936
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
6488
6937
  #else
@@ -6642,7 +7091,7 @@ VALUE ibm_db_conn_errormsg(int argc, VALUE *argv, VALUE self)
6642
7091
 
6643
7092
  rb_scan_args(argc, argv, "01", &connection);
6644
7093
 
6645
- rb_warn("Method conn_errormsg is deprecated, use getErrormsg");
7094
+ /*rb_warn("Method conn_errormsg is deprecated, use getErrormsg");*/
6646
7095
 
6647
7096
  if (!NIL_P(connection)) {
6648
7097
  Data_Get_Struct(connection, conn_handle, conn_res);
@@ -6796,7 +7245,7 @@ VALUE ibm_db_conn_error(int argc, VALUE *argv, VALUE self)
6796
7245
 
6797
7246
  rb_scan_args(argc, argv, "01", &connection);
6798
7247
 
6799
- rb_warn("Method conn_error is deprecated, use getErrorstate");
7248
+ /*rb_warn("Method conn_error is deprecated, use getErrorstate");*/
6800
7249
 
6801
7250
  if (!NIL_P(connection)) {
6802
7251
  Data_Get_Struct(connection, conn_handle, conn_res);
@@ -7267,7 +7716,7 @@ VALUE ibm_db_next_result(int argc, VALUE *argv, VALUE self)
7267
7716
  nextresultparams->stmt_res = stmt_res;
7268
7717
  nextresultparams->new_hstmt = &new_hstmt;
7269
7718
 
7270
- #ifdef GIL_RELEASE_VERSION
7719
+ #ifdef UNICODE_SUPPORT_VERSION
7271
7720
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLNextResult_helper, nextresultparams,
7272
7721
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
7273
7722
  #else
@@ -7366,7 +7815,7 @@ VALUE ibm_db_num_fields(int argc, VALUE *argv, VALUE self)
7366
7815
  result_cols_args->stmt_res = stmt_res;
7367
7816
  result_cols_args->count = 0;
7368
7817
 
7369
- #ifdef GIL_RELEASE_VERSION
7818
+ #ifdef UNICODE_SUPPORT_VERSION
7370
7819
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLNumResultCols_helper, result_cols_args,
7371
7820
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
7372
7821
  #else
@@ -7459,7 +7908,7 @@ VALUE ibm_db_num_rows(int argc, VALUE *argv, VALUE self)
7459
7908
  row_count_args->stmt_res = stmt_res;
7460
7909
  row_count_args->count = 0;
7461
7910
 
7462
- #ifdef GIL_RELEASE_VERSION
7911
+ #ifdef UNICODE_SUPPORT_VERSION
7463
7912
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLRowCount_helper, row_count_args,
7464
7913
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
7465
7914
  #else
@@ -7515,7 +7964,7 @@ static int _ruby_ibm_db_get_column_by_name(stmt_handle *stmt_res, VALUE column,
7515
7964
  if ( stmt_res->column_info == NULL ) {
7516
7965
  if ( release_gil == 1 ) {
7517
7966
 
7518
- #ifdef GIL_RELEASE_VERSION
7967
+ #ifdef UNICODE_SUPPORT_VERSION
7519
7968
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_get_result_set_info, stmt_res,
7520
7969
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
7521
7970
  #else
@@ -7678,7 +8127,7 @@ VALUE ibm_db_field_display_size(int argc, VALUE *argv, VALUE self)
7678
8127
  colattr_args->col_num = col+1;
7679
8128
  colattr_args->FieldIdentifier = SQL_DESC_DISPLAY_SIZE;
7680
8129
 
7681
- #ifdef GIL_RELEASE_VERSION
8130
+ #ifdef UNICODE_SUPPORT_VERSION
7682
8131
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLColAttributes_helper, colattr_args,
7683
8132
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
7684
8133
  #else
@@ -7998,7 +8447,7 @@ VALUE ibm_db_field_width(int argc, VALUE *argv, VALUE self)
7998
8447
  colattr_args->col_num = col+1;
7999
8448
  colattr_args->FieldIdentifier = SQL_DESC_LENGTH;
8000
8449
 
8001
- #ifdef GIL_RELEASE_VERSION
8450
+ #ifdef UNICODE_SUPPORT_VERSION
8002
8451
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLColAttributes_helper, colattr_args,
8003
8452
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
8004
8453
  #else
@@ -8104,7 +8553,7 @@ VALUE ibm_db_rollback(int argc, VALUE *argv, VALUE self)
8104
8553
  end_X_args->handleType = SQL_HANDLE_DBC;
8105
8554
  end_X_args->completionType = SQL_ROLLBACK; /*Remeber you are Rollingback the transaction*/
8106
8555
 
8107
- #ifdef GIL_RELEASE_VERSION
8556
+ #ifdef UNICODE_SUPPORT_VERSION
8108
8557
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLEndTran, end_X_args,
8109
8558
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
8110
8559
  #else
@@ -8404,6 +8853,14 @@ static VALUE _ruby_ibm_db_result_helper(ibm_db_result_args *data) {
8404
8853
  */
8405
8854
  in_length = in_length * 2;
8406
8855
  }
8856
+
8857
+ if( column_type == SQL_CHAR || column_type == SQL_VARCHAR ) {
8858
+ /* Multiply size by 4 to handle different client and server codepages.
8859
+ * factor of 4 should suffice as known characters today well fit in 4 bytes.
8860
+ */
8861
+ in_length = in_length * 4;
8862
+ }
8863
+
8407
8864
  out_ptr = (SQLPOINTER)ALLOC_N(char,in_length);
8408
8865
  memset(out_ptr, '\0', in_length);
8409
8866
  #endif
@@ -8429,7 +8886,7 @@ static VALUE _ruby_ibm_db_result_helper(ibm_db_result_args *data) {
8429
8886
  #ifdef UNICODE_SUPPORT_VERSION
8430
8887
  return_value = _ruby_ibm_db_export_sqlwchar_to_utf8_rstr(out_ptr, out_length);
8431
8888
  #else
8432
- return_value = rb_str_new2((char*)out_ptr);
8889
+ return_value = rb_str_new((char*)out_ptr, out_length);
8433
8890
  #endif
8434
8891
  ruby_xfree( out_ptr );
8435
8892
  out_ptr = NULL;
@@ -8685,7 +9142,7 @@ VALUE ibm_db_result(int argc, VALUE *argv, VALUE self)
8685
9142
  if ( !NIL_P( stmt ) ) {
8686
9143
  Data_Get_Struct(stmt, stmt_handle, result_args->stmt_res);
8687
9144
 
8688
- #ifdef GIL_RELEASE_VERSION
9145
+ #ifdef UNICODE_SUPPORT_VERSION
8689
9146
  ret_val = rb_thread_blocking_region( (void *)_ruby_ibm_db_result_helper, result_args,
8690
9147
  (void *)_ruby_ibm_db_Statement_level_UBF, result_args->stmt_res );
8691
9148
  #else
@@ -8937,20 +9394,20 @@ static VALUE _ruby_ibm_db_bind_fetch_helper(ibm_db_fetch_helper_args *data)
8937
9394
  #ifdef UNICODE_SUPPORT_VERSION
8938
9395
  rb_hash_aset(return_value, colName, _ruby_ibm_db_export_sqlwchar_to_utf8_rstr(row_data->str_val, out_length ));
8939
9396
  #else
8940
- rb_hash_aset(return_value, colName, rb_str_new2((char *)row_data->str_val));
9397
+ rb_hash_aset(return_value, colName, rb_str_new((char *)row_data->str_val, out_length));
8941
9398
  #endif
8942
9399
  }
8943
9400
  if ( op == FETCH_INDEX ) {
8944
9401
  #ifdef UNICODE_SUPPORT_VERSION
8945
9402
  rb_ary_store(return_value, i, _ruby_ibm_db_export_sqlwchar_to_utf8_rstr(row_data->str_val, out_length ));
8946
9403
  #else
8947
- rb_ary_store(return_value, i, rb_str_new2((char *)row_data->str_val));
9404
+ rb_ary_store(return_value, i, rb_str_new((char *)row_data->str_val, out_length));
8948
9405
  #endif
8949
9406
  } else if ( op == FETCH_BOTH ) {
8950
9407
  #ifdef UNICODE_SUPPORT_VERSION
8951
9408
  rb_hash_aset(return_value, INT2NUM(i), _ruby_ibm_db_export_sqlwchar_to_utf8_rstr(row_data->str_val, out_length ));
8952
9409
  #else
8953
- rb_hash_aset(return_value, INT2NUM(i), rb_str_new2((char *)row_data->str_val));
9410
+ rb_hash_aset(return_value, INT2NUM(i), rb_str_new((char *)row_data->str_val, out_length));
8954
9411
  #endif
8955
9412
  }
8956
9413
  break;
@@ -9488,7 +9945,7 @@ VALUE ibm_db_fetch_row(int argc, VALUE *argv, VALUE self)
9488
9945
  helper_args->arg_count = argc;
9489
9946
  helper_args->error = &error;
9490
9947
 
9491
- #ifdef GIL_RELEASE_VERSION
9948
+ #ifdef UNICODE_SUPPORT_VERSION
9492
9949
  ret_val = rb_thread_blocking_region( (void *)_ruby_ibm_db_fetch_row_helper, helper_args,
9493
9950
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
9494
9951
  #else
@@ -9561,7 +10018,7 @@ VALUE ibm_db_fetch_assoc(int argc, VALUE *argv, VALUE self) {
9561
10018
  helper_args->error = &error;
9562
10019
  helper_args->funcType = FETCH_ASSOC;
9563
10020
 
9564
- #ifdef GIL_RELEASE_VERSION
10021
+ #ifdef UNICODE_SUPPORT_VERSION
9565
10022
  ret_val = rb_thread_blocking_region( (void *)_ruby_ibm_db_bind_fetch_helper, helper_args,
9566
10023
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
9567
10024
  #else
@@ -9648,7 +10105,7 @@ VALUE ibm_db_fetch_object(int argc, VALUE *argv, VALUE self)
9648
10105
  helper_args->error = &error;
9649
10106
  helper_args->funcType = FETCH_ASSOC;
9650
10107
 
9651
- #ifdef GIL_RELEASE_VERSION
10108
+ #ifdef UNICODE_SUPPORT_VERSION
9652
10109
  row_res->hash = rb_thread_blocking_region( (void *)_ruby_ibm_db_bind_fetch_helper, helper_args,
9653
10110
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
9654
10111
  #else
@@ -9730,7 +10187,7 @@ VALUE ibm_db_fetch_array(int argc, VALUE *argv, VALUE self)
9730
10187
  helper_args->error = &error;
9731
10188
  helper_args->funcType = FETCH_INDEX;
9732
10189
 
9733
- #ifdef GIL_RELEASE_VERSION
10190
+ #ifdef UNICODE_SUPPORT_VERSION
9734
10191
  ret_val = rb_thread_blocking_region( (void *)_ruby_ibm_db_bind_fetch_helper, helper_args,
9735
10192
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
9736
10193
  #else
@@ -9806,7 +10263,7 @@ VALUE ibm_db_fetch_both(int argc, VALUE *argv, VALUE self)
9806
10263
  helper_args->error = &error;
9807
10264
  helper_args->funcType = FETCH_BOTH;
9808
10265
 
9809
- #ifdef GIL_RELEASE_VERSION
10266
+ #ifdef UNICODE_SUPPORT_VERSION
9810
10267
  ret_val = rb_thread_blocking_region( (void *)_ruby_ibm_db_bind_fetch_helper, helper_args,
9811
10268
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
9812
10269
  #else
@@ -10557,7 +11014,7 @@ VALUE ibm_db_server_info(int argc, VALUE *argv, VALUE self)
10557
11014
  getInfo_args->infoValue = NULL;
10558
11015
  getInfo_args->buff_length = 0;
10559
11016
 
10560
- #ifdef GIL_RELEASE_VERSION
11017
+ #ifdef UNICODE_SUPPORT_VERSION
10561
11018
  return_value = rb_thread_blocking_region( (void *)ibm_db_server_info_helper, getInfo_args,
10562
11019
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
10563
11020
  #else
@@ -10844,7 +11301,7 @@ VALUE ibm_db_client_info(int argc, VALUE *argv, VALUE self)
10844
11301
  getInfo_args->infoValue = NULL;
10845
11302
  getInfo_args->buff_length = 0;
10846
11303
 
10847
- #ifdef GIL_RELEASE_VERSION
11304
+ #ifdef UNICODE_SUPPORT_VERSION
10848
11305
  return_value = rb_thread_blocking_region( (void *)ibm_db_client_info_helper, getInfo_args,
10849
11306
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
10850
11307
  #else