Skip to content

Commit b556f27

Browse files
committed
ext/pgsql: pg_trace allow to refine its trace mode via 2 new constants.
- PGSQL_TRACE_SUPPRESS_TIMESTAMPS. - PGSQL_TRACE_REGRESS_MODE to have a more verbose and observable output to check possible regressions.
1 parent 6c532df commit b556f27

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

ext/pgsql/pgsql.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -2115,13 +2115,14 @@ PHP_FUNCTION(pg_trace)
21152115
{
21162116
char *z_filename, *mode = "w";
21172117
size_t z_filename_len, mode_len;
2118+
zend_long trace_mode = 0;
21182119
zval *pgsql_link = NULL;
21192120
PGconn *pgsql;
21202121
FILE *fp = NULL;
21212122
php_stream *stream;
21222123
pgsql_link_handle *link;
21232124

2124-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|sO!", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link, pgsql_link_ce) == FAILURE) {
2125+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|sO!l", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link, pgsql_link_ce, &trace_mode) == FAILURE) {
21252126
RETURN_THROWS();
21262127
}
21272128

@@ -2147,6 +2148,13 @@ PHP_FUNCTION(pg_trace)
21472148
}
21482149
php_stream_auto_cleanup(stream);
21492150
PQtrace(pgsql, fp);
2151+
if (trace_mode > 0) {
2152+
if (trace_mode > (PQTRACE_SUPPRESS_TIMESTAMPS|PQTRACE_REGRESS_MODE)) {
2153+
php_error_docref(NULL, E_WARNING, "Trace mode is invalid");
2154+
} else {
2155+
PQsetTraceFlags(pgsql, trace_mode);
2156+
}
2157+
}
21502158
RETURN_TRUE;
21512159
}
21522160
/* }}} */

ext/pgsql/pgsql.stub.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,16 @@
412412
* @cvalue PGSQL_DML_STRING
413413
*/
414414
const PGSQL_DML_STRING = UNKNOWN;
415+
/**
416+
* @var int
417+
* @cvalue PQTRACE_SUPPRESS_TIMESTAMPS
418+
*/
419+
const PGSQL_TRACE_SUPPRESS_TIMESTAMPS = UNKNOWN;
420+
/**
421+
* @var int
422+
* @cvalue PQTRACE_REGRESS_MODE
423+
*/
424+
const PGSQL_TRACE_REGRESS_MODE = UNKNOWN;
415425

416426
function pg_connect(string $connection_string, int $flags = 0): PgSql\Connection|false {}
417427

@@ -639,7 +649,7 @@ function pg_last_oid(PgSql\Result $result): string|int|false {}
639649
*/
640650
function pg_getlastoid(PgSql\Result $result): string|int|false {}
641651

642-
function pg_trace(string $filename, string $mode = "w", ?PgSql\Connection $connection = null): bool {}
652+
function pg_trace(string $filename, string $mode = "w", ?PgSql\Connection $connection = null, int $trace_mode = 0): bool {}
643653

644654
function pg_untrace(?PgSql\Connection $connection = null): bool {}
645655

ext/pgsql/pgsql_arginfo.h

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)