时间:2021-07-01 10:21:17 帮助过:2人阅读
以下代码段使用了 SQLError,并返回代码:
/* Declare required variables */ SQLHDBC dbc; SQLHSTMT stmt; SQLRETURN retcode; UCHAR errmsg[100]; /* Code omitted here */ retcode = SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt ); if( retcode == SQL_ERROR ){ SQLError( env, dbc, SQL_NULL_HSTMT, NULL, NULL, errmsg, sizeof(errmsg), NULL ); /* Assume that print_error is defined */ print_error( "Allocation failed", errmsg ); return; } /* Delete items for order 2015 */ retcode = SQLExecDirect( stmt, "DELETE FROM SalesOrderItems WHERE ID=2015", SQL_NTS ); if( retcode == SQL_ERROR ) { SQLError( env, dbc, stmt, NULL, NULL, errmsg, sizeof(errmsg), NULL ); /* Assume that print_error is defined */ print_error( "Failed to delete items", errmsg ); return; } |
以下代码段使用了 SQLGetDiagRec,并返回代码:
/* Declare required variables */ SQLHDBC dbc; SQLHSTMT stmt; SQLRETURN retcode; SQLSMALLINT errmsglen; SQLINTEGER errnative; UCHAR errmsg[255]; UCHAR errstate[5]; /* Code omitted here */ retcode = SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt ); if( retcode == SQL_ERROR ){ SQLGetDiagRec(SQL_HANDLE_DBC, dbc, 1, errstate, &errnative, errmsg, sizeof(errmsg), &errmsglen); /* Assume that print_error is defined */ print_error( "Allocation failed", errstate, errnative, errmsg ); return; } /* Delete items for order 2015 */ retcode = SQLExecDirect( stmt, "DELETE FROM SalesOrderItems WHERE ID=2015", SQL_NTS ); if( retcode == SQL_ERROR ) { SQLGetDiagRec(SQL_HANDLE_STMT, stmt, recnum, errstate, &errnative, errmsg, sizeof(errmsg), &errmsglen); /* Assume that print_error is defined */ print_error("Failed to delete items", errstate, errnative, errmsg ); return; } |
ODBC错误处理
标签: