From: Christian Grothoff Date: Tue, 19 Feb 2019 00:51:02 +0000 (+0100) Subject: fix possibility of NULL result for empty database X-Git-Tag: v0.11.0~63^2~32^2~27 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=472250336a3732a1afdd7d2f53386a650b812502;p=oweals%2Fgnunet.git fix possibility of NULL result for empty database --- diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c index 94db6e116..0a3018411 100644 --- a/src/datastore/plugin_datastore_postgres.c +++ b/src/datastore/plugin_datastore_postgres.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . @@ -153,7 +153,11 @@ init_connection (struct Plugin *plugin) "SELECT hash FROM gn090", 0), GNUNET_PQ_make_prepare ("estimate_size", - "SELECT SUM(LENGTH(value))+256*COUNT(*) AS total FROM gn090", + "SELECT CASE WHEN NOT EXISTS" + " (SELECT 1 FROM gn090)" + " THEN 0" + " ELSE (SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090)" + "END AS total", 0), GNUNET_PQ_PREPARED_STATEMENT_END };