AC_MSG_ERROR(could not find include/libpq-events.h)
fi
PHP_ADD_INCLUDE($PQ_DIR/include)
+
+ ifdef([AC_PROG_EGREP], [
+ AC_PROG_EGREP
+ ], [
+ AC_CHECK_PROG(EGREP, egrep, egrep)
+ ])
+
+ for PQ_DEF in PGRES_SINGLE_TUPLE PGRES_COPY_BOTH; do
+ AC_MSG_CHECKING(for $PQ_DEF)
+ if $EGREP -q $PQ_DEF $PQ_DIR/include/libpq-fe.h; then
+ AC_DEFINE([$PQ_DEF], [1], [Have $PQ_DEF])
+ AC_MSG_RESULT(yep)
+ else
+ AC_MSG_RESULT(nope)
+ fi
+ done
- PQ_SYM=PQregisterEventProc
- PHP_CHECK_LIBRARY(pq, $PQ_SYM, [
- PHP_ADD_LIBRARY_WITH_PATH(pq, $PQ_DIR/$PHP_LIBDIR, PQ_SHARED_LIBADD)
- PHP_SUBST(PQ_SHARED_LIBADD)
- ],[
- AC_MSG_ERROR(could not find $PQ_SYM in -lpq)
- ],[
- -L$PQ_DIR/$PHP_LIBDIR
+
+ AC_DEFUN([PQ_CHECK_FUNC], [
+ FAIL_HARD=$2
+
+ PHP_CHECK_LIBRARY(pq, $1, [
+ AC_DEFINE([HAVE_]translit($1,a-z,A-Z), 1, Have $1)
+ ], [
+ if test -n "$FAIL_HARD"; then
+ if "$FAIL_HARD"; then
+ AC_MSG_ERROR(could not find $PQ_SYM in -lpq)
+ fi
+ fi
+ ], [
+ -L$PQ_DIR/$PHP_LIBDIR
+ ])
])
- PHP_CHECK_LIBRARY(pq, PQlibVersion, [AC_DEFINE(HAVE_PQLIBVERSION, 1, Have PQlibVersion)])
- PHP_CHECK_LIBRARY(pq, PQconninfo, [AC_DEFINE(HAVE_PQCONNINFO, 1, Have PQconninfo)])
+
+ PQ_CHECK_FUNC(PQregisterEventProc, true)
+ PHP_ADD_LIBRARY_WITH_PATH(pq, $PQ_DIR/$PHP_LIBDIR, PQ_SHARED_LIBADD)
+ PHP_SUBST(PQ_SHARED_LIBADD)
+
+ PQ_CHECK_FUNC(PQlibVersion)
+ PQ_CHECK_FUNC(PQconninfo)
+ PQ_CHECK_FUNC(PQsetSingleRowMode)
PQ_SRC="\
src/php_pq_module.c\
<email>mike@php.net</email>
<active>yes</active>
</lead>
- <date>2014-10-15</date>
+ <date>2014-10-16</date>
<version>
- <release>0.5.2dev</release>
+ <release>0.5.2</release>
<api>0.5.0</api>
</version>
<stability>
</stability>
<license>BSD, revised</license>
<notes><![CDATA[
+* Fix build with PostgreSQL 9.1 and 9.0
]]></notes>
<contents>
<dir name="/">
#include <php.h>
#include <ext/date/php_date.h>
#include <ext/standard/php_string.h>
-#if defined(HAVE_JSON) && !defined(COMPILE_DL_JSON)
-# include <ext/json/php_json.h>
-#endif
#include <Zend/zend_interfaces.h>
HashTable *php_pq_parse_array(php_pqres_t *res, const char *val_str, size_t val_len, Oid typ TSRMLS_DC);
+
PHP_MINIT_FUNCTION(pq_misc);
#endif
#include <php.h>
#include <ext/standard/php_string.h>
#include <ext/standard/php_smart_str.h>
+#ifdef HAVE_JSON
#include <ext/json/php_json.h>
+#endif
#include <Zend/zend_interfaces.h>
smart_str str = {0};
switch (type) {
-#ifdef PHP_PQ_OID_JSON
+#if HAVE_JSON && defined(PHP_PQ_OID_JSON)
# ifdef PHP_PQ_OID_JSONB
case PHP_PQ_OID_JSONB:
# endif
struct apply_to_param_from_array_arg arg = {NULL};
switch (type) {
-#ifdef PHP_PQ_OID_JSON
+#if HAVE_JSON && defined(PHP_PQ_OID_JSON)
# ifdef PHP_PQ_OID_JSONB
case PHP_PQ_OID_JSONB:
# endif
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;
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;
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;
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;
if (!rc) {
throw_exce(EX_IO TSRMLS_CC, "Failed to %s cursor (%s)", *action == 'f' ? "fetch from" : "move in", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+#if HAVE_PQSETSINGLEROWMODE
} else if (obj->intern->conn->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn->intern->conn)) {
throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+#endif
} else {
php_pq_callback_recurse(&obj->intern->conn->intern->onevent, &resolver TSRMLS_CC);
obj->intern->conn->intern->poller = PQconsumeInput;
#include <php.h>
#include <ext/spl/spl_iterators.h>
+#if HAVE_JSON
#include <ext/json/php_json.h>
+#endif
#include <libpq-events.h>
#include "php_pq.h"
switch (PQresultStatus(obj->intern->res)) {
case PGRES_TUPLES_OK:
+#if HAVE_PGRES_SINGLE_TUPLE
case PGRES_SINGLE_TUPLE:
+#endif
if (PQntuples(obj->intern->res) <= iter->index) {
return FAILURE;
}
php_pqdt_from_string(val, len, "Y-m-d H:i:s.uO", zv TSRMLS_CC);
break;
-#ifdef PHP_PQ_OID_JSON
+#if HAVE_JSON && defined(PHP_PQ_OID_JSON)
# ifdef PHP_PQ_OID_JSONB
case PHP_PQ_OID_JSONB:
# endif
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("BAD_RESPONSE"), PGRES_BAD_RESPONSE TSRMLS_CC);
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("NONFATAL_ERROR"), PGRES_NONFATAL_ERROR TSRMLS_CC);
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("FATAL_ERROR"), PGRES_FATAL_ERROR TSRMLS_CC);
+#ifdef HAVE_PGRES_COPY_BOTH
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("COPY_BOTH"), PGRES_COPY_BOTH TSRMLS_CC);
+#endif
+#if HAVE_PGRES_SINGLE_TUPLE
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("SINGLE_TUPLE"), PGRES_SINGLE_TUPLE TSRMLS_CC);
+#endif
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("FETCH_ARRAY"), PHP_PQRES_FETCH_ARRAY 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("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);
+#if HAVE_JSON
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_JSON"), PHP_PQRES_CONV_JSON TSRMLS_CC);
+#endif
zend_declare_class_constant_long(php_pqres_class_entry, ZEND_STRL("CONV_ALL"), PHP_PQRES_CONV_ALL TSRMLS_CC);
return SUCCESS;
if (!rc) {
throw_exce(EX_IO TSRMLS_CC, "Failed to execute statement (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+#if HAVE_PQSETSINGLEROWMODE
} else if (obj->intern->conn->intern->unbuffered && !PQsetSingleRowMode(obj->intern->conn->intern->conn)) {
throw_exce(EX_RUNTIME TSRMLS_CC, "Failed to enable unbuffered mode (%s)", PHP_PQerrorMessage(obj->intern->conn->intern->conn));
+#endif
} else {
php_pq_callback_recurse(&obj->intern->conn->intern->onevent, &resolver TSRMLS_CC);
obj->intern->conn->intern->poller = PQconsumeInput;
<?php
-define("PQ_DSN", "");
+define("PQ_DSN", "host=localhost");
--EXPECTREGEX--
Test
(WP(RP)*)+S
-3(,\d+),+4
+(2,)*3(,\d)*,4
DONE
--EXPECTREGEX--
Test
(WP(RP)*)+S
-3(,\d+),+4
+(2,)*3(,\d)*,4
(WP(RP)*)+S
-3(,\d+),+4
+(2,)*3(,\d)*,4
DONE
["numCols"]=>
int(1)
["affectedRows"]=>
- int(1)
+ int(%d)
["fetchType"]=>
int(0)
["autoConvert"]=>
["numCols"]=>
int(3)
["affectedRows"]=>
- int(1)
+ int(%d)
["fetchType"]=>
int(0)
["autoConvert"]=>
["numCols"]=>
int(2)
["affectedRows"]=>
- int(1)
+ int(%d)
["fetchType"]=>
int(0)
["autoConvert"]=>
["numCols"]=>
int(2)
["affectedRows"]=>
- int(1)
+ int(%d)
["fetchType"]=>
int(0)
["autoConvert"]=>
--TEST--
async unbuffered exec
--SKIPIF--
-<?php include "_skipif.inc"; ?>
+<?php
+include "_skipif.inc";
+defined("pq\\Result::SINGLE_TUPLE") or die("skip need pq\\Result::SINGLE_TUPLE");
+?>
--FILE--
<?php
echo "Test\n";
--SKIPIF--
<?php
include "_skipif.inc";
+_ext("json");
?>
--INI--
date.timezone=UTC
$r = array($consumer->socket);
$w = null; $e = null;
-var_dump(stream_select($r, $w, $e, NULL));
+stream_select($r, $w, $e, NULL);
$consumer->poll();
$producer->notify("other", "this should not show up");
-var_dump(stream_select($r, $w, $e, 0));
+stream_select($r, $w, $e, 0,1000);
$consumer->poll();
$producer->notify("test", "just to be sure");
$r = array($consumer->socket);
$w = null; $e = null;
-var_dump(stream_select($r, $w, $e, 0));
+stream_select($r, $w, $e, 0,1000);
$consumer->poll();
$consumer->unlisten("test");
$r = array($consumer->socket);
$w = null; $e = null;
-var_dump(stream_select($r, $w, $e, 0));
+stream_select($r, $w, $e, 0,1000);
$consumer->poll();
?>
--EXPECTF--
Test
test(%d): this is a test
-int(1)
test(%d): this is an async test
-int(0)
-int(1)
test(%d): just to be sure
-int(0)
DONE
--TEST--
unbuffered result
--SKIPIF--
-<?php include "_skipif.inc"; ?>
+<?php
+include "_skipif.inc";
+defined("pq\\Result::SINGLE_TUPLE") or die("skip need pq\\Result::SINGLE_TUPLE");
+
+?>
--FILE--
<?php
echo "Test\n";