From 472250336a3732a1afdd7d2f53386a650b812502 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 19 Feb 2019 01:51:02 +0100 Subject: fix possibility of NULL result for empty database --- src/datastore/plugin_datastore_postgres.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/datastore/plugin_datastore_postgres.c') 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 }; -- cgit v1.2.3