guard against uninitialized property write, too
[m6w6/ext-pq] / src / php_pqconn.c
index 2588d42f0fb09d9739f072bce180503b7630bb70..c4d6c806341de53295bfec4bc1a2578144a732be 100644 (file)
@@ -219,7 +219,7 @@ static void php_pqconn_object_write_encoding(zval *object, void *o, zval *value
        }
 
        if (0 > PQsetClientEncoding(obj->intern->conn, Z_STRVAL_P(zenc))) {
-               zend_error(E_NOTICE, "Unrecognized encoding '%s'", Z_STRVAL_P(zenc));
+               php_error(E_NOTICE, "Unrecognized encoding '%s'", Z_STRVAL_P(zenc));
        }
 
        if (zenc != value) {
@@ -372,7 +372,7 @@ static void php_pqconn_object_write_def_fetch_type(zval *object, void *o, zval *
                }
        }
 
-       obj->intern->default_fetch_type = Z_LVAL_P(zft) & 0x2; /* two bits only */
+       obj->intern->default_fetch_type = Z_LVAL_P(zft) & 0x3; /* two bits only */
 
        if (zft != value) {
                zval_ptr_dtor(&zft);
@@ -402,7 +402,7 @@ static void php_pqconn_object_write_def_txn_isolation(zval *object, void *o, zva
                }
        }
 
-       obj->intern->default_txn_isolation = Z_LVAL_P(zti) & 0x2; /* two bits only */
+       obj->intern->default_txn_isolation = Z_LVAL_P(zti) & 0x3; /* two bits only */
 
        if (zti != value) {
                zval_ptr_dtor(&zti);
@@ -541,7 +541,12 @@ php_resource_factory_ops_t *php_pqconn_get_resource_factory_ops(void)
 
 static void php_pqconn_wakeup(php_persistent_handle_factory_t *f, void **handle TSRMLS_DC)
 {
-       // FIXME: ping server
+       PGresult *res = PQexec(*handle, "");
+       PHP_PQclear(res);
+
+       if (CONNECTION_OK != PQstatus(*handle)) {
+               PQreset(*handle);
+       }
 }
 
 static inline PGresult *unlisten(PGconn *conn, const char *channel_str, size_t channel_len TSRMLS_DC)