Author: byterock
Date: Thu Mar 13 08:20:32 2008
New Revision: 10921

Modified:
   dbd-oracle/branches/dblink/dbdimp.h
   dbd-oracle/branches/dblink/oci8.c

Log:
adding ora_dblink_lob and dblink_lob for use with dblink and 10g release 2

Modified: dbd-oracle/branches/dblink/dbdimp.h
==============================================================================
--- dbd-oracle/branches/dblink/dbdimp.h (original)
+++ dbd-oracle/branches/dblink/dbdimp.h Thu Mar 13 08:20:32 2008
@@ -69,6 +69,7 @@
     OCIDescribe         *dschp;    /* oci describe handle */
        ub2             stmt_type;      /* OCIAttrGet OCI_ATTR_STMT_TYPE        
*/
     U16                        auto_lob;
+    int                        dblink_lob; /*use dblink for lobs only for 10g 
Release 2. or later*/
     int                has_lobs;  /* Statement has boud LOBS*/
 
     lob_refetch_t *lob_refetch;

Modified: dbd-oracle/branches/dblink/oci8.c
==============================================================================
--- dbd-oracle/branches/dblink/oci8.c   (original)
+++ dbd-oracle/branches/dblink/oci8.c   Thu Mar 13 08:20:32 2008
@@ -25,6 +25,68 @@
     DBIS = dbistate;
 }
 
+static void *
+alloc_via_sv(STRLEN len, SV **svp, int mortal)
+{
+       dTHX;
+    SV *sv = newSVpv("",0);
+    sv_grow(sv, len+1);
+    memset(SvPVX(sv), 0, len);
+    if (mortal)
+       sv_2mortal(sv);
+    if (svp)
+       *svp = sv;
+    return SvPVX(sv);
+}
+
+char *
+find_ident_after(char *src, char *after, STRLEN *len, int copy)
+{
+
+    int seen_key = 0;
+    char *orig = src;
+    char *p;
+    while(*src) {
+       if (*src == '\'' || *src == '"') {
+           char delim = *src;
+           while(*src && *src != delim) ++src;
+       }
+       else if (*src == '-' && src[1] == '-') {
+           while(*src && *src != '\n') ++src;
+       }
+       else if (*src == '/' && src[1] == '*') {
+           while(*src && !(*src == '*' && src[1]=='/')) ++src;
+       }
+       else if (isALPHA(*src)) {
+           if (seen_key) {
+               char *start = src;
+               while(*src && (isALNUM(*src) || *src=='.' || *src=='$'))
+                   ++src;
+               *len = src - start;
+               if (copy) {
+                   p = (char*)alloc_via_sv(*len, 0, 1);
+                   strncpy(p, start, *len);
+                   p[*len] = '\0';
+                   return p;
+               }
+               return start;
+           }
+           else if (  toLOWER(*src)==toLOWER(*after)
+                   && (src==orig ? 1 : !isALPHA(src[-1]))
+           ) {
+               p = after;
+               while(*p && *src && toLOWER(*p)==toLOWER(*src))
+                   ++p, ++src;
+               if (!*p)
+                   seen_key = 1;
+           }
+           ++src;
+       }
+       else
+           ++src;
+    }
+    return NULL;
+}
 void
 dbd_init_oci_drh(imp_drh_t * imp_drh)
 {
@@ -255,6 +317,7 @@
     dTHX;
     D_imp_dbh_from_sth;
     sword status = 0;
+    IV  ora_dblink_lob =0; /*use dblink for lobs only for 10g Release 2. or 
later*/
     ub4   oparse_lng   = 1;  /* auto v6 or v7 as suits db connected to */
     int   ora_check_sql = 1;   /* to force a describe to check SQL     */
     IV    ora_placeholders = 1;        /* find and handle placeholders */
@@ -290,7 +353,10 @@
        DBD_ATTRIB_GET_IV(  attribs, "ora_parse_lang", 14, svp, oparse_lng);
        DBD_ATTRIB_GET_IV(  attribs, "ora_placeholders", 16, svp, 
ora_placeholders);
        DBD_ATTRIB_GET_IV(  attribs, "ora_auto_lob",   12, svp, ora_auto_lob);
+       DBD_ATTRIB_GET_IV(  attribs, "ora_dblink_lob",   14, svp, 
ora_dblink_lob);
+
        imp_sth->auto_lob = (ora_auto_lob) ? 1 : 0;
+       imp_sth->dblink_lob = (ora_auto_lob) ? 1 : 0;
        /* ora_check_sql only works for selects owing to Oracle behaviour */
        DBD_ATTRIB_GET_IV(  attribs, "ora_check_sql",  13, svp, ora_check_sql);
    }
@@ -1990,7 +2056,8 @@
 
 
     if (imp_sth->done_desc)
-       return 1;       /* success, already done it */
+         return 1;     /* success, already done it */
+
     imp_sth->done_desc = 1;
 
     /* ora_trunc is checked at fetch time */
@@ -2003,43 +2070,43 @@
        imp_sth->long_readlen = long_readlen;
 
     if (imp_sth->stmt_type != OCI_STMT_SELECT) { /* XXX DISABLED, see 
num_fields test below */
-       if (DBIS->debug >= 3)
-           PerlIO_printf(DBILOGFP, "    dbd_describe skipped for %s\n",
-               oci_stmt_type_name(imp_sth->stmt_type));
-       /* imp_sth memory was cleared when created so no setup required here    
*/
-       return 1;
+               if (DBIS->debug >= 3)
+                   PerlIO_printf(DBILOGFP, "    dbd_describe skipped for %s\n",
+                       oci_stmt_type_name(imp_sth->stmt_type));
+                       /* imp_sth memory was cleared when created so no setup 
required here    */
+               return 1;
     }
 
     if (DBIS->debug >= 3)
-       PerlIO_printf(DBILOGFP, "    dbd_describe %s (%s, lb %lu)...\n",
-           oci_stmt_type_name(imp_sth->stmt_type),
-           DBIc_ACTIVE(imp_sth) ? "implicit" : "EXPLICIT", (unsigned 
long)long_readlen);
+               PerlIO_printf(DBILOGFP, "    dbd_describe %s (%s, lb %lu)...\n",
+                   oci_stmt_type_name(imp_sth->stmt_type),
+                   DBIc_ACTIVE(imp_sth) ? "implicit" : "EXPLICIT", (unsigned 
long)long_readlen);
 
     /* We know it's a select and we've not got the description yet, so if the  
*/
     /* sth is not 'active' (executing) then we need an explicit describe.      
*/
     if ( !DBIc_ACTIVE(imp_sth) ) {
 
-       OCIStmtExecute_log_stat(imp_sth->svchp, imp_sth->stmhp, imp_sth->errhp,
-               0, 0, 0, 0, OCI_DESCRIBE_ONLY, status);
-       if (status != OCI_SUCCESS) {
-           oci_error(h, imp_sth->errhp, status,
-               ora_sql_error(imp_sth, "OCIStmtExecute/Describe"));
-           if (status != OCI_SUCCESS_WITH_INFO)
-               return 0;
-       }
+               OCIStmtExecute_log_stat(imp_sth->svchp, imp_sth->stmhp, 
imp_sth->errhp,
+                       0, 0, 0, 0, OCI_DESCRIBE_ONLY, status);
+               if (status != OCI_SUCCESS) {
+                   oci_error(h, imp_sth->errhp, status,
+                       ora_sql_error(imp_sth, "OCIStmtExecute/Describe"));
+                   if (status != OCI_SUCCESS_WITH_INFO)
+                               return 0;
+               }
     }
 
     OCIAttrGet_stmhp_stat(imp_sth, &num_fields, 0, OCI_ATTR_PARAM_COUNT, 
status);
     if (status != OCI_SUCCESS) {
-       oci_error(h, imp_sth->errhp, status, "OCIAttrGet OCI_ATTR_PARAM_COUNT");
-       return 0;
+               oci_error(h, imp_sth->errhp, status, "OCIAttrGet 
OCI_ATTR_PARAM_COUNT");
+               return 0;
     }
     if (num_fields == 0) {
-       if (DBIS->debug >= 3)
-           PerlIO_printf(DBILOGFP, "    dbd_describe skipped for %s (no fields 
returned)\n",
-               oci_stmt_type_name(imp_sth->stmt_type));
-       /* imp_sth memory was cleared when created so no setup required here    
*/
-       return 1;
+               if (DBIS->debug >= 3)
+                   PerlIO_printf(DBILOGFP, "    dbd_describe skipped for %s 
(no fields returned)\n",
+                       oci_stmt_type_name(imp_sth->stmt_type));
+               /* imp_sth memory was cleared when created so no setup required 
here    */
+               return 1;
     }
 
     DBIc_NUM_FIELDS(imp_sth) = num_fields;
@@ -2097,6 +2164,7 @@
        fbh->ftype   = 5;       /* default: return as null terminated string */
 
 
+PerlIO_printf(DBILOGFP, "fbh->dbtype=%d\n",fbh->dbtype);
        switch (fbh->dbtype) {
        /*      the simple types        */
        case   1:                               /* VARCHAR2     */
@@ -2157,23 +2225,23 @@
                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;
+               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;
 
        case 112:                               /* CLOB & NCLOB */
        case 113:                               /* BLOB         */
        case 114:                               /* BFILE        */
+
                fbh->ftype  = fbh->dbtype;
                 /* do we need some addition size logic here? (lab) */
                fbh->disize = fbh->dbsize *10 ; /* XXX! */
@@ -2182,6 +2250,11 @@
                fbh->bless  = "OCILobLocatorPtr";
                fbh->desc_t = OCI_DTYPE_LOB;
                OCIDescriptorAlloc_ok(imp_sth->envhp, &fbh->desc_h, 
fbh->desc_t);
+               if (imp_sth->dblink_lob){
+                       fbh->ftype=SQLT_CHR;
+               }
+        PerlIO_printf(DBILOGFP, " ok here is is sqlt_chr=%d, and 
imp_sth->dblink_lob=%d\n",SQLT_CHR,imp_sth->dblink_lob);
+
                break;
 
 #ifdef OCI_DTYPE_REF
@@ -2233,6 +2306,7 @@
        imp_sth->t_dbsize += fbh->dbsize;
        if (!avg_width)
            avg_width = fbh->dbsize;
+
        est_width += avg_width;
 
        if (DBIS->debug >= 2)
@@ -2278,6 +2352,11 @@
                    OCI_DEFAULT,
                    status);
 
+               if (status != OCI_SUCCESS) {
+                   oci_error(h, imp_sth->errhp, status, "OCIDefineByPos");
+                   ++num_errors;
+               }
+
                if (fbh->ftype == 108)  { /* Embedded object bind it 
differently*/
 
                        if (DBIS->debug >= 5){
@@ -2305,10 +2384,6 @@
 
                }
 
-               if (status != OCI_SUCCESS) {
-                   oci_error(h, imp_sth->errhp, status, "OCIDefineByPos");
-                   ++num_errors;
-               }
 
 
 
@@ -2329,9 +2404,9 @@
     }
 
     if (DBIS->debug >= 3)
-       PerlIO_printf(DBILOGFP,
-       "    dbd_describe'd %d columns (row bytes: %d max, %d est avg, cache: 
%d)\n",
-       (int)num_fields, imp_sth->t_dbsize, imp_sth->est_width, 
imp_sth->cache_rows);
+               PerlIO_printf(DBILOGFP,
+               "    dbd_describe'd %d columns (row bytes: %d max, %d est avg, 
cache: %d)\n",
+               (int)num_fields, imp_sth->t_dbsize, imp_sth->est_width, 
imp_sth->cache_rows);
 
     return (num_errors>0) ? 0 : 1;
 }
@@ -2553,69 +2628,9 @@
 #endif
 
 
-static void *
-alloc_via_sv(STRLEN len, SV **svp, int mortal)
-{
-       dTHX;
-    SV *sv = newSVpv("",0);
-    sv_grow(sv, len+1);
-    memset(SvPVX(sv), 0, len);
-    if (mortal)
-       sv_2mortal(sv);
-    if (svp)
-       *svp = sv;
-    return SvPVX(sv);
-}
 
 
-char *
-find_ident_after(char *src, char *after, STRLEN *len, int copy)
-{
 
-    int seen_key = 0;
-    char *orig = src;
-    char *p;
-    while(*src) {
-       if (*src == '\'' || *src == '"') {
-           char delim = *src;
-           while(*src && *src != delim) ++src;
-       }
-       else if (*src == '-' && src[1] == '-') {
-           while(*src && *src != '\n') ++src;
-       }
-       else if (*src == '/' && src[1] == '*') {
-           while(*src && !(*src == '*' && src[1]=='/')) ++src;
-       }
-       else if (isALPHA(*src)) {
-           if (seen_key) {
-               char *start = src;
-               while(*src && (isALNUM(*src) || *src=='.' || *src=='$'))
-                   ++src;
-               *len = src - start;
-               if (copy) {
-                   p = (char*)alloc_via_sv(*len, 0, 1);
-                   strncpy(p, start, *len);
-                   p[*len] = '\0';
-                   return p;
-               }
-               return start;
-           }
-           else if (  toLOWER(*src)==toLOWER(*after)
-                   && (src==orig ? 1 : !isALPHA(src[-1]))
-           ) {
-               p = after;
-               while(*p && *src && toLOWER(*p)==toLOWER(*src))
-                   ++p, ++src;
-               if (!*p)
-                   seen_key = 1;
-           }
-           ++src;
-       }
-       else
-           ++src;
-    }
-    return NULL;
-}
 
 
 

Reply via email to