--- odbcserver.c 2009-12-10 08:02:10.000000000 +0530 +++ otp_src_R13B03/lib/odbc/c_src/odbcserver.c 2009-12-10 15:26:21.000000000 +0530 @@ -151,7 +151,7 @@ static db_result_msg encode_empty_message(void); static db_result_msg encode_error_message(char *reason); static db_result_msg encode_atom_message(char *atom); -static db_result_msg encode_result(db_state *state); +static db_result_msg encode_result(db_state *state, SQLRETURN sql_result); static db_result_msg encode_result_set(SQLSMALLINT num_of_columns, db_state *state); static db_result_msg encode_out_params(db_state *state, @@ -585,12 +585,12 @@ /* OTP-5759, fails when 0 rows deleted */ if (result == SQL_NO_DATA_FOUND) { - msg = encode_result(state); + msg = encode_result(state, result); } else { /* Handle multiple result sets */ do { ei_x_encode_list_header(&dynamic_buffer(state), 1); - msg = encode_result(state); + msg = encode_result(state, result); /* We don't want to continue if an error occured */ if (msg.length != 0) { break; @@ -819,7 +819,7 @@ if(out_params(state)){ msg = encode_out_params(state, cols, params, num_param_values); }else{ - msg = encode_result(state); + msg = encode_result(state, SQL_SUCCESS); } if(msg.length == 0) { msg.buffer = dynamic_buffer(state).buff; @@ -984,7 +984,7 @@ /* Top encode function for db_query that encodes the resulting erlang term to be returned to the erlang client. */ -static db_result_msg encode_result(db_state *state) +static db_result_msg encode_result(db_state *state, SQLRETURN sql_result) { SQLSMALLINT num_of_columns = 0; SQLLEN RowCountPtr = 0; @@ -997,7 +997,12 @@ if(!sql_success(SQLNumResultCols(statement_handle(state), &num_of_columns))) { - DO_EXIT(EXIT_COLS); + if(SQL_NO_DATA_FOUND == sql_result) { + num_of_columns = 0; + } + else { + DO_EXIT(EXIT_COLS); + } } if (num_of_columns == 0) { @@ -1011,7 +1016,12 @@ } if(!sql_success(SQLRowCount(statement_handle(state), &RowCountPtr))) { - DO_EXIT(EXIT_ROWS); + if(SQL_NO_DATA_FOUND == sql_result) { + RowCountPtr = 0; + } + else { + DO_EXIT(EXIT_ROWS); + } } if(param_query(state) && update) { @@ -2475,9 +2485,8 @@ result = SQLGetDiagRec(handleType, handle, record_nr, current_sql_state, &nativeError, current_errmsg_pos, (SQLSMALLINT)errmsg_buffer_size, &errmsg_size); - if(result != SQL_SUCCESS && result != SQL_NO_DATA) { - - + /* SQL_SUCCESS_WITH_INFO not handled yet. SQL_NO_DATA indicates end of diag recs */ + if(result != SQL_SUCCESS) { break; } else { /* update the sqlstate in the diagnos record, because the SQLGetDiagRec