oracle / odpi

ODPI-C: Oracle Database Programming Interface for Drivers and Applications
https://oracle.github.io/odpi/
Other
265 stars 75 forks source link

Error binding RAW values to statement #95

Closed felipenoris closed 5 years ago

felipenoris commented 5 years ago

Hi! I'm trying to add support for RAW columns. I understand I should use dpiData_setBytes to set a dpiData to a vector of bytes, the same way I should do with strings.

But, what happens is that it fails on executing the statement after I bind a vector of bytes.

Oracle.execute!(conn, "CREATE TABLE TB_RAW ( RAW_BYTES RAW(2000) )")

bytes = UInt8[0x01, 0xff, 0x22] # a vector of 3 bytes

stmt = Oracle.Stmt(conn, "INSERT INTO TB_RAW ( RAW_BYTES ) VALUES ( :a )")
stmt[1] = bytes
Oracle.execute!(stmt) # will fail

Error message:

ORA-01465: invalid hex number

In the line stmt[1] = bytes what happens is:

This setup works well for VARCHAR/NVARCHAR fields. It also works to set and get values to a in-memory dpiData.

Is there something else I should be aware of when binding to RAW fields?

felipenoris commented 5 years ago

Looks like it also happens with BLOBs. Is that why you always set values to a BLOB using variables, like in 6a4a6f17d0391e36d637583c51adcc2cdba71ba0 ?

felipenoris commented 5 years ago

Wait, I might be doing something wrong... I'll reopen if it persists after some more tests.

lovetodream commented 1 year ago

I have the same problem, how did you end up solving this @felipenoris?

felipenoris commented 1 year ago

@lovetodream in short, you must always use a Variable.

See https://felipenoris.github.io/Oracle.jl/stable/tutorial/#Writing-to-a-BLOB

and https://github.com/felipenoris/Oracle.jl/blob/a22a33d18e0a56d536f7ec39b32d58760e6e1635/src/bind.jl#L59