Hopefully, this should be the correct lot of patches (I said that
before, didn't I :-). Once that memory allocation business with SQLite3
column names gets fixed (see previous patches), things are much simpler
and there is really no need for the bogus pool argument.
PS. Apologies for so many iterations. I'm kind of learning the
internals of both the database APIs and DBD as I'm trying to implement
this, so bear with me.
--
Bojan
--- apr-util-vanilla/include/apr_dbd.h 2006-02-14 21:14:07.000000000 +1100
+++ apr-util/include/apr_dbd.h 2006-02-24 06:28:16.000000000 +1100
@@ -220,6 +220,16 @@
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 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_dbd_results_t *res, int col);
+
/** apr_dbd_error: get current error message (if any)
*
* @param driver - the driver
--- apr-util-vanilla/include/private/apr_dbd_internal.h 2006-02-14 21:14:07.000000000 +1100
+++ apr-util/include/private/apr_dbd_internal.h 2006-02-24 06:28:36.000000000 +1100
@@ -246,6 +246,14 @@
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 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)(const apr_dbd_results_t *res, int col);
+
};
/* Export mutex lock/unlock for drivers that need it */
--- apr-util-vanilla/dbd/apr_dbd.c 2006-02-14 21:14:08.000000000 +1100
+++ apr-util/dbd/apr_dbd.c 2006-02-24 06:28:25.000000000 +1100
@@ -238,6 +238,11 @@
{
return driver->num_tuples(res);
}
+APU_DECLARE(const char*) apr_dbd_get_name(const apr_dbd_driver_t *driver,
+ apr_dbd_results_t *res, int col)
+{
+ return driver->get_name(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-util-vanilla/dbd/apr_dbd_mysql.c.vanilla 2006-02-24 08:46:16.000000000 +1100
+++ apr-util/dbd/apr_dbd_mysql.c 2006-02-24 11:05:39.000000000 +1100
@@ -115,6 +115,16 @@
}
return ret;
}
+
+static const char *dbd_mysql_get_name(const apr_dbd_results_t *res, int n)
+{
+ if ((n < 0) || (n >= mysql_num_fields(res->res))) {
+ return NULL;
+ }
+
+ return mysql_fetch_fields(res->res)[n].name;
+}
+
static int dbd_mysql_get_row(apr_pool_t *pool, apr_dbd_results_t *res,
apr_dbd_row_t **row, int rownum)
{
@@ -666,6 +676,7 @@
dbd_mysql_pvselect,
dbd_mysql_pquery,
dbd_mysql_pselect,
+ dbd_mysql_get_name
};
#endif
--- apr-util-vanilla/dbd/apr_dbd_pgsql.c 2006-02-14 21:14:08.000000000 +1100
+++ apr-util/dbd/apr_dbd_pgsql.c 2006-02-24 06:28:02.000000000 +1100
@@ -116,6 +116,11 @@
return 0;
}
+static const char *dbd_pgsql_get_name(const apr_dbd_results_t *res, int n)
+{
+ return (res->res ? PQfname(res->res, n) : NULL);
+}
+
static int dbd_pgsql_get_row(apr_pool_t *pool, apr_dbd_results_t *res,
apr_dbd_row_t **rowp, int rownum)
{
@@ -640,5 +645,6 @@
dbd_pgsql_pvselect,
dbd_pgsql_pquery,
dbd_pgsql_pselect,
+ dbd_pgsql_get_name
};
#endif
--- apr-util-vanilla/dbd/apr_dbd_sqlite2.c 2006-02-14 21:14:08.000000000 +1100
+++ apr-util/dbd/apr_dbd_sqlite2.c 2006-02-24 06:28:02.000000000 +1100
@@ -114,6 +114,15 @@
return ret;
}
+static const char *dbd_sqlite_get_name(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
--- apr-util-vanilla/dbd/apr_dbd_sqlite3.c 2006-02-14 21:14:08.000000000 +1100
+++ apr-util/dbd/apr_dbd_sqlite3.c 2006-02-24 06:28:02.000000000 +1100
@@ -177,6 +179,15 @@
return ret;
}
+static const char *dbd_sqlite3_get_name(const apr_dbd_results_t *res, int n)
+{
+ if ((n < 0) || (n >= res->sz)) {
+ return NULL;
+ }
+
+ return 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 +426,6 @@
dbd_sqlite3_pvselect,
dbd_sqlite3_pquery,
dbd_sqlite3_pselect,
+ dbd_sqlite3_get_name
};
#endif