Can OCI8 format RAW Oracle binary fields in hex

S

Sean Nakasone

I'm using the OCI8 module to dump out Oracle tables. Some of the fields
are defined as RAW and the dumped data is in binary format. Is there a
way to have this dumped as HEX? I wouldn't know which fields would be RAW
so I'm hoping OCI8 is smart enough to detect RAW fields and convert them
to HEX automatically.
 
K

KUBO Takehiro

Hi,

I'm using the OCI8 module to dump out Oracle tables. Some of the fields
are defined as RAW and the dumped data is in binary format. Is there a
way to have this dumped as HEX? I wouldn't know which fields would be RAW
so I'm hoping OCI8 is smart enough to detect RAW fields and convert them
to HEX automatically.

1. Change oci8.rb as follows.

From: (line 860 - 866)
-----------------------------------
when SQLT_LNG, SQLT_LBI
datasize = @ctx[OCI8::Util::CTX_LONG_READ_LEN]
when SQLT_CLOB
datatype = :nclob if p.attrGet(OCI_ATTR_CHARSET_FORM) == SQLCS_NCHAR
end
-----------------------------------
To: (line 860 - 868)
-----------------------------------
when SQLT_LNG, SQLT_LBI
datasize = @ctx[OCI8::Util::CTX_LONG_READ_LEN]
when SQLT_CLOB
datatype = :nclob if p.attrGet(OCI_ATTR_CHARSET_FORM) == SQLCS_NCHAR
when SQLT_BIN
datasize *= 2 if OCI8::BindType::Mapping[OCI8::SQLT_BIN] ==
OCI8::BindType::String
end
-----------------------------------

2. Add the following code to your code.

OCI8::BindType::Mapping[OCI8::SQLT_BIN] = OCI8::BindType::String

To revert the behavior:
OCI8::BindType::Mapping[OCI8::SQLT_BIN] = OCI8::BindType::RAW
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,270
Messages
2,571,351
Members
48,036
Latest member
nickwillsonn

Latest Threads

Top