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 Go to next message
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 #398673 is a reply to message #398366] Fri, 17 April 2009 02:01 Go to previous messageGo to next message
vicenzo
Messages: 28
Registered: December 2007
Location: Paris
Junior Member
Hi,

Using OCIRaw, you have to use sql code SQLT_BIN not SQLT_LVB.

[Updated on: Fri, 17 April 2009 02:01]

Report message to a moderator

Re: OCIRaw Array Bind [message #398701 is a reply to message #398673] Fri, 17 April 2009 03:21 Go to previous messageGo to next message
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 Go to previous message
_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

Previous Topic: OCIStmtFetch2 problem when fetched rows = 0
Next Topic: occi compile error
Goto Forum:
  


Current Time: Sun Nov 23 09:02:33 CST 2014

Total time taken to generate the page: 0.47032 seconds