Skip to content

Commit 2accbe3

Browse files
committed
PdoPgsql::setNoticeCallback() preferred over PDO::pgsqlSetNoticeCallback()
see php#14299
1 parent 2d177f1 commit 2accbe3

File tree

7 files changed

+53
-41
lines changed

7 files changed

+53
-41
lines changed

ext/pdo_pgsql/pdo_pgsql.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,37 @@ PHP_METHOD(PdoPgsql, getPid)
145145
pgsqlGetPid_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU);
146146
}
147147

148+
/* {{{ Sets a callback to receive DB notices (after client_min_messages has been set) */
149+
PHP_METHOD(PdoPgsql, setNoticeCallback)
150+
{
151+
zend_fcall_info fci = empty_fcall_info;
152+
zend_fcall_info_cache fcc = empty_fcall_info_cache;
153+
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "F!", &fci, &fcc)) {
154+
RETURN_THROWS();
155+
}
156+
157+
pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS);
158+
PDO_CONSTRUCT_CHECK_WITH_CLEANUP(cleanup);
159+
160+
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
161+
162+
pdo_pgsql_cleanup_notice_callback(H);
163+
164+
if (ZEND_FCC_INITIALIZED(fcc)) {
165+
H->notice_callback = emalloc(sizeof(zend_fcall_info_cache));
166+
zend_fcc_dup(H->notice_callback, &fcc);
167+
}
168+
169+
return;
170+
171+
cleanup:
172+
if (ZEND_FCC_INITIALIZED(fcc)) {
173+
zend_fcc_dtor(&fcc);
174+
}
175+
RETURN_THROWS();
176+
}
177+
/* }}} */
178+
148179
/* true global environment */
149180

150181
/* {{{ PHP_MINIT_FUNCTION */

ext/pdo_pgsql/pdo_pgsql.stub.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@ public function getNotify(int $fetchMode = PDO::FETCH_DEFAULT, int $timeoutMilli
5353

5454
public function getPid(): int {}
5555

56-
/** @implementation-alias PDO_PGSql_Ext::pgsqlSetNoticeCallback */
5756
public function setNoticeCallback(?callable $callback): void {}
5857
}

ext/pdo_pgsql/pdo_pgsql_arginfo.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static void pdo_pgsql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *i
132132
}
133133
/* }}} */
134134

135-
static void pdo_pgsql_cleanup_notice_callback(pdo_pgsql_db_handle *H) /* {{{ */
135+
void pdo_pgsql_cleanup_notice_callback(pdo_pgsql_db_handle *H) /* {{{ */
136136
{
137137
if (H->notice_callback) {
138138
zend_fcc_dtor(H->notice_callback);
@@ -1242,37 +1242,6 @@ PHP_METHOD(PDO_PGSql_Ext, pgsqlGetPid)
12421242
}
12431243
/* }}} */
12441244

1245-
/* {{{ Sets a callback to receive DB notices (after client_min_messages has been set) */
1246-
PHP_METHOD(PDO_PGSql_Ext, pgsqlSetNoticeCallback)
1247-
{
1248-
zend_fcall_info fci = empty_fcall_info;
1249-
zend_fcall_info_cache fcc = empty_fcall_info_cache;
1250-
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "F!", &fci, &fcc)) {
1251-
RETURN_THROWS();
1252-
}
1253-
1254-
pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS);
1255-
PDO_CONSTRUCT_CHECK_WITH_CLEANUP(cleanup);
1256-
1257-
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
1258-
1259-
pdo_pgsql_cleanup_notice_callback(H);
1260-
1261-
if (ZEND_FCC_INITIALIZED(fcc)) {
1262-
H->notice_callback = emalloc(sizeof(zend_fcall_info_cache));
1263-
zend_fcc_dup(H->notice_callback, &fcc);
1264-
}
1265-
1266-
return;
1267-
1268-
cleanup:
1269-
if (ZEND_FCC_INITIALIZED(fcc)) {
1270-
zend_fcc_dtor(&fcc);
1271-
}
1272-
RETURN_THROWS();
1273-
}
1274-
/* }}} */
1275-
12761245
static const zend_function_entry *pdo_pgsql_get_driver_methods(pdo_dbh_t *dbh, int kind)
12771246
{
12781247
switch (kind) {

ext/pdo_pgsql/pgsql_driver.stub.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public function pgsqlGetNotify(int $fetchMode = PDO::FETCH_DEFAULT, int $timeout
3434
/** @tentative-return-type */
3535
public function pgsqlGetPid(): int {}
3636

37-
/** @tentative-return-type */
37+
/* Do NOT add new methods here. See https://wiki.php.net/rfc/pdo_driver_specific_subclasses
38+
* Any new feature should be declared only on PdoPgsql.
39+
*/
40+
#if 1
41+
/** @implementation-alias PdoPgsql::setNoticeCallback */
3842
public function pgsqlSetNoticeCallback(?callable $callback): void {}
43+
#endif
3944
}

ext/pdo_pgsql/pgsql_driver_arginfo.h

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/pdo_pgsql/php_pdo_pgsql_int.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ enum pdo_pgsql_specific_constants {
108108
php_stream *pdo_pgsql_create_lob_stream(zval *pdh, int lfd, Oid oid);
109109
extern const php_stream_ops pdo_pgsql_lob_stream_ops;
110110

111+
void pdo_pgsql_cleanup_notice_callback(pdo_pgsql_db_handle *H);
112+
111113
void pdo_libpq_version(char *buf, size_t len);
112114
void pdo_pgsql_close_lob_streams(pdo_dbh_t *dbh);
113115

0 commit comments

Comments
 (0)