--- ../clean/asterisk-1.6.2.16.1/funcs/func_odbc.c 2010-06-03 21:51:06.000000000 +0200 +++ ./funcs/func_odbc.c 2011-02-12 16:39:20.000000000 +0200 @@ -325,9 +325,15 @@ } } - if (stmt && rows == 0 && ast_str_strlen(insertbuf) != 0) { - SQLCloseCursor(stmt); - SQLFreeHandle(SQL_HANDLE_STMT, stmt); + if (stmt) { + SQLRowCount(stmt, &rows); + } + + if (rows == 0 && ast_str_strlen(insertbuf) != 0) { + if (stmt) { + SQLCloseCursor(stmt); + SQLFreeHandle(SQL_HANDLE_STMT, stmt); + } for (dsn = 0; dsn < 5; dsn++) { if (!ast_strlen_zero(query->writehandle[dsn])) { obj = ast_odbc_request_obj(query->writehandle[dsn], 0); @@ -347,7 +353,6 @@ } } else if (stmt) { status = "SUCCESS"; - SQLRowCount(stmt, &rows); } AST_RWLIST_UNLOCK(&queries);