X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-pq;a=blobdiff_plain;f=src%2Fphp_pqconn.c;h=dd08ced5170743dddc3d608dccf68f9f949887a6;hp=573a49ea8f229923590a477bd72b8c814245b89f;hb=da7b5981c5ae28504434c492d468913645111d66;hpb=420e6ed4b6b95cf25985aed5dc6ddec06e823e41 diff --git a/src/php_pqconn.c b/src/php_pqconn.c index 573a49e..dd08ced 100644 --- a/src/php_pqconn.c +++ b/src/php_pqconn.c @@ -301,6 +301,27 @@ static void php_pqconn_object_read_port(zval *object, void *o, zval *return_valu } } +#if HAVE_PQCONNINFO +static void php_pqconn_object_read_params(zval *object, void *o, zval *return_value TSRMLS_DC) +{ + php_pqconn_object_t *obj = o; + PQconninfoOption *ptr, *params = PQconninfo(obj->intern->conn); + + array_init(return_value); + + if (params) { + for (ptr = params; ptr->keyword; ++ptr) { + if (ptr->val) { + add_assoc_string(return_value, ptr->keyword, ptr->val, 1); + } else { + add_assoc_null(return_value, ptr->keyword); + } + } + PQconninfoFree(params); + } +} +#endif + static void php_pqconn_object_read_options(zval *object, void *o, zval *return_value TSRMLS_DC) { php_pqconn_object_t *obj = o; @@ -573,7 +594,7 @@ static inline PGresult *unlisten(PGconn *conn, const char *channel_str, size_t c static int apply_unlisten(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key) { php_pqconn_object_t *obj = va_arg(argv, php_pqconn_object_t *); - PGresult *res = unlisten(obj->intern->conn, key->arKey, key->nKeyLength - 1); + PGresult *res = unlisten(obj->intern->conn, key->arKey, key->nKeyLength - 1 TSRMLS_CC); if (res) { PHP_PQclear(res); @@ -758,7 +779,7 @@ static PHP_METHOD(pqconn, unlisten) if (!obj->intern) { throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized"); } else if (SUCCESS == zend_hash_del(&obj->intern->listeners, channel_str, channel_len + 1)) { - PGresult *res = unlisten(obj->intern->conn, channel_str, channel_len); + PGresult *res = unlisten(obj->intern->conn, channel_str, channel_len TSRMLS_CC); if (res) { php_pqres_success(res TSRMLS_CC); @@ -1112,8 +1133,10 @@ static PHP_METHOD(pqconn, execAsync) { throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized"); } else if (!PQsendQuery(obj->intern->conn, query_str)) { throw_exce(EX_IO TSRMLS_CC, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->intern->conn)); +#if HAVE_PQSETSINGLEROWMODE } else if (obj->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn)) { throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn)); +#endif } else { php_pq_callback_recurse(&obj->intern->onevent, &resolver TSRMLS_CC); obj->intern->poller = PQconsumeInput; @@ -1201,8 +1224,10 @@ static PHP_METHOD(pqconn, execParamsAsync) { if (!rc) { throw_exce(EX_IO TSRMLS_CC, "Failed to execute query (%s)", PHP_PQerrorMessage(obj->intern->conn)); +#if HAVE_PQSETSINGLEROWMODE } else if (obj->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn)) { throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn)); +#endif } else { php_pq_callback_recurse(&obj->intern->onevent, &resolver TSRMLS_CC); obj->intern->poller = PQconsumeInput; @@ -1289,9 +1314,11 @@ STATUS php_pqconn_prepare_async(zval *object, php_pqconn_object_t *obj, const ch if (!PQsendPrepare(obj->intern->conn, name, query, params->type.count, params->type.oids)) { rv = FAILURE; throw_exce(EX_IO TSRMLS_CC, "Failed to prepare statement (%s)", PHP_PQerrorMessage(obj->intern->conn)); +#if HAVE_PQSETSINGLEROWMODE } else if (obj->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn)) { rv = FAILURE; throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn)); +#endif } else { rv = SUCCESS; obj->intern->poller = PQconsumeInput; @@ -1343,24 +1370,6 @@ static PHP_METHOD(pqconn, prepareAsync) { } } -static inline char *declare_str(const char *name_str, size_t name_len, unsigned flags, const char *query_str, size_t query_len) -{ - size_t decl_len = name_len + query_len + sizeof("DECLARE BINARY INSENSITIVE NO SCROLL CURSOR WITHOUT HOLD FOR "); - char *decl_str; - - decl_str = emalloc(decl_len); - decl_len = slprintf(decl_str, decl_len, "DECLARE %s %s %s %s CURSOR %s FOR %s", - name_str, - (flags & PHP_PQ_DECLARE_BINARY) ? "BINARY" : "", - (flags & PHP_PQ_DECLARE_INSENSITIVE) ? "INSENSITIVE" : "", - (flags & PHP_PQ_DECLARE_NO_SCROLL) ? "NO SCROLL" : - (flags & PHP_PQ_DECLARE_SCROLL) ? "SCROLL" : "", - (flags & PHP_PQ_DECLARE_WITH_HOLD) ? "WITH HOLD" : "", - query_str - ); - return decl_str; -} - STATUS php_pqconn_declare(zval *object, php_pqconn_object_t *obj, const char *decl TSRMLS_DC) { PGresult *res; @@ -1406,7 +1415,7 @@ static PHP_METHOD(pqconn, declare) { if (!obj->intern) { throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized"); } else { - char *decl = declare_str(name_str, name_len, flags, query_str, query_len); + char *decl = php_pqcur_declare_str(name_str, name_len, flags, query_str, query_len); if (SUCCESS != php_pqconn_declare(getThis(), obj, decl TSRMLS_CC)) { efree(decl); @@ -1437,9 +1446,11 @@ STATUS php_pqconn_declare_async(zval *object, php_pqconn_object_t *obj, const ch if (!PQsendQuery(obj->intern->conn, decl)) { rv = FAILURE; throw_exce(EX_IO TSRMLS_CC, "Failed to declare cursor (%s)", PHP_PQerrorMessage(obj->intern->conn)); +#if HAVE_PQSETSINGLEROWMODE } else if (obj->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn)) { rv = FAILURE; throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn)); +#endif } else { rv = SUCCESS; obj->intern->poller = PQconsumeInput; @@ -1471,7 +1482,7 @@ static PHP_METHOD(pqconn, declareAsync) { if (!obj->intern) { throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized"); } else { - char *decl = declare_str(name_str, name_len, flags, query_str, query_len); + char *decl = php_pqcur_declare_str(name_str, name_len, flags, query_str, query_len); if (SUCCESS != php_pqconn_declare_async(getThis(), obj, decl TSRMLS_CC)) { efree(decl); @@ -1989,7 +2000,7 @@ PHP_MINIT_FUNCTION(pqconn) php_pqconn_object_handlers.get_properties = php_pq_object_properties; php_pqconn_object_handlers.get_debug_info = php_pq_object_debug_info; - zend_hash_init(&php_pqconn_object_prophandlers, 19, NULL, NULL, 1); + zend_hash_init(&php_pqconn_object_prophandlers, 20, NULL, NULL, 1); zend_declare_property_long(php_pqconn_class_entry, ZEND_STRL("status"), CONNECTION_BAD, ZEND_ACC_PUBLIC TSRMLS_CC); ph.read = php_pqconn_object_read_status; @@ -2043,6 +2054,12 @@ PHP_MINIT_FUNCTION(pqconn) ph.read = php_pqconn_object_read_port; zend_hash_add(&php_pqconn_object_prophandlers, "port", sizeof("port"), (void *) &ph, sizeof(ph), NULL); +#if HAVE_PQCONNINFO + zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("params"), ZEND_ACC_PUBLIC TSRMLS_CC); + ph.read = php_pqconn_object_read_params; + zend_hash_add(&php_pqconn_object_prophandlers, "params", sizeof("params"), (void *) &ph, sizeof(ph), NULL); +#endif + zend_declare_property_null(php_pqconn_class_entry, ZEND_STRL("options"), ZEND_ACC_PUBLIC TSRMLS_CC); ph.read = php_pqconn_object_read_options; zend_hash_add(&php_pqconn_object_prophandlers, "options", sizeof("options"), (void *) &ph, sizeof(ph), NULL);