Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJ8Kr-002Z5T-1M for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Jun 2024 09:07:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sJ8Kn-00EmsK-Ih for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Jun 2024 09:07:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJ8Km-00EmrG-Ah for pgsql-hackers@lists.postgresql.org; Mon, 17 Jun 2024 09:07:30 +0000 Received: from wfout5-smtp.messagingengine.com ([64.147.123.148]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sJ8Kk-001izk-4h for pgsql-hackers@lists.postgresql.org; Mon, 17 Jun 2024 09:07:27 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id D36141C000F2; Mon, 17 Jun 2024 05:07:23 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 17 Jun 2024 05:07:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1718615243; x= 1718701643; bh=qx8SLDiOyLwwZ53ofuamGgclIEBbhwtLxXdD2aLJ9L8=; b=D scatp+ZDyLILXzGXEIOYhSPV4d33i3BYpHViDUUyW94mQdbYFkNO61be7x5hJVRP EV6WfflTgsQRyOeMehLyXldybwnoDs5Mm6ZZwpD6FUEZDn2TBDzeKDoYQpocuEwD ZCPq1XM/OL51pq0bRL42dfs9YzBHpigxsmYQ7xXMD0PEhAYoYs3cKcb4CP2wehVL wSUE5YVmuazmMlPiYmbZ+S5+RpKlAHlXYqTG0H2x/8rIDW20jrW4kSfcUcTFH/RG 6nte7cmzQmKM0WISCBnVmKo2cfGg7726Vyh33zgYbkXkvCHK44HWY0DolURtHePq YGPR7lNlKXepSo7BLJGcA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfedvhedguddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffehfffhjeejhffgieeuueekjeek fffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 17 Jun 2024 05:07:22 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1718615239; bh=rEsdsCSz32fX8G39HtwgTi4iY76FMk7PU+80GQT88pc=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=fQwuEYnSOzf09r06uNp8xB2qZBppQInr62dKyDu3pb8Dh/0c2fYXF2kSg4TrtCuVR R7lEZPwKFeMkLyiskvkBCwyPbkUmjleSVNIWYoDi3WExVOB1Llvabbs4urmqzL5xV2 pBItpAJequCM0HavqNholmtPeIRf8jN11jv+8syHxSeBmpMAYmHh0w+MAGGcxMrbX/ uATUHtf0vMA6WRE7eeX7KpIx4O7L5LTxmln61ZrMmrtCgbzKZC375qrooVnDYyy1Bz d8dwSfKtO/BLNAGvQuB8fM6rdFIAyHhXPCSekOapEDrx5M1vYqhFAwjrbYKMOHD8y9 WB8S78g8UWCiw== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 8FF65527; Mon, 17 Jun 2024 02:07:19 -0700 (PDT) Date: Mon, 17 Jun 2024 11:07:19 +0200 From: Alvaro Herrera To: Andrew Dunstan Cc: Andres Freund , PostgreSQL Hackers Subject: Re: Using LibPq in TAP tests via FFI Message-ID: <202406170907.7eirw73rtiet@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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)