PHP_ARG_WITH(pq, [whether to enable libpq (PostgreSQL) support],
[ --with-pq[=DIR] Include libpq support])
-PHP_ARG_WITH(pq-postgresql, [where to find PostgreSQL server headers],
-[ --with-pq-postgresql[=DIR] PQ: Define some standard type OIDs from catalog/pg_type.h], $PHP_PQ, no)
if test "$PHP_PQ" != "no"; then
SEARCH_PATH="/usr/local /usr /opt"
PHP_ADD_INCLUDE($ext_srcdir/src)
PHP_ADD_EXTENSION_DEP(pq, raphf)
- if test "$PHP_PQ_POSTGRESQL" != "no"; then
- if test "$PHP_PQ_POSTGRESQL" != "yes"; then
- SEARCH_PATH="$PHP_PQ_POSTGRESQL $SEARCH_PATH"
- fi
- CATALOG_PATH=""
- for i in $SEARCH_PATH; do
- CATALOG_PATH="$i/include/server/catalog/pg_type.h $CATALOG_PATH"
- CATALOG_PATH="$i/include/postgresql/server/catalog/pg_type.h $CATALOG_PATH"
- done
- for CATALOG in $CATALOG_PATH; do
- AC_MSG_CHECKING(for $CATALOG)
- if test -f "$CATALOG"; then
- AC_MSG_RESULT(yep)
- AC_PROG_AWK()
- $AWK -f $ext_srcdir/php_pq_type.awk < "$CATALOG" > $ext_srcdir/php_pq_type.h
- AC_DEFINE(HAVE_PHP_PQ_TYPE_H, 1, Have PostgreSQL type OID defs)
- break
- fi
- AC_MSG_RESULT(nope)
- done
- fi
fi
<file role="src" name="php_pq.h" />
<file role="src" name="php_pq_type.awk" />
<dir name="src">
+ <file role="src" name="php_pq_type.h" />
<file role="src" name="php_pq_callback.c" />
<file role="src" name="php_pq_callback.h" />
<file role="src" name="php_pqcancel.c" />
#define PHP_PQ_ERROR_H
#include <libpq-fe.h>
-#include "php_pqres.h"
typedef int STATUS; /* SUCCESS/FAILURE */
+#include "php_pqres.h"
+
/* TSRM morony */
#if PHP_VERSION_ID >= 50700
# define z_is_true(z) zend_is_true(z TSRMLS_CC)
#include "php_pq.h"
#include "php_pq_params.h"
+#undef PHP_PQ_TYPE
+#include "php_pq_type.h"
void php_pq_params_set_type_conv(php_pq_params_t *p, HashTable *conv)
{
case IS_ARRAY:
{
-
-#if HAVE_PHP_PQ_TYPE_H
-# undef PHP_PQ_TYPE
-# include "php_pq_type.h"
-#else
-# define PHP_PQ_TYPE_OF_ARRAY(oid) 0
-#endif
-
zval *tmp;
MAKE_STD_ZVAL(tmp);
Z_TYPE_P(tmp) = IS_STRING;
obj->intern->default_txn_deferrable = zend_is_true(value);
}
+static void php_pqconn_object_read_def_auto_conv(zval *object, void *o, zval *return_value TSRMLS_DC)
+{
+ php_pqconn_object_t *obj = o;
+
+ RETVAL_LONG(obj->intern->default_auto_convert);
+}
+static void php_pqconn_object_write_def_auto_conv(zval*object, void *o, zval *value TSRMLS_DC)
+{
+ php_pqconn_object_t *obj = o;
+ zval *zac = value;
+
+ if (Z_TYPE_P(zac) != IS_LONG) {
+ if (Z_REFCOUNT_P(zac) > 1) {
+ zval *tmp;
+ MAKE_STD_ZVAL(tmp);
+ ZVAL_ZVAL(tmp, zac, 1, 0);
+ convert_to_long(tmp);
+ zac = tmp;
+ } else {
+ convert_to_long_ex(&zac);
+ }
+ }
+
+ obj->intern->default_auto_convert = Z_LVAL_P(zac) & 0xff;
+
+ if (zac != value) {
+ zval_ptr_dtor(&zac);
+ }
+}
+
static STATUS php_pqconn_update_socket(zval *this_ptr, php_pqconn_object_t *obj TSRMLS_DC)
{
zval *zsocket, zmember;
zend_hash_apply_with_arguments(&evdata->obj->intern->listeners TSRMLS_CC, apply_unlisten, 1, evdata->obj);
/* release instance data */
- //memset(evdata, 0, sizeof(*evdata));
efree(evdata);
}
}
obj->intern = ecalloc(1, sizeof(*obj->intern));
+ obj->intern->default_auto_convert = PHP_PQRES_CONV_ALL;
+
zend_hash_init(&obj->intern->listeners, 0, NULL, (dtor_func_t) zend_hash_destroy, 0);
zend_hash_init(&obj->intern->converters, 0, NULL, ZVAL_PTR_DTOR, 0);
zend_hash_init(&obj->intern->eventhandlers, 0, NULL, (dtor_func_t) zend_hash_destroy, 0);
zend_hash_add(&php_pqconn_object_prophandlers, "defaultTransactionDeferrable", sizeof("defaultTransactionDeferrable"), (void *) &ph, sizeof(ph), NULL);
ph.write = NULL;
+ zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("defaultAutoConvert"), PHP_PQRES_CONV_ALL, ZEND_ACC_PUBLIC TSRMLS_CC);
+ ph.read = php_pqconn_object_read_def_auto_conv;
+ ph.write = php_pqconn_object_write_def_auto_conv;
+ zend_hash_add(&php_pqconn_object_prophandlers, "defaultAutoConvert", sizeof("defaultAutoConvert"), (void *) &ph, sizeof(ph), NULL);
+ ph.write = NULL;
+
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("OK"), CONNECTION_OK TSRMLS_CC);
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("BAD"), CONNECTION_BAD TSRMLS_CC);
zend_declare_class_constant_long(php_pqconn_class_entry, ZEND_STRL("STARTED"), CONNECTION_STARTED TSRMLS_CC);
unsigned default_txn_isolation:2;
unsigned default_txn_readonly:1;
unsigned default_txn_deferrable:1;
+ unsigned default_auto_convert:16;
} php_pqconn_t;
typedef struct php_pqconn_object {
#include "php_pq_object.h"
#include "php_pqexc.h"
#include "php_pqres.h"
+#undef PHP_PQ_TYPE
+#include "php_pq_type.h"
zend_class_entry *php_pqres_class_entry;
static zend_object_handlers php_pqres_object_handlers;
}
switch (typ) {
-#ifdef HAVE_PHP_PQ_TYPE_H
-# undef PHP_PQ_TYPE
-# include "php_pq_type.h"
case PHP_PQ_OID_BOOL:
if (!(res->auto_convert & PHP_PQRES_CONV_BOOL)) {
goto noconversion;
ZVAL_STRINGL(zv, val, len, 1);
}
break;
-#else
- case 16: /* BOOL */
- if (res->auto_convert & PHP_PQRES_CONV_BOOL) {
- ZVAL_BOOL(zv, *val == 't');
- break;
- }
- default:
- ZVAL_STRINGL(zv, val, len, 1);
-#endif
}
return zv;
} else {
zval *zv;
- zv = php_pq_typed_zval(&res_obj->intern->converters, PQgetvalue(res, row, c), PQgetlength(res, row, c), PQftype(res, c) TSRMLS_CC);
+ zv = php_pqres_typed_zval(res_obj->intern, PQgetvalue(res, row, c), PQgetlength(res, row, c), PQftype(res, c) TSRMLS_CC);
switch (fetch_type) {
case PHP_PQRES_FETCH_OBJECT:
zend_hash_init(&r->converters, 0, 0, ZVAL_PTR_DTOR, 0);
zend_hash_copy(&r->converters, &conn_obj->intern->converters, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+ r->auto_convert = conn_obj->intern->default_auto_convert;
r->default_fetch_type = conn_obj->intern->default_fetch_type;
php_pqres_create_object_ex(php_pqres_class_entry, r, &obj TSRMLS_CC);
}
}
+static void php_pqres_object_read_auto_conv(zval *object, void *o, zval *return_value TSRMLS_DC)
+{
+ php_pqres_object_t *obj = o;
+
+ RETVAL_LONG(obj->intern->auto_convert);
+}
+
+static void php_pqres_object_write_auto_conv(zval *object, void *o, zval *value TSRMLS_DC)
+{
+ php_pqres_object_t *obj = o;
+ zval *zauto_conv = value;
+
+ if (Z_TYPE_P(value) != IS_LONG) {
+ if (Z_REFCOUNT_P(value) > 1) {
+ zval *tmp;
+ MAKE_STD_ZVAL(tmp);
+ ZVAL_ZVAL(tmp, zauto_conv, 1, 0);
+ convert_to_long(tmp);
+ zauto_conv = tmp;
+ } else {
+ convert_to_long_ex(&zauto_conv);
+ }
+ }
+
+ obj->intern->auto_convert = Z_LVAL_P(zauto_conv);
+
+ if (zauto_conv != value) {
+ zval_ptr_dtor(&zauto_conv);
+ }
+}
+
static STATUS php_pqres_iteration(zval *this_ptr, php_pqres_object_t *obj, php_pqres_fetch_t fetch_type, zval ***row TSRMLS_DC)
{
STATUS rv;
zend_hash_add(&php_pqres_object_prophandlers, "fetchType", sizeof("fetchType"), (void *) &ph, sizeof(ph), NULL);
ph.write = NULL;
+ zend_declare_property_long(php_pqres_class_entry, ZEND_STRL("autoConvert"), PHP_PQRES_FETCH_ARRAY, ZEND_ACC_PUBLIC TSRMLS_CC);
+ ph.read = php_pqres_object_read_auto_conv;
+ ph.write = php_pqres_object_write_auto_conv;
+ zend_hash_add(&php_pqres_object_prophandlers, "autoConvert", sizeof("autoConvert"), (void *) &ph, sizeof(ph), NULL);
+ ph.write = NULL;
+
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("EMPTY_QUERY"), PGRES_EMPTY_QUERY TSRMLS_CC);
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("COMMAND_OK"), PGRES_COMMAND_OK TSRMLS_CC);
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("TUPLES_OK"), PGRES_TUPLES_OK TSRMLS_CC);
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("FETCH_ASSOC"), PHP_PQRES_FETCH_ASSOC TSRMLS_CC);
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("FETCH_OBJECT"), PHP_PQRES_FETCH_OBJECT TSRMLS_CC);
+ zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_BOOL"), PHP_PQRES_CONV_BOOL TSRMLS_CC);
+ zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_INT"), PHP_PQRES_CONV_INT TSRMLS_CC);
+ zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_FLOAT"), PHP_PQRES_CONV_FLOAT TSRMLS_CC);
+ zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_SCALAR"), PHP_PQRES_CONV_SCALAR TSRMLS_CC);
+ zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_ARRAY"), PHP_PQRES_CONV_ARRAY TSRMLS_CC);
+ zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_DATETIME"), PHP_PQRES_CONV_DATETIME TSRMLS_CC);
+ zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_ALL"), PHP_PQRES_CONV_ALL TSRMLS_CC);
+
return SUCCESS;
}
#define PHP_PQRES_H
#include "php_pqconn.h"
+
typedef enum php_pqres_fetch {
PHP_PQRES_FETCH_ARRAY,
PHP_PQRES_FETCH_ASSOC,
#define PHP_PQRES_CONV_BOOL 0x01
#define PHP_PQRES_CONV_INT 0x02
#define PHP_PQRES_CONV_FLOAT 0x04
-#define PHP_PQRES_CONV_ARRAY 0x08
-#define PHP_PQRES_CONV_DATETIME 0x10
+#define PHP_PQRES_CONV_SCALAR 0x0f
+#define PHP_PQRES_CONV_ARRAY 0x10
+#define PHP_PQRES_CONV_DATETIME 0x20
+#define PHP_PQRES_CONV_ALL 0xff
typedef struct php_pqres_iterator {
zend_object_iterator zi;
php_pqres_iterator_t *iter;
HashTable bound;
HashTable converters;
- unsigned default_fetch_type:2;
- unsigned auto_convert:6;
+ unsigned auto_convert;
+ php_pqres_fetch_t default_fetch_type;
} php_pqres_t;
typedef struct php_pqres_object {
ph.read = php_pqtypes_object_read_connection;
zend_hash_add(&php_pqtypes_object_prophandlers, "connection", sizeof("connection"), (void *) &ph, sizeof(ph), NULL);
-#ifdef HAVE_PHP_PQ_TYPE_H
# undef PHP_PQ_TYPE
# define PHP_PQ_TYPE(name, oid) zend_declare_class_constant_long(php_pqtypes_class_entry, ZEND_STRL(name), oid TSRMLS_CC);
# include "php_pq_type.h"
- zend_declare_class_constant_bool(php_pqtypes_class_entry, ZEND_STRL("DEFINED"), 1 TSRMLS_CC);
-#else
- zend_declare_class_constant_bool(php_pqtypes_class_entry, ZEND_STRL("DEFINED"), 0 TSRMLS_CC);
-#endif
return SUCCESS;
}