Index: trunk/psLib/src/db/psDB.c
===================================================================
--- trunk/psLib/src/db/psDB.c	(revision 19927)
+++ trunk/psLib/src/db/psDB.c	(revision 21401)
@@ -23,5 +23,5 @@
  * 4.1.2 or newer is required.
  *
- * $Id: psDB.c,v 1.170 2008-10-06 22:15:38 eugene Exp $
+ * $Id: psDB.c,v 1.171 2009-02-07 01:11:24 eugene Exp $
  */
 
@@ -254,14 +254,9 @@
     PS_ASSERT_PTR_NON_NULL(dbname, false);
 
-    psString query = NULL;
-    psStringAppend(&query, "CREATE DATABASE %s", dbname);
-
     // the MySQL C API notes that mysql_create_db() is deprecated
-    bool status = p_psDBRunQuery(dbh, query);
+    bool status = p_psDBRunQueryF(dbh, "CREATE DATABASE %s", dbname);
     if (!status) {
         psError(PS_ERR_UNKNOWN, false, "Failed to create new database.");
     }
-
-    psFree(query);
 
     psTrace("psLib.db", PS_LOG_INFO, "created a database named %s", dbname);
@@ -295,14 +290,9 @@
     PS_ASSERT_PTR_NON_NULL(dbname, false);
 
-    char            *query = NULL;
-    psStringAppend(&query, "DROP DATABASE %s", dbname);
-
     // the MySQL C API notes that mysql_drop_db() is deprecated
-    bool status = p_psDBRunQuery(dbh, query);
+    bool status = p_psDBRunQueryF(dbh, "DROP DATABASE %s", dbname);
     if (!status) {
         psError(PS_ERR_UNKNOWN, false, "Failed to drop database.");
     }
-
-    psFree(query);
 
     psTrace("psLib.db", PS_LOG_INFO, "dropped database %s", dbname);
@@ -346,14 +336,8 @@
 
     // Create SQL command string to drop table
-    psString query = NULL;
-    psStringAppend(&query, "DROP TABLE %s", tableName);
-
-    // Execute query
-    bool status = p_psDBRunQuery(dbh, query);
+    bool status = p_psDBRunQueryF(dbh, "DROP TABLE %s", tableName);
     if (!status) {
         psError(PS_ERR_UNKNOWN, false, _("Failed to drop table."));
     }
-
-    psFree(query);
 
     psTrace("psLib.db", PS_LOG_INFO, "dropped table %s", tableName);
@@ -818,4 +802,20 @@
 
 bool p_psDBRunQuery(psDB *dbh,
+                    const char *query)
+{
+    PS_ASSERT_PTR_NON_NULL(dbh, false);
+    PS_ASSERT_PTR_NON_NULL(query, false);
+
+    psTrace("psLib.db", PS_LOG_INFO, "Executing SQL:\n%s", query);
+
+    if (mysql_real_query(dbh->mysql, query, (unsigned long)strlen(query)) !=0) {
+        psError(mysqlTopsErr(dbh->mysql), true, _("Failed to execute SQL query.  Error: %s"), mysql_error(dbh->mysql));
+        return false;
+    }
+
+    return true;
+}
+
+bool p_psDBRunQueryF(psDB *dbh,
                     const char *format,
                     ...)
@@ -832,18 +832,12 @@
     va_end(ap);
 
-    psTrace("psLib.db", PS_LOG_INFO, "Executing SQL:\n%s", query);
-
-    if (mysql_real_query(dbh->mysql, query, (unsigned long)strlen(query)) !=0) {
-        psError(mysqlTopsErr(dbh->mysql), true, _("Failed to execute SQL query.  Error: %s"), mysql_error(dbh->mysql));
-        psFree(query);
-        return false;
-    }
+    bool status = p_psDBRunQuery (dbh, query);
 
     psFree(query);
 
-    return true;
-}
-
-long p_psDBRunQueryPrepared(psDB *dbh,
+    return status;
+}
+
+long p_psDBRunQueryPreparedF(psDB *dbh,
                             const psArray *rowSet,
                             const char *format,
@@ -855,15 +849,4 @@
 
     psString query = NULL;
-
-    // start lock on query cache
-    if (psMemGetThreadSafety()) {
-        pthread_mutex_lock(&preparedQueryMutex);
-    }
-
-    // initalize the prepared query cache
-    if (!preparedQuery) {
-        preparedQuery = psHashAlloc(10);
-        psMemSetPersistent(preparedQuery, true);
-    }
 
     // generate query string
@@ -873,4 +856,31 @@
     va_end(ap);
 
+    long status = p_psDBRunQueryPrepared(dbh, rowSet, query);
+
+    psFree(query);
+
+    return status;
+}
+
+long p_psDBRunQueryPrepared(psDB *dbh,
+                            const psArray *rowSet,
+                            const char *query
+    )                            
+{
+    PS_ASSERT_PTR_NON_NULL(dbh, -1);
+    PS_ASSERT_PTR_NON_NULL(rowSet, -1);
+    PS_ASSERT_PTR_NON_NULL(query, -1);
+
+    // start lock on query cache
+    if (psMemGetThreadSafety()) {
+        pthread_mutex_lock(&preparedQueryMutex);
+    }
+
+    // initalize the prepared query cache
+    if (!preparedQuery) {
+        preparedQuery = psHashAlloc(10);
+        psMemSetPersistent(preparedQuery, true);
+    }
+
     psTrace("psLib.db", PS_LOG_INFO, "Preparing SQL:\n%s", query);
 
@@ -889,5 +899,4 @@
             psError(PS_ERR_UNKNOWN, true, "Failed to prepare query.  Error: %s", mysql_stmt_error(*stmt));
             mysql_stmt_close(*stmt);
-            psFree(query);
 
             // end lock on query cache
@@ -909,6 +918,4 @@
         pthread_mutex_unlock(&preparedQueryMutex);
     }
-
-    psFree(query);
 
     // how many place holders are in our query
@@ -2041,5 +2048,5 @@
     // get field names
     while ((item = psListGetAndIncrement(cursor))) {
-        psStringAppend(&query, item->name);
+        psStringAppend(&query, "%s", item->name);
 
         // + , + _ between every field name
