- verify required tables at startup
authorAndreas Scherbaum <andreas@scherbaum.biz>
Thu, 21 Jun 2012 20:51:41 +0000 (22:51 +0200)
committerAndreas Scherbaum <andreas@scherbaum.biz>
Thu, 21 Jun 2012 20:51:41 +0000 (22:51 +0200)
db.pm
docbot.pl

diff --git a/db.pm b/db.pm
index 9555f4bb11be36341e0126b10210b6dabb777d7f..7265f5186653cd94dd8ec19f3db913fd577f881e 100644 (file)
--- a/db.pm
+++ b/db.pm
@@ -221,6 +221,37 @@ sub test_database {
 }
 
 
+# verify_tables()
+#
+# verify table existence
+#
+# parameter:
+#  - class name ($self)
+# return:
+#  - 0/1 (1 = OK)
+sub verify_tables {
+    my $self = shift;
+
+    my $query = "SELECT COUNT(1) AS count
+                   FROM information_schema.tables
+                  WHERE table_name IN ('docbot_key', 'docbot_url', 'docbot_user')";
+
+    my $st = $main::db->query($query);
+    if (!defined($st)) {
+        main::print_msg("Can't execute query - $DBI::errstr\n", ERROR);
+        return 0;
+    }
+
+    my @row = $st->fetchrow_array;
+    if ($row[0] != 3) {
+        main::print_msg("Missing one or more tables", ERROR);
+        return 0;
+    }
+
+    return 1;
+}
+
+
 # ping()
 #
 # execute a test query
index 59396ff8a536f8bd3c93939e06ef04f6f9dd9fd3..1f35bfbc56ff941c6b87e763c4088f785ece2a7f 100755 (executable)
--- a/docbot.pl
+++ b/docbot.pl
@@ -369,6 +369,10 @@ sub init_database {
     if (!$main::db->test_database()) {
         die("Could not test database connection!\n");
     }
+    # and verify table existence
+    if (!$main::db->verify_tables()) {
+        die("Required tables are not available!\n");
+    }
 }