From 8c7cc63fda969b67647ea8d621a63ea8ceeb30c8 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 16 Dec 2007 21:19:28 +0000 Subject: [PATCH] fix primary key of customer git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@80 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- www/inc/db.php | 35 +++++++++++++++++++++++++++-------- www/inc/db_scheme.php | 4 +++- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/www/inc/db.php b/www/inc/db.php index 02dbeb4..4a94b34 100644 --- a/www/inc/db.php +++ b/www/inc/db.php @@ -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;$icolumnFlag($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;$icolumnFlag($def[$i])." "; + } + } + $ret.=")"; + return $ret; + } + + /**creates primary key statement for sqlCreateTable*/ + protected function sqlCreateTablePrimaryKey(array $cols) + { + $ret="PRIMARY KEY("; + for($i=0;$i0)$ret.=","; + $ret.=$cols[$i]; } $ret.=")"; return $ret; @@ -236,7 +254,8 @@ abstract class DbEngine $tabs=$dbScheme->tableNames(); for($i=0;$icreateTable($tabs[$i],$dbScheme->tableDefinition($tabs[$i]))){ - print("DB Error while creating ".$tabs[$i].": ".$this->lastError()); + print("DB Error while creating ".$tabs[$i].": ".$this->lastError()."

\n"); + print("Last statement was: ".$this->sqlCreateTable($tabs[$i],$dbScheme->tableDefinition($tabs[$i]))."

\n"); $this->rollbackTransaction(); die("Unable to create database."); } diff --git a/www/inc/db_scheme.php b/www/inc/db_scheme.php index dee17b0..51d4aa8 100644 --- a/www/inc/db_scheme.php +++ b/www/inc/db_scheme.php @@ -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( -- 1.7.2.5