X-Git-Url: http://git.pjr.cc/?p=glcas.git;a=blobdiff_plain;f=libglcas%2Fconfig.php;fp=libglcas%2Fconfig.php;h=3f4588e07a4186910552c7e364d6512f7457bede;hp=499c97b2b2cb7d3dc1c3fc6e2dab330e9ba16fc1;hb=155c0a1bc81dff4fc1bb4bcebb754c961e457499;hpb=58365ecc64413d416dadaa82607e57a1f76eca7e diff --git a/libglcas/config.php b/libglcas/config.php index 499c97b..3f4588e 100644 --- a/libglcas/config.php +++ b/libglcas/config.php @@ -55,9 +55,9 @@ class GLCASConfig { function addData($configType, $configCat, $configName, $configVal) { - $sql = "insert into datatable values (NULL, '$configType', '$configCat', $configName', '$configVal')"; + $sql = "insert into datatable values (NULL, '$configType', '$configCat', '$configName', '$configVal')"; $this->dbobject->query($sql); - + error_log("CONFIG: adddata as $sql"); } function saveConfig() @@ -70,43 +70,53 @@ class GLCASConfig { $ret = null; $nret = 0; $haveWhere = false; + + $wheredata = "where data_type='$configType'"; if($configCat != "") { - $haveWhere = true; - $wheredata = "where data_category='$configCat'"; + $wheredata .= " and data_category='$configCat'"; } if($configName != "") { - if($haveWhere) { - $wheredata .= " and data_name='$configName'"; - } else { - $wheredata = "where data_name='$configName'"; - } + $wheredata .= " and data_name='$configName'"; } - $sql = "select data_val,data_category,data_name from datatable $wheredata"; + $sql = "select data_category,data_name,data_val from datatable $wheredata"; + error_log("CONFIG: get via $sql"); + $res = $this->dbobject->query($sql); foreach($res as $row) { - $ret[$nret]["val"] = $row[0]; - $ret[$nret]["cat"] = $row[1]; - $ret[$nret]["name"] = $row[2]; + $ret[$nret]["val"] = $row[2]; + $ret[$nret]["category"] = $row[0]; + $ret[$nret]["name"] = $row[1]; $nret++; } + if($nret == 0) return false; return $ret; } - function delData($configType, $configName, $configVal) + function delData($configType, $configCat, $configName="", $configVal="") { - $sql = "delete from datatable where data_type='$configType' and data_name='$configName' and data_val='$configVal')"; + $extrawhere = ""; + if($configName != "") { + $extrawhere = " and data_name='$configName'"; + } + if($configVal != "") { + $extrawhere .= " and data_val='$configVal'"; + } + $sql = "delete from datatable where data_type='$configType' and data_category='$configCat' $extrawhere"; $this->dbobject->query($sql); + + error_log("del all data was $sql"); } function delAllDAta($configType, $configCat) { - $sql = "delete from datatable where data_type='$configType' and data_name='$configName'"; + $sql = "delete from datatable where data_type='$configType' and data_category='$configCat'"; //echo "sql is $sql\n"; $this->dbobject->query($sql); + error_log("del all data was $sql"); } function setupTables() @@ -125,7 +135,7 @@ class GLCASConfig { $sql = 'CREATE TABLE "config" ( "configname" TEXT,"configvar" TEXT);'; $this->dbobject->query($sql); - $sql = 'CREATE TABLE "datatable" ("data_id" INTEGER PRIMARY KEY AUTOINCREMENT,"data_category" TEXT,"data_type" TEXT,"data_name" TEXT,"data_val" TEXT);'; + $sql = 'CREATE TABLE "datatable" ("data_id" INTEGER PRIMARY KEY AUTOINCREMENT,"data_type" TEXT,"data_category" TEXT,"data_name" TEXT,"data_val" TEXT);'; $this->dbobject->query($sql); $sql = 'CREATE TABLE sqlite_sequence(name,seq);';