From 391cbac1f2dd9f1c82102a1dcc5ec17c628eb118 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Wed, 23 Jun 2004 13:26:09 +0000 Subject: [PATCH] Return all results as strings until I can convince the other guys that it should be otherwise --- ext/pdo_firebird/config.m4 | 6 +-- ext/pdo_firebird/firebird_driver.c | 7 +-- ext/pdo_firebird/firebird_statement.c | 67 ++++++++++++++++++------- ext/pdo_firebird/package.xml | 10 ++-- ext/pdo_firebird/php_pdo_firebird_int.h | 4 ++ ext/pdo_firebird/tests/execute.phpt | 4 +- 6 files changed, 67 insertions(+), 31 deletions(-) diff --git a/ext/pdo_firebird/config.m4 b/ext/pdo_firebird/config.m4 index 8efbe1b60f..8af5e9b6d0 100644 --- a/ext/pdo_firebird/config.m4 +++ b/ext/pdo_firebird/config.m4 @@ -19,11 +19,11 @@ if test "$PHP_PDO_FIREBIRD" != "no"; then [ FIREBIRD_LIBNAME=gds ], [ - PHP_CHECK_LIBRARY(fbclient, isc_detach_database, + PHP_CHECK_LIBRARY(ib_util, isc_detach_database, [ - FIREBIRD_LIBNAME=fbclient + FIREBIRD_LIBNAME=ib_util ], [ - AC_MSG_ERROR([libgds or libfbclient not found! Check config.log for more information.]) + AC_MSG_ERROR([libgds or libib_util not found! Check config.log for more information.]) ], [ -L$FIREBIRD_LIBDIR ]) diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c index 663c250ff4..251e80ef5f 100644 --- a/ext/pdo_firebird/firebird_driver.c +++ b/ext/pdo_firebird/firebird_driver.c @@ -372,7 +372,7 @@ static int firebird_handle_rollback(pdo_dbh_t *dbh TSRMLS_DC) /* {{{ */ /* }}} */ /* used by prepare and exec to allocate a statement handle and prepare the SQL */ -static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, long sql_len, +static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, long sql_len, /* {{{ */ XSQLDA *out_sqlda, isc_stmt_handle *s, HashTable *named_params TSRMLS_DC) { pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; @@ -419,14 +419,14 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, long sql } } else { if ((in_param &= (sql[l] == '_') || (sql[l] >= 'A' && sql[l] <= 'Z') - || (sql[l] >= 'a' && sql[l] <= 'z') || (sql[l] >= '0' && sql[l] <= '9'))) { + || (sql[l] >= 'a' && sql[l] <= 'z') || (sql[l] >= '0' && sql[l] <= '9'))) { *ppname++ = sql[l]; continue; } else { *ppname++ = 0; if (named_params) { zend_hash_update(named_params, pname, (unsigned int)(ppname-pname), - (void*)&pindex, sizeof(long),NULL); + (void*)&pindex, sizeof(long)+1,NULL); } } } @@ -444,6 +444,7 @@ static int firebird_alloc_prepare_stmt(pdo_dbh_t *dbh, const char *sql, long sql efree(new_sql); return 1; } +/* }}} */ /* called by PDO to set a driver-specific dbh attribute */ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC) /* {{{ */ diff --git a/ext/pdo_firebird/firebird_statement.c b/ext/pdo_firebird/firebird_statement.c index 5e605f46d1..ee325453ec 100644 --- a/ext/pdo_firebird/firebird_statement.c +++ b/ext/pdo_firebird/firebird_statement.c @@ -56,7 +56,7 @@ static int firebird_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ int result = 1, i; /* release the statement */ - if (*S->name && isc_dsql_free_statement(S->H->isc_status, &S->stmt, DSQL_drop)) { + if (isc_dsql_free_statement(S->H->isc_status, &S->stmt, DSQL_drop)) { RECORD_ERROR(stmt); result = 0; } @@ -69,6 +69,9 @@ static int firebird_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */ } efree(S->fetch_buf); + zend_hash_destroy(S->named_params); + FREE_HASHTABLE(S->named_params); + /* clean up the input descriptor */ if (S->in_sqlda) { free_sqlda(S->in_sqlda); @@ -171,6 +174,7 @@ static int firebird_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC) /* {{{ } /* }}} */ +#if abies_0 /* internal function to override return types of parameters */ static void set_param_type(enum pdo_param_type *param_type, XSQLVAR const *var) /* {{{ */ { @@ -194,18 +198,17 @@ static void set_param_type(enum pdo_param_type *param_type, XSQLVAR const *var) case SQL_BLOB: *param_type = PDO_PARAM_STR; break; -#if abies_0 case SQL_FLOAT: case SQL_DOUBLE: *param_type = PDO_PARAM_DBL; break; -#endif } } /* }}} */ +#endif -#define FETCH_BUF(buf,type,len) ((buf) = (buf) ? (buf) : \ - emalloc((len) ? (len * sizeof(type)) : ((len) = sizeof(type)))) +#define FETCH_BUF(buf,type,len,lenvar) ((buf) = (buf) ? (buf) : \ + emalloc((len) ? (len * sizeof(type)) : ((*(unsigned long*)lenvar) = sizeof(type)))) /* fetch a blob into a fetch buffer */ static int firebird_fetch_blob(pdo_stmt_t *stmt, int colno, char **ptr, /* {{{ */ @@ -214,7 +217,7 @@ static int firebird_fetch_blob(pdo_stmt_t *stmt, int colno, char **ptr, /* {{{ * pdo_firebird_stmt *S = (pdo_firebird_stmt*)stmt->driver_data; pdo_firebird_db_handle *H = S->H; isc_blob_handle blobh = NULL; - static char const bl_items[] = { isc_info_blob_total_length }; + char const bl_item = isc_info_blob_total_length; char bl_info[20]; unsigned short i; int result = *len = 0; @@ -224,7 +227,7 @@ static int firebird_fetch_blob(pdo_stmt_t *stmt, int colno, char **ptr, /* {{{ * return 0; } - if (isc_blob_info(H->isc_status, &blobh, sizeof(bl_items), const_cast(bl_items), + if (isc_blob_info(H->isc_status, &blobh, 1, const_cast(&bl_item), sizeof(bl_info), bl_info)) { RECORD_ERROR(stmt); goto fetch_blob_end; @@ -283,6 +286,7 @@ fetch_blob_end: } return result; } +/* }}} */ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{{ */ unsigned long *len TSRMLS_DC) @@ -296,7 +300,8 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{ *len = 0; } else { /* override the column param type */ - set_param_type(&stmt->columns[colno].param_type,var); + /* set_param_type(&stmt->columns[colno].param_type,var); */ + stmt->columns[colno].param_type = PDO_PARAM_STR; if (var->sqlscale < 0) { static ISC_INT64 const scales[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, @@ -316,8 +321,7 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{ n = *(ISC_INT64*)var->sqldata; } - *len = 24; - *ptr = FETCH_BUF(S->fetch_buf[colno], char, *len); + *ptr = FETCH_BUF(S->fetch_buf[colno], char, 24, NULL); if (n >= 0) { *len = sprintf(*ptr, "%" LL_MASK "d.%0*" LL_MASK "d", @@ -332,6 +336,11 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{ switch (var->sqltype & ~1) { struct tm t; char *fmt; + +/** +* For the time being, this code has been changed to convert every returned value to a string +* before passing it back up to the PDO driver. +*/ case SQL_VARYING: *ptr = &var->sqldata[2]; @@ -341,13 +350,36 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{ *ptr = var->sqldata; *len = var->sqllen; break; +// --- cut here --- case SQL_SHORT: - *ptr = FETCH_BUF(S->fetch_buf[colno], long, *len); + *ptr = FETCH_BUF(S->fetch_buf[colno], char, 24, NULL); + *len = sprintf(*ptr, "%d", *(short*)var->sqldata); + break; + case SQL_LONG: + *ptr = FETCH_BUF(S->fetch_buf[colno], char, 24, NULL); + *len = sprintf(*ptr, "%ld", *(ISC_LONG*)var->sqldata); + break; + case SQL_INT64: + *ptr = FETCH_BUF(S->fetch_buf[colno], char, 24, NULL); + *len = sprintf(*ptr, "%" LL_MASK "d", *(ISC_INT64*)var->sqldata); + break; + case SQL_FLOAT: + *ptr = FETCH_BUF(S->fetch_buf[colno], char, 24, NULL); + *len = sprintf(*ptr, "%f", *(float*)var->sqldata); + break; + case SQL_DOUBLE: + *ptr = FETCH_BUF(S->fetch_buf[colno], char, 24, NULL); + *len = sprintf(*ptr, "%f" , *(double*)var->sqldata); + break; +// --- cut here --- +#if abies_0 + case SQL_SHORT: + *ptr = FETCH_BUF(S->fetch_buf[colno], long, 0, *len); *(long*)*ptr = *(short*)var->sqldata; break; case SQL_LONG: #if SIZEOF_LONG == 8 - *ptr = FETCH_BUF(S->fetch_buf[colno], long, *len); + *ptr = FETCH_BUF(S->fetch_buf[colno], long, 0, *len); *(long*)*ptr = *(ISC_LONG*)var->sqldata; #else *ptr = var->sqldata; @@ -358,19 +390,19 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{ #if SIZEOF_LONG == 8 *ptr = var->sqldata; #else - *len = 20; - *ptr = FETCH_BUF(S->fetch_buf[colno], char, *len); + *ptr = FETCH_BUF(S->fetch_buf[colno], char, 20, NULL); *len = sprintf(*ptr, "%" LL_MASK "d", *(ISC_INT64*)var->sqldata); #endif break; case SQL_FLOAT: - *ptr = FETCH_BUF(S->fetch_buf[colno], double, *len); + *ptr = FETCH_BUF(S->fetch_buf[colno], double, 0, *len); *(double*)*ptr = *(float*)var->sqldata; break; case SQL_DOUBLE: *ptr = var->sqldata; *len = sizeof(double); break; +#endif case SQL_TYPE_DATE: isc_decode_sql_date((ISC_DATE*)var->sqldata, &t); fmt = INI_STR("ibase.dateformat"); @@ -385,8 +417,7 @@ static int firebird_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, /* {{ } /* convert the timestamp into a string */ - *len = 80; /* TODO enough ? */ - *ptr = FETCH_BUF(S->fetch_buf[colno], char, *len); + *ptr = FETCH_BUF(S->fetch_buf[colno], char, *len = 80, NULL); *len = strftime(*ptr, *len, fmt, &t); break; case SQL_BLOB: @@ -458,7 +489,7 @@ static int firebird_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_dat long *index; /* try to determine the index by looking in the named_params hash */ - if (SUCCESS == zend_hash_find(S->named_params, param->name, param->namelen+1, &index)) { + if (SUCCESS == zend_hash_find(S->named_params, param->name, param->namelen+1, (void*)&index)) { param->paramno = *index; } else { /* ... or by looking in the input descriptor */ diff --git a/ext/pdo_firebird/package.xml b/ext/pdo_firebird/package.xml index 7659da742b..2ca1821496 100644 --- a/ext/pdo_firebird/package.xml +++ b/ext/pdo_firebird/package.xml @@ -1,6 +1,6 @@ - + PDO_Firebird Firebird/InterBase support for PDO @@ -16,17 +16,17 @@ This extension provides a Firebird/InterBase driver for PDO. It supports - InterBase versions 6.x/7.x and Firebird 1.x. + all versions of Firebird and InterBase versions 6 and up. PHP alpha 0.1 - 2004-06-12 + 2004-06-23 To compile and run this module, you will need to have the main PDO module and Firebird's - client library installed on your system. (InterBase 6 or higher should work as well) + or InterBase's client library installed on your system. @@ -48,7 +48,7 @@ - + diff --git a/ext/pdo_firebird/php_pdo_firebird_int.h b/ext/pdo_firebird/php_pdo_firebird_int.h index d037e98fb5..7e0e2e66a8 100644 --- a/ext/pdo_firebird/php_pdo_firebird_int.h +++ b/ext/pdo_firebird/php_pdo_firebird_int.h @@ -55,6 +55,10 @@ typedef void (__stdcall *info_func_t)(char*); typedef void (*info_func_t)(char*); #endif +#ifndef min +#define min(a,b) ((a)<(b)?(a):(b)) +#endif + typedef struct { /* the result of the last API call */ diff --git a/ext/pdo_firebird/tests/execute.phpt b/ext/pdo_firebird/tests/execute.phpt index d505156091..8975048325 100644 --- a/ext/pdo_firebird/tests/execute.phpt +++ b/ext/pdo_firebird/tests/execute.phpt @@ -47,9 +47,9 @@ bool(true) int(1) array(6) { ["ID"]=> - int(1) + string(1) "1" [0]=> - int(1) + string(1) "1" ["TEXT"]=> string(3) "bla" [1]=> -- 2.40.0