下面的函数将产生某种内存损坏,在执行另一个调用时会导致异常(由于内存损坏而无法识别):
{
ora::Statement stmt(__cn);
string sql("BEGIN Pckg.Sp_procA(:1, :2, :3, :4, :5, :6, :7, :8, "
":9, :10, :11, :12, :13, :14, :15, :payload); END;");
occi::Blob payload(__cn.getConnection());
occi::Environment* tempEnv = occi::Environment::createEnvironment();
occi::Timestamp reportTime(tempEnv);
reportTime.fromText(__report.report_time), "yyyy-mm-ddH24:mi:ss.ff");
stmt.setSQL(sql);
stmt.setString (1, "");
stmt.setString (2, "");
stmt.setString (3, __report.varA);
stmt.setString (4, __report.varB);
stmt.setInt (5, __report.varC);
stmt.setString (6, __report.varD);
stmt.setString (7, __report.varE);
stmt.setString (8, __report.varF);
stmt.setTimestamp(9, reportTime);
stmt.setNull (10, occi::OCCITIMESTAMP);
stmt.setString (11, __report.varG);
stmt.setString (12, __report.varH);
stmt.setString (13, __report.varI);
stmt.setString (14, __report.varK);
stmt.setString (15, __report.varX);
stmt.setBinaryStreamMode(16, __report.payload.Size(), true);
stmt.executeUpdate();
occi::Stream* streamedData = stmt.getStream(16);
streamedData->writeLastBuffer(__report.payload.GetPtr(), __report.payload.Size());
stmt.closeStream(streamedData);
occi::Environment::terminateEnvironment(tempEnv);
return true;
}
除非上面的代码被执行并且看起来像这样,否则下面的函数可以完美运行:
{
ora::Statement stmt(__cn);
string sql("BEGIN "
"Pckg.Sp_procB(:1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11); END;");
occi::Environment* tempEnv = occi::Environment::createEnvironment();
occi::Timestamp reportTime(tempEnv);
reportTime.fromText(__report.report_time, "yyyy-mm-dd HH24:mi:ss.ff");
stmt.setSQL(sql);
stmt.setString (1, "");
stmt.setString (2, "");
stmt.setString (3, __report.varA);
stmt.setString (4, __report.varB);
stmt.setInt (5, __report.varB);
stmt.setString (6, __report.varD);
stmt.setString (7, __report.varE);
stmt.setString (8, __report.varF);
stmt.setString (9, __report.varG);
stmt.setTimestamp(10, reportTime);
stmt.setNull (11, occi::OCCITIMESTAMP);
stmt.executeUpdate();
occi::Environment::terminateEnvironment(tempEnv);
return true;
}
我从 Oracle 的文档中得到了 blob 插入示例,但看不出有什么问题。第二个功能似乎也不错,这让我认为 Oracle 的 occi 可能存在某种会破坏内存的错误。有人对此有所了解或做过类似的事情吗?