From 45477c40560ea3bda92e4c03c7ed564228a92bd8 Mon Sep 17 00:00:00 2001 From: paulr Date: Sun, 11 Jul 2010 16:32:51 +1000 Subject: [PATCH] coding change, duh --- bin/pbdc.php | 14 +++++++++-- db/db.sql | 10 +++++++- lib/lib.php | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 4 deletions(-) diff --git a/bin/pbdc.php b/bin/pbdc.php index b0424bb..b7b8d07 100644 --- a/bin/pbdc.php +++ b/bin/pbdc.php @@ -65,9 +65,15 @@ function init() } echo "Creating database\n"; - $r = readline("Directory where automount occurs [/changer/]:"); - $r = readline("Number of drives [1]:"); - $r = readline("Size of tapes [20] (in gb):"); + $ra = readline("Directory where automount occurs [/changer/]:"); + $rb = readline("Number of drives [1]:"); + $rc = readline("Size of tapes [20] (in gb):"); + + if($ra == "") $ra = "/changer/"; + if($rb == "") $rb = 1; + if($rc == "") $rc = 20; + + db_getDB($changer_name); } function add_disk() @@ -116,5 +122,7 @@ function add_disk() } // now we try and init the disk + // we have to get automount directory config + //$k = mkdir(); } ?> \ No newline at end of file diff --git a/db/db.sql b/db/db.sql index 0a16ca9..7c8d722 100644 --- a/db/db.sql +++ b/db/db.sql @@ -1 +1,9 @@ -# some sql goes here +CREATE TABLE "disk_list" ( + "disk_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "disk_name" TEXT NOT NULL +); +CREATE TABLE sqlite_sequence(name,seq); +CREATE TABLE "config" ( + "config_name" TEXT NOT NULL, + "config_value" TEXT NOT NULL +); diff --git a/lib/lib.php b/lib/lib.php index b3d9bbc..42d30a5 100644 --- a/lib/lib.php +++ b/lib/lib.php @@ -1 +1,68 @@ Cannot open sqlitedb, ".$exep->getMessage()."
"; + return; + } + + + db_createDB($dbobject); + + return $dbobject; +} + +function db_createDB($dbobject) +{ + + if($dbobject->query("select * from disk_list")) { + //error_log("table exists?"); + } else { + //error_log("table not exists?"); + $dbobject->query('CREATE TABLE "disk_list" ("disk_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"disk_name" TEXT NOT NULL);'); + $dbobject->query('CREATE TABLE sqlite_sequence(name,seq)'); + $dbobject->query('CREATE TABLE "config" ("config_name" TEXT NOT NULL,"config_value" TEXT NOT NULL)'); + + // TODO create action group here + + } +} + +function conf_getVal($name) +{ + $db = db_getDB(); + + $sql = "select conf_val from conf where conf_name=='$name'"; + error_log("from getval: ".$sql); + + $res = $db->query($sql); + + if(!$res) return false; + + $val = false; + + foreach($res as $row) { + $val = $row["conf_val"]; + } + + return $val; +} + +function conf_setVal($name, $value) +{ + $db = db_getDB(); + + $sql = "delete from conf where conf_name=='$name'"; + $db->query($sql); + + $sql = "insert into conf values ('$name', '$value')"; + $db->query($sql); + + error_log("from setval: ".$sql); +} +?> \ No newline at end of file -- 1.7.0.4