+
+static inline PGresult *relisten(PGconn *conn, const char *channel_str, size_t channel_len)
+{
+ char *quoted_channel = PQescapeIdentifier(conn, channel_str, channel_len);
+ PGresult *res = NULL;
+
+ if (quoted_channel) {
+ smart_str cmd = {0};
+
+ smart_str_appends(&cmd, "LISTEN ");
+ smart_str_appends(&cmd, quoted_channel);
+ smart_str_0(&cmd);
+
+ res = PQexec(conn, smart_str_v(&cmd));
+
+ smart_str_free(&cmd);
+ PQfreemem(quoted_channel);
+ }
+
+ return res;
+}
+
+static int apply_relisten(zval *p, int argc, va_list argv, zend_hash_key *key)
+{
+ php_pqconn_object_t *obj = va_arg(argv, php_pqconn_object_t *);
+ PGresult *res = relisten(obj->intern->conn, key->key->val, key->key->len);
+
+ if (res) {
+ php_pqres_clear(res);
+ }
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+
+static int apply_reprepare(zval *p, int argc, va_list argv, zend_hash_key *key)
+{
+ php_pqconn_object_t *obj = va_arg(argv, php_pqconn_object_t *);
+ php_pqstm_t *stm = Z_PTR_P(p);
+
+ php_pqconn_prepare(NULL, obj, stm->name, stm->query, stm->params);
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+