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 &param : 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

  1. When executing the above code, I get ORA-32102: invalid OCI handle.
  2. The issue seems to be related to creating or using the oracle::occi::Blob object.
  3. 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() before open(), but the issue persists.
  • Ensured Image Data is Loaded Properly: Read image data into std::vector<unsigned char> before calling blob.write().
  • Checked Oracle Documentation: Oracle ORA-32102 Docs suggest this is an internal OCCI issue, but no clear solution.

Questions

  1. Is my approach to binding the BLOB incorrect?
  2. Should I create the BLOB differently, e.g., using stmt->setBlob() directly instead of oracle::occi::Blob blob(conn)?
  3. 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