Index: /trunk/ippTools/src/pxtables.c
===================================================================
--- /trunk/ippTools/src/pxtables.c	(revision 6256)
+++ /trunk/ippTools/src/pxtables.c	(revision 6256)
@@ -0,0 +1,114 @@
+#include "pxtools.h"
+
+bool pxCreateTables(pxConfig *config) {
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    if (!rawScienceExpCreateTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!rawImfileCreateTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!p2PendingExpCreateTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!p2PendingImfileCreateTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!p2DoneExpCreateTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!p2DoneImfileCreateTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!p3PendingExpCreateTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!masterDetrendFramesCreateTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!masterDetrendImfileCreateTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+
+    return true;
+}
+
+bool pxDeleteTables(pxConfig *config) {
+    char line[128], answer[128];
+
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    fprintf (stdout, "*** delete the P2 tables? ***\n");
+    fprintf (stdout, "*** to delete the tables, answer YES, and give password ***\n");
+    fprintf (stdout, "*** WARNING: this action is permanent ***\n\n");
+
+    fprintf (stdout, "delete the P2 tables (YES/[n]): ");
+    fgets (line, 128, stdin);
+    sscanf (line, "%s", answer);
+    if (strcmp (answer, "YES")) goto escape;
+
+    fprintf (stdout, "enter database connection password: ");
+    fgets (line, 128, stdin);
+    sscanf (line, "%s", answer);
+             
+    bool status;
+    psString dbPassword = psMetadataLookupStr(&status, config->site, "DBPASSWORD");
+    if (strcmp (answer, dbPassword)) goto escape;
+    psFree(dbPassword);
+
+    if (!rawScienceExpDropTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!rawImfileDropTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!p2PendingExpDropTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!p2PendingImfileDropTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!p2DoneExpDropTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!p2DoneImfileDropTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!p3PendingExpDropTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!masterDetrendFramesDropTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+    if (!masterDetrendImfileDropTable(config->database)) {
+        psError(PS_ERR_UNKNOWN, false, "database access failed");
+        return false;
+    }
+
+    return true;
+
+escape:
+    // XXX fix psMetadataLookupStr() to inc ref count
+    // psFree(dbPassword);
+    fprintf (stdout, "tables NOT deleted\n");
+
+    return false;
+}
