From 705c28cca502e9af36c3a4eb583c19d14e609566 Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Wed, 23 Jul 2008 19:03:17 +0000
Subject: [PATCH] added fix for removing multiple objects from associations

---
 .../accounting_storage/mysql/accounting_storage_mysql.c    | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c
index e27ae339f5d..0e06f7ce471 100644
--- a/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c
+++ b/src/plugins/accounting_storage/mysql/accounting_storage_mysql.c
@@ -769,7 +769,7 @@ static int _remove_common(mysql_conn_t *mysql_conn,
 /* 				       assoc_table, assoc_char); */
 		query = xstrdup_printf("select distinct t1.id "
 				       "from %s as t1, %s as t2 "
-				       "where %s && t1.lft between "
+				       "where (%s) && t1.lft between "
 				       "t2.lft and t2.rgt && t1.deleted=0 "
 				       " && t2.deleted=0;",
 				       assoc_table, assoc_table, assoc_char);
@@ -809,6 +809,11 @@ static int _remove_common(mysql_conn_t *mysql_conn,
 	} else 
 		loc_assoc_char = assoc_char;
 
+	if(!loc_assoc_char) {
+		debug2("No associations with object being deleted\n");
+		return rc;
+	}
+
 	if(!has_jobs)
 		query = xstrdup_printf(
 			"delete from %s where creation_time>%d && (%s);"
-- 
GitLab