3 function db_getDB($changer_name)
5 global $BASE_DATA, $BASE_LIB, $BACULA_USER;
8 $dbobject = new PDO("sqlite:$BASE_DATA/$changer_name".".db");
9 } catch(PDOException $exep) {
10 echo "<font color='red'>Cannot open sqlitedb, ".$exep->getMessage()."</font><br>";
15 db_createDB($dbobject);
20 function db_createDB($dbobject)
23 if($dbobject->query("select * from disk_list")) {
24 //error_log("table exists?");
26 //error_log("table not exists?");
27 $dbobject->query('CREATE TABLE "disk_list" ("disk_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"disk_name" TEXT NOT NULL);');
28 $dbobject->query('CREATE TABLE sqlite_sequence(name,seq)');
29 $dbobject->query('CREATE TABLE "config" ("config_name" TEXT NOT NULL,"config_value" TEXT NOT NULL)');
31 // TODO create action group here
36 function conf_getVal($changer, $name)
38 $db = db_getDB($changer);
40 $sql = "select config_value from config where config_name=='$name'";
41 //error_log("from getval: ".$sql);
43 $res = $db->query($sql);
45 if(!$res) return false;
49 foreach($res as $row) {
50 $val = $row["config_value"];
56 function conf_setVal($changer, $name, $value)
58 $db = db_getDB($changer);
60 $sql = "delete from config where config_name=='$name'";
63 $sql = "insert into config values ('$name', '$value')";
66 //error_log("from setval: ".$sql);
69 function add_diskToDB($changer, $diskid)
71 $db = db_getDB($changer);
73 $sql = "select * from disk_list where disk_name=='$diskid'";
74 $res = $db->query($sql);
75 if(!$res) return false;
78 foreach($res as $row) {
79 $val = $row["disk_id"];
83 $sql = "insert into disk_list values(NULL, '$diskid')";
85 return $db->lastInsertId();
87 echo "Disk already existed in db, will create more tapes?\n";