Here is a set of (hopefully better) patches against various files in apr_dbd code that enable the get_name support.

--
Bojan
--- include/apr_dbd.h.orig
+++ include/apr_dbd.h
@@ -210,6 +210,18 @@
 APU_DECLARE(const char*) apr_dbd_get_entry(const apr_dbd_driver_t *driver,
                                            apr_dbd_row_t *row, int col);

+/** apr_dbd_get_name: get an entry name from a result set
+ *
+ *  @param driver - the driver
+ *  @param pool - pool to allocate name from
+ *  @param res - result set pointer
+ *  @param col - entry number
+ *  @return name of the entry, or NULL if col is out of bounds.
+ */
+APU_DECLARE(const char*) apr_dbd_get_name(const apr_dbd_driver_t *driver,
+                                          apr_pool_t *pool,
+                                          apr_dbd_results_t *res, int col);
+
 /** apr_dbd_error: get current error message (if any)
  *
  *  @param driver - the driver
diff -rauN apr-util-vanilla/include/private/apr_dbd_internal.h apr-util/include/private/apr_dbd_internal.h
--- apr-util-vanilla/include/private/apr_dbd_internal.h	2005-10-15 14:24:51.000000000 +1000
+++ apr-util/include/private/apr_dbd_internal.h	2006-02-14 16:36:38.000000000 +1100
@@ -246,6 +246,16 @@
                    apr_dbd_results_t **res, apr_dbd_prepared_t *statement,
                    int random, int nargs, const char **args);
 
+    /** get_name: get an entry name from a result set
+     *
+     *  @param pool - pool to allocate the name
+     *  @param res - result set pointer
+     *  @param col - entry number
+     *  @return name of the entry, or NULL if col is out of bounds.
+     */
+    const char* (*get_name)(apr_pool_t *pool, const apr_dbd_results_t *res,
+                            int col);
+
 };
 
 /* Export mutex lock/unlock for drivers that need it */
diff -rauN apr-util-vanilla/dbd/apr_dbd.c apr-util/dbd/apr_dbd.c
--- apr-util-vanilla/dbd/apr_dbd.c	2006-02-14 21:14:08.000000000 +1100
+++ apr-util/dbd/apr_dbd.c	2006-02-14 21:16:39.000000000 +1100
@@ -238,6 +238,12 @@
 {
     return driver->num_tuples(res);
 }
+APU_DECLARE(const char*) apr_dbd_get_name(const apr_dbd_driver_t *driver,
+                                          apr_pool_t *pool,
+                                          apr_dbd_results_t *res, int col)
+{
+    return driver->get_name(pool,res,col);
+}
 APU_DECLARE(int) apr_dbd_get_row(const apr_dbd_driver_t *driver, apr_pool_t *pool,
                                  apr_dbd_results_t *res, apr_dbd_row_t **row,
                                  int rownum)
--- apr_dbd_mysql.c.vanilla	2006-02-13 17:45:20.000000000 +1100
+++ apr_dbd_mysql.c	2006-02-15 08:22:54.000000000 +1100
@@ -76,6 +76,7 @@
     MYSQL_RES *res;
     MYSQL_STMT *statement;
     MYSQL_BIND *bind;
+    MYSQL_FIELD *fields;
 };
 struct apr_dbd_row_t {
     MYSQL_ROW row;
@@ -105,6 +106,7 @@
             else {
                 (*results)->res = mysql_use_result(sql->conn);
             }
+            (*results)->fields = mysql_fetch_fields((*results)->res);
             apr_pool_cleanup_register(pool, (*results)->res,
                                       (void*)mysql_free_result,
                                       apr_pool_cleanup_null);
@@ -115,6 +117,17 @@
     }
     return ret;
 }
+
+static const char *dbd_mysql_get_name(apr_pool_t *pool,
+                                      const apr_dbd_results_t *res, int n)
+{
+  if ((n < 0) || (n >= mysql_num_fields(res->res))) {
+    return NULL;
+  }
+
+  return res->fields[n].name;
+}
+
 static int dbd_mysql_get_row(apr_pool_t *pool, apr_dbd_results_t *res,
                              apr_dbd_row_t **row, int rownum)
 {
@@ -388,6 +400,7 @@
             (*res)->random = random;
             (*res)->statement = statement->stmt;
             (*res)->res = mysql_stmt_result_metadata(statement->stmt);
+            (*res)->fields = mysql_fetch_fields((*res)->res);
             apr_pool_cleanup_register(pool, (*res)->res,
                 (void*)mysql_free_result, apr_pool_cleanup_null);
             nfields = mysql_num_fields((*res)->res);
@@ -465,6 +478,7 @@
             (*res)->random = random;
             (*res)->statement = statement->stmt;
             (*res)->res = mysql_stmt_result_metadata(statement->stmt);
+            (*res)->fields = mysql_fetch_fields((*res)->res);
             apr_pool_cleanup_register(pool, (*res)->res,
                 (void*)mysql_free_result, apr_pool_cleanup_null);
             nfields = mysql_num_fields((*res)->res);
@@ -666,6 +680,7 @@
     dbd_mysql_pvselect,
     dbd_mysql_pquery,
     dbd_mysql_pselect,
+    dbd_mysql_get_name
 };
 
 #endif
--- apr_dbd_oracle.c.orig       2006-02-13 14:28:27.160654000 -0500
+++ apr_dbd_oracle.c    2006-02-13 14:33:24.668866000 -0500
@@ -181,6 +181,7 @@
         char *stringval;
         OCILobLocator *lobval;
     } buf;
+    const char *name;
 } define_arg;

 struct apr_dbd_prepared_t {
@@ -525,6 +526,17 @@
 }
 #endif

+static const char *dbd_oracle_get_name(apr_pool_t *pool,
+                                       const apr_dbd_results_t *res, int n)
+{
+    define_arg *val = &res->statement->out[n];
+
+    if ((n < 0) || (n >= res->statement->nout)) {
+        return NULL;
+    }
+    return val->name;
+}
+
 static int dbd_oracle_get_row(apr_pool_t *pool, apr_dbd_results_t *res,
                               apr_dbd_row_t **rowp, int rownum)
 {
@@ -988,6 +999,8 @@
     int_errorcode;
     ub2 paramtype[DBD_ORACLE_MAX_COLUMNS];
     ub2 paramsize[DBD_ORACLE_MAX_COLUMNS];
+    const char *paramname[DBD_ORACLE_MAX_COLUMNS];
+    ub4 paramnamelen[DBD_ORACLE_MAX_COLUMNS];
     /* Perl uses 0 where we used 1 */
     sql->status = OCIStmtExecute(sql->svc, stmt->stmt, sql->err, 0, 0,
                                  NULL, NULL, OCI_DESCRIBE_ONLY);
@@ -1016,6 +1029,10 @@
             sql->status = OCIAttrGet(parms, OCI_DTYPE_PARAM,
                                      &paramsize[stmt->nout],
                                      0, OCI_ATTR_DATA_SIZE, sql->err);
+            sql->status = OCIAttrGet(parms, OCI_DTYPE_PARAM,
+                                     &paramname[stmt->nout],
+                                     &paramnamelen[stmt->nout],
+                                     OCI_ATTR_NAME, sql->err);
             ++stmt->nout;
         }
     }
@@ -1033,6 +1050,8 @@
     for (i=0; i<stmt->nout; ++i) {
         stmt->out[i].type = paramtype[i];
         stmt->out[i].len = stmt->out[i].sz = paramsize[i];
+        stmt->out[i].name = apr_pstrmemdup(stmt->pool,
+                                           paramname[i], paramnamelen[i]);
         switch (stmt->out[i].type) {
         default:
             switch (stmt->out[i].type) {
@@ -1890,6 +1909,7 @@
     dbd_oracle_pvquery,
     dbd_oracle_pvselect,
     dbd_oracle_pquery,
-    dbd_oracle_pselect
+    dbd_oracle_pselect,
+    dbd_oracle_get_name
 };
 #endif
diff -rauN apr-util-vanilla/dbd/apr_dbd_pgsql.c apr-util/dbd/apr_dbd_pgsql.c
--- apr-util-vanilla/dbd/apr_dbd_pgsql.c	2005-11-29 10:31:28.000000000 +1100
+++ apr-util/dbd/apr_dbd_pgsql.c	2006-02-14 15:41:27.000000000 +1100
@@ -116,6 +116,16 @@
     return 0;
 }
 
+static const char *dbd_pgsql_get_name(apr_pool_t *pool,
+                                      const apr_dbd_results_t *res, int n)
+{
+    if (!res->res || (n < 0) || (n >= res->sz)) {
+        return NULL;
+    }
+
+    return PQfname(res->res, n);
+}
+
 static int dbd_pgsql_get_row(apr_pool_t *pool, apr_dbd_results_t *res,
                              apr_dbd_row_t **rowp, int rownum)
 {
@@ -640,5 +649,6 @@
     dbd_pgsql_pvselect,
     dbd_pgsql_pquery,
     dbd_pgsql_pselect,
+    dbd_pgsql_get_name
 };
 #endif
diff -rauN apr-util-vanilla/dbd/apr_dbd_sqlite2.c apr-util/dbd/apr_dbd_sqlite2.c
--- apr-util-vanilla/dbd/apr_dbd_sqlite2.c	2006-01-27 16:15:48.000000000 +1100
+++ apr-util/dbd/apr_dbd_sqlite2.c	2006-02-14 16:28:25.000000000 +1100
@@ -114,6 +114,16 @@
     return ret;
 }
 
+static const char *dbd_sqlite_get_name(apr_pool_t *pool,
+                                       const apr_dbd_results_t *res, int n)
+{
+    if ((n < 0) || (n >= res->sz)) {
+        return NULL;
+    }
+
+    return res->res[n];
+}
+
 static int dbd_sqlite_get_row(apr_pool_t * pool, apr_dbd_results_t * res,
                               apr_dbd_row_t ** rowp, int rownum)
 {
@@ -383,5 +392,6 @@
     dbd_sqlite_pvselect,
     dbd_sqlite_pquery,
     dbd_sqlite_pselect,
+    dbd_sqlite_get_name
 };
 #endif
diff -rauN apr-util-vanilla/dbd/apr_dbd_sqlite3.c apr-util/dbd/apr_dbd_sqlite3.c
--- apr-util-vanilla/dbd/apr_dbd_sqlite3.c	2006-01-27 16:15:48.000000000 +1100
+++ apr-util/dbd/apr_dbd_sqlite3.c	2006-02-14 16:30:14.000000000 +1100
@@ -177,6 +177,16 @@
     return ret;
 }
 
+static const char *dbd_sqlite3_get_name(apr_pool_t *pool,
+                                        const apr_dbd_results_t *res, int n)
+{
+    if ((n < 0) || (n >= res->sz)) {
+        return NULL;
+    }
+
+    return apr_pstrdup(pool, res->next_row->columns[n]->name);
+}
+
 static int dbd_sqlite3_get_row(apr_pool_t *pool, apr_dbd_results_t *res,
                                apr_dbd_row_t **rowp, int rownum)
 {
@@ -415,5 +424,6 @@
     dbd_sqlite3_pvselect,
     dbd_sqlite3_pquery,
     dbd_sqlite3_pselect,
+    dbd_sqlite3_get_name
 };
 #endif

Reply via email to