DBD-Oracle
view release on metacpan or search on metacpan
need_allocate_rows=phs->ora_maxarray_numentries;
if( need_allocate_rows< phs->array_numstruct ){
need_allocate_rows=phs->array_numstruct;
}
buflen=need_allocate_rows* phs->maxlen; /* We need buffer for at least ora_maxarray_numentries entries */
/* Upgrade array buffer to new length */
if( ora_realloc_phs_array(phs,need_allocate_rows,buflen) ){
croak("Unable to bind %s - %d structures by %d bytes requires too much memory.",
phs->name, need_allocate_rows, buflen );
}else{
if (trace_level >= 2 || dbd_verbose >= 3 ){
PerlIO_printf(
DBIc_LOGPIO(imp_sth),
"dbd_rebind_ph_number_table(): ora_realloc_phs_array(,"
"need_allocate_rows=%d,buflen=%d) succeeded.\n",
need_allocate_rows,buflen);
}
}
/* If maximum allowed bind numentries is less than allowed,
* do not bind full array
*/
if( phs->array_numstruct > phs->ora_maxarray_numentries ){
phs->array_numstruct = phs->ora_maxarray_numentries;
}
/* Fill array buffer with data */
{
int i; /* Not to require C99 mode */
for(i=0;i<av_len(arr)+1;i++){
SV *item;
item=*(av_fetch(arr,i,0));
if( item ){
switch( phs->ora_internal_type ){
case SQLT_INT:
{
int ival =0;
int val_found=0;
/* Double values are converted as int(val) */
if( SvOK( item ) && ! SvIOK( item ) ){
double val=SvNVx( item );
if( SvNOK( item ) ){
ival=(int) val;
val_found=1;
}
}
/* Convert item, if possible. */
if( (!val_found) && SvOK( item ) && ! SvIOK( item ) ){
SvIVx( item );
}
if( SvIOK( item ) || val_found ){
if( ! val_found ){
ival=SvIV( item );
}
/* as phs->array_buf=malloc(), proper alignment is guaranteed */
*(int*)(phs->array_buf+phs->maxlen*i)=ival;
phs->array_indicators[i]=0;
}else{
if( SvOK( item ) ){
/* Defined NaN assumed =0 */
*(int*)(phs->array_buf+phs->maxlen*i)=0;
phs->array_indicators[i]=0;
}else{
/* NULL */
phs->array_indicators[i]=1;
}
}
phs->array_lengths[i]=sizeof(int);
if (trace_level >= 3 || dbd_verbose >= 3 ){
PerlIO_printf(
DBIc_LOGPIO(imp_sth), "dbd_rebind_ph_number_table(): "
"(integer) array[%d]=%d%s\n",
i, *(int*)(phs->array_buf+phs->maxlen*i),
phs->array_indicators[i] ? " (NULL)" : "" );
}
}
break;
case SQLT_FLT:
default:
{
phs->ora_internal_type=SQLT_FLT; /* Just in case */
/* Convert item, if possible. */
if( SvOK( item ) && ! SvNOK( item ) ){
SvNVx( item );
}
if( SvNOK( item ) ){
double val=SvNVx( item );
/* as phs->array_buf=malloc(), proper alignment is guaranteed */
*(double*)(phs->array_buf+phs->maxlen*i)=val;
phs->array_indicators[i]=0;
if (trace_level >= 3 || dbd_verbose >= 3 ){
PerlIO_printf(
DBIc_LOGPIO(imp_sth),
"dbd_rebind_ph_number_table(): "
"let (double) array[%d]=%f - NOT NULL\n",
i, val);
}
}else{
if( SvOK( item ) ){
/* Defined NaN assumed =0 */
*(double*)(phs->array_buf+phs->maxlen*i)=0;
phs->array_indicators[i]=0;
if (trace_level >= 2 || dbd_verbose >= 3 ){
STRLEN l;
char *p=SvPV(item,l);
PerlIO_printf(
DBIc_LOGPIO(imp_sth),
"dbd_rebind_ph_number_table(): "
"let (double) array[%d]=\"%s\" =NaN. Set =0 - NOT NULL\n",
i, p ? p : "<NULL>" );
}
}else{
/* NULL */
phs->array_indicators[i]=1;
if (trace_level >= 3 || dbd_verbose >= 3 ){
PerlIO_printf(
DBIc_LOGPIO(imp_sth),
"dbd_rebind_ph_number_table(): "
"let (double) array[%d] NULL\n",
i);
}
}
}
phs->array_lengths[i]=sizeof(double);
if (trace_level >= 3 || dbd_verbose >= 3 ){
PerlIO_printf(
DBIc_LOGPIO(imp_sth),
"dbd_rebind_ph_number_table(): "
"(double) array[%d]=%f%s\n",
i, *(double*)(phs->array_buf+phs->maxlen*i),
phs->array_indicators[i] ? " (NULL)" : "" );
}
}
break;
}
}else{
/* item not defined, mark NULL */
phs->array_indicators[i]=1;
if (trace_level >= 3 || dbd_verbose >= 3 ){
PerlIO_printf(
DBIc_LOGPIO(imp_sth),
"dbd_rebind_ph_number_table(): "
"Copying length=? array[%d]=NULL av_fetch failed.\n", i);
}
}
}
}
/* Do actual bind */
OCIBindByName_log_stat(imp_sth, imp_sth->stmhp, &phs->bndhp, imp_sth->errhp,
(text*)phs->name, (sb4)strlen(phs->name),
phs->array_buf,
phs->maxlen,
(ub2)phs->ora_internal_type, phs->array_indicators,
phs->array_lengths,
NULL,
(ub4)phs->ora_maxarray_numentries, /* max elements that can fit in allocated array */
(ub4 *)&(phs->array_numstruct), /* (ptr to) current number of elements in array */
OCI_DEFAULT, /* OCI_DATA_AT_EXEC (bind with callbacks) or OCI_DEFAULT */
status
);
if (status != OCI_SUCCESS) {
oci_error(sth, imp_sth->errhp, status, "OCIBindByName");
return 0;
}
OCIBindArrayOfStruct_log_stat(imp_sth, phs->bndhp, imp_sth->errhp,
(unsigned)phs->maxlen, /* Skip parameter for the next data value */
(unsigned)sizeof(OCIInd), /* Skip parameter for the next indicator value */
(unsigned)sizeof(unsigned short), /* Skip parameter for the next actual length value */
0, /* Skip parameter for the next column-level error code */
( run in 2.724 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )