Author: byterock
Date: Wed Jul 15 12:16:31 2009
New Revision: 13063
Modified:
dbd-oracle/branches/rs_array/dbdimp.c
dbd-oracle/branches/rs_array/dbdimp.h
dbd-oracle/branches/rs_array/oci8.c
dbd-oracle/branches/rs_array/t/34pres_lobs.t
Log:
working version
Modified: dbd-oracle/branches/rs_array/dbdimp.c
==============================================================================
--- dbd-oracle/branches/rs_array/dbdimp.c (original)
+++ dbd-oracle/branches/rs_array/dbdimp.c Wed Jul 15 12:16:31 2009
@@ -2955,7 +2955,7 @@
{
dTHR;
dTHX;
- ub4 row_count = 0;
+ int row_count = 0;
int debug = DBIS->debug;
int outparams = (imp_sth->out_params_av) ?
AvFILL(imp_sth->out_params_av)+1 : 0;
D_imp_dbh_from_sth;
@@ -3045,28 +3045,54 @@
PerlIO_printf(DBILOGFP,"Statement Execute Mode is %d
(%s)\n",imp_sth->exe_mode,oci_exe_mode(imp_sth->exe_mode));
OCIStmtExecute_log_stat(imp_sth->svchp, imp_sth->stmhp,
imp_sth->errhp,
- (ub4)(is_select ? 0: 1),
+ (ub4)(is_select ? (
imp_sth->row_cache_off ? 0 : imp_sth->rs_array_size) : 1),
0, 0, 0,(ub4)imp_sth->exe_mode,status);
-
- if (status != OCI_SUCCESS) { /* may be OCI_ERROR or
OCI_SUCCESS_WITH_INFO etc */
- /* we record the error even for OCI_SUCCESS_WITH_INFO */
- oci_error(sth, imp_sth->errhp, status,
ora_sql_error(imp_sth,"OCIStmtExecute"));
- /* but only bail out here if not OCI_SUCCESS_WITH_INFO
*/
- if (status != OCI_SUCCESS_WITH_INFO)
- return -2;
+ if (status != OCI_SUCCESS){
+
+ if ((status != OCI_NO_DATA) && (imp_sth->row_cache_off)
&& (is_select)) {
+ /* may be OCI_ERROR or OCI_SUCCESS_WITH_INFO etc */
+ /* but OCI_NO_DATA with a select means the exe got all the rows
in 1 shot (a warning really according to oralce )
+ /* we record the error even for
OCI_SUCCESS_WITH_INFO */
+ oci_error(sth, imp_sth->errhp, status,
ora_sql_error(imp_sth,"OCIStmtExecute"));
+ /* but only bail out here if not
OCI_SUCCESS_WITH_INFO */
+ if (status != OCI_SUCCESS_WITH_INFO)
+ return -2;
+ }
}
- if (is_select) {
+
+ /* Can do this here as it does not do a server round trip */
+
+ OCIAttrGet_stmhp_stat(imp_sth, &row_count,0,OCI_ATTR_ROW_COUNT,
status);
+
+
+
+ if (is_select) { /*only need this on a select*/
DBIc_ACTIVE_on(imp_sth);
- DBIc_ROW_COUNT(imp_sth) = 0; /* reset (possibly re-exec'ing) */
- row_count = 0;
- /*reinit the rs_array as well
- as we may have more thatn one exe on a prepare*/
- rs_array_init(imp_sth);
- }
- else {
- OCIAttrGet_stmhp_stat(imp_sth, &row_count, 0,
OCI_ATTR_ROW_COUNT, status);
+ DBIc_ROW_COUNT(imp_sth) = row_count;
+
+ if (!imp_sth->row_cache_off){
+ /*reinit the rs_array as well if we have to
+ as we may have more than one exe on a prepare*/
+ imp_sth->rs_fetch_count = 1;
+ if (row_count < imp_sth->rs_array_size){ /*got
them all*/
+ imp_sth->rs_all_fetched = 1;
+
+ }
+ imp_sth->rs_array_status =OCI_SUCCESS;
+ imp_sth->rs_array_num_rows = row_count;
+ imp_dbh->RowsInCache = row_count;
+ imp_sth->rs_array_idx =-1;
+
+
+ if (DBIS->debug >= 3 || dbd_verbose >= 3 )
+ PerlIO_printf(DBILOGFP, "
rs_array_init:imp_sth->rs_array_size=%d, rs_array_idx=%d, prefetch_rows=%d,
rs_array_status=%s\n",imp_sth->rs_array_size,imp_sth->rs_array_idx,imp_sth->prefetch_rows,oci_status_name(imp_sth->rs_array_status));
+
+ }
+
+
+
}
if (debug >= 2 || dbd_verbose >= 3 ) {
Modified: dbd-oracle/branches/rs_array/dbdimp.h
==============================================================================
--- dbd-oracle/branches/rs_array/dbdimp.h (original)
+++ dbd-oracle/branches/rs_array/dbdimp.h Wed Jul 15 12:16:31 2009
@@ -121,6 +121,7 @@
int rs_array_num_rows; /* num rows in
last fetch */
int rs_array_idx; /* index of
current row */
sword rs_array_status; /* status of last fetch
*/
+ int rs_all_fetched;
};
#define IMP_STH_EXECUTING 0x0001
@@ -347,7 +348,6 @@
void * oci_db_handle(imp_dbh_t *imp_dbh, int handle_type, int flags);
void * oci_st_handle(imp_sth_t *imp_sth, int handle_type, int flags);
void fb_ary_free(fb_ary_t *fb_ary);
-void rs_array_init(imp_sth_t *imp_sth);
Modified: dbd-oracle/branches/rs_array/oci8.c
==============================================================================
--- dbd-oracle/branches/rs_array/oci8.c (original)
+++ dbd-oracle/branches/rs_array/oci8.c Wed Jul 15 12:16:31 2009
@@ -2632,40 +2632,6 @@
return;
}
-void rs_array_init(imp_sth_t *imp_sth)
-{
- dTHX;
-/* if (imp_sth->rs_array_on!=1 ||
- imp_sth->rs_array_size<1 ||
- imp_sth->rs_array_size>128){
-
- imp_sth->rs_array_on=0;
- imp_sth->rs_array_size=1;
-
- }*/
- imp_sth->rs_array_num_rows =0;
- imp_sth->rs_array_idx =0;
- imp_sth->rs_fetch_count =0;
- /*imp_sth->prefetch_rows =0;
- imp_sth->prefetch_memory =0;*/
- imp_sth->rs_array_status =OCI_SUCCESS;
-
- if (DBIS->debug >= 3 || dbd_verbose >= 3 )
- PerlIO_printf(DBILOGFP, "
rs_array_init:imp_sth->rs_array_size=%d, rs_array_idx=%d, prefetch_rows=%d,
rs_array_status=%s\n",imp_sth->rs_array_size,imp_sth->rs_array_idx,imp_sth->prefetch_rows,oci_status_name(imp_sth->rs_array_status));
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
/*static int /* --- Setup the row cache for this sth --- */
@@ -2788,7 +2754,7 @@
*/
- /*if (DBIS->debug >= 3 || dbd_verbose >= 3 || oci_warn) /*will also
display if oci_want is on*/
+ if (DBIS->debug >= 3 || dbd_verbose >= 3 || oci_warn) /*will also
display if oci_want is on*/
PerlIO_printf(DBILOGFP,
" cache settings RowCacheSize=%d,
OCI_ATTR_PREFETCH_ROWS=%lu, OCI_ATTR_PREFETCH_MEMORY=%lu, Rows per Fetch=%d,
Multiple Row Fetch=%s\n",
imp_dbh->RowCacheSize,(unsigned long) (prefetch_rows),
(unsigned long) (prefetch_mem),cache_rows,(imp_sth->row_cache_off)?"Off":"On");
@@ -3078,7 +3044,6 @@
/* set long_readlen for SELECT or PL/SQL with output placeholders */
imp_sth->long_readlen = long_readlen;
-PerlIO_printf(DBILOGFP, "\n\n SQL=%s\n\n",imp_sth->statement);
if (imp_sth->stmt_type != OCI_STMT_SELECT) { /* XXX DISABLED, see
num_fields test below */
if (DBIS->debug >= 3 || dbd_verbose >= 3 )
@@ -3174,7 +3139,7 @@
fbh->name = SvPVX(fbh->name_sv);
fbh->ftype = 5; /* default: return as null terminated
string */
- if (DBIS->debug >= 4 || dbd_verbose <= 4 )
+ if (DBIS->debug >= 4 || dbd_verbose >= 4 )
PerlIO_printf(DBILOGFP, "Describe col #%d
type=%d(%s),%d\n",i,fbh->dbtype,sql_typecode_name(fbh->dbtype),ORA_DATE);
switch (fbh->dbtype) {
@@ -3328,11 +3293,11 @@
if (imp_sth->pers_lob){ /*get as one peice
fasted but limited to how big you can get.*/
fbh->pers_lob = 1;
- if (long_readlen){
- fbh->disize =
fbh->disize*10; /*default size*/
+ if (!long_readlen){
+ fbh->disize =
fbh->dbsize*10; /*default size*/
}
else {
- fbh->disize =
long_readlen;/*user set max value for the fetch*/
+ fbh->disize =
fbh->dbsize+long_readlen;/*user set max value for the fetch*/
}
if (fbh->dbtype == ORA_CLOB){
fbh->ftype = SQLT_CHR;
@@ -3426,7 +3391,7 @@
break;
}
- if (DBIS->debug >= 3 || dbd_verbose <= 3 )
+ if (DBIS->debug >= 3 || dbd_verbose >= 3 )
PerlIO_printf(DBILOGFP,
"Described col %2d: dbtype %d(%s), scale %d,
prec %d, nullok %d, name %s\n"
" : dbsize %d, char_used %d,
char_size %d, csid %d, csform %d(%s), disize %d\n",
@@ -3467,16 +3432,15 @@
imp_fbh_t *fbh = &imp_sth->fbh[i-1];
int ftype = fbh->ftype;
/* add space for STRING null term, or VAR len prefix */
+
sb4 define_len = (ftype==94||ftype==95) ? fbh->disize+4 :
fbh->disize;
fb_ary_t *fb_ary;
-
if (fbh->clbk_lob || fbh->piece_lob ){/*init the cb_abuf with
this call*/
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);
}
-
fb_ary = fbh->fb_ary;
if (fbh->ftype == SQLT_BIN) {
@@ -3489,7 +3453,7 @@
(dvoid*)&((OCIStmt **)fb_ary->abuf)[0],
OCI_HTYPE_STMT, status);
}
-
+
OCIDefineByPos_log_stat(imp_sth->stmhp,
&fbh->defnp,
imp_sth->errhp,
@@ -3502,8 +3466,7 @@
fb_ary->arcode,
fbh->define_mode,
status);
-
-
+
if (fbh->clbk_lob){
/* use a dynamic callback for persistent binary and
char lobs*/
OCIDefineDynamic_log_stat(fbh->defnp,imp_sth->errhp,(dvoid *) fbh,status);
@@ -3540,7 +3503,7 @@
#ifdef OCI_ATTR_CHARSET_FORM
if ( (fbh->dbtype == 1) && fbh->csform ) {
/* csform may be 0 when talking to Oracle 8.0 database*/
- if (DBIS->debug >= 3 || dbd_verbose <= 3 )
+ if (DBIS->debug >= 3 || dbd_verbose >= 3 )
PerlIO_printf(DBILOGFP, " calling
OCIAttrSet OCI_ATTR_CHARSET_FORM with csform=%d (%s)\n",
fbh->csform,oci_csform_name(fbh->csform) );
OCIAttrSet_log_stat( fbh->defnp, (ub4)
OCI_HTYPE_DEFINE, (dvoid *) &fbh->csform,
(ub4) 0, (ub4)
OCI_ATTR_CHARSET_FORM, imp_sth->errhp, status );
@@ -3625,30 +3588,34 @@
}
else { /*Array Fetch the New Noraml Super speedy and
very nice*/
+ /*PerlIO_printf(DBILOGFP,"run
imp_sth->rs_array_num_rows=%d
imp_sth->rs_array_idx=%d,rs_array_size=%d\n",imp_sth->rs_array_num_rows,imp_sth->rs_array_idx,imp_sth->rs_array_size);*/
-/* PerlIO_printf(DBILOGFP, " dbd_st_fetch
fields...a\n");*/
imp_dbh->RowsInCache--;
imp_sth->rs_array_idx++;
- /*PerlIO_printf(DBILOGFP," \n
imp_sth->rs_array_idx=%d,rs_array_num_rows=%d\n",imp_sth->rs_array_idx,imp_sth->rs_array_num_rows);
-*/
+
if
(imp_sth->rs_array_num_rows<=imp_sth->rs_array_idx &&
(imp_sth->rs_array_status==OCI_SUCCESS ||
imp_sth->rs_array_status==OCI_SUCCESS_WITH_INFO)) {
-/* PerlIO_printf(DBILOGFP, " dbd_st_fetch
fields...b\n");*/
-
-
OCIStmtFetch_log_stat(imp_sth->stmhp,imp_sth->errhp,imp_sth->rs_array_size,(ub2)OCI_FETCH_NEXT,OCI_DEFAULT,status);
- imp_sth->rs_array_status=status;
- imp_sth->rs_fetch_count++;
- if (oci_warn &&
(imp_sth->rs_array_status == OCI_SUCCESS_WITH_INFO)) {
- oci_error(sth, imp_sth->errhp,
status, "OCIStmtFetch");
+ if (imp_sth->rs_all_fetched){
+ imp_sth->rs_array_status =
OCI_NO_DATA;
}
- OCIAttrGet_stmhp_stat(imp_sth,
&imp_sth->rs_array_num_rows,0,OCI_ATTR_ROWS_FETCHED, status);
- imp_sth->rs_array_idx=0;
- imp_dbh->RowsInCache
=imp_sth->rs_array_size;
- if (DBIS->debug >= 4 || dbd_verbose >=
4 || oci_warn)
-
PerlIO_printf(DBILOGFP,"...Fetched %d rows\n",imp_sth->rs_array_num_rows);
-
- }
-
- if
(imp_sth->rs_array_num_rows>imp_sth->rs_array_idx) /* set status to success
if rows in cache */
+ else {
+
OCIStmtFetch_log_stat(imp_sth->stmhp,imp_sth->errhp,imp_sth->rs_array_size,(ub2)OCI_FETCH_NEXT,OCI_DEFAULT,status);
+ imp_sth->rs_array_status=status;
+ imp_sth->rs_fetch_count++;
+ if (oci_warn &&
(imp_sth->rs_array_status == OCI_SUCCESS_WITH_INFO)) {
+ oci_error(sth,
imp_sth->errhp, status, "OCIStmtFetch");
+ }
+ OCIAttrGet_stmhp_stat(imp_sth,
&imp_sth->rs_array_num_rows,0,OCI_ATTR_ROWS_FETCHED, status);
+ imp_sth->rs_array_idx=0;
+ imp_dbh->RowsInCache
=imp_sth->rs_array_size;
+ if (DBIS->debug >= 4 ||
dbd_verbose >= 4 || oci_warn)
+
PerlIO_printf(DBILOGFP,"...Fetched %d rows\n",imp_sth->rs_array_num_rows);
+ }
+
+ }
+
+ if
(imp_sth->rs_array_num_rows>imp_sth->rs_array_idx )
+ /* set status to success if rows in cache */
+ /* if No data then all the rows are already
in cache */
status=OCI_SUCCESS;
else
status=imp_sth->rs_array_status;
Modified: dbd-oracle/branches/rs_array/t/34pres_lobs.t
==============================================================================
--- dbd-oracle/branches/rs_array/t/34pres_lobs.t (original)
+++ dbd-oracle/branches/rs_array/t/34pres_lobs.t Wed Jul 15 12:16:31 2009
@@ -30,7 +30,7 @@
my $dbuser = $ENV{ORACLE_USERID} || 'scott/tiger';
my $dbh = DBI->connect($dsn, $dbuser, '', { RaiseError=>1,
AutoCommit=>1,
- PrintError => 0
,LongReadLen=>10000000});
+ PrintError => 0
,LongReadLen=>2000000});
# check that our db handle is good
my $ora_oci = DBD::Oracle::ORA_OCI(); # dualvar