Author: byterock
Date: Fri May 16 09:56:42 2008
New Revision: 11283
Modified:
dbd-oracle/trunk/dbdimp.c
dbd-oracle/trunk/dbdimp.h
dbd-oracle/trunk/oci8.c
Log:
well code is messy but it is working will have to look at null next
Modified: dbd-oracle/trunk/dbdimp.c
==============================================================================
--- dbd-oracle/trunk/dbdimp.c (original)
+++ dbd-oracle/trunk/dbdimp.c Fri May 16 09:56:42 2008
@@ -271,12 +271,32 @@
/* --- allocate and free oracle oci 'array' buffers --- */
+/* --- allocate and free oracle oci 'array' buffers for callback--- */
+
+fb_ary_t *
+fb_ary_cb_alloc(ub4 piece_size, ub4 max_len, int size)
+{
+ fb_ary_t *fb_ary;
+ /* these should be reworked to only to one Newz() */
+ /* and setup the pointers in the head fb_ary struct */
+ Newz(42, fb_ary, sizeof(fb_ary_t), fb_ary_t);
+ Newz(42, fb_ary->abuf, size * piece_size, ub1);
+ Newz(42, fb_ary->cb_abuf, size * max_len, ub1);
+ Newz(42, fb_ary->aindp, (unsigned)size, sb2);
+ Newz(42, fb_ary->arlen, (unsigned)size, ub2);
+ Newz(42, fb_ary->arcode, (unsigned)size, ub2);
+ fb_ary->bufl = piece_size;
+ fb_ary->cb_bufl = max_len;
+ return fb_ary;
+}
+
+
+/* --- allocate and free oracle oci 'array' buffers --- */
+
fb_ary_t *
fb_ary_alloc(ub4 bufl, int size)
{
- dTHR;
- dTHX;
- fb_ary_t *fb_ary;
+ fb_ary_t *fb_ary;
/* these should be reworked to only to one Newz() */
/* and setup the pointers in the head fb_ary struct */
Newz(42, fb_ary, sizeof(fb_ary_t), fb_ary_t);
@@ -285,7 +305,7 @@
Newz(42, fb_ary->arlen, (unsigned)size, ub2);
Newz(42, fb_ary->arcode, (unsigned)size, ub2);
fb_ary->bufl = bufl;
-
+ fb_ary->cb_bufl = bufl;
return fb_ary;
}
@@ -296,7 +316,9 @@
Safefree(fb_ary->aindp);
Safefree(fb_ary->arlen);
Safefree(fb_ary->arcode);
+ Safefree(fb_ary->cb_abuf);
Safefree(fb_ary);
+
}
Modified: dbd-oracle/trunk/dbdimp.h
==============================================================================
--- dbd-oracle/trunk/dbdimp.h (original)
+++ dbd-oracle/trunk/dbdimp.h Fri May 16 09:56:42 2008
@@ -73,6 +73,7 @@
int pers_lob; /*use dblink for lobs only
for 10g Release 2. or later*/
ub4 piece_size; /*used in callback to set
the size of the piece to get*/
int has_lobs; /* Statement has bound LOBS*/
+
lob_refetch_t *lob_refetch;
int nested_cursor; /* cursors fetched from SELECTs */
AV *bind_tuples; /* Bind tuples in array execute, or NULL */
@@ -121,8 +122,11 @@
typedef struct fb_ary_st fb_ary_t; /* field buffer array */
struct fb_ary_st { /* field buffer array EXPERIMENTAL */
ub4 bufl; /* length of data buffer */
+ ub4 cb_bufl; /* length of piece of data fetched in callback */
+ ub4 piece_count;
sb2 *aindp; /* null/trunc indicator variable */
ub1 *abuf; /* data buffer (points to sv data) */
+ ub1 *cb_abuf; /*yet another buffer for picewise callbacks*/
ub2 *arlen; /* length of returned data */
ub2 *arcode; /* field level error status */
};
@@ -174,8 +178,11 @@
ub1 csform; /* OCI_ATTR_CHARSET_FORM */
ub4 disize; /* max display/buffer size */
+ ub4 piece_size; /*used in callback to set the size
of the piece to get*/
+
char *bless; /* for Oracle::OCI style handle data */
void *special; /* hook for special purposes (LOBs etc)
*/
+ int pers_lob; /*for persistant lobs 10g Release
2. or later*/
/* Our storage space for the field data as it's fetched */
sword ftype; /* external datatype we wish to get */
@@ -263,6 +270,8 @@
void ora_free_templob _((SV *sth, imp_sth_t *imp_sth, OCILobLocator *lobloc));
int ora_dbtype_is_long _((int dbtype));
fb_ary_t *fb_ary_alloc _((ub4 bufl, int size));
+fb_ary_t *fb_ary_cb_alloc _((ub4 bufl,ub4 cb_bufl, int size));
+
int ora_db_reauthenticate _((SV *dbh, imp_dbh_t *imp_dbh, char *uid, char
*pwd));
void dbd_phs_sv_complete _((phs_t *phs, SV *sv, I32 debug));
Modified: dbd-oracle/trunk/oci8.c
==============================================================================
--- dbd-oracle/trunk/oci8.c (original)
+++ dbd-oracle/trunk/oci8.c Fri May 16 09:56:42 2008
@@ -590,41 +590,104 @@
/* -------------------------------------------------------------- */
/* Fetch callback to specify buffers. */
/* -------------------------------------------------------------- */
-static sb4 presist_lob_fetch_cbk(dvoid *octxp, OCIDefine *dfnhp, ub4 iter,
dvoid **bufpp,
+static sb4 presist_lob_fetch_cbk(dvoid *octxp, OCIDefine *dfnhp, ub4 iter,
dvoid **bufpp,
ub4 **alenpp, ub1 *piecep, dvoid **indpp, ub2 **rcpp)
{
dTHX;
+ static int a = 0;
+
imp_fbh_t *fbh =(imp_fbh_t*)octxp;
- fb_ary_t *fb_ary;
+ fb_ary_t *fb_ary;
fb_ary = fbh->fb_ary;
*indpp = (dvoid *) 0;
*rcpp = (ub2 *) 0;
+ /* PerlIO_printf(DBILOGFP,"-->in fb_ary->piece_count=%d a=%d *piecep=%d\n",
fb_ary->piece_count,a,*piecep);
+
+ /* if (fb_ary->piece_count
+ *piecep =OCI_LAST_PIECE;
+ /* PerlIO_printf(DBILOGFP,"Getting OCI_%s_PIECE .... \n",
+ (piecep[0]==(ub1)OCI_ONE_PIECE) ? "ONE" :
+ (piecep[0]==(ub1)OCI_FIRST_PIECE) ? "FIRST" :
+ (piecep[0]==(ub1)OCI_NEXT_PIECE) ? "NEXT" :
+ (piecep[0]==(ub1)OCI_LAST_PIECE) ? "LAST" : "???");
+ */
+ /* if (fb_ary->piece_count == 1 ){
+ /* fb_ary->bufl=fbh->piece_size; /*reset this back to the disize */
+ /* fb_ary->cb_bufl=fbh->disize;
+ * PerlIO_printf(DBILOGFP," first\n");
+ }*/
+ /* fb_ary->cb_bufl=fbh->*/
*bufpp = (dvoid *) fb_ary->abuf;
*alenpp = &fb_ary->bufl;
- /*ind = 0;
+/* a++;
+
+ PerlIO_printf(DBILOGFP,"BEFORE DID COPY fb_ary->bufl=%d,fbh->piece_size=%d
\n",fb_ary->bufl,fbh->piece_size);
+*/
+ if (fb_ary->piece_count > 0 && fb_ary->bufl == fbh->piece_size){
+
+/* PerlIO_printf(DBILOGFP,"DID COPY fb_ary->bufl=%d\n",fb_ary->bufl);*/
+
+ fb_ary->cb_abuf= strncat( fb_ary->cb_abuf, fb_ary->abuf,fb_ary->bufl);
+
+ }
+
+ fb_ary->piece_count++;
+
+ /* PerlIO_printf(DBILOGFP," strlen(fb_ary->cb_abuf)=%d
\n",strlen(fb_ary->cb_abuf));*/
+
+ /* PerlIO_printf(DBILOGFP," fb_ary->piece_count is
=%d\n",fb_ary->piece_count);*/
+
+
+
+/* if (a<=1)
+ {
+ /*piecep = OCI_FIRST_PIECE;*
+ PerlIO_printf(DBILOGFP,"Select callback: 0th piece\n");
+ }
+ else if (a<3)
+ {
+ /*piecep = OCI_NEXT_PIECE;*
+ PerlIO_printf(DBILOGFP,"Select callback: %d'th piece:\n", a-1);
+ }
+ else {
+ /*piecep = OCI_LAST_PIECE;*
+ PerlIO_printf(DBILOGFP,"Select callback: %d'th piece: \n", a-1);
+ a = 0;
+ }
+*/
+ /* *bufpp = (dvoid *) fb_ary->cb_abuf;
+ *alenpp = &fb_ary->cb_bufl;
+ PerlIO_printf(DBILOGFP," cbk 2\n");*/
+
+/* strncat(fb_ary->abuf, fb_ary->cb_abuf,fb_ary->cb_bufl);*/
+
+
+
+ /*ind = 0;
+
if (glGetInd)
*indpp = (dvoid *) &ind;
else
*indpp = (dvoid *)0;
-
+
rc = 0;
if (glGetRc)
*rcpp = (ub2 *) &rc;
else
*rcpp = (ub2 *)0;
-
+
/* switch (piecep[0]) {
-
+
case OCI_ONE_PIECE:
PerlIO_printf(DBILOGFP," OCI_ONE_PIECE\n");
break;
case OCI_FIRST_PIECE:
-
-
+
+
/* (void)SvUPGRADE(sv, SVt_PV);*/
/* SvGROW(sv,fb_ary->bufl);
-
+
PerlIO_printf(DBILOGFP," first piece \n");
/* sv=newSVpvn((char*)bufpp, fb_ary->bufl);
PerlIO_printf(DBILOGFP,"SvLEN(sv)=%d\n",SvLEN(sv));
@@ -634,35 +697,36 @@
/* sv_setpvn(sv,(char*)(*bufpp), fb_ary->bufl);*/
/* PerlIO_printf(DBILOGFP,"SvLEN(sv)=%d\n",SvLEN(sv));
break;
-
+
case OCI_NEXT_PIECE:
PerlIO_printf(DBILOGFP," OCI_NEXT_PIECE\n");
-
- /* sv_catpv(sv,(char *) bufpp);
+
+ /* sv_catpv(sv,(char *) bufpp);
PerlIO_printf(DBILOGFP,"SvLEN(sv)=%d\n",SvLEN(sv));
/* row_data=&fb_ary->abuf[0]+(fb_ary->bufl);
p = (char*)row_data;
PerlIO_printf(DBILOGFP," OCI_FIRST_PIECE\n"); */
-
+
/* bufpp[fb_ary->bufl] = '\0';*/
/* PerlIO_printf(DBILOGFP,"strlen(p)=%s\n",strlen(p));
-
-
+
+
break;
-
+
case OCI_LAST_PIECE:
PerlIO_printf(DBILOGFP," OCI_LAST_PIECE\n");
break;
default:
PerlIO_printf(DBILOGFP,"ERROR: piece-wise fetching, \n");
- break;
+ break;
}
-
- PerlIO_printf(DBILOGFP," done internal loop\n");*/
-
+ */
+/* PerlIO_printf(DBILOGFP,"<---out fb_ary->piece_count=%d a=%d
*piecep=%d\n", fb_ary->piece_count,a,*piecep);*/
+
+
return OCI_CONTINUE;
-
+
}
#ifdef UTF8_SUPPORT
@@ -1796,27 +1860,27 @@
sword status = OCI_NEED_DATA;
fb_ary_t *fb_ary = fbh->fb_ary;
ub1* row_data=&fb_ary->abuf[0]+(fb_ary->bufl*fbh->imp_sth->rs_array_idx);
-
+
if (DBIS->debug <= 4) {
PerlIO_printf(DBILOGFP, " getting an Presistant Binaray
lob with picewise fetch row_data =%d\n",row_data);
}
-
+
PerlIO_printf(DBILOGFP, "status=%d\n",status);
-
+
while (status == OCI_NEED_DATA){
- OCIStmtGetPieceInfo(fbh->imp_sth->stmhp,
+ OCIStmtGetPieceInfo(fbh->imp_sth->stmhp,
fbh->imp_sth->errhp,
&hdlptr, &hdltype,
&in_out, &iter, &idx, &piece);
OCIStmtSetPieceInfo((dvoid *)hdlptr, (ub4)hdltype,
fbh->imp_sth->errhp, (dvoid *) &row_data, &alen, piece,
(dvoid *)&indptr, &rcode);
- sv_catpv(dest_sv, row_data);
- status = OCIStmtFetch(fbh->imp_sth->stmhp,fbh->imp_sth->errhp,
(ub4) 1,
+ sv_catpv(dest_sv, row_data);
+ status = OCIStmtFetch(fbh->imp_sth->stmhp,fbh->imp_sth->errhp,
(ub4) 1,
(ub2)
OCI_FETCH_NEXT, (ub4) OCI_DEFAULT);
-
+
PerlIO_printf(DBILOGFP, "status=%d\n",status);
- }
+ }
return 1;
}
@@ -2215,7 +2279,7 @@
int nested_cursors = 0;
ub4 i = 0;
sword status;
-
+
if (imp_sth->done_desc)
return 1; /* success, already done it */
@@ -2284,8 +2348,8 @@
fbh->imp_sth = imp_sth;
fbh->field_num = i;
fbh->define_mode = OCI_DEFAULT;
-
-
+
+
OCIParamGet_log_stat(imp_sth->stmhp, OCI_HTYPE_STMT,
imp_sth->errhp,
(dvoid**)&fbh->parmdp, (ub4)i, status);
@@ -2406,11 +2470,15 @@
fbh->ftype = fbh->dbtype;
/* do we need some addition size logic here? (lab) */
if (imp_sth->pers_lob){ /*this only works on
10.2 */
+
+ fbh->pers_lob = 1;
fbh->define_mode = OCI_DYNAMIC_FETCH; /*
piecwise fetch*/
- fbh->disize = imp_sth->long_readlen; /*user set max
value*/
+ fbh->disize = imp_sth->long_readlen;
/*user set max value*/
+ fbh->piece_size = imp_sth->piece_size;
+
if (!imp_sth->piece_size){ /*if not set use max
value*/
imp_sth->piece_size=imp_sth->long_readlen;
- }
+ }
if (fbh->dbtype == 112){
fbh->ftype = SQLT_CHR;
} else {
@@ -2507,14 +2575,16 @@
sb4 define_len = (ftype==94||ftype==95) ? fbh->disize+4 :
fbh->disize;
fb_ary_t *fb_ary;
fbh->fb_ary = fb_ary_alloc(define_len, 1);
- if (imp_sth->pers_lob){
- fbh->fb_ary = fb_ary_alloc(imp_sth->piece_size,
imp_sth->rs_array_size);
+
+ if (fbh->pers_lob){
+ fbh->fb_ary =
fb_ary_cb_alloc(imp_sth->piece_size,define_len, imp_sth->rs_array_size);
+
} else {
- fbh->fb_ary = fb_ary_alloc(define_len,
imp_sth->rs_array_size);
-
+ fbh->fb_ary = fb_ary_alloc(define_len,
imp_sth->rs_array_size);
}
- fb_ary = fbh->fb_ary;
-
+
+ fb_ary = fbh->fb_ary;
+
if (fbh->ftype == SQLT_BIN) {
define_len++;
/*add one extra byte incase the size of the lob is
equal to the define_len*/
@@ -2525,6 +2595,7 @@
(dvoid*)&((OCIStmt **)fb_ary->abuf)[0],
OCI_HTYPE_STMT, status);
}
+
OCIDefineByPos_log_stat(imp_sth->stmhp,
&fbh->defnp,
imp_sth->errhp,
@@ -2537,7 +2608,7 @@
fb_ary->arcode,
fbh->define_mode,
status);
-
+
if (imp_sth->pers_lob) {
/* uses a dynamic callback for persistent
binary and char lobs*/
@@ -2545,7 +2616,7 @@
(OCICallbackDefine)
presist_lob_fetch_cbk);
}
-
+
if (fbh->ftype == 108) { /* Embedded object bind it
differently*/
@@ -2637,7 +2708,7 @@
status = OCI_SUCCESS;
} else {
- if (DBIS->debug >= 3){
+ if (DBIS->debug <= 3){
PerlIO_printf(DBILOGFP, " dbd_st_fetch %d fields...\n",
DBIc_NUM_FIELDS(imp_sth));
}
@@ -2701,7 +2772,7 @@
av = DBIS->get_fbav(imp_sth);
- if (DBIS->debug >= 3) {
+ if (DBIS->debug <= 3) {
PerlIO_printf(DBILOGFP, " dbd_st_fetch %d fields %s\n",
num_fields, oci_status_name(status));
}
@@ -2709,14 +2780,14 @@
err = 0;
-
+
for(i=0; i < num_fields; ++i) {
imp_fbh_t *fbh = &imp_sth->fbh[i];
fb_ary_t *fb_ary = fbh->fb_ary;
int rc = fb_ary->arcode[imp_sth->rs_array_idx];
ub1*
row_data=&fb_ary->abuf[0]+(fb_ary->bufl*imp_sth->rs_array_idx);
SV *sv = AvARRAY(av)[i]; /* Note: we (re)use the SV in the AV
*/;
-
+
if (rc == 1406 /* field was truncated
*/
&& ora_dbtype_is_long(fbh->dbtype)/* field is a LONG
*/
){
@@ -2735,7 +2806,7 @@
}
-
+
if (rc == 0 || /* the normal case*/
(imp_sth->pers_lob && rc == 1406 &&
DBIc_has(imp_sth,DBIcf_LongTruncOk))/*or a trunckated record when using 10.2
Persistent Lob interface*/
) {
@@ -2747,10 +2818,33 @@
} else {
if (fbh->ftype == SQLT_BIN){ /*This uses a picewise fecth call
to presist_lob_fetch_cbk*/
- *(fb_ary->abuf+(fb_ary->bufl))='\0'; /* add a null
teminator*/
- sv_setpvn(sv, (char*)fb_ary->abuf,
strlen((char*)fb_ary->abuf));
- fb_ary->bufl=imp_sth->piece_size; /*reset this back
to piece_size */
-
+ ub4
actual_bufl=imp_sth->piece_size*(fb_ary->piece_count-1)+fb_ary->bufl;
+ /* the actual size of the data returned is the #of
Pieces * pice_size + any left over which will be in bufl*/
+
+ /* PerlIO_printf(DBILOGFP," actual_bufl=%d\n",
actual_bufl);*/
+
+ *(fb_ary->cb_abuf+(actual_bufl))='\0'; /* add a null
teminator*/
+
+ sv_setpvn(sv, (char*)fb_ary->cb_abuf, actual_bufl);
+
+
+ /* PerlIO_printf(DBILOGFP,"fetch 1
imp_sth->piece_sizel=%d\n", imp_sth->piece_size);
+ PerlIO_printf(DBILOGFP,"fetch 1
imp_sth->long_readlen=%d\n", imp_sth->long_readlen);
+
+ PerlIO_printf(DBILOGFP,"fetch 1 fbh->piece_size=%d\n",
fbh->piece_size);
+ PerlIO_printf(DBILOGFP,"fetch 1
fbh->disize=%d\n", fbh->disize);
+ */
+ fb_ary->piece_count=0;/*reset this back to the disize */
+ /* PerlIO_printf(DBILOGFP,"fetch 1 fb_ary->bufl=%d\n",
fb_ary->bufl);
+ PerlIO_printf(DBILOGFP,"fetch 1 fb_ary->cb_bufl=%d\n",
fb_ary->cb_bufl);
+ */
+ fb_ary->bufl=fbh->piece_size; /*reset this back to the
disize */
+ fb_ary->cb_bufl=fbh->disize; /*reset this back to
piece_size */
+
+/* PerlIO_printf(DBILOGFP,"fetch 1 fb_ary->bufl=%d\n",
fb_ary->bufl);
+ PerlIO_printf(DBILOGFP,"fetch 1
fb_ary->cb_bufl=%d\n", fb_ary->cb_bufl);
+*/
+
} else {
int datalen =
fb_ary->arlen[imp_sth->rs_array_idx];
char *p = (char*)row_data;