Home » Developer & Programmer » Precompilers, OCI & OCCI » OCIRaw Array Bind (Oracle 10.2.0.4.0 -> centOS)
OCIRaw Array Bind [message #398366] |
Thu, 16 April 2009 02:09 |
khansamjath
Messages: 2 Registered: April 2009
|
Junior Member |
|
|
I want to insert data into a RAW column in a table. The below code snippet is used for the same
OCIRaw **l_rawPtr = new OCIRaw*[10];
for(int i=0;i<10;i++)
{ l_rawPtr[i] = NULL; }
int max = 0;
for(int i=0;i<10;i++)
{
OCIRawAssignBytes(l_environment, l_error, l_char, strlen((const char*)l_char), &l_rawPtr[i])
OCIRawAllocSize(l_environment,l_error,l_rawPtr[i],&l_l);
if(l_l > max) max = l_l;
}
OCIBind *def1 = NULL, *def2 = NULL;
sb2 m_inullIndicator[10];
if (OCIBindByPos ( l_stmt, &def1, l_error, 1, l_rawPtr, max, SQLT_LVB, (sb2*)0, (ub2 *)0,(ub2 *)0, 0, (ub4 *)0,OCI_DEFAULT) )
{
getError(l_error);
exit(0);
}
int errr = 0;
if (errr = OCIStmtExecute(l_service, l_stmt,l_error, (ub4) 10, (ub4) 0, (OCISnapshot *) NULL, (OCISnapshot *) NULL, (ub4) OCI_DEFAULT))
{
getError(l_error);
if (errr != OCI_NO_DATA) return errr;
}
When the statement is getting executed, i am getting the following error.
Error - ORA-01458: invalid length inside variable character string
Could anybody help me to fix this
|
|
|
|
Re: OCIRaw Array Bind [message #398701 is a reply to message #398673] |
Fri, 17 April 2009 03:21 |
khansamjath
Messages: 2 Registered: April 2009
|
Junior Member |
|
|
If I use SQLT_BIN, the data is stored in the different format than RAW, probably VARRAW.
The other thing i noticed was,
I have a select query on the same table, selecting the raw column. After executing the query, I used OCIParamGet() to get the Parameter Descriptor and checked for the Column Type. It corresponds to SQLT_BIN.
But if I use SQLT_BIN in OCIDefineByPos() (single row fetch), i am getting the results with the first 4 characters getting truncated. But, If I use SQLT_LVB, it gives me the proper result.
Some documentations on ORacle suggest to SQLT_LVB as well.
|
|
|
Re: OCIRaw Array Bind [message #507314 is a reply to message #398366] |
Fri, 13 May 2011 10:00 |
|
_Nikotin
Messages: 1 Registered: May 2011 Location: Russia
|
Junior Member |
|
|
OCIRaw *raws[N];
// ... fill the raws with data
int maxallocsize = 0;
for (i = 0; i < N; i++)
{
int allocsize;
OCIRawAllocSize(envhp, errhp, raws[i], (ub4 *)(&allocsize));
if (allocsize > maxallocsize)
maxallocsize = allocsize;
}
char *rawcopy = (char *)malloc((maxallocsize + 4) * N);
for (i = 0; i < N; i++)
{
int allocsize;
OCIRawAllocSize(envhp, errhp, raws[i], (ub4 *)(&allocsize));
memcpy(rawcopy + i * (maxallocsize + 4), raws[i], allocsize + 4);
}
OCIStmt *stmt;
OCIHandleAlloc(envhp, &stmt, OCI_HTYPE_STMT, 0, 0);
OCIBind *bndp = (OCIBind *)0;
const char *query = "INSERT INTO ... VALUES(:param)";
OCIStmtPrepare(stmt, errhp, (text *)query, (ub4)strlen(query), OCI_NTV_SYNTAX, OCI_DEFAULT));
OCIBindByName(stmt, &bndp, errhp, (text *)":param", -1,
(dvoid *)rawcopy, maxallocsize + sizeof(int), SQLT_LVB, 0, 0, 0, 0, 0, OCI_DEFAULT);
OCIStmtExecute(svchp, stmt, errhp, N, 0, NULL, NULL, OCI_DEFAULT);
[Updated on: Fri, 13 May 2011 10:14] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu Nov 21 10:50:28 CST 2024
|