apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r590501 - in /apr/apr-util/trunk: CHANGES dbd/apr_dbd.c dbd/apr_dbd_freetds.c dbd/apr_dbd_mysql.c dbd/apr_dbd_oracle.c dbd/apr_dbd_pgsql.c dbd/apr_dbd_sqlite2.c dbd/apr_dbd_sqlite3.c include/apr_dbd.h include/private/apr_dbd_internal.h
Date Tue, 30 Oct 2007 22:54:40 GMT
Author: bojan
Date: Tue Oct 30 15:54:37 2007
New Revision: 590501

URL: http://svn.apache.org/viewvc?rev=590501&view=rev
Log:
Introduce apr_dbd_open_ex()
NOTE: FreeTDS driver needs to be fixed to use the new error argument

Modified:
    apr/apr-util/trunk/CHANGES
    apr/apr-util/trunk/dbd/apr_dbd.c
    apr/apr-util/trunk/dbd/apr_dbd_freetds.c
    apr/apr-util/trunk/dbd/apr_dbd_mysql.c
    apr/apr-util/trunk/dbd/apr_dbd_oracle.c
    apr/apr-util/trunk/dbd/apr_dbd_pgsql.c
    apr/apr-util/trunk/dbd/apr_dbd_sqlite2.c
    apr/apr-util/trunk/dbd/apr_dbd_sqlite3.c
    apr/apr-util/trunk/include/apr_dbd.h
    apr/apr-util/trunk/include/private/apr_dbd_internal.h

Modified: apr/apr-util/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/CHANGES?rev=590501&r1=590500&r2=590501&view=diff
==============================================================================
--- apr/apr-util/trunk/CHANGES [utf-8] (original)
+++ apr/apr-util/trunk/CHANGES [utf-8] Tue Oct 30 15:54:37 2007
@@ -1,6 +1,8 @@
                                                      -*- coding: utf-8 -*-
 Changes with APR-util 1.3.0
   
+  *) Introduce apr_dbd_open_ex() [Bojan Smojver]
+
   *) Make md5 hash files portable between EBCDIC and ASCII platforms  
      [David Jones]
 

Modified: apr/apr-util/trunk/dbd/apr_dbd.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/dbd/apr_dbd.c?rev=590501&r1=590500&r2=590501&view=diff
==============================================================================
--- apr/apr-util/trunk/dbd/apr_dbd.c (original)
+++ apr/apr-util/trunk/dbd/apr_dbd.c Tue Oct 30 15:54:37 2007
@@ -183,21 +183,32 @@
 
     return rv;
 }
-APU_DECLARE(apr_status_t) apr_dbd_open(const apr_dbd_driver_t *driver,
-                                       apr_pool_t *pool, const char *params,
-                                       apr_dbd_t **handle)
+APU_DECLARE(apr_status_t) apr_dbd_open_ex(const apr_dbd_driver_t *driver,
+                                          apr_pool_t *pool, const char *params,
+                                          apr_dbd_t **handle,
+                                          const char **error)
 {
     apr_status_t rv;
-    *handle = (driver->open)(pool, params);
+    *handle = (driver->open)(pool, params, error);
     if (*handle == NULL) {
         return APR_EGENERAL;
     }
     rv = apr_dbd_check_conn(driver, pool, *handle);
     if ((rv != APR_SUCCESS) && (rv != APR_ENOTIMPL)) {
+        /* XXX: rv is APR error code, but apr_dbd_error() takes int! */
+        if (error) {
+            *error = apr_dbd_error(driver, *handle, rv);
+        }
         apr_dbd_close(driver, *handle);
         return APR_EGENERAL;
     }
     return APR_SUCCESS;
+}
+APU_DECLARE(apr_status_t) apr_dbd_open(const apr_dbd_driver_t *driver,
+                                       apr_pool_t *pool, const char *params,
+                                       apr_dbd_t **handle)
+{
+    return apr_dbd_open_ex(driver,pool,params,handle,NULL);
 }
 APU_DECLARE(int) apr_dbd_transaction_start(const apr_dbd_driver_t *driver,
                                            apr_pool_t *pool, apr_dbd_t *handle,

Modified: apr/apr-util/trunk/dbd/apr_dbd_freetds.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/dbd/apr_dbd_freetds.c?rev=590501&r1=590500&r2=590501&view=diff
==============================================================================
--- apr/apr-util/trunk/dbd/apr_dbd_freetds.c (original)
+++ apr/apr-util/trunk/dbd/apr_dbd_freetds.c Tue Oct 30 15:54:37 2007
@@ -528,7 +528,8 @@
     return (trans->handle->err == SUCCEED) ? 0 : 1;
 }
 
-static DBPROCESS *freetds_open(apr_pool_t *pool, const char *params)
+static DBPROCESS *freetds_open(apr_pool_t *pool, const char *params,
+                               const char **error)
 {
     char *server = NULL;
     DBPROCESS *process;
@@ -543,6 +544,7 @@
     char *databaseName = NULL;
 
     /* FIXME - this uses malloc */
+    /* FIXME - pass error message back to the caller in case of failure */
     login = dblogin();
     if (login == NULL) {
         return NULL;
@@ -612,10 +614,12 @@
 
     return process;
 }
-static apr_dbd_t *dbd_freetds_open(apr_pool_t *pool, const char *params)
+static apr_dbd_t *dbd_freetds_open(apr_pool_t *pool, const char *params,
+                                   const char **error)
 {
     apr_dbd_t *sql;
-    DBPROCESS *process = freetds_open(pool, params);
+    /* FIXME - pass error message back to the caller in case of failure */
+    DBPROCESS *process = freetds_open(pool, params, error);
     if (process == NULL) {
         return NULL;
     }

Modified: apr/apr-util/trunk/dbd/apr_dbd_mysql.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/dbd/apr_dbd_mysql.c?rev=590501&r1=590500&r2=590501&view=diff
==============================================================================
--- apr/apr-util/trunk/dbd/apr_dbd_mysql.c (original)
+++ apr/apr-util/trunk/dbd/apr_dbd_mysql.c Tue Oct 30 15:54:37 2007
@@ -1064,7 +1064,8 @@
     return trans->mode = (mode & TXN_MODE_BITS);
 }
 
-static apr_dbd_t *dbd_mysql_open(apr_pool_t *pool, const char *params)
+static apr_dbd_t *dbd_mysql_open(apr_pool_t *pool, const char *params,
+                                 const char **error)
 {
     static const char *const delims = " \r\n\t;|,";
     const char *ptr;
@@ -1155,6 +1156,9 @@
                                    fields[5].value, flags);
 
     if(real_conn == NULL) {
+        if (error) {
+            *error = apr_pstrdup(pool, mysql_error(sql->conn));
+        }
         mysql_close(sql->conn);
         return NULL;
     }

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=590501&r1=590500&r2=590501&view=diff
==============================================================================
--- apr/apr-util/trunk/dbd/apr_dbd_oracle.c (original)
+++ apr/apr-util/trunk/dbd/apr_dbd_oracle.c Tue Oct 30 15:54:37 2007
@@ -91,6 +91,8 @@
 
 #define CHECK_CONN_QUERY "SELECT 1 FROM dual"
 
+#define ERR_BUF_SIZE 200
+
 #ifdef DEBUG
 #include <stdio.h>
 #endif
@@ -141,7 +143,7 @@
     OCISession *auth;
     apr_dbd_transaction_t* trans;
     apr_pool_t *pool;
-    char buf[200];        /* for error messages */
+    char buf[ERR_BUF_SIZE]; /* for error messages */
     apr_size_t long_size;
     apr_dbd_prepared_t *check_conn_stmt;
 };
@@ -437,10 +439,11 @@
 #endif
 }
 
-static apr_dbd_t *dbd_oracle_open(apr_pool_t *pool, const char *params)
+static apr_dbd_t *dbd_oracle_open(apr_pool_t *pool, const char *params,
+                                  const char **error)
 {
     apr_dbd_t *ret = apr_pcalloc(pool, sizeof(apr_dbd_t));
-    int_errorcode;
+    int errorcode;
 
     char *BLANK = "";
     struct {
@@ -519,6 +522,9 @@
         printf("OPEN ERROR %d (alloc svr): %s\n", ret->status, ret->buf);
         break;
 #else
+        *error = apr_pcalloc(pool, ERR_BUF_SIZE);
+        OCIErrorGet(ret->err, 1, NULL, &errorcode, (unsigned char*)(*error),
+                    ERR_BUF_SIZE, OCI_HTYPE_ERROR);
         return NULL;
 #endif
     case OCI_SUCCESS:
@@ -535,6 +541,9 @@
         printf("OPEN ERROR %d (alloc svc): %s\n", ret->status, ret->buf);
         break;
 #else
+        *error = apr_pcalloc(pool, ERR_BUF_SIZE);
+        OCIErrorGet(ret->err, 1, NULL, &errorcode, (unsigned char*)(*error),
+                    ERR_BUF_SIZE, OCI_HTYPE_ERROR);
         return NULL;
 #endif
     case OCI_SUCCESS:
@@ -555,6 +564,9 @@
         printf("OPEN ERROR: %s\n", ret->buf);
         break;
 #else
+        *error = apr_pcalloc(pool, ERR_BUF_SIZE);
+        OCIErrorGet(ret->err, 1, NULL, &errorcode, (unsigned char*)(*error),
+                    ERR_BUF_SIZE, OCI_HTYPE_ERROR);
         return NULL;
 #endif
     case OCI_SUCCESS:
@@ -571,6 +583,9 @@
         printf("OPEN ERROR %d (server attach): %s\n", ret->status, ret->buf);
         break;
 #else
+        *error = apr_pcalloc(pool, ERR_BUF_SIZE);
+        OCIErrorGet(ret->err, 1, NULL, &errorcode, (unsigned char*)(*error),
+                    ERR_BUF_SIZE, OCI_HTYPE_ERROR);
         return NULL;
 #endif
     case OCI_SUCCESS:
@@ -586,6 +601,9 @@
         printf("OPEN ERROR %d (attr set): %s\n", ret->status, ret->buf);
         break;
 #else
+        *error = apr_pcalloc(pool, ERR_BUF_SIZE);
+        OCIErrorGet(ret->err, 1, NULL, &errorcode, (unsigned char*)(*error),
+                    ERR_BUF_SIZE, OCI_HTYPE_ERROR);
         return NULL;
 #endif
     case OCI_SUCCESS:
@@ -601,6 +619,9 @@
         printf("OPEN ERROR %d (alloc auth): %s\n", ret->status, ret->buf);
         break;
 #else
+        *error = apr_pcalloc(pool, ERR_BUF_SIZE);
+        OCIErrorGet(ret->err, 1, NULL, &errorcode, (unsigned char*)(*error),
+                    ERR_BUF_SIZE, OCI_HTYPE_ERROR);
         return NULL;
 #endif
     case OCI_SUCCESS:
@@ -616,6 +637,9 @@
         printf("OPEN ERROR %d (attr username): %s\n", ret->status, ret->buf);
         break;
 #else
+        *error = apr_pcalloc(pool, ERR_BUF_SIZE);
+        OCIErrorGet(ret->err, 1, NULL, &errorcode, (unsigned char*)(*error),
+                    ERR_BUF_SIZE, OCI_HTYPE_ERROR);
         return NULL;
 #endif
     case OCI_SUCCESS:
@@ -631,6 +655,9 @@
         printf("OPEN ERROR %d (attr password): %s\n", ret->status, ret->buf);
         break;
 #else
+        *error = apr_pcalloc(pool, ERR_BUF_SIZE);
+        OCIErrorGet(ret->err, 1, NULL, &errorcode, (unsigned char*)(*error),
+                    ERR_BUF_SIZE, OCI_HTYPE_ERROR);
         return NULL;
 #endif
     case OCI_SUCCESS:
@@ -646,6 +673,9 @@
         printf("OPEN ERROR %d (session begin): %s\n", ret->status, ret->buf);
         break;
 #else
+        *error = apr_pcalloc(pool, ERR_BUF_SIZE);
+        OCIErrorGet(ret->err, 1, NULL, &errorcode, (unsigned char*)(*error),
+                    ERR_BUF_SIZE, OCI_HTYPE_ERROR);
         return NULL;
 #endif
     case OCI_SUCCESS:
@@ -660,6 +690,9 @@
                     sizeof(ret->buf), OCI_HTYPE_ERROR);
         printf("OPEN ERROR %d (attr session): %s\n", ret->status, ret->buf);
 #else
+        *error = apr_pcalloc(pool, ERR_BUF_SIZE);
+        OCIErrorGet(ret->err, 1, NULL, &errorcode, (unsigned char*)(*error),
+                    ERR_BUF_SIZE, OCI_HTYPE_ERROR);
         return NULL;
 #endif
         break;

Modified: apr/apr-util/trunk/dbd/apr_dbd_pgsql.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/dbd/apr_dbd_pgsql.c?rev=590501&r1=590500&r2=590501&view=diff
==============================================================================
--- apr/apr-util/trunk/dbd/apr_dbd_pgsql.c (original)
+++ apr/apr-util/trunk/dbd/apr_dbd_pgsql.c Tue Oct 30 15:54:37 2007
@@ -1176,7 +1176,8 @@
     return trans->mode = (mode & TXN_MODE_BITS);
 }
 
-static apr_dbd_t *dbd_pgsql_open(apr_pool_t *pool, const char *params)
+static apr_dbd_t *dbd_pgsql_open(apr_pool_t *pool, const char *params,
+                                 const char **error)
 {
     apr_dbd_t *sql;
     
@@ -1187,6 +1188,9 @@
      * liable to segfault, so just close it out now.  it would be nice
      * if we could give an indication of why we failed to connect... */
     if (PQstatus(conn) != CONNECTION_OK) {
+        if (error) {
+            *error = apr_pstrdup(pool, PQerrorMessage(conn));
+        }
         PQfinish(conn);
         return NULL;
     }

Modified: apr/apr-util/trunk/dbd/apr_dbd_sqlite2.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/dbd/apr_dbd_sqlite2.c?rev=590501&r1=590500&r2=590501&view=diff
==============================================================================
--- apr/apr-util/trunk/dbd/apr_dbd_sqlite2.c (original)
+++ apr/apr-util/trunk/dbd/apr_dbd_sqlite2.c Tue Oct 30 15:54:37 2007
@@ -446,7 +446,14 @@
     return trans->mode = (mode & TXN_MODE_BITS);
 }
 
-static apr_dbd_t *dbd_sqlite_open(apr_pool_t * pool, const char *params_)
+static apr_status_t error_free(void *data)
+{
+    free(data);
+    return APR_SUCCESS;
+}
+
+static apr_dbd_t *dbd_sqlite_open(apr_pool_t * pool, const char *params_,
+                                  const char **error)
 {
     apr_dbd_t *sql;
     sqlite *conn = NULL;
@@ -465,7 +472,19 @@
             iperms = atoi(perm);
     }
 
-    conn = sqlite_open(params, iperms, NULL);
+    if (error) {
+        *error = NULL;
+
+        conn = sqlite_open(params, iperms, (char **)error);
+
+        if (*error) {
+            apr_pool_cleanup_register(pool, *error, error_free,
+                                      apr_pool_cleanup_null);
+        }
+    }
+    else {
+        conn = sqlite_open(params, iperms, NULL);
+    }
 
     sql = apr_pcalloc(pool, sizeof(*sql));
     sql->conn = conn;

Modified: apr/apr-util/trunk/dbd/apr_dbd_sqlite3.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/dbd/apr_dbd_sqlite3.c?rev=590501&r1=590500&r2=590501&view=diff
==============================================================================
--- apr/apr-util/trunk/dbd/apr_dbd_sqlite3.c (original)
+++ apr/apr-util/trunk/dbd/apr_dbd_sqlite3.c Tue Oct 30 15:54:37 2007
@@ -814,7 +814,8 @@
     return trans->mode = (mode & TXN_MODE_BITS);
 }
 
-static apr_dbd_t *dbd_sqlite3_open(apr_pool_t *pool, const char *params)
+static apr_dbd_t *dbd_sqlite3_open(apr_pool_t *pool, const char *params,
+                                   const char **error)
 {
     apr_dbd_t *sql = NULL;
     sqlite3 *conn = NULL;
@@ -823,6 +824,9 @@
         return NULL;
     sqlres = sqlite3_open(params, &conn);
     if (sqlres != SQLITE_OK) {
+        if (error) {
+            *error = apr_pstrdup(pool, sqlite3_errmsg(conn));
+        }
         sqlite3_close(conn);
         return NULL;
     }

Modified: apr/apr-util/trunk/include/apr_dbd.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/include/apr_dbd.h?rev=590501&r1=590500&r2=590501&view=diff
==============================================================================
--- apr/apr-util/trunk/include/apr_dbd.h (original)
+++ apr/apr-util/trunk/include/apr_dbd.h Tue Oct 30 15:54:37 2007
@@ -105,12 +105,13 @@
 APU_DECLARE(apr_status_t) apr_dbd_get_driver(apr_pool_t *pool, const char *name,
                                              const apr_dbd_driver_t **driver);
 
-/** apr_dbd_open: open a connection to a backend
+/** apr_dbd_open_ex: open a connection to a backend
  *
  *  @param pool - working pool
  *  @param params - arguments to driver (implementation-dependent)
  *  @param handle - pointer to handle to return
  *  @param driver - driver struct.
+ *  @param error - descriptive error.
  *  @return APR_SUCCESS for success
  *  @return APR_EGENERAL if driver exists but connection failed
  *  @remarks PostgreSQL: the params is passed directly to the PQconnectdb()
@@ -134,6 +135,21 @@
  *  this value is 1 MB. The value associated with "group" determines which
  *  group from configuration file to use (see MYSQL_READ_DEFAULT_GROUP option
  *  of mysql_options() in MySQL manual).
+ */
+APU_DECLARE(apr_status_t) apr_dbd_open_ex(const apr_dbd_driver_t *driver,
+                                          apr_pool_t *pool, const char *params,
+                                          apr_dbd_t **handle,
+                                          const char **error);
+
+/** apr_dbd_open: open a connection to a backend
+ *
+ *  @param pool - working pool
+ *  @param params - arguments to driver (implementation-dependent)
+ *  @param handle - pointer to handle to return
+ *  @param driver - driver struct.
+ *  @return APR_SUCCESS for success
+ *  @return APR_EGENERAL if driver exists but connection failed
+ *  @see apr_dbd_open_ex
  */
 APU_DECLARE(apr_status_t) apr_dbd_open(const apr_dbd_driver_t *driver,
                                        apr_pool_t *pool, const char *params,

Modified: apr/apr-util/trunk/include/private/apr_dbd_internal.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/include/private/apr_dbd_internal.h?rev=590501&r1=590500&r2=590501&view=diff
==============================================================================
--- apr/apr-util/trunk/include/private/apr_dbd_internal.h (original)
+++ apr/apr-util/trunk/include/private/apr_dbd_internal.h Tue Oct 30 15:54:37 2007
@@ -62,10 +62,12 @@
      *  a lifetime other than a request
      *
      *  @param pool - a pool to use for error messages (if any).
-     *  @param s - server rec managing the underlying connection/pool.
+     *  @param params - connection parameters.
+     *  @param error - descriptive error.
      *  @return database handle, or NULL on error.
      */
-    apr_dbd_t *(*open)(apr_pool_t *pool, const char *params);
+    apr_dbd_t *(*open)(apr_pool_t *pool, const char *params,
+                       const char **error);
 
     /** check_conn: check status of a database connection
      *



Mime
View raw message