[英]Issue on ocilib error handling, how to correctly catch logs errors with ocilib?
I have a problem with error handling on ocilib. 我对ocilib进行错误处理时遇到问题。
I am currently using the OCILIB provides two mechanisms for error handling: 我当前正在使用OCILIB提供两种错误处理机制:
How I am initializing : 我如何初始化:
if (!isInit && !OCI_Initialize(&OracleManager::errorHandler, NULL, OCI_ENV_DEFAULT | OCI_ENV_CONTEXT))
throw ibs::exceptions::trace::db(61400, mManager.getMessage(61400));
My error handling callback : 我的错误处理回调:
static void errorHandler(OCI_Error *error)
{
LOG_(ibs::io::log::IN_CONSOLE, plog::debug) << OCI_GetSql(OCI_ErrorGetStatement(error));
LOG_(ibs::io::log::IN_FILE, plog::debug) << OCI_GetSql(OCI_ErrorGetStatement(error));
throw ibs::exceptions::trace::db(61403, "code: " + std::to_string(OCI_ErrorGetOCICode(error)) + ", " + OCI_ErrorGetString(error));
}
Contextual thread error handling : 上下文线程错误处理:
if (!OCI_ExecuteStmt(mSt, query.c_str()))
{
OCI_Error *err = OCI_GetLastError();
if (err == nullptr || OCI_ErrorGetOCICode(err) == 0)
{
LOG_(ibs::io::log::IN_CONSOLE, plog::debug) << query;
LOG_(ibs::io::log::IN_FILE, plog::debug) << query;
throw ibs::exceptions::trace::db(61407, mManager.getMessage(61407));
}
errorHandler(err);
}
My problem is : 我的问题是:
On my first insertion (on database) error : Ocilib call my callback with the correct error description. 在我的第一次插入(在数据库上)错误:Ocilib用正确的错误描述调用我的回调。
On my second (and more) insertion error : Ocilib does not call my callback BUT OCI_ExecuteStmt() return me "false" and my data is not inserted into the database. 关于我的第二个(或更多)插入错误:Ocilib不调用我的回调,但OCI_ExecuteStmt()返回我为“ false”,并且我的数据未插入数据库中。
The fact that an error is detected is correct, it must be. 检测到错误的事实必须是正确的。 But, for my second (and more) error, I have no information's about my error.
但是,对于第二个(以及更多个)错误,我没有关于错误的任何信息。
For traceability purpose, I need to known : Why my data are rejected ? 出于可追溯性目的,我需要知道:为什么我的数据被拒绝?
My problem is that I have this information only for the first error. 我的问题是我只有第一个错误才有此信息。
And even for the contextual thread error handling, the OCI_GetLastError() function return me a null pointer even if the data was rejected and OCI_ExecuteStmt() return me "false". 甚至对于上下文线程错误处理,即使数据被拒绝,OCI_GetLastError()函数也向我返回空指针,而OCI_ExecuteStmt()返回我为“ false”。
For example : 例如 :
Maybe I am doing something wrong on how I handle errors. 也许我在处理错误方面做错了。 Help would be appreciated.
帮助将不胜感激。
Using 4.6.2 ocilib version on a C++11 application. 在C ++ 11应用程序上使用4.6.2 ocilib版本。
Can you open an issue on ocilib GitHub repo with a sample code reproducting the issue? 您可以在ocilib GitHub存储库上打开一个问题,并提供重现该问题的示例代码吗?
Btw, as you're coding in C++, why not using Ocilib C++ API? 顺便说一句,当您使用C ++进行编码时,为什么不使用Ocilib C ++ API?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.