apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Keiner <rick_kei...@yahoo.com>
Subject Re: Dealing with types in apr_dbd
Date Mon, 18 Jul 2005 18:22:38 GMT
What would the time frame be for implementing these changes if adopted? 
I have some modifications for apr_dbd_sqlite3 and would like to have 
this implemented at the same time. But, of course, the other drivers are 
affected and that would need coordination. In fact, a more general 
question is: When will apr_dbd be part of a release?

Rick Keiner



Nick Kew <nick@webthing.com> wrote:The current apr_dbd implementation represents all
data as strings
(const char*). This is fine with pgsql, mysql and sqlite.

I'm attempting to hack up apr_dbd for oracle, and it appears altogether
less happy with this approach. So I'm contemplating replacing const char*
with an apr_dbd_datum_t, comprising an enum { string, int, etc .... } to
indicate data type and a union { string, int, etc } for the data.
That'll be something that can grow as and when someone implements
more data types.

I attach a tentative proposal (patch) for how this will affect the API.
Obviously the existing code will need to be updated accordingly
if we adopt it.

Thoughts?

Talking of oracle, I'm using the docs at
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96584/toc.htm
It sucks mightily: it's horribly self-contradictory, and in many places 
downright wrong. Anyone know of a better reference?


-- 
Nick Kew
Index: include/apr_dbd.h
===================================================================
--- include/apr_dbd.h (revision 210060)
+++ include/apr_dbd.h (working copy)
@@ -34,6 +34,20 @@
typedef struct apr_dbd_prepared_t apr_dbd_prepared_t;
#endif

+typedef struct apr_dbd_datum_t {
+ enum {
+ APR_DBD_VALUE_NULL,
+ APR_DBD_VALUE_STRING,
+ APR_DBD_VALUE_INT,
+ APR_DBD_VALUE_FLOAT
+ } type;
+ union {
+ const char* stringval;
+ long intval;
+ double floatval;
+ } value;
+} apr_dbd_datum_t;
+
typedef struct apr_dbd_driver_t {
/** name */
const char *name;
@@ -158,9 +172,10 @@
*
* @param row - row pointer
* @param col - entry number
- * @return value from the row, or NULL if col is out of bounds.
+ * @param val - entry to fill
+ * @return 0 for success, -1 for no data, +1 for general error
*/
- const char *(*get_entry)(const apr_dbd_row_t *row, int col);
+ int (*get_entry)(const apr_dbd_row_t *row, int col, apr_dbd_datum_t *val);

/** error: get current error message (if any)
*
@@ -232,7 +247,8 @@
* @return 0 for success or error code
*/
int (*pquery)(apr_pool_t *pool, apr_dbd_t *handle, int *nrows,
- apr_dbd_prepared_t *statement, int nargs, const char **args);
+ apr_dbd_prepared_t *statement, int nargs,
+ apr_dbd_datum_t **args);

/** pselect: select using a prepared statement + args
*
@@ -247,7 +263,7 @@
*/
int (*pselect)(apr_pool_t *pool, apr_dbd_t *handle,
apr_dbd_results_t **res, apr_dbd_prepared_t *statement,
- int random, int nargs, const char **args);
+ int random, int nargs, apr_dbd_datum_t **args);


} apr_dbd_driver_t;
@@ -476,11 +492,12 @@
* @param col - entry number
* @return value from the row, or NULL if col is out of bounds.
*/
-APU_DECLARE(const char*) apr_dbd_get_entry(apr_dbd_driver_t *driver,
- apr_dbd_row_t *row, int col);
+APU_DECLARE(int) apr_dbd_get_entry(apr_dbd_driver_t *driver,
+ apr_dbd_row_t *row, int col,
+ apr_dbd_datum_t *val);
#else
-#define apr_dbd_get_entry(driver,row,col) \
- (driver)->get_entry((row),(col))
+#define apr_dbd_get_entry(driver,row,col,val) \
+ (driver)->get_entry((row),(col),(val))
#endif

#ifdef DOXYGEN
@@ -557,7 +574,7 @@
APU_DECLARE(int) apr_dbd_pquery(apr_dbd_driver_t *driver, apr_pool_t *pool,
apr_dbd_t *handle, int *nrows,
apr_dbd_prepared_t *statement, int nargs,
- const char **args);
+ apr_dbd_datum_t **args);
#else
#define apr_dbd_pquery(driver,pool,handle,nrows,statement,nargs,args) \
(driver)->pquery((pool),(handle),(nrows),(statement), \
@@ -580,7 +597,7 @@
APU_DECLARE(int) apr_dbd_pselect(apr_dbd_driver_t *driver, apr_pool_t *pool,
apr_dbd_t *handle, apr_dbd_results_t **res,
apr_dbd_prepared_t *statement, int random,
- int nargs, const char **args);
+ int nargs, apr_dbd_datum_t **args);
#else
#define apr_dbd_pselect(driver,pool,handle,res,statement,random,nargs,args) \
(driver)->pselect((pool),(handle),(res),(statement), \


Mime
View raw message