ext/ibm_db.c in ibm_db-0.9.4 vs ext/ibm_db.c in ibm_db-0.9.5
- old
+ new
@@ -8,11 +8,11 @@
| Dan Scott, Helmut Tessarek, Sam Ruby, Kellen Bombardier, |
| Tony Cairns, Manas Dadarkar, Swetha Patel, Salvador Ledezma |
+----------------------------------------------------------------------+
*/
-#define MODULE_RELEASE "0.9.4"
+#define MODULE_RELEASE "0.9.5"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -3748,11 +3748,12 @@
if (!conn_res->handle_active) {
rb_throw("Connection is not active", Qnil);
}
- return_str = ALLOC_N(char, SQL_SQLSTATE_SIZE + 1);
+ return_str = ALLOC_N(char, DB2_MAX_ERR_MSG_LEN);
+ memset(return_str, 0, DB2_MAX_ERR_MSG_LEN);
_ruby_ibm_db_check_sql_errors(conn_res->hdbc, SQL_HANDLE_DBC, -1, 0, return_str, DB2_ERRMSG, conn_res->errormsg_recno_tracker);
if(conn_res->errormsg_recno_tracker - conn_res->error_recno_tracker >= 1)
conn_res->error_recno_tracker = conn_res->errormsg_recno_tracker;
conn_res->errormsg_recno_tracker++;
@@ -4678,11 +4679,11 @@
return rc;
}
/* }}} */
/* {{{ static RETCODE _ruby_ibm_db_get_data2(stmt_handle *stmt_res, int col_num, short ctype, void *buff, int in_length, SQLINTEGER *out_length) */
-static RETCODE _ruby_ibm_db_get_data2(stmt_handle *stmt_res, SQLUSMALLINT col_num, SQLSMALLINT ctype, SQLPOINTER buff, SQLLEN in_length, SQLINTEGER *out_length)
+static RETCODE _ruby_ibm_db_get_data2(stmt_handle *stmt_res, SQLUSMALLINT col_num, SQLSMALLINT ctype, SQLPOINTER buff, SQLLEN read_length, SQLLEN buff_length, SQLINTEGER *out_length)
{
RETCODE rc=SQL_SUCCESS;
SQLHANDLE new_hstmt;
SQLSMALLINT locType = ctype;
SQLSMALLINT targetCType = ctype;
@@ -4690,13 +4691,13 @@
rc = SQLAllocHandle(SQL_HANDLE_STMT, stmt_res->hdbc, &new_hstmt);
if ( rc < SQL_SUCCESS ) {
return SQL_ERROR;
}
- rc = SQLGetSubString((SQLHSTMT)new_hstmt, stmt_res->column_info[col_num-1].loc_type,
- stmt_res->column_info[col_num-1].lob_loc, 1, in_length, targetCType,
- buff, in_length, out_length, &stmt_res->column_info[col_num-1].loc_ind);
+rc = SQLGetSubString((SQLHSTMT)new_hstmt, stmt_res->column_info[col_num-1].loc_type,
+ stmt_res->column_info[col_num-1].lob_loc, 1, read_length, targetCType,
+ buff, buff_length, out_length, &stmt_res->column_info[col_num-1].loc_ind);
if ( rc == SQL_ERROR ) {
_ruby_ibm_db_check_sql_errors((SQLHSTMT)new_hstmt, SQL_HANDLE_STMT, rc, 1, NULL, -1, 1);
}
SQLFreeHandle(SQL_HANDLE_STMT, new_hstmt);
@@ -4858,11 +4859,11 @@
out_char_ptr = (char*)ALLOC_N(char,in_length+1);
if ( out_char_ptr == NULL ) {
rb_throw("Failed to Allocate Memory for LOB Data", Qnil);
return Qfalse;
}
- rc = _ruby_ibm_db_get_data2(stmt_res, col_num+1, SQL_C_CHAR, (void*)out_char_ptr, in_length+1, &out_length);
+ rc = _ruby_ibm_db_get_data2(stmt_res, col_num+1, SQL_C_CHAR, (void*)out_char_ptr, in_length, in_length+1, &out_length);
if (rc == SQL_ERROR) {
return Qfalse;
}
return rb_str_new2(out_char_ptr);
@@ -4898,11 +4899,11 @@
out_ptr = (SQLPOINTER)ALLOC_N(char,in_length);
if ( out_ptr == NULL ) {
rb_throw("Failed to Allocate Memory for LOB Data", Qnil);
return Qfalse;
}
- rc = _ruby_ibm_db_get_data2(stmt_res, col_num+1, lob_bind_type, (char *)out_ptr, in_length, &out_length);
+ rc = _ruby_ibm_db_get_data2(stmt_res, col_num+1, lob_bind_type, (char *)out_ptr, in_length, in_length, &out_length);
if (rc == SQL_ERROR) {
return Qfalse;
}
return rb_str_new((char*)out_ptr,out_length);
default:
@@ -4922,11 +4923,11 @@
out_ptr = (SQLPOINTER)ALLOC_N(char, in_length);
if ( out_ptr == NULL ) {
rb_throw("Failed to Allocate Memory for XML Data", Qnil);
return Qfalse;
}
- rc = _ruby_ibm_db_get_data2(stmt_res, col_num+1, SQL_C_BINARY, (SQLPOINTER)out_ptr, in_length, &out_length);
+ rc = _ruby_ibm_db_get_data2(stmt_res, col_num+1, SQL_C_BINARY, (SQLPOINTER)out_ptr, in_length, in_length, &out_length);
if (rc == SQL_ERROR) {
return Qfalse;
}
return rb_str_new((char*)out_ptr,out_length);
@@ -5212,11 +5213,11 @@
/* fall-through */
case BINARY:
out_ptr = (SQLPOINTER)ALLOC_N(char, tmp_length);
- rc = _ruby_ibm_db_get_data2(stmt_res, i+1, lob_bind_type, (char *)out_ptr, tmp_length, &out_length);
+ rc = _ruby_ibm_db_get_data2(stmt_res, i+1, lob_bind_type, (char *)out_ptr, tmp_length, tmp_length, &out_length);
if (rc == SQL_ERROR) {
ruby_xfree(out_ptr);
out_length = 0;
}
@@ -5312,24 +5313,24 @@
if ( out_ptr == NULL ) {
rb_throw("Failed to Allocate Memory for LOB Data", Qnil);
return Qfalse;
}
- rc = _ruby_ibm_db_get_data2(stmt_res, i+1, SQL_C_CHAR, out_ptr, tmp_length+1, &out_length);
+ rc = _ruby_ibm_db_get_data2(stmt_res, i+1, SQL_C_CHAR, out_ptr, tmp_length, tmp_length+1, &out_length);
if (rc == SQL_ERROR) {
ruby_xfree(out_ptr);
- tmp_length = 0;
+ out_length = 0;
} else {
out_ptr[tmp_length] = '\0';
}
if ( op & FETCH_ASSOC ) {
- rb_hash_aset(return_value, rb_str_new2((char*)stmt_res->column_info[i].name), rb_str_new((char*)out_ptr, tmp_length));
+ rb_hash_aset(return_value, rb_str_new2((char*)stmt_res->column_info[i].name), rb_str_new((char*)out_ptr, out_length));
}
if ( op == FETCH_INDEX ) {
- rb_ary_store(return_value, i, rb_str_new((char*)out_ptr, tmp_length));
+ rb_ary_store(return_value, i, rb_str_new((char*)out_ptr, out_length));
} else if ( op == FETCH_BOTH ) {
- rb_hash_aset(return_value, INT2NUM(i), rb_str_new((char*)out_ptr, tmp_length));
+ rb_hash_aset(return_value, INT2NUM(i), rb_str_new((char*)out_ptr, out_length));
}
}
break;
default: