Index: /trunk/psLib/src/db/psDB.c
===================================================================
--- /trunk/psLib/src/db/psDB.c	(revision 21400)
+++ /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
Index: /trunk/psLib/src/db/psDB.h
===================================================================
--- /trunk/psLib/src/db/psDB.h	(revision 21400)
+++ /trunk/psLib/src/db/psDB.h	(revision 21401)
@@ -22,5 +22,5 @@
  * perform basic database operations.
  *
- * $Id: psDB.h,v 1.37 2007-09-05 23:20:04 jhoblitt Exp $
+ * $Id: psDB.h,v 1.38 2009-02-07 01:11:24 eugene Exp $
  */
 
@@ -119,5 +119,5 @@
 );
 
-/** Executes a SQL query
+/** Formats and Executes a SQL query
  *
  * This function will execute a string as a raw SQL query.  No additional
@@ -127,5 +127,5 @@
  * @return bool:    true on success
  */
-bool p_psDBRunQuery(
+bool p_psDBRunQueryF(
     psDB *dbh,                         ///< Database handle
     const char *format,                ///< SQL string to execute
@@ -133,5 +133,5 @@
 ) PS_ATTR_FORMAT(printf, 2, 3);
 
-/** Executes a SQL query as a prepared statement
+/** Executes a SQL query
  *
  * This function will execute a string as a raw SQL query.  No additional
@@ -139,7 +139,20 @@
  * dialect is provided.  Caveat emptor.
  *
+ * @return bool:    true on success
+ */
+bool p_psDBRunQuery(
+    psDB *dbh,                         ///< Database handle
+    const char *query                ///< SQL string to execute
+    );
+
+/** Formats and Executes a SQL query as a prepared statement
+ *
+ * This function will execute a string as a raw SQL query.  No additional
+ * processing of the string or abstraction of the underlying database's SQL
+ * dialect is provided.  Caveat emptor.
+ *
  * @return long:    the number of database rows affected
  */
-long p_psDBRunQueryPrepared(
+long p_psDBRunQueryPreparedF(
     psDB *dbh,                          ///< Database handle
     const psArray *rowSet,              ///< row data as psArray of psMetadata
@@ -147,4 +160,18 @@
     ...
 ) PS_ATTR_FORMAT(printf, 3, 4);
+
+/** Executes a SQL query as a prepared statement
+ *
+ * This function will execute a string as a raw SQL query.  No additional
+ * processing of the string or abstraction of the underlying database's SQL
+ * dialect is provided.  Caveat emptor.
+ *
+ * @return long:    the number of database rows affected
+ */
+long p_psDBRunQueryPrepared(
+    psDB *dbh,                          ///< Database handle
+    const psArray *rowSet,              ///< row data as psArray of psMetadata
+    const char *query			///< SQL string to execute
+);
 
 /** Fetches the result of a SQL query
