/**returns the correct name/coding of a flag:
primarykey, notnull, unique (implies notnull), foreignkey:$table:$col, defaultint:$val, defaultstr:$val, index*/
- protected function columnFlag($flag)
+ protected function columnFlag($flag,$col)
{
if($flag=="primarykey")return "PRIMARY KEY";
if($flag=="notnull")return "NOT NULL";
$ret.=$this->dataType($def[0])." ";
//get flags
for($i=0;$i<count($def);$i++)
- $ret.=$this->columnFlag($def[$i])." ";
+ $ret.=$this->columnFlag($def[$i],$col)." ";
}
}
+ $ret.=$this->createTableExtras($tablename,$table);
$ret.=")";
return $ret;
}
+ /**This function can be used to amend the column definitions of a table; if overwritten it must return a string*/
+ protected function createTableExtras($tablename,$table)
+ {
+ return "";
+ }
+
/**creates primary key statement for sqlCreateTable*/
protected function sqlCreateTablePrimaryKey(array $cols)
{
}
//insert some defaults
$this->insert("config",array("ckey"=>"MagicSmokeVersion","cval"=>$this->needVersion()));
+ $this->insert("config",array("ckey"=>"ValidVouchers","cval"=>"10 20 25 50"));
+ $this->insert("config",array("ckey"=>"OrderStop","cval"=>"24"));
+ $this->insert("config",array("ckey"=>"SaleStop","cval"=>"0"));
+ $this->insert("config",array("ckey"=>"TicketIDChars","cval"=>"10"));
+ $this->insert("config",array("ckey"=>"VoucherIDChars","cval"=>"10"));
$this->insert("host",array("hostname"=>"_any"));
$this->insert("host",array("hostname"=>"_anon"));
$this->insert("host",array("hostname"=>"_online"));
private $dbname="";
private $engine="InnoDB";
private $charset="utf8";
+ //used for table creation to work around mysql bugs
+ private $tableappend;
/**initialize driver*/
public function __construct($server,$user,$pass)
$this->engine=$e;
}
+ /**set the default charset for tables and connections*/
+ public function setCharacterSet($c)
+ {
+ $this->charset=$c;
+ }
+
public function tryConnect()
{
//connect
protected function createTable($tn,$t)
{
- return mysqli_query($this->dbhdl,$this->sqlCreateTable($tn,$t)." engine=".$this->engine);
+ $this->tableappend="";
+ $sql=$this->sqlCreateTable($tn,$t)." engine=".$this->engine." default charset=".$this->charset;
+ print("<pre>\n$sql\n</pre>\n");
+ return mysqli_query($this->dbhdl,$sql);
+ }
+
+ protected function createTableExtras($tablename,$table)
+ {
+ return $this->tableappend;
}
protected function tableName($tn)
return parent::dataType($type);
}
- protected function columnFlag($flag)
+ protected function columnFlag($flag,$col)
{
//FIXME: currently MySQL does not mark columns for indexing, since the syntax is somewhat different --> this needs to be fixed!
- if($flag=="index")return "";
+ if($flag=="index"){
+ $this->tableappend.=", INDEX(".$col.")";
+ return "";
+ }
+ //MySQL::InnoDB is buggy, it accepts references only as appendix
+ $tpa=explode(":",$flag);
+ if($tpa[0]=="foreignkey"){
+ if(count($tpa)<3)
+ return false;
+ $this->tableappend.=", FOREIGN KEY (".$col.") REFERENCES ".$this->tableName($tpa[1])."($tpa[2])";
+ return "";
+ }
//fallback to SQL standard
- return parent::columnFlag($flag);
+ return parent::columnFlag($flag,$col);
}
public function insert($table,array $values)
$this->scheme["users"]=array(
"uname" => array("string:64","primarykey"),
"passwd" => array("string","notnull"),
- //more detailed data that can be displayed to customers
+ //more detailed data that can be displayed to admins
"description" => array("text")
);
$this->scheme["userrole"]=array(
);
//orders by customers
$this->scheme["order"]=array(
- "orderid" => array("seq32","primarykey"),
+ "orderid" => array("int32","primarykey"),
//customer
"customerid" => array("int32","foreignkey:customer:customerid"),
//seller (_online for web forms)
);
//tickets
$this->scheme["ticket"]=array(
- "ticketid" => array("seq64","primarykey"),
+ "ticketid" => array("string:32","primarykey"),
"eventid" => array("int32","foreignkey:event:eventid"),
//initially a copy from event, can be adjusted by seller
"price" => array("int32","notnull"),
"reservedby" => array("string:64","foreignkey:users:uname"),
"reservetimeout" => array("int32"),
//sold to someone (may be NULL for direct sales or reserves)
- "oderid" => array("int32","foreignkey:orders:orderid")
+ "orderid" => array("int32","foreignkey:order:orderid")
);
//vouchers and re-imbursments
$this->scheme["voucher"]=array(
- //a 16char code (code39: case-insensitive letters+digits) for the voucher)
- "voucherid" => array("string:16","primarykey"),
+ //a 8-32 char code (code39: case-insensitive letters+digits) for the voucher)
+ "voucherid" => array("string:32","primarykey"),
//if ordered: order-info
"price" => array("int32","notnull"),
- "oderid" => array("int32","foreignkey:orders:orderid"),
+ "orderid" => array("int32","foreignkey:order:orderid"),
//unix-timestamp of original sales date/time
"salestime" => array("int32","notnull"),
//remaining value in cents