Home » Developer & Programmer » Precompilers, OCI & OCCI » OCI Query (merged)
OCI Query (merged) [message #391437] Thu, 12 March 2009 04:47 Go to next message
vaishali.verma18
Messages: 6
Registered: March 2009
Junior Member
Can anybody give me the sample code in OCI in C for receiving records of table in array of structure?
Or dynamically storing the resultset in an array..using array of pointers to structure...
Or any other help is invited
Razz
OCI Query [message #391439 is a reply to message #391437] Thu, 12 March 2009 04:56 Go to previous messageGo to next message
vaishali.verma18
Messages: 6
Registered: March 2009
Junior Member
Can any body help me in some sample code....
I want to save the resultset in an array of structure...
Or dynamically allocate user memory to array of pointers to structure...that will help in storing the resultset
...Ny kind of help wud be a favor
Razz
Re: OCI Query (merged) [message #391441 is a reply to message #391437] Thu, 12 March 2009 05:04 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Oracle® Call Interface Programmer's Guide

Regards
Michel
Re: OCI Query [message #391447 is a reply to message #391439] Thu, 12 March 2009 05:10 Go to previous messageGo to next message
vaishali.verma18
Messages: 6
Registered: March 2009
Junior Member
Hey does not want a programmer guide ...I already have...
need some code...
Re: OCI Query [message #391449 is a reply to message #391447] Thu, 12 March 2009 05:11 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Guide contains code.
You can also go to otn.oracle.com which contain many code examples.

And you should be more polite, if you want help.

Regards
Michel

[Updated on: Thu, 12 March 2009 05:11]

Report message to a moderator

Re: OCI Query [message #391452 is a reply to message #391449] Thu, 12 March 2009 05:15 Go to previous messageGo to next message
vaishali.verma18
Messages: 6
Registered: March 2009
Junior Member
I knw dear guide have code...I am stuck..and sorry if u find the answer to be v blunt...i also want the code for the query
select count(*) from tablename...

If you cud really help me out..
Smile
Re: OCI Query (merged) [message #391454 is a reply to message #391437] Thu, 12 March 2009 05:25 Go to previous message
vaishali.verma18
Messages: 6
Registered: March 2009
Junior Member
please look at the approach I am going with...M unable to understand y the statement is not getting executed...I am new to OCI..Plz help me..
Sad


typedef struct structEmployeeTab_t
{
int empno;
char ename[20];
char job[20];
int sal;
int deptno;
}EmployeeTab_t;


S32 oci_allocate_memory()
{
int i;
printf("Inside oci_allocate_memory\n");
for(i=0;i<NO_OF_ROWS;i++)
{
EmployeeTab_p[i]=(EmployeeTab_t *)malloc(sizeof(EmployeeTab_t));
if (NULL == EmployeeTab_p [i])
{
printf("Error in Initializing Memory for Employee Table Structure \n");
return UTIL_FAILURE;
break;
}
else
{
//printf("Memory Allocation for Employee Table Structure SUCCESS!!!\n");
}

}
return UTIL_SUCCESS;
}

void oci_define(OciHandle_t *ctxptr)
{
int i;
static int j=1;
printf("Inside oci_define\n");

for(i=1;i<=NoOfRows;i++)
{

checkerr(ctxptr->errhp,status=OCIDefineByPos(ctxptr->stmthp, &ctxptr->dfnhp, ctxptr->errhp,j, &EmployeeTab_p[i]->empno,sizeof(EmployeeTab_p[i]), SQLT_INT, NULL, NULL,NULL, OCI_DEFAULT));
j++;
/* checkerr(ctxptr->errhp,status= OCIDefineByPos(ctxptr->stmthp, &ctxptr->dfnhp, ctxptr->errhp, j, (dvoid *) &EmployeeTab_p[i]->ename,(sb4)sizeof(EmployeeTab_p[i]), SQLT_STR, (dvoid *) 0, (ub2 *)0,
(ub2 *)0, OCI_DEFAULT));
j++;

checkerr(ctxptr->errhp,status= OCIDefineByPos(ctxptr->stmthp, &ctxptr->dfnhp,ctxptr->errhp, j, (dvoid *) &EmployeeTab_p[i]->job,(sb4)sizeof(EmployeeTab_p[i]), SQLT_STR, (dvoid *) 0, (ub2 *)0,
(ub2 *)0, OCI_DEFAULT));
j++;*/
checkerr(ctxptr->errhp,status=OCIDefineByPos(ctxptr->stmthp, &ctxptr->dfnhp, ctxptr->errhp,j, &EmployeeTab_p[i]->sal,sizeof(EmployeeTab_p[i]), SQLT_INT, NULL, NULL,NULL, OCI_DEFAULT));
j++;

checkerr(ctxptr->errhp,status=OCIDefineByPos(ctxptr->stmthp, &ctxptr->dfnhp, ctxptr->errhp,j, &EmployeeTab_p[i]->deptno,sizeof(EmployeeTab_p[i]), SQLT_INT, NULL, NULL,NULL, OCI_DEFAULT));
j++;
//}
checkerr(ctxptr->errhp,status=OCIDefineArrayOfStruct(ctxptr->dfnhp,ctxptr->errhp,(ub4)sizeof(EmployeeTab_t), 0, 0, 0));
}

S32 oci_execute_statement(OciHandle_t *ctxptr)
{
S32 iter = UTIL_FALSE;
S32 count = 1;
S32 noOfRows;
printf("Executing OCIStmtExecute\n");
checkerr(ctxptr->errhp, status=OCIStmtExecute(ctxptr->svchp,ctxptr->stmthp,ctxptr->errhp, (ub4) count, (ub4) iter, (CONST OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_COMMIT_ON_SUCCESS));


}



Logs:


Inside oci_allocate_memory
oci_Init SUCCESS 0
Inside oci_connect
OCILogon SUCCESS!!!
oci_connect SUCCESS
query to be executed select empno,sal,deptno from empo
Executing OCIStmtPrepare
OCIStmtPrepare SUCCESS!!!
Inside oci_define
Executing OCIStmtExecute
Error - ORA-01007: variable not in select list

OCIStmtExecute FAILED!!!
Inside oci_fetch_rows
Previous Topic: Pro*C: cursor leak with cursor array
Next Topic: PCC-S-02345 - 11g Client to 10g Server
Goto Forum:
  


Current Time: Tue Nov 26 21:17:43 CST 2024