Index: trunk/ippTools/src/stacktool.c
===================================================================
--- trunk/ippTools/src/stacktool.c	(revision 27678)
+++ trunk/ippTools/src/stacktool.c	(revision 27679)
@@ -753,8 +753,9 @@
     }
 
+    psString whereClause = psStringCopy(""); // WHERE conditions to add
     if (psListLength(where->list)) {
-        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
-        psStringAppend(&query, " AND %s", whereClause);
-        psFree(whereClause);
+        psString new = psDBGenerateWhereConditionSQL(where, NULL);
+        psStringAppend(&whereClause, "\nAND %s", new);
+        psFree(new);
     }
     psFree(where);
@@ -767,5 +768,5 @@
     }
 
-    if (!p_psDBRunQuery(config->dbh, query)) {
+    if (!p_psDBRunQueryF(config->dbh, query, whereClause)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         psFree(query);
