AW: [odb-users] Storing files in an oracle database

Marcel Nehring mne at qosmotec.com
Wed Jan 13 10:11:09 EST 2016


Hi ODB users, Hi Boris,

I am picking up on this issue since I was not yet able to solve it.

> Skimming through the OCI docs, BFILE appears to be special in that on INSERT or UPDATE you specify the file name, not its data. Not sure what SELECT returns...

It returns a locator similar to a SELECT on a BLOB column.

> I wonder if there is a way to cast BFILE to BLOB? If this were possible then you could map BFILE to BLOB and use the BFILENAME function for INSERT and UPDATE (the 'to' expression)

To me it seems that it is not possible to cast BFILE to BLOB. Although both data types behave very similar when reading from the database, a simple cast doesn't seem to help. I am getting an ORA-00932 error.

My basic idea this time was to split my internal data members into two. One for the filename and one for the file contents. Since you mentioned that ODB can be smart when handling LOBs the usage of virtual data members didn't seem to be required anymore.
In principle it should therefore work to map BFILE to BLOB (what turned out to not work) when reading from the database and use the second member containing the filename when inserting/updating the database:

//...

#pragma db map type("BFILE") as("BLOB") to("BFILENAME('ODB_DATA_DIR', (?))") from("(?)"))

PRAGMA_DB(column("FILE") type("BFILE") get(std::vector<char>(cbegin(this.m_filename), cend(this.m_filename))))
std::vector<char> m_contents;

PRAGMA_DB(transient)
std::string m_filename;

//...

However this crashes when trying to persist a new object since in the param_callback() method of the std::vector<char> and BLOB value traits front() is called on an empty vector.

So in the end I was neither able to read my class from the database (after manual insertion) nor to persist it.

Are there any other ODB mechanisms I could try to solve the problem?

Thanks in advance.

Regards,
Marcel




More information about the odb-users mailing list