mirror of
https://github.com/php/php-src.git
synced 2024-11-23 18:04:36 +08:00
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. Close GH-11041
This commit is contained in:
parent
84c185c8ba
commit
7ec8ae12c4
2
NEWS
2
NEWS
@ -124,6 +124,8 @@ PHP NEWS
|
||||
(David Carlier)
|
||||
. Added GH-9344, pipeline mode support. (David Carlier)
|
||||
. pg_cancel use thread safe PQcancel api instead. (David Carlier)
|
||||
. pg_trace new PGSQL_TRACE_SUPPRESS_TIMESTAMPS/PGSQL_TRACE_REGRESS_MODE
|
||||
contants support. (David Carlier)
|
||||
|
||||
- Phar:
|
||||
. Fix memory leak in phar_rename_archive(). (stkeke)
|
||||
|
12
UPGRADING
12
UPGRADING
@ -214,11 +214,15 @@ PHP 8.3 UPGRADE NOTES
|
||||
- PCNTL:
|
||||
. SIGINFO
|
||||
|
||||
- PGSQL:
|
||||
. PGSQL_TRACE_SUPPRESS_TIMESTAMPS.
|
||||
. PGSQL_TRACE_REGRESS_MODE.
|
||||
|
||||
- Posix:
|
||||
. POSIX_SC_ARG_MAX
|
||||
. POSIX_SC_PAGESIZE
|
||||
. POSIX_SC_NPROCESSORS_CONF
|
||||
. POSIX_SC_NPROCESSORS_ONLN
|
||||
. POSIX_SC_ARG_MAX.
|
||||
. POSIX_SC_PAGESIZE.
|
||||
. POSIX_SC_NPROCESSORS_CONF.
|
||||
. POSIX_SC_NPROCESSORS_ONLN.
|
||||
|
||||
- Sockets:
|
||||
. SO_ATTACH_REUSEPORT_CBPF (Linux only).
|
||||
|
@ -2115,13 +2115,14 @@ PHP_FUNCTION(pg_trace)
|
||||
{
|
||||
char *z_filename, *mode = "w";
|
||||
size_t z_filename_len, mode_len;
|
||||
zend_long trace_mode = 0;
|
||||
zval *pgsql_link = NULL;
|
||||
PGconn *pgsql;
|
||||
FILE *fp = NULL;
|
||||
php_stream *stream;
|
||||
pgsql_link_handle *link;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|sO!", &z_filename, &z_filename_len, &mode, &mode_len, &pgsql_link, pgsql_link_ce) == FAILURE) {
|
||||
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) {
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
@ -2147,6 +2148,19 @@ PHP_FUNCTION(pg_trace)
|
||||
}
|
||||
php_stream_auto_cleanup(stream);
|
||||
PQtrace(pgsql, fp);
|
||||
if (trace_mode > 0) {
|
||||
#ifdef PQTRACE_REGRESS_MODE
|
||||
if (!(trace_mode & (PQTRACE_SUPPRESS_TIMESTAMPS|PQTRACE_REGRESS_MODE))) {
|
||||
zend_argument_value_error(4, "must be PGSQL_TRACE_SUPPRESS_TIMESTAMPS and/or PGSQL_TRACE_REGRESS_MODE");
|
||||
RETURN_THROWS();
|
||||
} else {
|
||||
PQsetTraceFlags(pgsql, trace_mode);
|
||||
}
|
||||
#else
|
||||
zend_argument_value_error(4, "cannot set as trace is unsupported");
|
||||
RETURN_THROWS();
|
||||
#endif
|
||||
}
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
@ -412,6 +412,20 @@ namespace {
|
||||
* @cvalue PGSQL_DML_STRING
|
||||
*/
|
||||
const PGSQL_DML_STRING = UNKNOWN;
|
||||
#ifdef PQTRACE_SUPPPRESS_TIMESTAMPS
|
||||
/**
|
||||
* @var int
|
||||
* @cvalue PQTRACE_SUPPRESS_TIMESTAMPS
|
||||
*/
|
||||
const PGSQL_TRACE_SUPPRESS_TIMESTAMPS = UNKNOWN;
|
||||
#endif
|
||||
#ifdef PQTRACE_REGRESS_MODE
|
||||
/**
|
||||
* @var int
|
||||
* @cvalue PQTRACE_REGRESS_MODE
|
||||
*/
|
||||
const PGSQL_TRACE_REGRESS_MODE = UNKNOWN;
|
||||
#endif
|
||||
|
||||
#ifdef LIBPQ_HAS_PIPELINING
|
||||
/**
|
||||
@ -662,7 +676,7 @@ namespace {
|
||||
*/
|
||||
function pg_getlastoid(PgSql\Result $result): string|int|false {}
|
||||
|
||||
function pg_trace(string $filename, string $mode = "w", ?PgSql\Connection $connection = null): bool {}
|
||||
function pg_trace(string $filename, string $mode = "w", ?PgSql\Connection $connection = null, int $trace_mode = 0): bool {}
|
||||
|
||||
function pg_untrace(?PgSql\Connection $connection = null): bool {}
|
||||
|
||||
|
9
ext/pgsql/pgsql_arginfo.h
generated
9
ext/pgsql/pgsql_arginfo.h
generated
@ -1,5 +1,5 @@
|
||||
/* This is a generated file, edit the .stub.php file instead.
|
||||
* Stub hash: c4ff82a0df3e65eae3abbb8c9910978f28bf6ac4 */
|
||||
* Stub hash: f18a73443942daa2b3695e8750c8daaea6b96194 */
|
||||
|
||||
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_connect, 0, 1, PgSql\\Connection, MAY_BE_FALSE)
|
||||
ZEND_ARG_TYPE_INFO(0, connection_string, IS_STRING, 0)
|
||||
@ -198,6 +198,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_trace, 0, 1, _IS_BOOL, 0)
|
||||
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, mode, IS_STRING, 0, "\"w\"")
|
||||
ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, connection, PgSql\\Connection, 1, "null")
|
||||
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, trace_mode, IS_LONG, 0, "0")
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
#define arginfo_pg_untrace arginfo_pg_close
|
||||
@ -808,6 +809,12 @@ static void register_pgsql_symbols(int module_number)
|
||||
REGISTER_LONG_CONSTANT("PGSQL_DML_EXEC", PGSQL_DML_EXEC, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PGSQL_DML_ASYNC", PGSQL_DML_ASYNC, CONST_PERSISTENT);
|
||||
REGISTER_LONG_CONSTANT("PGSQL_DML_STRING", PGSQL_DML_STRING, CONST_PERSISTENT);
|
||||
#if defined(PQTRACE_SUPPPRESS_TIMESTAMPS)
|
||||
REGISTER_LONG_CONSTANT("PGSQL_TRACE_SUPPRESS_TIMESTAMPS", PQTRACE_SUPPRESS_TIMESTAMPS, CONST_PERSISTENT);
|
||||
#endif
|
||||
#if defined(PQTRACE_REGRESS_MODE)
|
||||
REGISTER_LONG_CONSTANT("PGSQL_TRACE_REGRESS_MODE", PQTRACE_REGRESS_MODE, CONST_PERSISTENT);
|
||||
#endif
|
||||
#if defined(LIBPQ_HAS_PIPELINING)
|
||||
REGISTER_LONG_CONSTANT("PGSQL_PIPELINE_SYNC", PGRES_PIPELINE_SYNC, CONST_PERSISTENT);
|
||||
#endif
|
||||
|
26
ext/pgsql/tests/pg_trace.phpt
Normal file
26
ext/pgsql/tests/pg_trace.phpt
Normal file
@ -0,0 +1,26 @@
|
||||
--TEST--
|
||||
pg_trace
|
||||
--EXTENSIONS--
|
||||
pgsql
|
||||
--SKIPIF--
|
||||
<?php include("skipif.inc"); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
include('config.inc');
|
||||
|
||||
$db = pg_connect($conn_str);
|
||||
$tracefile = __DIR__ . '/trace.tmp';
|
||||
|
||||
try {
|
||||
pg_trace($tracefile, 'w', $db, 56432);
|
||||
} catch (ValueError $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
var_dump(pg_trace($tracefile, 'w', $db, 0));
|
||||
$res = pg_query($db, 'select 1');
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
pg_trace(): Argument #4 ($trace_mode) cannot set as trace is unsupported
|
||||
bool(true)
|
Loading…
Reference in New Issue
Block a user