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;
$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.");
}
$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(