diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-02-19 01:51:02 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-02-19 01:51:02 +0100 |
commit | 472250336a3732a1afdd7d2f53386a650b812502 (patch) | |
tree | 19f3a45fbcba03b271bfe8fa6e23dd517b7a6134 /src/datastore | |
parent | f773f02add14b65827db296848244f901e797ae5 (diff) | |
download | gnunet-472250336a3732a1afdd7d2f53386a650b812502.tar.gz gnunet-472250336a3732a1afdd7d2f53386a650b812502.zip |
fix possibility of NULL result for empty database
Diffstat (limited to 'src/datastore')
-rw-r--r-- | src/datastore/plugin_datastore_postgres.c | 8 |
1 files changed, 6 insertions, 2 deletions
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 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -153,7 +153,11 @@ init_connection (struct Plugin *plugin) | |||
153 | "SELECT hash FROM gn090", | 153 | "SELECT hash FROM gn090", |
154 | 0), | 154 | 0), |
155 | GNUNET_PQ_make_prepare ("estimate_size", | 155 | GNUNET_PQ_make_prepare ("estimate_size", |
156 | "SELECT SUM(LENGTH(value))+256*COUNT(*) AS total FROM gn090", | 156 | "SELECT CASE WHEN NOT EXISTS" |
157 | " (SELECT 1 FROM gn090)" | ||
158 | " THEN 0" | ||
159 | " ELSE (SELECT SUM(LENGTH(value))+256*COUNT(*) FROM gn090)" | ||
160 | "END AS total", | ||
157 | 0), | 161 | 0), |
158 | GNUNET_PQ_PREPARED_STATEMENT_END | 162 | GNUNET_PQ_PREPARED_STATEMENT_END |
159 | }; | 163 | }; |