From: Chris Wright Date: Fri, 12 Dec 2014 00:18:50 +0000 (+0000) Subject: Add $query and $types properties to Statement X-Git-Tag: v0.6.0RC1~21^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=3b0f6e8d71bc2a7c4f2649fb81ae305f93f9efc3;p=m6w6%2Fext-pq Add $query and $types properties to Statement --- diff --git a/src/php_pqstm.c b/src/php_pqstm.c index 178342a..10d5768 100644 --- a/src/php_pqstm.c +++ b/src/php_pqstm.c @@ -132,6 +132,31 @@ static void php_pqstm_object_read_connection(zval *object, void *o, zval *return php_pq_object_to_zval(obj->intern->conn, &return_value TSRMLS_CC); } +static void php_pqstm_object_read_query(zval *object, void *o, zval *return_value TSRMLS_DC) +{ + php_pqstm_object_t *obj = o; + + RETVAL_STRING(obj->intern->query, 1); +} + +static void php_pqstm_object_read_types(zval *object, void *o, zval *return_value) +{ + int i; + HashTable *ht; + php_pqstm_object_t *obj; + + obj = (php_pqstm_object_t *)o; + ht = (HashTable *)emalloc(sizeof(HashTable)); + + zend_hash_init(ht, obj->intern->params->type.count, NULL, ZVAL_PTR_DTOR, 0); + Z_TYPE_P(return_value) = IS_ARRAY; + Z_ARRVAL_P(return_value) = ht; + + for (i = 0; i < obj->intern->params->type.count; i++) { + add_next_index_long(return_value, (long)obj->intern->params->type.oids[i]); + } +} + php_pqstm_t *php_pqstm_init(php_pqconn_object_t *conn, const char *name, const char *query, php_pq_params_t *params TSRMLS_DC) { php_pqstm_t *stm = ecalloc(1, sizeof(*stm)); @@ -491,6 +516,14 @@ PHP_MINIT_FUNCTION(pqstm) ph.read = php_pqstm_object_read_connection; zend_hash_add(&php_pqstm_object_prophandlers, "connection", sizeof("connection"), (void *) &ph, sizeof(ph), NULL); + zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("query"), ZEND_ACC_PUBLIC TSRMLS_CC); + ph.read = php_pqstm_object_read_query; + zend_hash_add(&php_pqstm_object_prophandlers, "query", sizeof("query"), (void *) &ph, sizeof(ph), NULL); + + zend_declare_property_null(php_pqstm_class_entry, ZEND_STRL("types"), ZEND_ACC_PUBLIC TSRMLS_CC); + ph.read = php_pqstm_object_read_types; + zend_hash_add(&php_pqstm_object_prophandlers, "types", sizeof("types"), (void *) &ph, sizeof(ph), NULL); + return SUCCESS; } diff --git a/tests/stm_props001.phpt b/tests/stm_props001.phpt new file mode 100644 index 0000000..33a733f --- /dev/null +++ b/tests/stm_props001.phpt @@ -0,0 +1,32 @@ +--TEST-- +Statement properties +--SKIPIF-- + +--FILE-- +connection); +var_dump($n === $s->name); +var_dump($q === $s->query); +var_dump($t === $s->types); + +?> +Done +--EXPECT-- +Test +bool(true) +bool(true) +bool(true) +bool(true) +Done