ibm_db 2.5.7-x86-mingw32 → 2.5.9-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES CHANGED
@@ -1,5 +1,9 @@
1
1
  Change Log
2
2
  ==============
3
+ 2012/01/03 (IBM_DB adapter 2.5.9, driver 2.5.9) :
4
+ - Support for Create and Drop database on DB2 LUW with DB2 client version V97fp4 and above
5
+ - Fixed bug #29482 - Fixed bigint being returned as string in the adapter
6
+
3
7
  2011/09/18 (IBM_DB adapter 2.5.7, driver 2.5.7) :
4
8
  - Support for Rails-3.1.0
5
9
  - Fixed bug #29052 -> prepare results in empty error message
data/README CHANGED
@@ -1,5 +1,5 @@
1
1
  =====================================================================
2
- README for the IBM_DB Adapter (2.5.7) and Driver (2.5.7) (2011/09/18)
2
+ README for the IBM_DB Adapter (2.5.9) and Driver (2.5.9) (2012/01/03)
3
3
  For ActiveRecord Version >= 1.15.5 (and Rails >= 1.2.5)
4
4
  =====================================================================
5
5
 
data/ext/extconf.rb CHANGED
@@ -7,7 +7,7 @@
7
7
  # +----------------------------------------------------------------------+
8
8
 
9
9
  require 'mkmf'
10
- WIN = RUBY_PLATFORM =~ /mswin/
10
+ WIN = RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
11
11
 
12
12
  # use ENV['DB2DIR'] or latest db2 you can find
13
13
  # (we need to revisit default when db2 10.x comes out)
data/ext/ibm_db.c CHANGED
@@ -12,7 +12,7 @@
12
12
  +----------------------------------------------------------------------+
13
13
  */
14
14
 
15
- #define MODULE_RELEASE "2.5.7"
15
+ #define MODULE_RELEASE "2.5.9"
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 )*/
@@ -2435,7 +2492,7 @@ static VALUE _ruby_ibm_db_connect_helper( int argc, VALUE *argv, int isPersisten
2435
2492
  }
2436
2493
 
2437
2494
  /* Call the function where the actual logic is being run*/
2438
- #ifdef GIL_RELEASE_VERSION
2495
+ #ifdef UNICODE_SUPPORT_VERSION
2439
2496
  return_value = rb_thread_blocking_region( (void *)_ruby_ibm_db_connect_helper2, helper_args,
2440
2497
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
2441
2498
  #else
@@ -2776,6 +2833,366 @@ VALUE ibm_db_pconnect(int argc, VALUE *argv, VALUE self)
2776
2833
 
2777
2834
  return _ruby_ibm_db_connect_helper( argc, argv, 1);
2778
2835
  }
2836
+ /*
2837
+ * CreateDB helper
2838
+ */
2839
+ VALUE ruby_ibm_db_createDb_helper(VALUE connection, VALUE dbName, VALUE codeSet, VALUE mode, int createNX) {
2840
+
2841
+ VALUE return_value = Qfalse;
2842
+ #ifdef UNICODE_SUPPORT_VERSION
2843
+ VALUE dbName_utf16 = Qnil;
2844
+ VALUE codeSet_utf16 = Qnil;
2845
+ VALUE mode_utf16 = Qnil;
2846
+ #endif
2847
+
2848
+ int rc;
2849
+
2850
+ create_drop_db_args *create_db_args = NULL;
2851
+ conn_handle *conn_res;
2852
+
2853
+ if (!NIL_P(connection)) {
2854
+ Data_Get_Struct(connection, conn_handle, conn_res);
2855
+
2856
+ if( 0 == createDbSupported ) {
2857
+ rb_warn("Create Database not supported: This function is only supported from DB2 Client v97fp4 version and onwards");
2858
+ return Qfalse;
2859
+ }
2860
+
2861
+ if (!conn_res->handle_active) {
2862
+ rb_warn("Connection is not active");
2863
+ return Qfalse;
2864
+ }
2865
+
2866
+ if (!NIL_P(dbName)) {
2867
+ create_db_args = ALLOC( create_drop_db_args );
2868
+ memset(create_db_args,'\0',sizeof(struct _ibm_db_create_drop_db_args_struct));
2869
+
2870
+ #ifdef UNICODE_SUPPORT_VERSION
2871
+ dbName_utf16 = _ruby_ibm_db_export_str_to_utf16(dbName);
2872
+
2873
+ create_db_args->dbName = (SQLWCHAR*)RSTRING_PTR(dbName_utf16);
2874
+ create_db_args->dbName_string_len = RSTRING_LEN(dbName_utf16)/sizeof(SQLWCHAR); /*RSTRING_LEN returns number of bytes*/
2875
+
2876
+ if(!NIL_P(codeSet)){
2877
+ codeSet_utf16 = _ruby_ibm_db_export_str_to_utf16(codeSet);
2878
+ create_db_args->codeSet = (SQLWCHAR*)RSTRING_PTR(codeSet_utf16);
2879
+ create_db_args->codeSet_string_len = RSTRING_LEN(codeSet_utf16)/sizeof(SQLWCHAR); /*RSTRING_LEN returns number of bytes*/
2880
+ } else {
2881
+ create_db_args->codeSet = NULL;
2882
+ }
2883
+
2884
+ if(!NIL_P(mode)) {
2885
+ mode_utf16 = _ruby_ibm_db_export_str_to_utf16(mode);
2886
+ create_db_args->mode = (SQLWCHAR*)RSTRING_PTR(mode_utf16);
2887
+ create_db_args->mode_string_len = RSTRING_LEN(mode_utf16)/sizeof(SQLWCHAR); /*RSTRING_LEN returns number of bytes*/
2888
+ } else {
2889
+ create_db_args->mode = NULL;
2890
+ }
2891
+ #else
2892
+ create_db_args->dbName = (SQLCHAR*)rb_str2cstr(dbName, &(create_db_args->dbName_string_len));
2893
+ if(!NIL_P(codeSet)){
2894
+ create_db_args->codeSet = (SQLCHAR*)rb_str2cstr(codeSet, &(create_db_args->codeSet_string_len));
2895
+ } else {
2896
+ create_db_args->codeSet = NULL;
2897
+ }
2898
+ if(!NIL_P(mode)) {
2899
+ create_db_args->mode = (SQLCHAR*)rb_str2cstr(mode, &(create_db_args->mode_string_len));
2900
+ } else {
2901
+ create_db_args->mode = NULL;
2902
+ }
2903
+ #endif
2904
+ } else {
2905
+ rb_warn("Invalid Parameter: Database Name cannot be nil");
2906
+ return Qfalse;
2907
+ }
2908
+
2909
+ create_db_args->conn_res = conn_res;
2910
+
2911
+ _ruby_ibm_db_clear_conn_err_cache();
2912
+
2913
+ #ifdef UNICODE_SUPPORT_VERSION
2914
+ rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLCreateDB_helper, create_db_args,
2915
+ (void *)_ruby_ibm_db_Connection_level_UBF, NULL );
2916
+ #else
2917
+ rc = _ruby_ibm_db_SQLCreateDB_helper( create_db_args );
2918
+ #endif
2919
+
2920
+ if ( rc == SQL_ERROR ) {
2921
+ conn_res->error_recno_tracker = 1;
2922
+ conn_res->errormsg_recno_tracker = 1;
2923
+ _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, NULL, -1, 1, 0 );
2924
+ if(conn_res->sqlcode == -1005 && 1 == createNX) {
2925
+ return_value = Qtrue; /*Return true if database already exists and Create if not existing called*/
2926
+ /*Clear the error messages*/
2927
+ #ifdef UNICODE_SUPPORT_VERSION
2928
+ memset( conn_res->ruby_error_state, '\0', (SQL_SQLSTATE_SIZE + 1) * sizeof(SQLWCHAR) );
2929
+ memset( conn_res->ruby_error_msg, '\0', (DB2_MAX_ERR_MSG_LEN + 1) * sizeof(SQLWCHAR) );
2930
+ #else
2931
+ memset( conn_res->ruby_error_state, '\0', SQL_SQLSTATE_SIZE + 1 );
2932
+ memset( conn_res->ruby_error_msg, '\0', DB2_MAX_ERR_MSG_LEN + 1 );
2933
+ #endif
2934
+ } else {
2935
+ return_value = Qfalse;
2936
+ }
2937
+ } else {
2938
+ return_value = Qtrue;
2939
+ }
2940
+ }
2941
+
2942
+ /*Free memory allocated*/
2943
+ if( create_db_args != NULL ) {
2944
+ ruby_xfree( create_db_args );
2945
+ create_db_args = NULL;
2946
+ }
2947
+
2948
+ return return_value;
2949
+ }
2950
+ /* */
2951
+ /*
2952
+ * IBM_DB.createDB -- Creates a Database
2953
+ *
2954
+ * ===Description
2955
+ * bool IBM_DB.createDB ( resource connection , string dbName [, String codeSet, String mode] )
2956
+ *
2957
+ * Creates a database with the specified name. Returns true if operation successful else false
2958
+ *
2959
+ * ===Parameters
2960
+ *
2961
+ * connection
2962
+ * A valid database connection resource variable as returned from IBM_DB.connect() or IBM_DB.pconnect() with parameter ATTACH=true specified.
2963
+ * IBM_DB.connect('DRIVER={IBM DB2 ODBC DRIVER};ATTACH=true;HOSTNAME=myhost;PORT=1234;PROTOCOL=TCPIP;UID=user;PWD=secret;','','')
2964
+ * Note: Database is not specified. In this case we connect to the instance only.
2965
+ *
2966
+ * dbName
2967
+ * Name of the database that is to be created.
2968
+ *
2969
+ * codeSet
2970
+ * Database code set information.
2971
+ * Note: If the value of the codeSet argument is not specified,
2972
+ * the database is created in the Unicode code page for DB2 data servers and in the UTF-8 code page for IDS data servers
2973
+ *
2974
+ * mode
2975
+ * Database logging mode.
2976
+ * Note: This value is applicable only to IDS data servers
2977
+ *
2978
+ * ===Return Values
2979
+ *
2980
+ * Returns TRUE on success or FALSE on failure.
2981
+ */
2982
+ VALUE ibm_db_createDB(int argc, VALUE *argv, VALUE self)
2983
+ {
2984
+ VALUE connection = Qnil;
2985
+ VALUE dbName = Qnil;
2986
+ VALUE codeSet = Qnil;
2987
+ VALUE mode = Qnil;
2988
+
2989
+ rb_scan_args(argc, argv, "22", &connection, &dbName, &codeSet, &mode);
2990
+
2991
+ return ruby_ibm_db_createDb_helper(connection, dbName, codeSet, mode, 0);
2992
+ }
2993
+ /*
2994
+ * DropDb helper
2995
+ */
2996
+ VALUE ruby_ibm_db_dropDb_helper(VALUE connection, VALUE dbName) {
2997
+ #ifdef UNICODE_SUPPORT_VERSION
2998
+ VALUE dbName_utf16 = Qnil;
2999
+ #endif
3000
+
3001
+ VALUE return_value = Qfalse;
3002
+
3003
+ int rc;
3004
+
3005
+ create_drop_db_args *drop_db_args = NULL;
3006
+ conn_handle *conn_res = NULL;
3007
+
3008
+ if (!NIL_P(connection)) {
3009
+ Data_Get_Struct(connection, conn_handle, conn_res);
3010
+
3011
+ if( 0 == dropDbSupported ) {
3012
+ rb_warn("Drop Database not supported: This function is only supported from DB2 Client v97fp4 version and onwards");
3013
+ return Qfalse;
3014
+ }
3015
+
3016
+ if (!conn_res->handle_active) {
3017
+ rb_warn("Connection is not active");
3018
+ return Qfalse;
3019
+ }
3020
+
3021
+ if (!NIL_P(dbName)) {
3022
+ drop_db_args = ALLOC( create_drop_db_args );
3023
+ memset(drop_db_args,'\0',sizeof(struct _ibm_db_create_drop_db_args_struct));
3024
+
3025
+ #ifdef UNICODE_SUPPORT_VERSION
3026
+ dbName_utf16 = _ruby_ibm_db_export_str_to_utf16(dbName);
3027
+
3028
+ drop_db_args->dbName = (SQLWCHAR*)RSTRING_PTR(dbName_utf16);
3029
+ drop_db_args->dbName_string_len = RSTRING_LEN(dbName_utf16)/sizeof(SQLWCHAR); /*RSTRING_LEN returns number of bytes*/
3030
+ #else
3031
+ drop_db_args->dbName = (SQLCHAR*)rb_str2cstr(dbName, &(drop_db_args->dbName_string_len));
3032
+ #endif
3033
+ } else {
3034
+ rb_warn("Invalid Parameter: Database Name cannot be nil");
3035
+ return Qfalse;
3036
+ }
3037
+
3038
+ drop_db_args->conn_res = conn_res;
3039
+
3040
+ _ruby_ibm_db_clear_conn_err_cache();
3041
+
3042
+ #ifdef UNICODE_SUPPORT_VERSION
3043
+ rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLDropDB_helper, drop_db_args,
3044
+ (void *)_ruby_ibm_db_Connection_level_UBF, NULL );
3045
+ #else
3046
+ rc = _ruby_ibm_db_SQLDropDB_helper( drop_db_args );
3047
+ #endif
3048
+
3049
+ if ( rc == SQL_ERROR ) {
3050
+ conn_res->error_recno_tracker = 1;
3051
+ conn_res->errormsg_recno_tracker = 1;
3052
+ _ruby_ibm_db_check_sql_errors( conn_res, DB_CONN, conn_res->hdbc, SQL_HANDLE_DBC, rc, 1, NULL, NULL, -1, 1, 0 );
3053
+ return_value = Qfalse;
3054
+ } else {
3055
+ return_value = Qtrue;
3056
+ }
3057
+ }
3058
+
3059
+ /*Free memory allocated*/
3060
+ if( drop_db_args != NULL ) {
3061
+ ruby_xfree( drop_db_args );
3062
+ drop_db_args = NULL;
3063
+ }
3064
+
3065
+ return return_value;
3066
+ }
3067
+ /* */
3068
+ /*
3069
+ * IBM_DB.dropDB -- Drops the mentioned Database
3070
+ *
3071
+ * ===Description
3072
+ * bool IBM_DB.dropDB ( resource connection , string dbName [, String codeSet, String mode] )
3073
+ *
3074
+ * Drops a database with the specified name. Returns true if operation successful else false
3075
+ *
3076
+ * ===Parameters
3077
+ *
3078
+ * connection
3079
+ * A valid database connection resource variable as returned from IBM_DB.connect() or IBM_DB.pconnect() with parameter ATTACH=true specified.
3080
+ * IBM_DB.connect('DRIVER={IBM DB2 ODBC DRIVER};ATTACH=true;HOSTNAME=myhost;PORT=1234;PROTOCOL=TCPIP;UID=user;PWD=secret;','','')
3081
+ * Note: Database is not specified. In this case we connect to the instance only.
3082
+ * dbName
3083
+ * Name of the database that is to be created.
3084
+ *
3085
+ * ===Return Values
3086
+ *
3087
+ * Returns TRUE on success or FALSE on failure.
3088
+ */
3089
+ VALUE ibm_db_dropDB(int argc, VALUE *argv, VALUE self)
3090
+ {
3091
+ VALUE connection = Qnil;
3092
+ VALUE dbName = Qnil;
3093
+
3094
+ rb_scan_args(argc, argv, "2", &connection, &dbName);
3095
+
3096
+ return ruby_ibm_db_dropDb_helper(connection, dbName);
3097
+ }
3098
+ /* */
3099
+ /*
3100
+ * IBM_DB.recreateDB -- Recreates an Existing database
3101
+ *
3102
+ * ===Description
3103
+ * bool IBM_DB.recreateDB ( resource connection , string dbName [, String codeSet, String mode] )
3104
+ *
3105
+ * Recreates a database with the specified name. This method will drop an existing database and then re-create it.
3106
+ * If database doesnot exist the method will return false.
3107
+ * Returns true if operation successful else false
3108
+ *
3109
+ * ===Parameters
3110
+ *
3111
+ * connection
3112
+ * A valid database connection resource variable as returned from IBM_DB.connect() or IBM_DB.pconnect() with parameter ATTACH=true specified.
3113
+ * IBM_DB.connect('DRIVER={IBM DB2 ODBC DRIVER};ATTACH=true;HOSTNAME=myhost;PORT=1234;PROTOCOL=TCPIP;UID=user;PWD=secret;','','')
3114
+ * Note: Database is not specified. In this case we connect to the instance only.
3115
+ *
3116
+ * dbName
3117
+ * Name of the database that is to be created.
3118
+ *
3119
+ * codeSet
3120
+ * Database code set information.
3121
+ * Note: If the value of the codeSet argument is not specified,
3122
+ * the database is created in the Unicode code page for DB2 data servers and in the UTF-8 code page for IDS data servers
3123
+ *
3124
+ * mode
3125
+ * Database logging mode.
3126
+ * Note: This value is applicable only to IDS data servers
3127
+ *
3128
+ * ===Return Values
3129
+ *
3130
+ * Returns TRUE on success or FALSE on failure.
3131
+ */
3132
+ /*VALUE ibm_db_recreateDB(int argc, VALUE *argv, VALUE self)
3133
+ {
3134
+ VALUE connection = Qnil;
3135
+ VALUE dbName = Qnil;
3136
+ VALUE codeSet = Qnil;
3137
+ VALUE mode = Qnil;
3138
+ VALUE return_value = Qnil;
3139
+
3140
+ rb_scan_args(argc, argv, "22", &connection, &dbName, &codeSet, &mode);
3141
+
3142
+ return_value = ruby_ibm_db_dropDb_helper(connection, dbName);
3143
+
3144
+ if(return_value == Qfalse) {
3145
+ return Qfalse;
3146
+ }
3147
+
3148
+ return ruby_ibm_db_createDb_helper(connection, dbName, codeSet, mode);
3149
+ }*/
3150
+ /* */
3151
+ /*
3152
+ * IBM_DB.createDBNX -- creates a database if it does not exist aleady
3153
+ *
3154
+ * ===Description
3155
+ * bool IBM_DB.createDBNX ( resource connection , string dbName [, String codeSet, String mode] )
3156
+ *
3157
+ * 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.
3158
+ * If database doesnot exist the method will return false.
3159
+ * Returns true if operation successful else false
3160
+ *
3161
+ * ===Parameters
3162
+ *
3163
+ * connection
3164
+ * A valid database connection resource variable as returned from IBM_DB.connect() or IBM_DB.pconnect() with parameter ATTACH=true specified.
3165
+ * IBM_DB.connect('DRIVER={IBM DB2 ODBC DRIVER};ATTACH=true;HOSTNAME=myhost;PORT=1234;PROTOCOL=TCPIP;UID=user;PWD=secret;','','')
3166
+ * Note: Database is not specified. In this case we connect to the instance only.
3167
+ *
3168
+ * dbName
3169
+ * Name of the database that is to be created.
3170
+ *
3171
+ * codeSet
3172
+ * Database code set information.
3173
+ * Note: If the value of the codeSet argument is not specified,
3174
+ * the database is created in the Unicode code page for DB2 data servers and in the UTF-8 code page for IDS data servers
3175
+ *
3176
+ * mode
3177
+ * Database logging mode.
3178
+ * Note: This value is applicable only to IDS data servers
3179
+ *
3180
+ * ===Return Values
3181
+ *
3182
+ * Returns TRUE on success or FALSE on failure.
3183
+ */
3184
+ VALUE ibm_db_createDBNX(int argc, VALUE *argv, VALUE self)
3185
+ {
3186
+ VALUE connection = Qnil;
3187
+ VALUE dbName = Qnil;
3188
+ VALUE codeSet = Qnil;
3189
+ VALUE mode = Qnil;
3190
+ VALUE return_value = Qnil;
3191
+
3192
+ rb_scan_args(argc, argv, "22", &connection, &dbName, &codeSet, &mode);
3193
+
3194
+ return ruby_ibm_db_createDb_helper(connection, dbName, codeSet, mode, 1);
3195
+ }
2779
3196
  /* */
2780
3197
 
2781
3198
  /*
@@ -2984,7 +3401,7 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
2984
3401
  case 3:
2985
3402
  param_type = SQL_PARAM_INPUT;
2986
3403
 
2987
- #ifdef GIL_RELEASE_VERSION
3404
+ #ifdef UNICODE_SUPPORT_VERSION
2988
3405
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLDescribeParam_helper, data,
2989
3406
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res);
2990
3407
  #else
@@ -3004,7 +3421,7 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
3004
3421
 
3005
3422
  case 4:
3006
3423
 
3007
- #ifdef GIL_RELEASE_VERSION
3424
+ #ifdef UNICODE_SUPPORT_VERSION
3008
3425
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLDescribeParam_helper, data,
3009
3426
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res);
3010
3427
  #else
@@ -3024,7 +3441,7 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
3024
3441
 
3025
3442
  case 5:
3026
3443
 
3027
- #ifdef GIL_RELEASE_VERSION
3444
+ #ifdef UNICODE_SUPPORT_VERSION
3028
3445
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLDescribeParam_helper, data,
3029
3446
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
3030
3447
  #else
@@ -3045,7 +3462,7 @@ VALUE ibm_db_bind_param_helper(int argc, char * varname, long varname_len ,long
3045
3462
 
3046
3463
  case 6:
3047
3464
 
3048
- #ifdef GIL_RELEASE_VERSION
3465
+ #ifdef UNICODE_SUPPORT_VERSION
3049
3466
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLDescribeParam_helper, data,
3050
3467
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
3051
3468
  #else
@@ -3277,7 +3694,7 @@ VALUE ibm_db_close(int argc, VALUE *argv, VALUE self)
3277
3694
  end_X_args->handleType = SQL_HANDLE_DBC;
3278
3695
  end_X_args->completionType = SQL_ROLLBACK; /*Remeber you are rolling back the transaction*/
3279
3696
 
3280
- #ifdef GIL_RELEASE_VERSION
3697
+ #ifdef UNICODE_SUPPORT_VERSION
3281
3698
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLEndTran, end_X_args,
3282
3699
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
3283
3700
  #else
@@ -3295,7 +3712,7 @@ VALUE ibm_db_close(int argc, VALUE *argv, VALUE self)
3295
3712
  }
3296
3713
  }
3297
3714
 
3298
- #ifdef GIL_RELEASE_VERSION
3715
+ #ifdef UNICODE_SUPPORT_VERSION
3299
3716
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLDisconnect_helper, &(conn_res->hdbc),
3300
3717
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
3301
3718
  #else
@@ -3472,7 +3889,7 @@ VALUE ibm_db_column_privileges(int argc, VALUE *argv, VALUE self)
3472
3889
  }
3473
3890
  col_privileges_args->stmt_res = stmt_res;
3474
3891
 
3475
- #ifdef GIL_RELEASE_VERSION
3892
+ #ifdef UNICODE_SUPPORT_VERSION
3476
3893
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLColumnPrivileges_helper, col_privileges_args,
3477
3894
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
3478
3895
  #else
@@ -3652,7 +4069,7 @@ VALUE ibm_db_columns(int argc, VALUE *argv, VALUE self)
3652
4069
  }
3653
4070
  col_metadata_args->stmt_res = stmt_res;
3654
4071
 
3655
- #ifdef GIL_RELEASE_VERSION
4072
+ #ifdef UNICODE_SUPPORT_VERSION
3656
4073
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLColumns_helper, col_metadata_args,
3657
4074
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
3658
4075
  #else
@@ -3818,7 +4235,7 @@ VALUE ibm_db_foreign_keys(int argc, VALUE *argv, VALUE self)
3818
4235
 
3819
4236
  col_metadata_args->stmt_res = stmt_res;
3820
4237
 
3821
- #ifdef GIL_RELEASE_VERSION
4238
+ #ifdef UNICODE_SUPPORT_VERSION
3822
4239
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLForeignKeys_helper, col_metadata_args,
3823
4240
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
3824
4241
  #else
@@ -3974,7 +4391,7 @@ VALUE ibm_db_primary_keys(int argc, VALUE *argv, VALUE self)
3974
4391
  }
3975
4392
  col_metadata_args->stmt_res = stmt_res;
3976
4393
 
3977
- #ifdef GIL_RELEASE_VERSION
4394
+ #ifdef UNICODE_SUPPORT_VERSION
3978
4395
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLPrimaryKeys_helper, col_metadata_args,
3979
4396
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
3980
4397
  #else
@@ -4165,7 +4582,7 @@ VALUE ibm_db_procedure_columns(int argc, VALUE *argv, VALUE self)
4165
4582
  }
4166
4583
  col_metadata_args->stmt_res = stmt_res;
4167
4584
 
4168
- #ifdef GIL_RELEASE_VERSION
4585
+ #ifdef UNICODE_SUPPORT_VERSION
4169
4586
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLProcedureColumns_helper, col_metadata_args,
4170
4587
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res);
4171
4588
  #else
@@ -4322,7 +4739,7 @@ VALUE ibm_db_procedures(int argc, VALUE *argv, VALUE self)
4322
4739
  }
4323
4740
  proc_metadata_args->stmt_res = stmt_res;
4324
4741
 
4325
- #ifdef GIL_RELEASE_VERSION
4742
+ #ifdef UNICODE_SUPPORT_VERSION
4326
4743
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLProcedures_helper, proc_metadata_args,
4327
4744
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res);
4328
4745
  #else
@@ -4499,7 +4916,7 @@ VALUE ibm_db_special_columns(int argc, VALUE *argv, VALUE self)
4499
4916
  }
4500
4917
  col_metadata_args->stmt_res = stmt_res;
4501
4918
 
4502
- #ifdef GIL_RELEASE_VERSION
4919
+ #ifdef UNICODE_SUPPORT_VERSION
4503
4920
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLSpecialColumns_helper, col_metadata_args,
4504
4921
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res);
4505
4922
  #else
@@ -4694,7 +5111,7 @@ VALUE ibm_db_statistics(int argc, VALUE *argv, VALUE self)
4694
5111
  }
4695
5112
  col_metadata_args->stmt_res = stmt_res;
4696
5113
 
4697
- #ifdef GIL_RELEASE_VERSION
5114
+ #ifdef UNICODE_SUPPORT_VERSION
4698
5115
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLStatistics_helper, col_metadata_args,
4699
5116
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
4700
5117
  #else
@@ -4853,7 +5270,7 @@ VALUE ibm_db_table_privileges(int argc, VALUE *argv, VALUE self)
4853
5270
 
4854
5271
  table_privileges_args->stmt_res = stmt_res;
4855
5272
 
4856
- #ifdef GIL_RELEASE_VERSION
5273
+ #ifdef UNICODE_SUPPORT_VERSION
4857
5274
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLTablePrivileges_helper, table_privileges_args,
4858
5275
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
4859
5276
  #else
@@ -5027,7 +5444,7 @@ VALUE ibm_db_tables(int argc, VALUE *argv, VALUE self)
5027
5444
 
5028
5445
  table_metadata_args->stmt_res = stmt_res;
5029
5446
 
5030
- #ifdef GIL_RELEASE_VERSION
5447
+ #ifdef UNICODE_SUPPORT_VERSION
5031
5448
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLTables_helper, table_metadata_args,
5032
5449
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
5033
5450
  #else
@@ -5109,7 +5526,7 @@ VALUE ibm_db_commit(int argc, VALUE *argv, VALUE self)
5109
5526
  end_X_args->handleType = SQL_HANDLE_DBC;
5110
5527
  end_X_args->completionType = SQL_COMMIT; /*Remeber you are Commiting the transaction*/
5111
5528
 
5112
- #ifdef GIL_RELEASE_VERSION
5529
+ #ifdef UNICODE_SUPPORT_VERSION
5113
5530
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLEndTran, end_X_args,
5114
5531
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
5115
5532
  #else
@@ -5189,7 +5606,7 @@ static int _ruby_ibm_db_do_prepare(conn_handle *conn_res, VALUE stmt, stmt_handl
5189
5606
  prepare_args->stmt_res = stmt_res;
5190
5607
 
5191
5608
  /* Prepare the stmt. The cursor type requested has already been set in _ruby_ibm_db_assign_options */
5192
- #ifdef GIL_RELEASE_VERSION
5609
+ #ifdef UNICODE_SUPPORT_VERSION
5193
5610
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLPrepare_helper, prepare_args,
5194
5611
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
5195
5612
  #else
@@ -5327,7 +5744,7 @@ VALUE ibm_db_exec(int argc, VALUE *argv, VALUE self)
5327
5744
 
5328
5745
  exec_direct_args->stmt_res = stmt_res;
5329
5746
 
5330
- #ifdef GIL_RELEASE_VERSION
5747
+ #ifdef UNICODE_SUPPORT_VERSION
5331
5748
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLExecDirect_helper, exec_direct_args,
5332
5749
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
5333
5750
  #else
@@ -5402,7 +5819,7 @@ VALUE ibm_db_free_result(int argc, VALUE *argv, VALUE self)
5402
5819
  freeStmt_args->stmt_res = stmt_res;
5403
5820
  freeStmt_args->option = SQL_CLOSE;
5404
5821
 
5405
- #ifdef GIL_RELEASE_VERSION
5822
+ #ifdef UNICODE_SUPPORT_VERSION
5406
5823
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLFreeStmt_helper, freeStmt_args,
5407
5824
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
5408
5825
  #else
@@ -6507,7 +6924,7 @@ VALUE ibm_db_execute(int argc, VALUE *argv, VALUE self)
6507
6924
  bind_array->num = 0;
6508
6925
  bind_array->error = &error;
6509
6926
 
6510
- #ifdef GIL_RELEASE_VERSION
6927
+ #ifdef UNICODE_SUPPORT_VERSION
6511
6928
  ret_value = rb_thread_blocking_region( (void *)_ruby_ibm_db_execute_helper, bind_array,
6512
6929
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
6513
6930
  #else
@@ -7292,7 +7709,7 @@ VALUE ibm_db_next_result(int argc, VALUE *argv, VALUE self)
7292
7709
  nextresultparams->stmt_res = stmt_res;
7293
7710
  nextresultparams->new_hstmt = &new_hstmt;
7294
7711
 
7295
- #ifdef GIL_RELEASE_VERSION
7712
+ #ifdef UNICODE_SUPPORT_VERSION
7296
7713
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLNextResult_helper, nextresultparams,
7297
7714
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
7298
7715
  #else
@@ -7391,7 +7808,7 @@ VALUE ibm_db_num_fields(int argc, VALUE *argv, VALUE self)
7391
7808
  result_cols_args->stmt_res = stmt_res;
7392
7809
  result_cols_args->count = 0;
7393
7810
 
7394
- #ifdef GIL_RELEASE_VERSION
7811
+ #ifdef UNICODE_SUPPORT_VERSION
7395
7812
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLNumResultCols_helper, result_cols_args,
7396
7813
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
7397
7814
  #else
@@ -7484,7 +7901,7 @@ VALUE ibm_db_num_rows(int argc, VALUE *argv, VALUE self)
7484
7901
  row_count_args->stmt_res = stmt_res;
7485
7902
  row_count_args->count = 0;
7486
7903
 
7487
- #ifdef GIL_RELEASE_VERSION
7904
+ #ifdef UNICODE_SUPPORT_VERSION
7488
7905
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLRowCount_helper, row_count_args,
7489
7906
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
7490
7907
  #else
@@ -7540,7 +7957,7 @@ static int _ruby_ibm_db_get_column_by_name(stmt_handle *stmt_res, VALUE column,
7540
7957
  if ( stmt_res->column_info == NULL ) {
7541
7958
  if ( release_gil == 1 ) {
7542
7959
 
7543
- #ifdef GIL_RELEASE_VERSION
7960
+ #ifdef UNICODE_SUPPORT_VERSION
7544
7961
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_get_result_set_info, stmt_res,
7545
7962
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
7546
7963
  #else
@@ -7703,7 +8120,7 @@ VALUE ibm_db_field_display_size(int argc, VALUE *argv, VALUE self)
7703
8120
  colattr_args->col_num = col+1;
7704
8121
  colattr_args->FieldIdentifier = SQL_DESC_DISPLAY_SIZE;
7705
8122
 
7706
- #ifdef GIL_RELEASE_VERSION
8123
+ #ifdef UNICODE_SUPPORT_VERSION
7707
8124
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLColAttributes_helper, colattr_args,
7708
8125
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
7709
8126
  #else
@@ -8023,7 +8440,7 @@ VALUE ibm_db_field_width(int argc, VALUE *argv, VALUE self)
8023
8440
  colattr_args->col_num = col+1;
8024
8441
  colattr_args->FieldIdentifier = SQL_DESC_LENGTH;
8025
8442
 
8026
- #ifdef GIL_RELEASE_VERSION
8443
+ #ifdef UNICODE_SUPPORT_VERSION
8027
8444
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLColAttributes_helper, colattr_args,
8028
8445
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
8029
8446
  #else
@@ -8129,7 +8546,7 @@ VALUE ibm_db_rollback(int argc, VALUE *argv, VALUE self)
8129
8546
  end_X_args->handleType = SQL_HANDLE_DBC;
8130
8547
  end_X_args->completionType = SQL_ROLLBACK; /*Remeber you are Rollingback the transaction*/
8131
8548
 
8132
- #ifdef GIL_RELEASE_VERSION
8549
+ #ifdef UNICODE_SUPPORT_VERSION
8133
8550
  rc = rb_thread_blocking_region( (void *)_ruby_ibm_db_SQLEndTran, end_X_args,
8134
8551
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
8135
8552
  #else
@@ -8710,7 +9127,7 @@ VALUE ibm_db_result(int argc, VALUE *argv, VALUE self)
8710
9127
  if ( !NIL_P( stmt ) ) {
8711
9128
  Data_Get_Struct(stmt, stmt_handle, result_args->stmt_res);
8712
9129
 
8713
- #ifdef GIL_RELEASE_VERSION
9130
+ #ifdef UNICODE_SUPPORT_VERSION
8714
9131
  ret_val = rb_thread_blocking_region( (void *)_ruby_ibm_db_result_helper, result_args,
8715
9132
  (void *)_ruby_ibm_db_Statement_level_UBF, result_args->stmt_res );
8716
9133
  #else
@@ -9513,7 +9930,7 @@ VALUE ibm_db_fetch_row(int argc, VALUE *argv, VALUE self)
9513
9930
  helper_args->arg_count = argc;
9514
9931
  helper_args->error = &error;
9515
9932
 
9516
- #ifdef GIL_RELEASE_VERSION
9933
+ #ifdef UNICODE_SUPPORT_VERSION
9517
9934
  ret_val = rb_thread_blocking_region( (void *)_ruby_ibm_db_fetch_row_helper, helper_args,
9518
9935
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
9519
9936
  #else
@@ -9586,7 +10003,7 @@ VALUE ibm_db_fetch_assoc(int argc, VALUE *argv, VALUE self) {
9586
10003
  helper_args->error = &error;
9587
10004
  helper_args->funcType = FETCH_ASSOC;
9588
10005
 
9589
- #ifdef GIL_RELEASE_VERSION
10006
+ #ifdef UNICODE_SUPPORT_VERSION
9590
10007
  ret_val = rb_thread_blocking_region( (void *)_ruby_ibm_db_bind_fetch_helper, helper_args,
9591
10008
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
9592
10009
  #else
@@ -9673,7 +10090,7 @@ VALUE ibm_db_fetch_object(int argc, VALUE *argv, VALUE self)
9673
10090
  helper_args->error = &error;
9674
10091
  helper_args->funcType = FETCH_ASSOC;
9675
10092
 
9676
- #ifdef GIL_RELEASE_VERSION
10093
+ #ifdef UNICODE_SUPPORT_VERSION
9677
10094
  row_res->hash = rb_thread_blocking_region( (void *)_ruby_ibm_db_bind_fetch_helper, helper_args,
9678
10095
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
9679
10096
  #else
@@ -9755,7 +10172,7 @@ VALUE ibm_db_fetch_array(int argc, VALUE *argv, VALUE self)
9755
10172
  helper_args->error = &error;
9756
10173
  helper_args->funcType = FETCH_INDEX;
9757
10174
 
9758
- #ifdef GIL_RELEASE_VERSION
10175
+ #ifdef UNICODE_SUPPORT_VERSION
9759
10176
  ret_val = rb_thread_blocking_region( (void *)_ruby_ibm_db_bind_fetch_helper, helper_args,
9760
10177
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
9761
10178
  #else
@@ -9831,7 +10248,7 @@ VALUE ibm_db_fetch_both(int argc, VALUE *argv, VALUE self)
9831
10248
  helper_args->error = &error;
9832
10249
  helper_args->funcType = FETCH_BOTH;
9833
10250
 
9834
- #ifdef GIL_RELEASE_VERSION
10251
+ #ifdef UNICODE_SUPPORT_VERSION
9835
10252
  ret_val = rb_thread_blocking_region( (void *)_ruby_ibm_db_bind_fetch_helper, helper_args,
9836
10253
  (void *)_ruby_ibm_db_Statement_level_UBF, stmt_res );
9837
10254
  #else
@@ -10582,7 +10999,7 @@ VALUE ibm_db_server_info(int argc, VALUE *argv, VALUE self)
10582
10999
  getInfo_args->infoValue = NULL;
10583
11000
  getInfo_args->buff_length = 0;
10584
11001
 
10585
- #ifdef GIL_RELEASE_VERSION
11002
+ #ifdef UNICODE_SUPPORT_VERSION
10586
11003
  return_value = rb_thread_blocking_region( (void *)ibm_db_server_info_helper, getInfo_args,
10587
11004
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
10588
11005
  #else
@@ -10869,7 +11286,7 @@ VALUE ibm_db_client_info(int argc, VALUE *argv, VALUE self)
10869
11286
  getInfo_args->infoValue = NULL;
10870
11287
  getInfo_args->buff_length = 0;
10871
11288
 
10872
- #ifdef GIL_RELEASE_VERSION
11289
+ #ifdef UNICODE_SUPPORT_VERSION
10873
11290
  return_value = rb_thread_blocking_region( (void *)ibm_db_client_info_helper, getInfo_args,
10874
11291
  (void *)_ruby_ibm_db_Connection_level_UBF, NULL);
10875
11292
  #else
data/ext/ruby_ibm_db.h 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, 2010 |
5
+ | (C) Copyright IBM Corporation 2006, 2007, 2008, 2009, 2010, 2012 |
6
6
  +----------------------------------------------------------------------+
7
7
  | Authors: Sushant Koduru, Lynh Nguyen, Kanchana Padmanabhan, |
8
8
  | Dan Scott, Helmut Tessarek, Kellen Bombardier, Sam Ruby |
@@ -135,6 +135,9 @@ void Init_ibm_db();
135
135
  /* Function Declarations */
136
136
 
137
137
  VALUE ibm_db_connect(int argc, VALUE *argv, VALUE self);
138
+ VALUE ibm_db_createDB(int argc, VALUE *argv, VALUE self);
139
+ VALUE ibm_db_dropDB(int argc, VALUE *argv, VALUE self);
140
+ VALUE ibm_db_createDBNX(int argc, VALUE *argv, VALUE self);
138
141
  VALUE ibm_db_commit(int argc, VALUE *argv, VALUE self);
139
142
  VALUE ibm_db_pconnect(int argc, VALUE *argv, VALUE self);
140
143
  VALUE ibm_db_autocommit(int argc, VALUE *argv, VALUE self);
@@ -2,7 +2,7 @@
2
2
  +----------------------------------------------------------------------+
3
3
  | Licensed Materials - Property of IBM |
4
4
  | |
5
- | (C) Copyright IBM Corporation 2009, 2010 |
5
+ | (C) Copyright IBM Corporation 2009, 2010, 2012 |
6
6
  +----------------------------------------------------------------------+
7
7
  | Authors: Praveen Devarao |
8
8
  +----------------------------------------------------------------------+
@@ -372,6 +372,113 @@ int _ruby_ibm_db_SQLExecDirect_helper(exec_cum_prepare_args *data) {
372
372
  return rc;
373
373
  }
374
374
 
375
+ /*
376
+ This function calls SQLCreateDb cli call
377
+ */
378
+ int _ruby_ibm_db_SQLCreateDB_helper(create_drop_db_args *data) {
379
+ int rc = 0;
380
+ #ifndef UNICODE_SUPPORT_VERSION
381
+ #ifdef _WIN32
382
+ HINSTANCE cliLib = NULL;
383
+ FARPROC sqlcreatedb;
384
+ cliLib = DLOPEN( LIBDB2 );
385
+ sqlcreatedb = DLSYM( cliLib, "SQLCreateDb" );
386
+ #elif _AIX
387
+ void *cliLib = NULL;
388
+ typedef int (*sqlcreatedbType)( SQLHDBC, SQLCHAR *, SQLINTEGER, SQLCHAR *, SQLINTEGER, SQLCHAR *, SQLINTEGER );
389
+ sqlcreatedbType sqlcreatedb;
390
+ /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
391
+ cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
392
+ sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDb" );
393
+ #else
394
+ void *cliLib = NULL;
395
+ typedef int (*sqlcreatedbType)( SQLHDBC, SQLCHAR *, SQLINTEGER, SQLCHAR *, SQLINTEGER, SQLCHAR *, SQLINTEGER );
396
+ sqlcreatedbType sqlcreatedb;
397
+ cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
398
+ sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDb" );
399
+ #endif
400
+ #else
401
+ #ifdef _WIN32
402
+ HINSTANCE cliLib = NULL;
403
+ FARPROC sqlcreatedb;
404
+ cliLib = DLOPEN( LIBDB2 );
405
+ sqlcreatedb = DLSYM( cliLib, "SQLCreateDbW" );
406
+ #elif _AIX
407
+ void *cliLib = NULL;
408
+ typedef int (*sqlcreatedbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER );
409
+ sqlcreatedbType sqlcreatedb;
410
+ /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
411
+ cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
412
+ sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDbW" );
413
+ #else
414
+ void *cliLib = NULL;
415
+ typedef int (*sqlcreatedbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER, SQLWCHAR *, SQLINTEGER );
416
+ sqlcreatedbType sqlcreatedb;
417
+ cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
418
+ sqlcreatedb = (sqlcreatedbType) DLSYM( cliLib, "SQLCreateDbW" );
419
+ #endif
420
+ #endif
421
+
422
+ rc = (*sqlcreatedb)( (SQLHSTMT) data->conn_res->hdbc, data->dbName, (SQLINTEGER)data->dbName_string_len,
423
+ data->codeSet, (SQLINTEGER)data->codeSet_string_len,
424
+ data->mode, (SQLINTEGER)data->mode_string_len );
425
+ DLCLOSE( cliLib );
426
+ return rc;
427
+ }
428
+
429
+ /*
430
+ This function calls SQLDropDb cli call
431
+ */
432
+ int _ruby_ibm_db_SQLDropDB_helper(create_drop_db_args *data) {
433
+ int rc = 0;
434
+ #ifndef UNICODE_SUPPORT_VERSION
435
+ #ifdef _WIN32
436
+ HINSTANCE cliLib = NULL;
437
+ FARPROC sqldropdb;
438
+ cliLib = DLOPEN( LIBDB2 );
439
+ sqldropdb = DLSYM( cliLib, "SQLDropDb" );
440
+ #elif _AIX
441
+ void *cliLib = NULL;
442
+ typedef int (*sqldropdbType)( SQLHDBC, SQLCHAR *, SQLINTEGER);
443
+ sqldropdbType sqldropdb;
444
+ /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
445
+ cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
446
+ sqldropdb = (sqldropdbType) DLSYM( cliLib, "SQLDropDb" );
447
+ #else
448
+ void *cliLib = NULL;
449
+ typedef int (*sqldropdbType)( SQLHDBC, SQLCHAR *, SQLINTEGER);
450
+ sqldropdbType sqldropdb;
451
+ cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
452
+ sqldropdb = (sqldropdbType) DLSYM( cliLib, "SQLDropDb" );
453
+ #endif
454
+ #else
455
+ #ifdef _WIN32
456
+ HINSTANCE cliLib = NULL;
457
+ FARPROC sqldropdb;
458
+ cliLib = DLOPEN( LIBDB2 );
459
+ sqldropdb = DLSYM( cliLib, "SQLDropDbW" );
460
+ #elif _AIX
461
+ void *cliLib = NULL;
462
+ typedef int (*sqldropdbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER);
463
+ sqldropdbType sqldropdb;
464
+ /* On AIX CLI library is in archive. Hence we will need to specify flags in DLOPEN to load a member of the archive*/
465
+ cliLib = DLOPEN( LIBDB2, RTLD_MEMBER | RTLD_LAZY );
466
+ sqldropdb = (sqldropdbType) DLSYM( cliLib, "SQLDropDbW" );
467
+ #else
468
+ void *cliLib = NULL;
469
+ typedef int (*sqldropdbType)( SQLHDBC, SQLWCHAR *, SQLINTEGER);
470
+ sqldropdbType sqldropdb;
471
+ cliLib = DLOPEN( LIBDB2, RTLD_LAZY );
472
+ sqldropdb = (sqldropdbType) DLSYM( cliLib, "SQLDropDbW" );
473
+ #endif
474
+ #endif
475
+
476
+ rc = (*sqldropdb)( (SQLHSTMT) data->conn_res->hdbc, data->dbName, (SQLINTEGER)data->dbName_string_len );
477
+
478
+ DLCLOSE( cliLib );
479
+ return rc;
480
+ }
481
+
375
482
  /*
376
483
  This function calls SQLPrepare cli call to prepare the given statement
377
484
  */
@@ -2,7 +2,7 @@
2
2
  +----------------------------------------------------------------------+
3
3
  | Licensed Materials - Property of IBM |
4
4
  | |
5
- | (C) Copyright IBM Corporation 2009, 2010 |
5
+ | (C) Copyright IBM Corporation 2009, 2010, 2012 |
6
6
  +----------------------------------------------------------------------+
7
7
  | Authors: Praveen Devarao |
8
8
  +----------------------------------------------------------------------+
@@ -11,6 +11,35 @@
11
11
  #ifndef RUBY_IBM_DB_CLI_H
12
12
  #define RUBY_IBM_DB_CLI_H
13
13
 
14
+ #ifdef _WIN32
15
+ #include <windows.h>
16
+ #else
17
+ #include <dlfcn.h>
18
+ #endif
19
+
20
+ #ifdef _WIN32
21
+ #define DLOPEN LoadLibrary
22
+ #define DLSYM GetProcAddress
23
+ #define DLCLOSE FreeLibrary
24
+ #define LIBDB2 "db2cli.dll"
25
+ #elif _AIX
26
+ #define DLOPEN dlopen
27
+ #define DLSYM dlsym
28
+ #define DLCLOSE dlclose
29
+ #ifdef __64BIT__
30
+ /*64-bit library in the archive libdb2.a*/
31
+ #define LIBDB2 "libdb2.a(shr_64.o)"
32
+ #else
33
+ /*32-bit library in the archive libdb2.a*/
34
+ #define LIBDB2 "libdb2.a(shr.o)"
35
+ #endif
36
+ #else
37
+ #define DLOPEN dlopen
38
+ #define DLSYM dlsym
39
+ #define DLCLOSE dlclose
40
+ #define LIBDB2 "libdb2.so.1"
41
+ #endif
42
+
14
43
  #include <ruby.h>
15
44
  #include <stdio.h>
16
45
  #include <string.h>
@@ -54,6 +83,8 @@ typedef struct _conn_handle_struct {
54
83
  SQLPOINTER ruby_error_state;
55
84
  SQLSMALLINT ruby_error_msg_len;
56
85
 
86
+ SQLINTEGER sqlcode;
87
+
57
88
  } conn_handle;
58
89
 
59
90
  typedef union {
@@ -114,6 +145,7 @@ typedef struct _stmt_handle_struct {
114
145
  SQLPOINTER ruby_stmt_err_msg;
115
146
  SQLPOINTER ruby_stmt_err_state;
116
147
  SQLSMALLINT ruby_stmt_err_msg_len;
148
+ SQLINTEGER sqlcode;
117
149
  } stmt_handle;
118
150
 
119
151
  /*
@@ -211,6 +243,25 @@ typedef struct _ibm_db_exec_direct_args_struct {
211
243
  long stmt_string_len;
212
244
  } exec_cum_prepare_args;
213
245
 
246
+ /*
247
+ Structure holding the necessary info to be passed to SQLCreateDB and SQLDropDB CLI call
248
+ */
249
+ typedef struct _ibm_db_create_drop_db_args_struct {
250
+ conn_handle *conn_res;
251
+ #ifdef UNICODE_SUPPORT_VERSION
252
+ SQLWCHAR *dbName;
253
+ SQLWCHAR *codeSet;
254
+ SQLWCHAR *mode;
255
+ #else
256
+ SQLCHAR *dbName;
257
+ SQLCHAR *codeSet;
258
+ SQLCHAR *mode;
259
+ #endif
260
+ long dbName_string_len;
261
+ long codeSet_string_len;
262
+ long mode_string_len;
263
+ } create_drop_db_args;
264
+
214
265
  /*
215
266
  Structure holding the necessary info to be passed to SQLParamData and SQLPutData CLI call
216
267
  */
@@ -427,5 +478,7 @@ int _ruby_ibm_db_SQLGetConnectAttr_helper(get_handle_attr_args *data);
427
478
  int _ruby_ibm_db_SQLBindFileToParam_helper(stmt_handle *stmt_res, param_node *curr);
428
479
  int _ruby_ibm_db_SQLBindParameter_helper(bind_parameter_args *data);
429
480
  void _ruby_ibm_db_Statement_level_UBF(stmt_handle *stmt_res);
481
+ int _ruby_ibm_db_SQLCreateDB_helper(create_drop_db_args *data);
482
+ int _ruby_ibm_db_SQLDropDB_helper(create_drop_db_args *data);
430
483
 
431
484
  #endif /* RUBY_IBM_DB_CLI_H */
@@ -117,24 +117,31 @@ module ActiveRecord
117
117
  # Flag to decide if quoted literal replcement should take place. By default it is ON. Set it to OFF if using Pstmt
118
118
  set_quoted_literal_replacement = IBM_DB::QUOTED_LITERAL_REPLACEMENT_ON
119
119
 
120
- # Retrieves the database alias (local catalog name) or remote name
121
- # (for remote TCP/IP connections) from the +config+ hash
122
- # or raises ArgumentError in case of failure.
123
- if config.has_key?(:database)
124
- database = config[:database].to_s
125
- else
126
- raise ArgumentError, "Missing argument: a database name needs to be specified."
127
- end
128
-
129
120
  # Retrieves database user credentials from the +config+ hash
130
121
  # or raises ArgumentError in case of failure.
131
122
  if !config.has_key?(:username) || !config.has_key?(:password)
132
123
  raise ArgumentError, "Missing argument(s): Username/Password for #{config[:database]} is not specified"
133
124
  else
125
+ if(config[:username].to_s.nil? || config[:password].to_s.nil?)
126
+ raise ArgumentError, "Username/Password cannot be nil"
127
+ end
134
128
  username = config[:username].to_s
135
129
  password = config[:password].to_s
136
130
  end
137
131
 
132
+ if(config.has_key?(:dbops) && config[:dbops] == true)
133
+ return ConnectionAdapters::IBM_DBAdapter.new(nil, logger, config, {})
134
+ end
135
+
136
+ # Retrieves the database alias (local catalog name) or remote name
137
+ # (for remote TCP/IP connections) from the +config+ hash
138
+ # or raises ArgumentError in case of failure.
139
+ if config.has_key?(:database)
140
+ database = config[:database].to_s
141
+ else
142
+ raise ArgumentError, "Missing argument: a database name needs to be specified."
143
+ end
144
+
138
145
  # Providing default schema (username) when not specified
139
146
  config[:schema] = config.has_key?(:schema) ? config[:schema].to_s : config[:username].to_s
140
147
 
@@ -232,8 +239,6 @@ module ActiveRecord
232
239
  :binary
233
240
  when /smallint/i
234
241
  :boolean
235
- when /bigint/i
236
- :bigint
237
242
  when /int|serial/i
238
243
  :integer
239
244
  when /decimal|numeric|decfloat/i
@@ -652,6 +657,10 @@ module ActiveRecord
652
657
  # It connects to the database with the initially provided credentials
653
658
  def connect
654
659
  # If the type of connection is net based
660
+ if(@username.nil? || @password.nil?)
661
+ raise ArgumentError, "Username/Password cannot be nil"
662
+ end
663
+
655
664
  begin
656
665
  if @host
657
666
  @conn_string = "DRIVER={IBM DB2 ODBC DRIVER};\
@@ -694,6 +703,7 @@ module ActiveRecord
694
703
  # * true if succesfull
695
704
  # * false if the connection is already closed
696
705
  # * nil if an error is raised
706
+ return nil if @connection.nil? || @connection == false
697
707
  IBM_DB.close(@connection) rescue nil
698
708
  end
699
709
 
@@ -1387,6 +1397,63 @@ module ActiveRecord
1387
1397
  }
1388
1398
  end
1389
1399
 
1400
+ def build_conn_str_for_dbops()
1401
+ connect_str = "DRIVER={IBM DB2 ODBC DRIVER};ATTACH=true;"
1402
+ if(!@host.nil?)
1403
+ connect_str << "HOSTNAME=#{@host};"
1404
+ connect_str << "PORT=#{@port};"
1405
+ connect_str << "PROTOCOL=TCPIP;"
1406
+ end
1407
+ connect_str << "UID=#{@username};PWD=#{@password};"
1408
+ return connect_str
1409
+ end
1410
+
1411
+ def drop_database(dbName)
1412
+ connect_str = build_conn_str_for_dbops()
1413
+
1414
+ #Ensure connection is closed before trying to drop a database.
1415
+ #As a connect call would have been made by call seeing connection in active
1416
+ disconnect!
1417
+
1418
+ begin
1419
+ dropConn = IBM_DB.connect(connect_str, '', '')
1420
+ rescue StandardError => connect_err
1421
+ raise "Failed to connect to server due to: #{connect_err}"
1422
+ end
1423
+
1424
+ if(IBM_DB.dropDB(dropConn,dbName))
1425
+ IBM_DB.close(dropConn)
1426
+ return true
1427
+ else
1428
+ error = IBM_DB.getErrormsg(dropConn, IBM_DB::DB_CONN)
1429
+ IBM_DB.close(dropConn)
1430
+ raise "Could not drop Database due to: #{error}"
1431
+ end
1432
+ end
1433
+
1434
+ def create_database(dbName, codeSet=nil, mode=nil)
1435
+ connect_str = build_conn_str_for_dbops()
1436
+
1437
+ #Ensure connection is closed before trying to drop a database.
1438
+ #As a connect call would have been made by call seeing connection in active
1439
+ disconnect!
1440
+
1441
+ begin
1442
+ createConn = IBM_DB.connect(connect_str, '', '')
1443
+ rescue StandardError => connect_err
1444
+ raise "Failed to connect to server due to: #{connect_err}"
1445
+ end
1446
+
1447
+ if(IBM_DB.createDB(createConn,dbName,codeSet,mode))
1448
+ IBM_DB.close(createConn)
1449
+ return true
1450
+ else
1451
+ error = IBM_DB.getErrormsg(createConn, IBM_DB::DB_CONN)
1452
+ IBM_DB.close(createConn)
1453
+ raise "Could not create Database due to: #{error}"
1454
+ end
1455
+ end
1456
+
1390
1457
  # IBM data servers do not support limits on certain data types (unlike MySQL)
1391
1458
  # Limit is supported for the {float, decimal, numeric, varchar, clob, blob, graphic, vargraphic} data types.
1392
1459
  def type_to_sql(type, limit = nil, precision = nil, scale = nil)
Binary file
Binary file
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibm_db
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 9
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
8
  - 5
8
- - 7
9
- version: 2.5.7
9
+ - 9
10
+ version: 2.5.9
10
11
  platform: x86-mingw32
11
12
  authors:
12
13
  - IBM
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-09-20 00:00:00 +05:30
18
+ date: 2012-01-03 00:00:00 +05:30
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 41
28
30
  segments:
29
31
  - 1
30
32
  - 15
@@ -102,6 +104,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
104
  requirements:
103
105
  - - ">="
104
106
  - !ruby/object:Gem::Version
107
+ hash: 59
105
108
  segments:
106
109
  - 1
107
110
  - 8
@@ -112,6 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
115
  requirements:
113
116
  - - ">="
114
117
  - !ruby/object:Gem::Version
118
+ hash: 3
115
119
  segments:
116
120
  - 0
117
121
  version: "0"