[Orclib-users] newbie question on implementing bulk operations
Open source C and C++ library for accessing Oracle Databases
Brought to you by:
vince_del_paris
|
From: <mod...@co...> - 2012-04-05 04:48:59
|
Hi, I've been successfully using OCILIB to access PL/SQL stored procedures in Oracle 11.2 database from C program. Now I need to download a lot of array data, so I thought I'd use bulk operations for a fast download. Since I know my connection is good, I must be getting the syntax wrong in my code. I've tried to follow the user manual and any examples I can find online, but there's nothing covering my exact situation. I was hoping someone could give me a sanity check on my OCILIB implementation below. I'm using gcc compiler with -std=C89 switch.
OCI_Connection *cn;
OCI_Statement *st;
char report_name[60];
double * d1, * d2, * d3;
int * i1;
unsigned int pts = 9; /* pts is actually determined when the program executes, but I set it to 9 here to simply the code for example only */
...
/* allocate array memory */
d1 = malloc( sizeof(double) * pts );
d2 = malloc( sizeof(double) * pts );
d3 = malloc( sizeof(double) * pts );
i1 = malloc( sizeof(int) * pts );
...
if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
return EXIT_FAILURE;
cn = OCI_ConnectionCreate("<removed>", "myschema", "myuser", OCI_SESSION_DEFAULT);
st = OCI_StatementCreate(cn);
...
/* database table 'my_table' has columns:
dd1 is binary_double
dd2 is binary_double
dd3 is binary_double
ii1 is number(8,0)
report_name is varchar2(60 bytes)
edge is char(1 byte) */
OCI_Prepare(st, "select dd1, dd2, dd3, ii1 into :out_d1, :out_d2, :out_d3, :out_i1 from my_table where report_name = :in_report_name and edge = 'a'");
OCI_BindString(st, ":in_report_name", report_name, 60);
OCI_BindArraySetSize(st, pts);
OCI_BindArrayOfDoubles(st, ":out_d1", (double*) d1, 0);
OCI_BindArrayOfDoubles(st, ":out_d2", (double*) d2, 0);
OCI_BindArrayOfDoubles(st, ":out_d3", (double*) d3, 0);
OCI_BindArrayOfInts(st, ":out_apron_tie", (int*) i1, 0);
OCI_Execute(st);
/* TEST */
printf("\nd1[0] = %g ", d1[0]);
printf("\nd1[1] = %g ", d1[1]);
OCI_Cleanup();
return EXIT_SUCCESS;
Thanks for any comments
|