Author: byterock
Date: Tue Mar 25 07:58:39 2008
New Revision: 11000

Modified:
   dbd-oracle/trunk/oci8.c

Log:
fixed bug for older clients (oci <=8)

Modified: dbd-oracle/trunk/oci8.c
==============================================================================
--- dbd-oracle/trunk/oci8.c     (original)
+++ dbd-oracle/trunk/oci8.c     Tue Mar 25 07:58:39 2008
@@ -1521,6 +1521,9 @@
  2. bind with dty = SQLT_NTY
  3. OCIDefineObject using the TDO
  4. on fetech get the null indicator of the objcet with OCIObjectGetInd
+    The the obj_ind is for the entier object not the propertiesy so you call 
it once it
+    gets all of the indicators for the objects so you pass it into 
ociobjectgetattr and that
+    function will set attr_null_status in the get below.
  5. interate over the atributes of the object
 
 The thing to remember is that OCI and C have no way of representing a DB NULLs 
so we use the OCIInd find out
@@ -2094,11 +2097,10 @@
     DBIc_NUM_FIELDS(imp_sth) = num_fields;
     Newz(42, imp_sth->fbh, num_fields, imp_fbh_t);
 
-
-
     /* Get number of fields and space needed for field names   */
+/* loop though the fields and get all the fileds and thier types to get back*/
 
-    for(i = 1; i <= num_fields; ++i) {
+    for(i = 1; i <= num_fields; ++i) { /*start define of filed struct[i] fbh */
                char *p;
                ub4 atrlen;
                int avg_width = 0;
@@ -2106,9 +2108,9 @@
                fbh->imp_sth   = imp_sth;
                fbh->field_num = i;
 
-
                OCIParamGet_log_stat(imp_sth->stmhp, OCI_HTYPE_STMT, 
imp_sth->errhp,
                                (dvoid**)&fbh->parmdp, (ub4)i, status);
+
                if (status != OCI_SUCCESS) {
                    oci_error(h, imp_sth->errhp, status, "OCIParamGet");
                    return 0;
@@ -2148,147 +2150,148 @@
 
                switch (fbh->dbtype) {
                /*      the simple types        */
-               case   1:                               /* VARCHAR2     */
-                       avg_width = fbh->dbsize / 2;
+                       case   1:                               /* VARCHAR2     
*/
+                               avg_width = fbh->dbsize / 2;
                /* FALLTHRU */
-               case  96:                               /* CHAR         */
-                       if ( CSFORM_IMPLIES_UTF8(fbh->csform) && 
!CS_IS_UTF8(fbh->csid) )
-                           fbh->disize = fbh->dbsize * 4;
-                       else
-                           fbh->disize = fbh->dbsize;
-
-                       fbh->prec   = fbh->disize;
-                       break;
-               case  23:                               /* RAW          */
-                       fbh->disize = fbh->dbsize * 2;
-                       fbh->prec   = fbh->disize;
-                       break;
-
-               case   2:                               /* NUMBER       */
-               case  21:                               /* BINARY FLOAT 
os-endian       */
-               case  22:                               /* BINARY DOUBLE 
os-endian      */
-               case 100:                               /* BINARY FLOAT 
oracle-endian   */
-               case 101:                               /* BINARY DOUBLE 
oracle-endian  */
-                       fbh->disize = 130+38+3;         /* worst case   */
-                       avg_width = 4;     /* NUMBER approx +/- 1_000_000 */
-                       break;
-
-               case  12:                               /* DATE         */
-                       /* actually dependent on NLS default date format*/
-                       fbh->disize = 75;       /* a generous default   */
-                       fbh->prec   = fbh->disize;
-                       avg_width = 8;  /* size in SQL*Net packet  */
-                       break;
-
-               case   8:                               /* LONG         */
-                       if ( CSFORM_IMPLIES_UTF8(fbh->csform) && 
!CS_IS_UTF8(fbh->csid) )
-                       fbh->disize = long_readlen * 4;
-            else
-                fbh->disize = long_readlen;
-
-                /* not governed by else: */
-                       fbh->dbsize = (fbh->disize>65535) ? 65535 : fbh->disize;
-                       fbh->ftype  = 94; /* VAR form */
-                       fbh->fetch_func = fetch_func_varfield;
-                       ++has_longs;
-                       break;
-               case  24:                               /* LONG RAW     */
-                       fbh->disize = long_readlen * 2;
-                       fbh->dbsize = (fbh->disize>65535) ? 65535 : fbh->disize;
-                       fbh->ftype  = 95; /* VAR form */
-                       fbh->fetch_func = fetch_func_varfield;
-                       ++has_longs;
-                       break;
-
-               case  11:                               /* ROWID        */
-               case 104:                               /* ROWID Desc   */
-                       fbh->disize = 20;
-                       fbh->prec   = fbh->disize;
-                       break;
-               case 108:                            /* some sort of embedded 
object */
-
-               fbh->ftype  = fbh->dbtype;  /*varray or alike */
-               fbh->fetch_func = fetch_func_oci_object; /* need a new fetch 
function for it */
-               fbh->fetch_cleanup = fetch_cleanup_oci_object; /* clean up any 
AV  from the fetch*/
-               fbh->desc_t = SQLT_NTY;
-            if (!imp_sth->dschp){
-                       OCIHandleAlloc_ok(imp_sth->envhp, &imp_sth->dschp, 
OCI_HTYPE_DESCRIBE, status);
-                       if (status != OCI_SUCCESS) {
-                                       oci_error(h,imp_sth->errhp, status, 
"OCIHandleAlloc");
-                                       ++num_errors;
-                               }
+                       case  96:                               /* CHAR         
*/
+                               if ( CSFORM_IMPLIES_UTF8(fbh->csform) && 
!CS_IS_UTF8(fbh->csid) )
+                                   fbh->disize = fbh->dbsize * 4;
+                               else
+                                   fbh->disize = fbh->dbsize;
+
+                               fbh->prec   = fbh->disize;
+                               break;
+                       case  23:                               /* RAW          
*/
+                               fbh->disize = fbh->dbsize * 2;
+                               fbh->prec   = fbh->disize;
+                               break;
+
+                       case   2:                               /* NUMBER       
*/
+                       case  21:                               /* BINARY FLOAT 
os-endian       */
+                       case  22:                               /* BINARY 
DOUBLE os-endian      */
+                       case 100:                               /* BINARY FLOAT 
oracle-endian   */
+                       case 101:                               /* BINARY 
DOUBLE oracle-endian  */
+                               fbh->disize = 130+38+3;         /* worst case   
*/
+                               avg_width = 4;     /* NUMBER approx +/- 
1_000_000 */
+                               break;
+
+                       case  12:                               /* DATE         
*/
+                               /* actually dependent on NLS default date 
format*/
+                               fbh->disize = 75;       /* a generous default   
*/
+                               fbh->prec   = fbh->disize;
+                               avg_width = 8;  /* size in SQL*Net packet  */
+                               break;
+
+                       case   8:                               /* LONG         
*/
+                               if ( CSFORM_IMPLIES_UTF8(fbh->csform) && 
!CS_IS_UTF8(fbh->csid) )
+                               fbh->disize = long_readlen * 4;
+                   else
+                       fbh->disize = long_readlen;
+
+                       /* not governed by else: */
+                               fbh->dbsize = (fbh->disize>65535) ? 65535 : 
fbh->disize;
+                               fbh->ftype  = 94; /* VAR form */
+                               fbh->fetch_func = fetch_func_varfield;
+                               ++has_longs;
+                               break;
+                       case  24:                               /* LONG RAW     
*/
+                               fbh->disize = long_readlen * 2;
+                               fbh->dbsize = (fbh->disize>65535) ? 65535 : 
fbh->disize;
+                               fbh->ftype  = 95; /* VAR form */
+                               fbh->fetch_func = fetch_func_varfield;
+                               ++has_longs;
+                               break;
+
+                       case  11:                               /* ROWID        
*/
+                       case 104:                               /* ROWID Desc   
*/
+                               fbh->disize = 20;
+                               fbh->prec   = fbh->disize;
+                               break;
+                       case 108:                            /* some sort of 
embedded object */
+
+                   fbh->ftype  = fbh->dbtype;  /*varray or alike */
+                   fbh->fetch_func = fetch_func_oci_object; /* need a new 
fetch function for it */
+                   fbh->fetch_cleanup = fetch_cleanup_oci_object; /* clean up 
any AV  from the fetch*/
+                   fbh->desc_t = SQLT_NTY;
+                   if (!imp_sth->dschp){
+                       OCIHandleAlloc_ok(imp_sth->envhp, &imp_sth->dschp, 
OCI_HTYPE_DESCRIBE, status);
+                       if (status != OCI_SUCCESS) {
+                                               oci_error(h,imp_sth->errhp, 
status, "OCIHandleAlloc");
+                                               ++num_errors;
+                                       }
 
-               }
-            break;
+                   }
+                   break;
 
-               case 112:                               /* CLOB & NCLOB */
-               case 113:                               /* BLOB         */
-               case 114:                               /* BFILE        */
-                       fbh->ftype  = fbh->dbtype;
+                       case 112:                               /* CLOB & NCLOB 
*/
+                       case 113:                               /* BLOB         
*/
+                       case 114:                               /* BFILE        
*/
+                               fbh->ftype  = fbh->dbtype;
                 /* do we need some addition size logic here? (lab) */
-                       if (imp_sth->pers_lob){ /*this only works on 10.2 */
+                               if (imp_sth->pers_lob){ /*this only works on 
10.2 */
 
-                   fbh->disize = imp_sth->long_readlen; /*user set max value*/
-                   if (fbh->dbtype == 112){
-                       fbh->ftype  = SQLT_CHR;
-                   } else {
-                               fbh->ftype  = SQLT_BIN; /*other Binary*/
-                       }
+                           fbh->disize = imp_sth->long_readlen; /*user set max 
value*/
+                           if (fbh->dbtype == 112){
+                               fbh->ftype  = SQLT_CHR;
+                           } else {
+                                       fbh->ftype  = SQLT_BIN; /*other Binary*/
+                               }
 
-                       } else {
-                               fbh->disize = fbh->dbsize *10 ; /* XXX! */
-                               fbh->fetch_func = (imp_sth->auto_lob) ? 
fetch_func_autolob : fetch_func_getrefpv;
-                               fbh->bless  = "OCILobLocatorPtr";
-                               fbh->desc_t = OCI_DTYPE_LOB;
-                               OCIDescriptorAlloc_ok(imp_sth->envhp, 
&fbh->desc_h, fbh->desc_t);
-                       }
+                               } else {
+                                       fbh->disize = fbh->dbsize *10 ; /* XXX! 
*/
+                                       fbh->fetch_func = (imp_sth->auto_lob) ? 
fetch_func_autolob : fetch_func_getrefpv;
+                                       fbh->bless  = "OCILobLocatorPtr";
+                                       fbh->desc_t = OCI_DTYPE_LOB;
+                                       OCIDescriptorAlloc_ok(imp_sth->envhp, 
&fbh->desc_h, fbh->desc_t);
+                               }
 
-                       break;
+                               break;
 
 #ifdef OCI_DTYPE_REF
-               case 111:                               /* REF          */
-                       fbh_setup_getrefpv(fbh, OCI_DTYPE_REF, "OCIRefPtr");
-                       break;
+                       case 111:                               /* REF          
*/
+                               fbh_setup_getrefpv(fbh, OCI_DTYPE_REF, 
"OCIRefPtr");
+                               break;
 #endif
 
-               case 116:                               /* RSET         */
-                       fbh->ftype  = fbh->dbtype;
-                       fbh->disize = sizeof(OCIStmt *);
-                       fbh->fetch_func = fetch_func_rset;
-                       fbh->fetch_cleanup = fetch_cleanup_rset;
-                       nested_cursors++;
-                       break;
+                       case 116:                               /* RSET         
*/
+                               fbh->ftype  = fbh->dbtype;
+                               fbh->disize = sizeof(OCIStmt *);
+                               fbh->fetch_func = fetch_func_rset;
+                               fbh->fetch_cleanup = fetch_cleanup_rset;
+                               nested_cursors++;
+                               break;
+
+                       case 182:                  /* INTERVAL YEAR TO MONTH */
+                       case 183:                  /* INTERVAL DAY TO SECOND */
+                       case 190:                  /* INTERVAL DAY TO SECOND */
+                       case 187:                  /* TIMESTAMP */
+                       case 188:                  /* TIMESTAMP WITH TIME ZONE  
*/
+                       case 232:                  /* TIMESTAMP WITH LOCAL TIME 
ZONE */
+                               /* actually dependent on NLS default date 
format*/
+                               fbh->disize = 75;       /* XXX */
+                               break;
 
-               case 182:                  /* INTERVAL YEAR TO MONTH */
-               case 183:                  /* INTERVAL DAY TO SECOND */
-               case 190:                  /* INTERVAL DAY TO SECOND */
-               case 187:                  /* TIMESTAMP */
-               case 188:                  /* TIMESTAMP WITH TIME ZONE  */
-               case 232:                  /* TIMESTAMP WITH LOCAL TIME ZONE */
-                       /* actually dependent on NLS default date format*/
-                       fbh->disize = 75;       /* XXX */
-                       break;
-
-               default:
+                       default:
                        /* XXX unhandled type may lead to errors or worse */
-                       fbh->ftype  = fbh->dbtype;
-                       fbh->disize = fbh->dbsize;
-                       p = "Field %d has an Oracle type (%d) which is not 
explicitly supported%s";
-                       if (DBIS->debug >= 1)
-                           PerlIO_printf(DBILOGFP, p, i, fbh->dbtype, "\n");
-                       if (dowarn)
-                           warn(p, i, fbh->dbtype, "");
-                       break;
+                               fbh->ftype  = fbh->dbtype;
+                               fbh->disize = fbh->dbsize;
+                               p = "Field %d has an Oracle type (%d) which is 
not explicitly supported%s";
+                               if (DBIS->debug >= 1)
+                                   PerlIO_printf(DBILOGFP, p, i, fbh->dbtype, 
"\n");
+                               if (dowarn)
+                                   warn(p, i, fbh->dbtype, "");
+                               break;
                }
+
                if (DBIS->debug >= 3)
-           PerlIO_printf(DBILOGFP,
-               "    col %2d: dbtype %d, scale %d, prec %d, nullok %d, name 
%s\n"
-                "          : dbsize %d, char_used %d, char_size %d, csid %d, 
csform %d, disize %d\n",
-                       i, fbh->dbtype, fbh->scale, fbh->prec, fbh->nullok, 
fbh->name,
-                       fbh->dbsize, fbh->len_char_used, fbh->len_char_size, 
fbh->csid, fbh->csform, fbh->disize);
+                 PerlIO_printf(DBILOGFP,
+                   "    col %2d: dbtype %d, scale %d, prec %d, nullok %d, name 
%s\n"
+                    "          : dbsize %d, char_used %d, char_size %d, csid 
%d, csform %d, disize %d\n",
+                                       i, fbh->dbtype, fbh->scale, fbh->prec, 
fbh->nullok, fbh->name,
+                                       fbh->dbsize, fbh->len_char_used, 
fbh->len_char_size, fbh->csid, fbh->csform, fbh->disize);
 
                if (fbh->ftype == 5)    /* XXX need to handle wide chars 
somehow */
-                   fbh->disize += 1;   /* allow for null terminator */
+                       fbh->disize += 1;       /* allow for null terminator */
 
        /* dbsize can be zero for 'select NULL ...'                     */
 
@@ -2301,44 +2304,46 @@
 
                if (DBIS->debug >= 2)
                    dbd_fbh_dump(fbh, (int)i, 0);
-       }
 
-       imp_sth->est_width = est_width;
+    }/* end define of filed struct[i] fbh*/
+
+    imp_sth->est_width = est_width;
 
-       sth_set_row_cache(h, imp_sth,
+    sth_set_row_cache(h, imp_sth,
                        (nested_cursors) ? imp_dbh->max_nested_cursors / 
nested_cursors : 0,
                        (int)num_fields, has_longs );
 
-       /* Initialise cache counters */
-       imp_sth->in_cache  = 0;
-       imp_sth->eod_errno = 0;
-
-               for(i=1; i <= num_fields; ++i) {
-                       imp_fbh_t *fbh = &imp_sth->fbh[i-1];
-                       int ftype = fbh->ftype;
-                       /* add space for STRING null term, or VAR len prefix */
-                       ub4 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);
-                       fb_ary = fbh->fb_ary;
-
-                       if (fbh->ftype == 116) { /* RSET */
-                           OCIHandleAlloc_ok(imp_sth->envhp,
-                               (dvoid*)&((OCIStmt **)fb_ary->abuf)[0],
-                                OCI_HTYPE_STMT, status);
-                       }
+    /* Initialise cache counters */
+    imp_sth->in_cache  = 0;
+    imp_sth->eod_errno = 0;
 
-                   OCIDefineByPos_log_stat(imp_sth->stmhp,
-                       &fbh->defnp,
-                           imp_sth->errhp,
-                           (ub4) i,
-                           (fbh->desc_h) ? (dvoid*)&fbh->desc_h : 
(dvoid*)fb_ary->abuf,
-                           (fbh->desc_h) ?                   -1 :         
define_len,
-                           (ub2)fbh->ftype,
-                           fb_ary->aindp,
-                           (ftype==94||ftype==95) ? NULL : fb_ary->arlen,
-                           fb_ary->arcode,
-                           OCI_DEFAULT,
+    /* now set up the oci call with define by pos*/
+       for(i=1; i <= num_fields; ++i) {
+               imp_fbh_t *fbh = &imp_sth->fbh[i-1];
+               int ftype = fbh->ftype;
+               /* add space for STRING null term, or VAR len prefix */
+               ub4 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);
+               fb_ary = fbh->fb_ary;
+
+               if (fbh->ftype == 116) { /* RSET */
+                   OCIHandleAlloc_ok(imp_sth->envhp,
+                       (dvoid*)&((OCIStmt **)fb_ary->abuf)[0],
+                        OCI_HTYPE_STMT, status);
+               }
+
+           OCIDefineByPos_log_stat(imp_sth->stmhp,
+               &fbh->defnp,
+                   imp_sth->errhp,
+                   (ub4) i,
+                   (fbh->desc_h) ? (dvoid*)&fbh->desc_h : (dvoid*)fb_ary->abuf,
+                   (fbh->desc_h) ?                   -1 :         define_len,
+                   (ub2)fbh->ftype,
+                   fb_ary->aindp,
+                   (ftype==94||ftype==95) ? NULL : fb_ary->arlen,
+                   fb_ary->arcode,
+                   OCI_DEFAULT,
                            status);
 
                        if (fbh->ftype == 108)  { /* Embedded object bind it 
differently*/

Reply via email to