Hello,

I attached a patch that splits the offending query in two versions: one
for MySQL and one generic SQL. Tested here for PostgreSQL 9.1.

Regards
Georg


On 16.05.2012 18:20, Georg Altmann wrote:
> Hello,
> 
> I just ran into the issue described at
> http://bugs.bacula.org/view.php?id=1859
> 
-- 
PGP-Key: 0x1E320E65
D150 7783 A0D1 7507 1266  C5B3 BBF1 9C42 1E32 0E65
From 407176f058a1e6196a95e7244e638db718caf8ba Mon Sep 17 00:00:00 2001
From: Georg Altmann <georg.altm...@informatik.stud.uni-erlangen.de>
Date: Wed, 16 May 2012 19:34:32 +0200
Subject: [PATCH] Split db_update_counter_record queries into MySQL specific
 and generic SQL.

---
 bacula/src/cats/sql_update.c |   25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/bacula/src/cats/sql_update.c b/bacula/src/cats/sql_update.c
index 422edd8..11bc456 100644
--- a/bacula/src/cats/sql_update.c
+++ b/bacula/src/cats/sql_update.c
@@ -250,11 +250,30 @@ db_update_client_record(JCR *jcr, B_DB *mdb, CLIENT_DBR *cr)
 int db_update_counter_record(JCR *jcr, B_DB *mdb, COUNTER_DBR *cr)
 {
    char esc[MAX_ESCAPE_NAME_LENGTH];
+   /* See Bug #1859
+    * Special update query for MySQL:
+    * MinValue and MaxValue are invalid unless qualified as
+    * Counters.MinValue and Counters.MaxValuein MySQL.
+    * The qualified syntax is invalid SQL and fails for other DBMS.
+    */
+   const char fmt_generic[] =
+      "UPDATE Counters SET "
+      "MinValue=%d,MaxValue=%d,CurrentValue=%d,WrapCounter='%s'"
+      "WHERE Counter='%s'";
+   const char fmt_mysql[] =
+      "UPDATE Counters SET "
+      "Counters.MinValue=%d,Counters.MaxValue=%d,CurrentValue=%d,WrapCounter='%s'"
+      "WHERE Counter='%s'";
+   const char *fmt = NULL;
+
    db_lock(mdb);
    mdb->db_escape_string(jcr, esc, cr->Counter, strlen(cr->Counter));
-   Mmsg(mdb->cmd,
-"UPDATE Counters SET Counters.MinValue=%d,Counters.MaxValue=%d,CurrentValue=%d,"
-"WrapCounter='%s' WHERE Counter='%s'",
+   if(mdb->db_get_type_index() == SQL_TYPE_MYSQL) {
+      fmt = fmt_mysql;
+   } else {
+      fmt = fmt_generic;
+   }
+   Mmsg(mdb->cmd, fmt,
       cr->MinValue, cr->MaxValue, cr->CurrentValue,
       cr->WrapCounter, esc);
 
-- 
1.7.10

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Bacula-devel mailing list
Bacula-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bacula-devel

Reply via email to