]> granicus.if.org Git - php/commitdiff
Return all results as strings until I can convince the other guys that
authorArd Biesheuvel <abies@php.net>
Wed, 23 Jun 2004 13:26:09 +0000 (13:26 +0000)
committerArd Biesheuvel <abies@php.net>
Wed, 23 Jun 2004 13:26:09 +0000 (13:26 +0000)
it should be otherwise

ext/pdo_firebird/config.m4
ext/pdo_firebird/firebird_driver.c
ext/pdo_firebird/firebird_statement.c
ext/pdo_firebird/package.xml
ext/pdo_firebird/php_pdo_firebird_int.h
ext/pdo_firebird/tests/execute.phpt

index 8efbe1b60f62f56128fc96111a6d14ed1655f4bc..8af5e9b6d05076d59fa412eeb989d13928df5a1f 100644 (file)
@@ -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
     ])
index 663c250ff4d609d6788aa530732929af7bcb5152..251e80ef5f7124ed6eca91a95e1e2e280cbd10d6 100644 (file)
@@ -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) /* {{{ */
index 5e605f46d142f21a9e358e857dca3b27c35b11af..ee325453ec972a75d552b4303abafc39dbcedf2e 100644 (file)
@@ -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 */
index 7659da742bf897093c7c72e58eafd47928f36a1b..2ca18214962031d974e83e0794bc0e5993e7d750 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="iso-8859-1"?>\r
 <!DOCTYPE package SYSTEM "../pear/package.dtd">\r
-<package version="1.0"><!-- $Id: package.xml,v 1.3 2004-06-12 16:58:20 abies Exp $ -->\r
+<package version="1.0"><!-- $Id: package.xml,v 1.4 2004-06-23 13:26:08 abies Exp $ -->\r
  <name>PDO_Firebird</name>\r
  <summary>Firebird/InterBase support for PDO</summary>\r
  <maintainers>\r
 </configureoptions>\r
  <description>\r
         This extension provides a Firebird/InterBase driver for PDO. It supports\r
-        InterBase versions 6.x/7.x and Firebird 1.x.\r
+        all versions of Firebird and InterBase versions 6 and up.\r
  </description>\r
  <license>PHP</license>\r
  <release>\r
   <state>alpha</state>\r
   <version>0.1</version>\r
-  <date>2004-06-12</date>\r
+  <date>2004-06-23</date>\r
 \r
   <notes>\r
    To compile and run this module, you will need to have the main PDO module and Firebird's\r
-   client library installed on your system. (InterBase 6 or higher should work as well)\r
+   or InterBase's client library installed on your system.\r
   </notes>\r
 \r
   <filelist>\r
@@ -48,7 +48,7 @@
 \r
   </filelist>\r
   <deps>\r
-   <dep type="php" rel="ge" version="5.0.0RC3"/>\r
+   <dep type="php" rel="ge" version="5.0.0"/>\r
    <dep type="ext" rel="ge" name="pdo" version="0.1"/>\r
   </deps>\r
  </release>\r
index d037e98fb5baf8dc6fe7bd8f106d2cf6ffd95f1f..7e0e2e66a81a6d03859cb9959dd66ad7d8ab1a3d 100644 (file)
@@ -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 */
index d505156091e2eec5e263003b8331668c2cacb81a..89750483255f1e659063039ebee1b3b01295b29b 100644 (file)
@@ -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]=>