Index: branches/simmosaic_branches/ippTools/src/pxadmin.c
===================================================================
--- branches/simmosaic_branches/ippTools/src/pxadmin.c	(revision 24860)
+++ branches/simmosaic_branches/ippTools/src/pxadmin.c	(revision 27839)
@@ -2,5 +2,5 @@
  * pxadmin.c
  *
- * Copyright (C) 2006-2008  Joshua Hoblitt
+ * Copyright (C) 2006-2009  Joshua Hoblitt
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -31,4 +31,5 @@
 bool createMirrorMode(pxConfig *config);
 bool deleteMode(pxConfig *config);
+static bool insert_dbversion(pxConfig * config, const char *versionString);
 static bool runMultipleStatments(pxConfig *config, const char *query);
 
@@ -93,5 +94,5 @@
     psString query = pxDataGet("pxadmin_create_tables.sql");
     if (!query) {
-        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
         return false;
     }
@@ -113,4 +114,9 @@
     psFree(query);
 
+    if (!insert_dbversion(config, IPPDB_VERSION)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to set database version");
+        return false;
+    }
+
     // COMMIT
     if (!psDBCommit(config->dbh)) {
@@ -129,5 +135,5 @@
     psString query = pxDataGet("pxadmin_create_mirror_tables.sql");
     if (!query) {
-        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
         return false;
     }
@@ -149,4 +155,9 @@
     psFree(query);
 
+    if (!insert_dbversion(config, IPPDB_VERSION)) {
+        psError(PS_ERR_UNKNOWN, false, "failed to set database version");
+        return false;
+    }
+
     // COMMIT
     if (!psDBCommit(config->dbh)) {
@@ -209,5 +220,5 @@
     psString query = pxDataGet("pxadmin_drop_tables.sql");
     if (!query) {
-        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
+        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
         return false;
     }
@@ -262,2 +273,35 @@
     return true;
 }
+
+#ifdef notdef
+static bool update_dbversion(pxConfig * config, const char *versionString)
+{
+    psString query = pxDataGet("pxadmin_update_version.sql");
+    if (!query) {
+        psError(PS_ERR_UNKNOWN, false, "failed to retrieve SQL statement");
+        psFree(query);
+        return false;
+    }
+    if (!p_psDBRunQueryF(config->dbh, query, versionString)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+    return true;
+}
+#endif
+static bool insert_dbversion(pxConfig * config, const char *versionString)
+{
+    psString query = "INSERT INTO dbversion VALUES('%s', CURRENT_TIMESTAMP())";
+    if (!query) {
+        psError(PS_ERR_UNKNOWN, false, "failed to retrieve SQL statement");
+        psFree(query);
+        return false;
+    }
+    if (!p_psDBRunQueryF(config->dbh, query, versionString)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+    return true;
+}
