apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r421212 - /apr/apr-util/trunk/dbd/apr_dbd_oracle.c
Date Wed, 12 Jul 2006 09:55:24 GMT
Author: niq
Date: Wed Jul 12 02:55:23 2006
New Revision: 421212

URL: http://svn.apache.org/viewvc?rev=421212&view=rev
Log:
Prepared statement handling & params format patch for Oracle Driver
(Chris Darroch, under PR#37664)

Modified:
    apr/apr-util/trunk/dbd/apr_dbd_oracle.c

Modified: apr/apr-util/trunk/dbd/apr_dbd_oracle.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/dbd/apr_dbd_oracle.c?rev=421212&r1=421211&r2=421212&view=diff
==============================================================================
--- apr/apr-util/trunk/dbd/apr_dbd_oracle.c (original)
+++ apr/apr-util/trunk/dbd/apr_dbd_oracle.c Wed Jul 12 02:55:23 2006
@@ -236,29 +236,37 @@
 {
     apr_status_t rv = APR_SUCCESS;
     OCIStmt *stmt;
-    OCIError *err;
     apr_hash_index_t *index;
     apr_pool_t *cachepool = apr_hash_pool_get(oracle_statements);
 
+#ifdef PREPARE2
+    OCIError *err;
+
     if (OCIHandleAlloc(dbd_oracle_env, (dvoid**)&err, OCI_HTYPE_ERROR, 0, NULL)
        != OCI_SUCCESS) {
         return APR_EGENERAL;
     }
+#endif
 
     for (index = apr_hash_first(cachepool, oracle_statements);
          index != NULL;
          index = apr_hash_next(index)) {
         apr_hash_this(index, NULL, NULL, (void**)&stmt);
+#ifdef PREPARE2
         if (OCIStmtRelease(stmt, err, NULL, 0, OCI_DEFAULT) != OCI_SUCCESS) {
             rv = APR_EGENERAL;
         }
+#else
         if (OCIHandleFree(stmt, OCI_HTYPE_STMT) != OCI_SUCCESS) {
             rv = APR_EGENERAL;
         }
+#endif
     }
+#ifdef PREPARE2
     if (OCIHandleFree(err, OCI_HTYPE_ERROR) != OCI_SUCCESS) {
         rv = APR_EGENERAL;
     }
+#endif
     return rv;
 }
 #endif
@@ -621,33 +629,31 @@
     }
 }
 
-static int freeStatement(void *statement)
+static apr_status_t freeStatement(void *statement)
 {
-    int ret = 0;
-
-    apr_dbd_t *sql = ((apr_dbd_prepared_t*)statement)->handle;
+    int rv = APR_SUCCESS;
     OCIStmt *stmt = ((apr_dbd_prepared_t*)statement)->stmt;
-    OCIError *err = sql->err;
 
-    sql->status = OCIStmtRelease(stmt, err, NULL, 0, OCI_DEFAULT);
-    switch (sql->status) {
-    case OCI_SUCCESS:
-        break;
-    default:
-        ++ret;
-        break;
-    }
+#ifdef PREPARE2
+    OCIError *err;
 
-    sql->status = OCIHandleFree(stmt, OCI_HTYPE_STMT);
-    switch (sql->status) {
-    case OCI_SUCCESS:
-        break;
-    default:
-        ++ret;
-        break;
+    if (OCIHandleAlloc(dbd_oracle_env, (dvoid**)&err, OCI_HTYPE_ERROR,
+                       0, NULL) != OCI_SUCCESS) {
+        return APR_EGENERAL;
+    }
+    if (OCIStmtRelease(stmt, err, NULL, 0, OCI_DEFAULT) != OCI_SUCCESS) {
+        rv = APR_EGENERAL;
+    }
+    if (OCIHandleFree(err, OCI_HTYPE_ERROR) != OCI_SUCCESS) {
+        rv = APR_EGENERAL;
+    }
+#else
+    if (OCIHandleFree(stmt, OCI_HTYPE_STMT) != OCI_SUCCESS) {
+        rv = APR_EGENERAL;
     }
+#endif
 
-    return ret;
+    return rv;
 }
 
 static int dbd_oracle_select(apr_pool_t *pool, apr_dbd_t *sql,
@@ -675,6 +681,7 @@
     int ret = 0;
     apr_pool_t *pool;
     apr_dbd_prepared_t *statement = NULL;
+    sword status;
 
     if (sql->trans && sql->trans->status == TRANS_ERROR) {
         return 1;
@@ -763,6 +770,7 @@
     }
 #endif
     /* translate from apr_dbd to native query format */
+    stmt->nargs = 0;
     for (sqlptr = (char*)query; *sqlptr; ++sqlptr) {
         if ((sqlptr[0] == '%') && isalnum(sqlptr[1])) {
             ++stmt->nargs;
@@ -1011,9 +1019,8 @@
         break;
     case OCI_ERROR:
 #ifdef DEBUG
-        sql->status = OCIErrorGet(sql->err, 1, NULL, &errorcode,
-                                  sql->buf, sizeof(sql->buf),
-                                  OCI_HTYPE_ERROR);
+        OCIErrorGet(sql->err, 1, NULL, &errorcode,
+                    sql->buf, sizeof(sql->buf), OCI_HTYPE_ERROR);
         printf("Describing prepared statement: %s\n", sql->buf);
 #endif
     default:
@@ -1151,7 +1158,6 @@
     OCISnapshot *newsnapshot = NULL;
     apr_dbd_transaction_t* trans = sql->trans;
     int i;
-    int n;
     int exec_mode;
     int_errorcode;
 
@@ -1183,15 +1189,18 @@
     for (i=0; i<statement->nargs; ++i) {
         switch (statement->args[i].type) {
         case APR_DBD_ORACLE_INT:
-            n = va_arg(args, int);
-            sprintf(statement->args[i].value.stringval, "%d", n);
+            arg = va_arg(args, char*);
+            sscanf(arg, "%d", statement->args[i].value.ival);
             break;
         case APR_DBD_ORACLE_FLOAT:
-            *statement->args[i].value.floatval = va_arg(args, double);
+            arg = va_arg(args, char*);
+            sscanf(arg, "%lf", statement->args[i].value.floatval);
             break;
         case APR_DBD_ORACLE_BLOB:
         case APR_DBD_ORACLE_CLOB:
-            /* Nothing works */
+            sql->status = OCIAttrSet(statement->args[i].value.lobval,
+                                     OCI_DTYPE_LOB, &null, 0,
+                                     OCI_ATTR_LOBEMPTY, sql->err);
             break;
         case APR_DBD_ORACLE_LOB:
             /* requires strlen() over large data, which may fail for binary */
@@ -1229,8 +1238,8 @@
         break;
     case OCI_ERROR:
 #ifdef DEBUG
-        sql->status = OCIErrorGet(sql->err, 1, NULL, &errorcode,
-                                  sql->buf, sizeof(sql->buf), OCI_HTYPE_ERROR);
+        OCIErrorGet(sql->err, 1, NULL, &errorcode,
+                    sql->buf, sizeof(sql->buf), OCI_HTYPE_ERROR);
         printf("Execute error %d: %s\n", sql->status, sql->buf);
 #endif
         /* fallthrough */
@@ -1241,50 +1250,6 @@
         return 1;
     }
 
-    for (i=0; i<statement->nargs; ++i) {
-        /* what should these really be? */
-        ub1 csfrm = SQLCS_IMPLICIT;
-        ub2 csid = 0;
-        ub4 len = statement->args[i].len;
-        switch (statement->args[i].type) {
-        case APR_DBD_ORACLE_BLOB:
-        case APR_DBD_ORACLE_CLOB:
-            /* doesn't work - use APR_DBD_ORACLE_LOB instead */
-            sql->status = OCILobEnableBuffering(sql->svc, sql->err,statement->args[i].value.lobval);
-#ifdef DEBUG
-            if (sql->status == OCI_ERROR) {
-                sql->status = OCIErrorGet(sql->err, 1, NULL, &errorcode,
-                                          sql->buf, sizeof(sql->buf),
-                                          OCI_HTYPE_ERROR);
-                printf("LOB error %d: %s\n", sql->status, sql->buf);
-            }
-#endif
-            sql->status = OCILobWrite(sql->svc, sql->err,
-                                      statement->args[i].value.lobval,
-                                      &len, 0, (dvoid*) arg, strlen(arg),
-                                      OCI_ONE_PIECE, NULL, NULL, csid, csfrm);
-            break;
-        default:
-            break;
-        }
-        switch (sql->status) {
-        case OCI_SUCCESS:
-            break;
-        case OCI_ERROR:
-#ifdef DEBUG
-            sql->status = OCIErrorGet(sql->err, 1, NULL, &errorcode,
-                                      sql->buf, sizeof(sql->buf), OCI_HTYPE_ERROR);
-            printf("LOB error %d: %s\n", sql->status, sql->buf);
-#endif
-            /* fallthrough */
-        default:
-            if (TXN_NOTICE_ERRORS(trans)) {
-                trans->status = TRANS_ERROR;
-            }
-            return 1;
-        }
-    }
-
     sql->status = OCIAttrGet(statement->stmt, OCI_HTYPE_STMT, nrows, 0,
                              OCI_ATTR_ROW_COUNT, sql->err);
     return 0;
@@ -1378,8 +1343,8 @@
         break;
     case OCI_ERROR:
 #ifdef DEBUG
-        sql->status = OCIErrorGet(sql->err, 1, NULL, &errorcode,
-                                  sql->buf, sizeof(sql->buf), OCI_HTYPE_ERROR);
+        OCIErrorGet(sql->err, 1, NULL, &errorcode,
+                    sql->buf, sizeof(sql->buf), OCI_HTYPE_ERROR);
         printf("Execute error %d: %s\n", sql->status, sql->buf);
 #endif
         /* fallthrough */
@@ -1433,10 +1398,12 @@
         int len;
         switch (statement->args[i].type) {
         case APR_DBD_ORACLE_INT:
-            *statement->args[i].value.ival = va_arg(args, int);
+            arg = va_arg(args, char*);
+            sscanf(arg, "%d", statement->args[i].value.ival);
             break;
         case APR_DBD_ORACLE_FLOAT:
-            *statement->args[i].value.floatval = va_arg(args, double);
+            arg = va_arg(args, char*);
+            sscanf(arg, "%lf", statement->args[i].value.floatval);
             break;
         case APR_DBD_ORACLE_BLOB:
         case APR_DBD_ORACLE_CLOB:
@@ -1471,11 +1438,11 @@
         break;
     case OCI_ERROR:
 #ifdef DEBUG
-        sql->status = OCIErrorGet(sql->err, 1, NULL, &errorcode,
-                                  sql->buf, sizeof(sql->buf),
-                                  OCI_HTYPE_ERROR);
+        OCIErrorGet(sql->err, 1, NULL, &errorcode,
+                    sql->buf, sizeof(sql->buf), OCI_HTYPE_ERROR);
         printf("Executing prepared statement: %s\n", sql->buf);
 #endif
+        /* fallthrough */
     default:
         if (TXN_NOTICE_ERRORS(trans)) {
             trans->status = TRANS_ERROR;
@@ -1530,11 +1497,9 @@
         nargs = statement->nargs;
     }
     for (i=0; i<nargs; ++i) {
-        int foo;
         switch (statement->args[i].type) {
         case APR_DBD_ORACLE_INT:
-            sscanf(values[i], "%d", &foo);
-            *statement->args[i].value.ival = foo;
+            sscanf(values[i], "%d", statement->args[i].value.ival);
             break;
         case APR_DBD_ORACLE_FLOAT:
             sscanf(values[i], "%lf", statement->args[i].value.floatval);
@@ -1566,11 +1531,11 @@
         break;
     case OCI_ERROR:
 #ifdef DEBUG
-        sql->status = OCIErrorGet(sql->err, 1, NULL, &errorcode,
-                                  sql->buf, sizeof(sql->buf),
-                                  OCI_HTYPE_ERROR);
+        OCIErrorGet(sql->err, 1, NULL, &errorcode,
+                    sql->buf, sizeof(sql->buf), OCI_HTYPE_ERROR);
         printf("Executing prepared statement: %s\n", sql->buf);
 #endif
+        /* fallthrough */
     default:
         if (TXN_NOTICE_ERRORS(trans)) {
             trans->status = TRANS_ERROR;
@@ -1737,9 +1702,8 @@
             break;
         case OCI_ERROR:
 #ifdef DEBUG
-            sql->status = OCIErrorGet(sql->err, 1, NULL, &errorcode,
-                                      sql->buf, sizeof(sql->buf),
-                                      OCI_HTYPE_ERROR);
+            OCIErrorGet(sql->err, 1, NULL, &errorcode,
+                        sql->buf, sizeof(sql->buf), OCI_HTYPE_ERROR);
             printf("Finding LOB length: %s\n", sql->buf);
             break;
 #endif
@@ -1770,9 +1734,8 @@
                 break;
 #ifdef DEBUG
             case OCI_ERROR:
-                sql->status = OCIErrorGet(sql->err, 1, NULL, &errorcode,
-                                          sql->buf, sizeof(sql->buf),
-                                          OCI_HTYPE_ERROR);
+                OCIErrorGet(sql->err, 1, NULL, &errorcode,
+                            sql->buf, sizeof(sql->buf), OCI_HTYPE_ERROR);
                 printf("Reading LOB character set: %s\n", sql->buf);
                 break; /*** XXX?? ***/
 #endif
@@ -1804,9 +1767,8 @@
             break;
 #ifdef DEBUG
         case OCI_ERROR:
-            sql->status = OCIErrorGet(sql->err, 1, NULL, &errorcode,
-                                      sql->buf, sizeof(sql->buf),
-                                      OCI_HTYPE_ERROR);
+            OCIErrorGet(sql->err, 1, NULL, &errorcode,
+                        sql->buf, sizeof(sql->buf), OCI_HTYPE_ERROR);
             printf("Reading LOB: %s\n", sql->buf);
             buf = NULL; /*** XXX?? ***/
             break;



Mime
View raw message