OCICollAppend(.) fails & OCICollSize(.) fails : OCI Error : 21500, 21560
654443Aug 24 2008 — edited Aug 27 2008Hi,
My aggregate member function output/OUT parameter is a nested table or collection : table_out1 :
table_out1 TABLE OF NTAB_TYPE
Name Null? Type
-----
--------
-----
EMPNO NUMBER
SALARY NUMBER
TST CHAR(10)
TE CHAR(10)
And this table_out1 is not part/column of any database table.
I am just using this table_out1 instance : returnValue : as a empty collection initially and then I am appending elements or objects
of type : NTAB_TYPE into this collection and then outputting the results(the entire collection items) directly to the sql prompt
after the completion of the ODCIAggregateTerminate member function. I am creating the new Objects by iterating through a set p :
and then corresponding creating objects using : OCIObjectNew(...)
But my problem is the OCICollSize(..) fails and throws an error : ORA-21500 or ORA-21560 .....
If I still go further and execute the OCICollApend(..) then it fails at that moment and gives me the same ORA-21500 or ORA-21560.
It fails at the very first element or when I am trying to append for the first time as the collection is empty.
The elem & elemind of OCICollAppend() : respectively : tmp & tmp_ind in my function ODCIAggregateTerminate are not null as I can check
them in my code ..So may be I am suspecting that the collection being empty it is throwing the error : but since in my case the collection
is an OUT/Output parameter so it should successfully append but it is not happening so..
When I check the OCI Collection size of returnValue : table_out1 : the value is nested_table size : 134580616
member function ODCIAggregateTerminate(
self IN OUT MinDistanceImpl, returnValue OUT table_out1,
flags IN number)
return number
as language C
library custagg name "ODCIAggregateTerminate"
with context
parameters (
context,
self,
self INDICATOR STRUCT,
returnValue ,
returnValue INDICATOR,
flags,
flags INDICATOR ,
RETURN ),
typedef OCITable table_out1;
struct ntab_type
{
OCINumber empno;
OCINumber salary;
OCIString * tst;
OCIString * te;
};
typedef struct ntab_type ntab_type;
struct ntab_type_ind
{
OCIInd _atomic;
OCIInd empno;
OCIInd salary;
OCIInd tst;
OCIInd te;
};
typedef struct ntab_type_ind ntab_type_ind;
extern "C" OCINumber * ODCIAggregateTerminate(
OCIExtProcContext *context,
MinDistanceImpl * self,
MinDistanceImpl_ind * self_ind,
table_out1 * returnValue,
short * returnValue_ind,
OCINumber * flags,
short flags_ind)
{
......Some previous code goes here...................
ntab_type * tmp = (ntab_type *) 0;
ntab_type_ind * tmp_ind = (ntab_type_ind *) 0;
returnValue = (table_out1 *) 0; // Can comment this : as it does not make any difference
OCIType out_tdo = (OCIType )0;
set<Outdata*>::iterator it;
for (it = storedCtx->l.p.begin(); it != storedCtx->l.p.end(); it++) {
fprintf(pFile, " in term set is : salary : %d , s.end : %s", (*it)->salary, (*it)->iend);
fflush(pFile);
int sal = (*it)->salary;
char time = (char )malloc(10*sizeof(char) + 1);
strcpy(time,(*it)->iend);
static sword status = 0;
if(( status = OCITypeByName(handles.envhp, handles.errhp, handles.svchp, (const text *) "SYS", (ub4) strlen("SYS"),
(const text *) "NTAB_TYPE", (ub4) strlen("NTAB_TYPE"), (text *)0, (ub4) 0,
OCI_DURATION_SESSION, OCI_TYPEGET_ALL, &out_tdo)) != OCI_SUCCESS)
{
fprintf (pFile, "Ocitypename - Fail\n");
fflush(pFile);
checkerr(&handles, status);
}
if((status = OCIObjectNew(handles.envhp,handles.errhp,handles.svchp, OCI_TYPECODE_OBJECT, out_tdo, (dvoid *)0,
OCI_DURATION_SESSION, TRUE, (dvoid**)&tmp)) != OCI_SUCCESS)
{
fprintf (pFile, "OCIOBJECTNEW - Fail\n");
fflush(pFile);
checkerr(&handles, status);
}
OCINumberFromInt( handles.errhp,&sal,sizeof(int),OCI_NUMBER_SIGNED, &tmp->empno);
if (checkerr(&handles, OCINumberFromInt( handles.errhp,&sal,sizeof(int),OCI_NUMBER_SIGNED,&tmp->salary)))
{
int success = ODCI_SUCCESS;
OCINumberFromInt( handles.errhp,&success,sizeof(int),OCI_NUMBER_SIGNED,returned );
*returnValue_ind = OCI_IND_NULL;
return returned;
}
if (checkerr(&handles, OCIStringAssignText(handles.envhp,handles.errhp, (CONST text *) time, strlen(time), &tmp->tst)))
{
int success = ODCI_SUCCESS;
OCINumberFromInt( handles.errhp,&success,sizeof(int),OCI_NUMBER_SIGNED,returned );
*returnValue_ind = OCI_IND_NULL;
return returned;
}
if (checkerr(&handles, OCIStringAssignText(handles.envhp,handles.errhp, (CONST text *) time, (ub2)strlen(time), &tmp->te)))
{
int success = ODCI_SUCCESS;
OCINumberFromInt( handles.errhp,&success,sizeof(int),OCI_NUMBER_SIGNED,returned );
*returnValue_ind = OCI_IND_NULL;
return returned;
}
char * ctst1 = (char *)OCIStringPtr(handles.envhp, tmp->tst);
char * cte1 = (char *)OCIStringPtr(handles.envhp, tmp->te);
fprintf(pFile, "from ctst1 & cte1 values");
-----
tmp->tst : %s | tmp->te : %s | \n", ctst1, cte1);
fflush (pFile);
if(tmp_ind==OCI_IND_NOTNULL)
{
fprintf(pFile, " Oci tmp_ind not null...\n");
fflush(pFile);
}
else {
fprintf(pFile, " After OCI tmp_ind is NULL ...\n");
fflush(pFile);
}
sb4 sz;
if((status = OCICollSize(handles.envhp, handles.errhp,(CONST OCIColl *) returnValue, &sz)) != OCI_SUCCESS)
{
fprintf (pFile, "nested_table size error : %d\n", (int)sz);
fflush(pFile);
checkerr(&handles, status);
}
else {
fprintf (pFile, "nested_table_returnValue_size : %d\n", (int)sz);
fflush(pFile);
}
if (( status = OCICollAppend(hand*les.envhp, handles.errhp, (CONST dvoid *)tmp, (CONST dvoid *)tmp_ind, (OCIColl *)returnValue))
!= OCI_SUCCESS)
{
fprintf (pFile, "OCICollAppend - Fail\n");
fflush(pFile);
checkerr(&handles, status);
}
writing some status info of the program to the file : ( I deleted few printf statements in the above code..)
In ODCIAggregateTerminate Function!
in term set is : salary : 99 , s.end : 1999-10-10 sal value is : 99 After initializing sal is : 99 , time : 1999-10-10
******************Ocitypename - successfully done ***********************
**************before tmp_ind---> oci-ind-null ***********************
***************after tmp_ind---> oci-ind-null ***********************
OCIObjectNew created successfully
Before OCI Number conversion :
Before OCIstringassign text convs...terminate para....
After oci string assign text for tmp.tst...
After oci string assign text for tmp.tst...
After oci string assign text for tmp.te...
from ctst1 & cte1 values-----
tmp->tst : 1999-10-10 | tmp->te : 1999-10-10 |
Oci tmp_ind not null...
nested_table size error : 134580616
****************************In checkerr module *********************************************!
OCI error code 21500
****************************closing of checkerr module *********************************************!