Home » Developer & Programmer » Precompilers, OCI & OCCI » Array bind - Strings (Oracle)
icon5.gif  Array bind - Strings [message #472013] Wed, 18 August 2010 05:26 Go to next message
rcs.raja
Messages: 3
Registered: December 2009
Location: Bangalore
Junior Member
Hi,

I am trying to insert multiple rows using array bind feature.

The following is working fine & inserting rows as expected.


char values[3][2] = { "1", "2", "3" };
ub2 lenp[3];
lenp[0] = lenp[1] = lenp[2] = 2;


pos = 1;
dt_type = SQLT_STR;
value_ptr = &values;
sz = sizeof(values[0]);

if ((r=OCIBindByPos(sh, &bndhp, err,
(ub4) pos, // position
value_ptr, // value pointer
sz, // size
dt_type,
(dvoid *) 0, // indp
(ub2 *) &lenp, // alenp
(ub2 *) 0, // rcodep
(ub4 ) 0, // maxarr_len
(ub4 *) 0, // curelp
(ub4) OCI_DEFAULT))) {

checkerr(err, r);
return 0;
}


If I trying the following code


char *vs1 = "1";
char *vs2 = "2";
char *vs3 = "3";

char *values[3];
values[0] = vs1;
values[1] = vs2;
values[2] = vs3;

ub2 lenp[3];
lenp[0] = lenp[1] = lenp[2] = 2;

...
pos = 1;
dt_type = SQLT_STR;
value_ptr = &values;
sz = sizeof(char *);

if ((r=OCIBindByPos(sh, &bndhp, err,
(ub4) pos, // position
value_ptr, // value pointer
sz, // size
dt_type,
(dvoid *) 0, // indp
(ub2 *) &lenp, // alenp
(ub2 *) 0, // rcodep
(ub4 ) 0, // maxarr_len
(ub4 *) 0, // curelp
(ub4) OCI_DEFAULT))) {

checkerr(err, r);
return 0;
}

OCIStmtExecute() is failing with the following error

Error - ORA-01480: trailing null missing from STR bind value


Am I missing any thing here. Or is there anyother way to do it

Thanks
Chandra
Confused

[Updated on: Wed, 18 August 2010 05:29]

Report message to a moderator

Re: Array bind - Strings [message #477954 is a reply to message #472013] Tue, 05 October 2010 06:28 Go to previous message
clancypc
Messages: 36
Registered: December 2006
Member
In the first example you were inserting an array of strings,
char values [3] [2];
An array of 3 strings of size 2 chars.

In the second example you are inserting a single string of size 3 bytes (char *values[3]), but you are not null terminating the string you are putting a value in each of the 3 bytes.
Previous Topic: compressed oracle connections
Next Topic: Passing array of structure to oracle procedure and returning back.
Goto Forum:
  


Current Time: Thu Nov 21 10:37:35 CST 2024