fix some typos
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 4 Aug 2007 16:39:10 +0000 (16:39 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sat, 4 Aug 2007 16:39:10 +0000 (16:39 +0000)
add setConfig to $db
add update() to $db

git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@17 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

www/inc/db.php
www/inc/db_mysql.php
www/inc/listing.php
www/index.php

index adad151..00b4495 100644 (file)
@@ -56,6 +56,9 @@ abstract class DbEngine
        /**insert values into a table*/
        public abstract function insert($table,array $values);
        
+       /**update database values*/
+       public abstract function update($table,array $values,$where);
+       
        /**creates a table; the argument is an array of the form "col-name" => array("col-type", "flags"...); use sqlCreateTable() etc. to create the actual statement*/
        protected abstract function createTable($tablename,$table);
        
@@ -150,6 +153,31 @@ abstract class DbEngine
                return $ret;
        }
        
+       /**creates a SQL92 statement for updates*/
+       protected function sqlUpdate($table,array $values,$where)
+       {
+               global $dbScheme;
+               $ret="UPDATE ".$this->tableName($table)." SET ";
+               reset($values);
+               $cm="";
+               while(list($k,$v)=each($values)){
+                       $ret.=$cm;$cm=",";
+                       //append column name
+                       $ret.=$k."=";
+                       //append value
+                       if($dbScheme->isIntColumn($table,$k))
+                               $val.=$this->escapeInt($v);
+                       else
+                       if($dbScheme->isStringColumn($table,$k))
+                               $val.=$this->escapeString($v);
+                       else
+                               //don't know how to escape it...
+                               $val.="NULL";
+               }
+               $ret.=" WHERE ".$where;
+               return $ret;
+       }
+       
        /**escapes integers; the default implementation just makes sure it is an int*/
        protected function escapeInt($i)
        {
@@ -170,6 +198,16 @@ abstract class DbEngine
                return false;
        }
        
+       /**sets a config setting*/
+       public function setConfig($key,$val)
+       {
+               $this->beginTransaction();
+               $mar=$this->select("config","cval","ckey='".addslashes($key)."'");
+               if(count($mar)>0)$this->update("config",array("cval"=>$val),"ckey='".addslashes($key)."'");
+               else $this->insert("config",array("ckey"=>$key,"cval"=>$val));
+               $this->commitTransaction();
+       }
+       
        /**tries to find out whether the connected DB version is usable*/
        public function canUseDb()
        {
index 0032133..1ed42f4 100644 (file)
@@ -120,6 +120,11 @@ class MysqlEngine extends DbEngine
                return mysql_query($this->sqlInsert($table,$values));
        }
        
+       public function update($table,array $values,$where)
+       {
+               mysql_query($this->sqlUpdate($table,$values,$where));
+       }
+       
        public function lastError()
        {
                return mysql_error();
index c51fdb3..108e9e0 100644 (file)
@@ -7,7 +7,7 @@ function createlist()
        $p=new Parser("index.html");
        $p->setVar("ROLE","buyer");
        $list="";
-       $temp=$p->getVar("EVENT");;
+       $temp=$p->getVar("EVENT");
        //fake1
        $p->setVars(array("DATE"=>"heute","PLACE"=>"nirgendwo","EVENTNAME"=>"Hurrah Jazz Club","ARTIST"=>"Broken Blech","PRICE"=>"567,00","ID"=>"1"));
        $list.=$p->parse($temp);
index 7c0a0d9..e8b71e1 100644 (file)
@@ -8,8 +8,8 @@ include('inc/parser.php');
 
 //set common basics
 $mode="index";
-if(isset($_GET[mode])){
-       $mode=$_GET[mode];
+if(isset($_GET["mode"])){
+       $mode=$_GET["mode"];
 }
 $parser=new Parser();