admin管理员组文章数量:1352341
I'm working with Oracle OCCI to insert images as BLOBs into my database. However, I keep encountering the following error:
ORA-32102: invalid OCI handle
Context
I'm trying to insert an image as a BLOB. Currently, I store the path of the image, but now I need to store the actual image as binary data. Below is my implementation:
Code Snippets
connect.cpp
// ORA-32102 (invalid OCI handle) when inserting BLOB
for (const auto ¶m : params.blobs) {
try {
oracle::occi::Blob blob(conn); // Create a temporary BLOB
blob.open(OCCI_LOB_READWRITE);
blob.write(param.second.size(), (unsigned char *)param.second.data(), param.second.size());
blob.close();
stmt->setBlob(param.first, blob);
} catch (SQLException &e) {
std::cerr << "BLOB Binding Error: " << e.getMessage() << std::endl;
}
}
connect.hpp
struct SqlParam {
std::vector<std::pair<unsigned int, std::string>> strings;
std::vector<std::pair<unsigned int, int>> integers;
std::vector<std::pair<unsigned int, oracle::occi::Date>> dates;
std::vector<std::pair<unsigned int, oracle::occi::Timestamp>> timestamps;
std::vector<std::pair<unsigned int, std::vector<unsigned char>>> blobs;
};
Issue
- When executing the above code, I get
ORA-32102: invalid OCI handle
. - The issue seems to be related to creating or using the
oracle::occi::Blob
object. - If I replace the BLOB insertion with simple string insertion (using
std::vector<std::pair<unsigned int, std::string>> strings
), it works fine.
What I Have Tried
- Checked OCI Connection: The
conn
object is valid when inserting other data types (e.g., strings and integers). - Pre-Allocating BLOB Before Writing: Tried
blob.setEmpty()
beforeopen()
, but the issue persists. - Ensured Image Data is Loaded Properly: Read image data into
std::vector<unsigned char>
before callingblob.write()
. - Checked Oracle Documentation: Oracle ORA-32102 Docs suggest this is an internal OCCI issue, but no clear solution.
Questions
- Is my approach to binding the BLOB incorrect?
- Should I create the BLOB differently, e.g., using
stmt->setBlob()
directly instead oforacle::occi::Blob blob(conn)
? - Do I need to explicitly initialize the BLOB before writing?
Any guidance would be appreciated!
本文标签: cORA32102 (invalid OCI handle) Issue When Inserting BLOB in Oracle OCCIStack Overflow
版权声明:本文标题:c++ - ORA-32102 (invalid OCI handle) Issue When Inserting BLOB in Oracle OCCI - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743911285a2560446.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论