From d1175ff471ff814e652f48cb97132dae51939037 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Wed, 15 Feb 2023 02:50:49 +0800 Subject: [PATCH] Fix #2777 --- server/util-server.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/server/util-server.js b/server/util-server.js index edce28901..e099f673b 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -292,14 +292,23 @@ exports.postgresQuery = function (connectionString, query) { client.end(); } else { // Connected here - client.query(query, (err, res) => { - if (err) { - reject(err); - } else { - resolve(res); + try { + // No query provided by user, use SELECT 1 + if (!query || (typeof query === "string" && query.trim() === "")) { + query = "SELECT 1"; } - client.end(); - }); + + client.query(query, (err, res) => { + if (err) { + reject(err); + } else { + resolve(res); + } + client.end(); + }); + } catch (e) { + reject(e); + } } });