extended result type handling with catalog/pg_type.h
[m6w6/ext-pq] / src / php_pq_misc.c
index c1f83337b13ef6a68fc6c9cb94e5ea99921c55b4..943aa57ffce27eaee0791adf0cc89b4b8196d28e 100644 (file)
@@ -15,7 +15,7 @@
 #endif
 
 #include <php.h>
-
+#include <ext/date/php_date.h>
 #include <libpq/libpq-fs.h>
 
 #include "php_pq.h"
@@ -86,21 +86,37 @@ static int apply_to_param(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_k
        params = (char ***) va_arg(argv, char ***);
        zdtor = (HashTable *) va_arg(argv, HashTable *);
 
-       if (Z_TYPE_PP(zparam) == IS_NULL) {
+       switch (Z_TYPE_PP(zparam)) {
+       case IS_NULL:
                **params = NULL;
                ++*params;
-       } else {
-               if (Z_TYPE_PP(zparam) != IS_STRING) {
-                       convert_to_string_ex(zparam);
-               }
+               break;
+
+       case IS_BOOL:
+               **params = Z_BVAL_PP(zparam) ? "t" : "f";
+               ++*params;
+               break;
 
+       case IS_DOUBLE:
+               SEPARATE_ZVAL(zparam);
+               Z_TYPE_PP(zparam) = IS_STRING;
+               Z_STRLEN_PP(zparam) = spprintf(&Z_STRVAL_PP(zparam), 0, "%F", Z_DVAL_PP((zval **)p));
+               /* no break */
+
+       default:
+               convert_to_string_ex(zparam);
+               /* no break */
+
+       case IS_STRING:
                **params = Z_STRVAL_PP(zparam);
                ++*params;
 
                if (*zparam != *(zval **)p) {
                        zend_hash_next_index_insert(zdtor, zparam, sizeof(zval *), NULL);
                }
+               break;
        }
+
        return ZEND_HASH_APPLY_KEEP;
 }
 
@@ -158,6 +174,24 @@ Oid *php_pq_ntypes_to_array(zend_bool fill, int argc, ...)
 }
 */
 
+zval *php_pq_date_from_string(char *datetime_str, size_t datetime_len, zval *zv TSRMLS_DC)
+{
+       php_date_obj *dobj;
+
+       if (!zv) {
+               MAKE_STD_ZVAL(zv);
+       }
+
+       php_date_instantiate(php_date_get_date_ce(), zv TSRMLS_CC);
+       dobj = zend_object_store_get_object(zv TSRMLS_CC);
+       if (!php_date_initialize(dobj, datetime_str, datetime_len, NULL, NULL, 1 TSRMLS_CC)) {
+               zval_dtor(zv);
+               ZVAL_NULL(zv);
+       }
+
+       return zv;
+}
+
 /*
  * Local variables:
  * tab-width: 4