Return-Path: Delivered-To: apmail-apr-dev-archive@www.apache.org Received: (qmail 79972 invoked from network); 11 Jul 2005 03:58:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 11 Jul 2005 03:58:16 -0000 Received: (qmail 22270 invoked by uid 500); 11 Jul 2005 03:58:14 -0000 Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 22220 invoked by uid 500); 11 Jul 2005 03:58:14 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Id: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 22207 invoked by uid 99); 11 Jul 2005 03:58:14 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Jul 2005 20:58:14 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [80.229.52.226] (HELO asgard.webthing.com) (80.229.52.226) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 10 Jul 2005 20:58:11 -0700 Received: from asgard (asgard [192.168.10.2]) by asgard.webthing.com (Postfix) with ESMTP id 6C10964525 for ; Mon, 11 Jul 2005 04:59:26 +0100 (BST) From: Nick Kew Organization: WebThing Ltd To: dev@apr.apache.org Subject: Dealing with types in apr_dbd Date: Mon, 11 Jul 2005 04:59:22 +0100 User-Agent: KMail/1.7.2 MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_d6e0CDkg5nVeT1k" Message-Id: <200507110459.25606.nick@webthing.com> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --Boundary-00=_d6e0CDkg5nVeT1k Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 --Boundary-00=_d6e0CDkg5nVeT1k Content-Type: text/x-diff; charset="us-ascii"; name="typed-dbd" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="typed-dbd" 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), \ --Boundary-00=_d6e0CDkg5nVeT1k--