From 53f8ebb99e268ce751bcb166841fdc228c97a7d2 Mon Sep 17 00:00:00 2001
From: Marco van Wieringen <marco.van.wieringen@bareos.com>
Date: Mon, 24 Nov 2014 14:35:06 +0100
Subject: [PATCH] Use DB engine specific queries fro dropping temp table.

Fixes #368: Bareos and PostgreSQL errors
---
 src/cats/sql_cmds.c |   17 +++++++++++++++--
 src/dird/ua_prune.c |    5 +----
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/cats/sql_cmds.c b/src/cats/sql_cmds.c
index 9d8942a..83897bf 100644
--- a/src/cats/sql_cmds.c
+++ b/src/cats/sql_cmds.c
@@ -95,9 +95,22 @@ const char *sel_JobMedia =
    "AND Job.JobTDate<%s";
 
 /* Delete temp tables and indexes  */
+static const char *drop_deltabs_default =
+   "DROP TABLE DelCandidates";
+
 const char *drop_deltabs[] = {
-   "DROP TABLE DelCandidates",
-   NULL};
+   /* MySQL */
+   "DROP TABLE IF EXISTS DelCandidates",
+
+   /* Postgresql */
+   "DROP TABLE IF EXISTS DelCandidates",
+
+   /* SQLite3 */
+   drop_deltabs_default,
+
+   /* Ingres */
+   drop_deltabs_default
+};
 
 const char *create_delindex = "CREATE INDEX DelInx1 ON DelCandidates (JobId)";
 
diff --git a/src/dird/ua_prune.c b/src/dird/ua_prune.c
index 0a15cd0..3f1e586 100644
--- a/src/dird/ua_prune.c
+++ b/src/dird/ua_prune.c
@@ -566,10 +566,7 @@ bail_out:
 
 static void drop_temp_tables(UAContext *ua)
 {
-   int i;
-   for (i=0; drop_deltabs[i]; i++) {
-      db_sql_query(ua->db, drop_deltabs[i]);
-   }
+   db_sql_query(ua->db, drop_deltabs[db_get_type_index(ua->db)]);
 }
 
 static bool create_temp_tables(UAContext *ua)
-- 
1.7.3.2

