Change "tracefile" to overwrite by default, use "+" to append

It seems more convenient, even if a bit dangerous, to make overwrite the
default mode.
This commit is contained in:
Vadim Zeitlin
2025-03-06 00:41:28 +01:00
parent 3f8d4c9398
commit 0798333a8e
2 changed files with 14 additions and 3 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ session sql("postgresql://dbname=mydatabase");
The set of parameters used in the connection string for PostgreSQL is the same as accepted by the [PQconnectdb](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PQCONNECTDB) function from the `libpq` library, however in addition to standard PostgreSQL connection parameters, SOCI PostgreSQL backend accepts a couple of additional ones:
* `tracefile`: if specified, enables tracing all database activity using [PQtrace()](https://www.postgresql.org/docs/current/libpq-control.html#LIBPQ-PQTRACE) into the specified file. Note that this file is appended to if it already exists.
* `tracefile`: if specified, enables tracing all database activity using [PQtrace()](https://www.postgresql.org/docs/current/libpq-control.html#LIBPQ-PQTRACE) into the file with the given path. Note that this file is overwritten by default, prepend it with a plus sign, i.e. use `tracefile=+/path/to/file`, to append to the file instead.
* `singlerow` or `singlerows`: if set to `true` or `yes`, enables single-row mode for the session (see below).
#### Single Row Mode
+13 -2
View File
@@ -188,9 +188,20 @@ void postgresql_session_backend::connect(
single_row_mode_ = connection_parameters::is_true_value(name, value);
}
if (params.extract_option("tracefile", value))
if (params.extract_option("tracefile", value) && !value.empty())
{
traceFile_ = fopen(value.c_str(), "a");
const char* mode;
if (value.front() == '+')
{
mode = "a";
value.erase(0, 1);
}
else
{
mode = "w";
}
traceFile_ = fopen(value.c_str(), mode);
if (!traceFile_)
{
std::ostringstream oss;