public inbox for [email protected]
help / color / mirror / Atom feedFrom: Alvaro Herrera <[email protected]>
To: Andrew Dunstan <[email protected]>
Cc: Andres Freund <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: Using LibPq in TAP tests via FFI
Date: Mon, 17 Jun 2024 11:07:19 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAD5tBcKwpcXYGbgewQDi8LzdrEZ6td-kVwHDRiirsK2M_wQSXw@mail.gmail.com>
On 2024-Jun-16, Andrew Dunstan wrote:
> +sub query_oneval
> +{
> + my $self = shift;
> + my $sql = shift;
> + my $missing_ok = shift; # default is not ok
> + my $conn = $self->{conn};
> + my $result = PQexec($conn, $sql);
> + my $ok = $result && (PQresultStatus($result) == PGRES_TUPLES_OK);
> + unless ($ok)
> + {
> + PQclear($result) if $result;
> + return undef;
> + }
> + my $ntuples = PQntuples($result);
> + return undef if ($missing_ok && !$ntuples);
> + my $nfields = PQnfields($result);
> + die "$ntuples tuples != 1 or $nfields fields != 1"
> + if $ntuples != 1 || $nfields != 1;
> + my $val = PQgetvalue($result, 0, 0);
> + if ($val eq "")
> + {
> + $val = undef if PGgetisnull($result, 0, 0);
> + }
> + PQclear($result);
> + return $val;
> +}
Hmm, here you use PGgetisnull, is that a typo for PQgetisnull? If it
is, then I wonder why doesn't this fail in some obvious way? Is this
part dead code maybe?
> +# return tuples like psql's -A -t mode.
> +
> +sub query_tuples
> +{
> + my $self = shift;
> + my @results;
> + foreach my $sql (@_)
> + {
> + my $res = $self->query($sql);
> + # join will render undef as an empty string here
> + no warnings qw(uninitialized);
> + my @tuples = map { join('|', @$_); } @{$res->{rows}};
> + push(@results, join("\n",@tuples));
> + }
> + return join("\n",@results);
> +}
You made this function join the tuples from multiple queries together,
but the output format doesn't show anything for queries that return
empty. I think this strategy doesn't cater for the case of comparing
results from multiple queries very well, because it might lead to sets
of queries that return empty result for different queries reported as
identical when they aren't. Maybe add a separator line between the
results from each query, when there's more than one? (Perhaps just
"join('--\n', @results)" in that last line does the trick?)
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
"The Postgresql hackers have what I call a "NASA space shot" mentality.
Quite refreshing in a world of "weekend drag racer" developers."
(Scott Marlowe)
view thread (2+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: Using LibPq in TAP tests via FFI
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox