--- unmodified/otp_src_R13B03/lib/odbc/c_src/odbcserver.c 2009-11-20 19:06:30.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; @@ -749,11 +749,12 @@ byte *sql; db_result_msg msg; int i, num_param_values, ver = 0, - erl_type = 0, index = 0, size = 0, cols = 0; + erl_type = 0, index = 0, size = 0, cols = 0; long long_num_param_values; param_status param_status; diagnos diagnos; - param_array *params; + param_array *params; + SQLRETURN result; if (associated_result_set(state)) { clean_state(state); @@ -784,10 +785,16 @@ num_param_values, state); if(params != NULL) { - if(!sql_success(SQLExecDirect(statement_handle(state), - sql, SQL_NTS))) { - diagnos = get_diagnos(SQL_HANDLE_STMT, statement_handle(state)); - msg = encode_error_message(diagnos.error_msg); + + result = SQLExecDirect(statement_handle(state), sql, SQL_NTS); + if (!sql_success(result) || result == SQL_NO_DATA) { + diagnos = get_diagnos(SQL_HANDLE_STMT, statement_handle(state)); + } + /* SQL_NO_DATA and SQLSTATE 00000 indicate success for + updates/deletes that affect no rows */ + if(!sql_success(result) && + !(result == SQL_NO_DATA && !strcmp((char *)diagnos.sqlState, INFO))) { + msg = encode_error_message(diagnos.error_msg); } else { for (i = 0; i < param_status.params_processed; i++) { switch (param_status.param_status_array[i]) { @@ -812,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; @@ -977,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; @@ -990,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) { @@ -1004,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) { @@ -2452,6 +2469,7 @@ int acc_errmsg_size; byte *current_errmsg_pos; SQLCHAR current_sql_state[SQL_STATE_SIZE]; + SQLRETURN result; diagnos.error_msg[0] = 0; @@ -2464,12 +2482,11 @@ /* Foreach diagnostic record in the current set of diagnostic records the error message is obtained */ for(record_nr = 1; ;record_nr++) { - if(SQLGetDiagRec(handleType, handle, record_nr, current_sql_state, + result = SQLGetDiagRec(handleType, handle, record_nr, current_sql_state, &nativeError, current_errmsg_pos, - (SQLSMALLINT)errmsg_buffer_size, &errmsg_size) - != SQL_SUCCESS) { - - + (SQLSMALLINT)errmsg_buffer_size, &errmsg_size); + /* 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