fix primary key of customer
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 16 Dec 2007 21:19:28 +0000 (21:19 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 16 Dec 2007 21:19:28 +0000 (21:19 +0000)
git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@80 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

www/inc/db.php
www/inc/db_scheme.php

index 02dbeb4..4a94b34 100644 (file)
@@ -118,13 +118,31 @@ abstract class DbEngine
                reset($table);
                while(list($col,$def)=each($table)){
                        $ret.=$cm;$cm=",";
-                       //column name
-                       $ret.=$col." ";
-                       //get type
-                       $ret.=$this->dataType($def[0])." ";
-                       //get flags
-                       for($i=0;$i<count($def);$i++)
-                               $ret.=$this->columnFlag($def[$i])." ";
+                       //check whether this is a special column
+                       if(substr($col,0,1)==":"){
+                               if($col==":primarykey")$ret.=$this->sqlCreateTablePrimaryKey($def);
+                               else die("Unknown special column ".$col." while creating table ".$tablename);
+                       }else{
+                               //column name
+                               $ret.=$col." ";
+                               //get type
+                               $ret.=$this->dataType($def[0])." ";
+                               //get flags
+                               for($i=0;$i<count($def);$i++)
+                                       $ret.=$this->columnFlag($def[$i])." ";
+                       }
+               }
+               $ret.=")";
+               return $ret;
+       }
+       
+       /**creates primary key statement for sqlCreateTable*/
+       protected function sqlCreateTablePrimaryKey(array $cols)
+       {
+               $ret="PRIMARY KEY(";
+               for($i=0;$i<count($cols);$i++){
+                       if($i>0)$ret.=",";
+                       $ret.=$cols[$i];
                }
                $ret.=")";
                return $ret;
@@ -236,7 +254,8 @@ abstract class DbEngine
                $tabs=$dbScheme->tableNames();
                for($i=0;$i<count($tabs);$i++){
                        if(!$this->createTable($tabs[$i],$dbScheme->tableDefinition($tabs[$i]))){
-                               print("DB Error while creating ".$tabs[$i].": ".$this->lastError());
+                               print("DB Error while creating ".$tabs[$i].": ".$this->lastError()."<p>\n");
+                               print("Last statement was: ".$this->sqlCreateTable($tabs[$i],$dbScheme->tableDefinition($tabs[$i]))."<p>\n");
                                $this->rollbackTransaction();
                                die("Unable to create database.");
                        }
index dee17b0..51d4aa8 100644 (file)
@@ -138,8 +138,10 @@ class DbScheme {
                $this->scheme["cart_ticket"]=array(
                        "cartid" => array("string:32","notnull","foreignkey:cart:cartid"),
                        //tickets in the cart
-                       "eventid" => array("int32","foreignkey:event:eventid","primarykey"),
+                       "eventid" => array("int32","notnull","foreignkey:event:eventid"),
                        "amount" => array("int32","notnull"),
+                       //primary key definition
+                       ":primarykey" => array("cartid","eventid")
                );
                //buying vouchers
                $this->scheme["cart_voucher"]=array(