Since yesterday I discoved that my patch to DBD-Oracle-1.12 to support
BFILE LOBs treats a non-existent BFILE as an error.  This patch causes
them to be treated as if they exist but are of zero length.  I tried
having the fetch function return undef instead, but this caused some
higher-level DBD or DBI code to report an error on that row.

The appended patch should be applied on top of my previous patch.

David Hull

--- oci8.c      2001/10/10 20:43:27     1.3
+++ oci8.c      2001/10/11 20:29:26
@@ -1,5 +1,5 @@
 /*
-   $Id: oci8.c,v 1.3 2001/10/10 20:43:27 hull Exp $
+   $Id: oci8.c,v 1.4 2001/10/11 20:29:31 hull Exp $
 
    Copyright (c) 1998,1999,2000,2001  Tim Bunce
 
@@ -697,15 +697,27 @@
     imp_sth_t *imp_sth = fbh->imp_sth;
     OCILobLocator *lobloc = (OCILobLocator*)fbh->desc_h;
     sword status;
+    boolean exists = 1;
 
     /* this function is not called for NULL lobs */
 
     /* The length is expressed in terms of bytes for BLOBs and BFILEs, */
     /* and in terms of characters for CLOBs                            */
-    OCILobGetLength_log_stat(imp_sth->svchp, imp_sth->errhp, lobloc, &loblen, status);
-    if (status != OCI_SUCCESS) {
-       oci_error(sth, imp_sth->errhp, status, "OCILobGetLength");
-       return 0;
+    if (fbh->dbtype==114) {
+       /* For BFILES, if the file doesn't exist treat it as length 0.  */
+       OCILobFileExists_log_stat(imp_sth->svchp, imp_sth->errhp, lobloc,
+           &exists, status);
+       if (status != OCI_SUCCESS) {
+           oci_error(sth, imp_sth->errhp, status, "OCILobFileExists");
+           return 0;
+       }
+    }
+    if (exists) {
+       OCILobGetLength_log_stat(imp_sth->svchp, imp_sth->errhp, lobloc, &loblen, 
+status);
+       if (status != OCI_SUCCESS) {
+           oci_error(sth, imp_sth->errhp, status, "OCILobGetLength");
+           return 0;
+       }
     }
 
     amtp = (loblen > imp_sth->long_readlen) ? imp_sth->long_readlen : loblen;
--- ocitrace.h  2001/10/10 20:43:28     1.2
+++ ocitrace.h  2001/10/11 20:07:08
@@ -143,6 +143,13 @@
          OciTp, ul_t(md),(void*)cp,(void*)mlf,(void*)rlf,(void*)mfp,   \
          oci_status_name(stat)),stat : stat
 
+#define OCILobFileExists_log_stat(sh,eh,lh,exists,stat) \
+       stat=OCILobFileExists(sh,eh,lh,exists);                         \
+       (DBD_OCI_TRACEON) ? fprintf(DBD_OCI_TRACEFP,                    \
+         "%sLobGetFileExists(%p,%p,%p,%p)=%s\n",                       \
+         OciTp, (void*)sh,(void*)eh,(void*)lh,(void*)exists,           \
+         oci_status_name(stat)),stat : stat
+
 #define OCILobGetLength_log_stat(sh,eh,lh,l,stat)                      \
        stat=OCILobGetLength(sh,eh,lh,l);                               \
        (DBD_OCI_TRACEON) ? fprintf(DBD_OCI_TRACEFP,                    \

Reply via email to