Skip to content

Commit 57b8e39

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 57b8e39

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

ext/pgsql/pgsql.c

Lines changed: 13 additions & 1 deletion
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,17 @@ PHP_FUNCTION(pg_trace)
21472148
}
21482149
php_stream_auto_cleanup(stream);
21492150
PQtrace(pgsql, fp);
2151+
if (trace_mode > 0) {
2152+
#ifdef PQTRACE_REGRESS_MODE
2153+
if (trace_mode > (PQTRACE_SUPPRESS_TIMESTAMPS|PQTRACE_REGRESS_MODE)) {
2154+
zend_argument_value_error(2, "must be PGSQL_TRACE_SUPPRESS_TIMESTAMPS and/or PGSQL_TRACE_REGRESS_MODE");
2155+
} else {
2156+
PQsetTraceFlags(pgsql, trace_mode);
2157+
}
2158+
#else
2159+
zend_argument_value_error(2, "cannot set the trace mode as it's unsupported");
2160+
#endif
2161+
}
21502162
RETURN_TRUE;
21512163
}
21522164
/* }}} */

ext/pgsql/pgsql.stub.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,20 @@
412412
* @cvalue PGSQL_DML_STRING
413413
*/
414414
const PGSQL_DML_STRING = UNKNOWN;
415+
#ifdef PQTRACE_SUPPPRESS_TIMESTAMPS
416+
/**
417+
* @var int
418+
* @cvalue PQTRACE_SUPPRESS_TIMESTAMPS
419+
*/
420+
const PGSQL_TRACE_SUPPRESS_TIMESTAMPS = UNKNOWN;
421+
#endif
422+
#ifdef PQTRACE_REGRESS_MODE
423+
/**
424+
* @var int
425+
* @cvalue PQTRACE_REGRESS_MODE
426+
*/
427+
const PGSQL_TRACE_REGRESS_MODE = UNKNOWN;
428+
#endif
415429

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

@@ -639,7 +653,7 @@ function pg_last_oid(PgSql\Result $result): string|int|false {}
639653
*/
640654
function pg_getlastoid(PgSql\Result $result): string|int|false {}
641655

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

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

ext/pgsql/pgsql_arginfo.h

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

0 commit comments

Comments
 (0)