From a9d458e38ea18f749e74e3ee57a2d99960fad9d1 Mon Sep 17 00:00:00 2001 From: konrad Date: Tue, 3 Feb 2009 15:28:26 +0000 Subject: [PATCH] woc is not able to rebuild DB schema git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@260 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- wob/audit.wolf | 23 +++ wob/basics.wolf | 55 ++++++- wob/cart.wolf | 40 +++++ wob/customer.wolf | 24 +++ wob/event.wolf | 33 ++++ wob/magicsmoke.wolf | 9 +- wob/order.wolf | 7 + woc/phpout.cpp | 34 ++++ woc/processor.cpp | 206 +++++++++++++++++++++- woc/processor.h | 28 +++- www/inc/db/db_scheme.php | 417 +------------------------------------------- www/inc/loader.php | 3 + www/inc/wbase/autoload.php | 1 + www/inc/wbase/schema.php | 165 +++++++++++++++++ 14 files changed, 618 insertions(+), 427 deletions(-) create mode 100644 wob/audit.wolf create mode 100644 wob/cart.wolf create mode 100644 wob/customer.wolf create mode 100644 wob/event.wolf create mode 100644 www/inc/wbase/schema.php diff --git a/wob/audit.wolf b/wob/audit.wolf new file mode 100644 index 0000000..94395a9 --- /dev/null +++ b/wob/audit.wolf @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/wob/basics.wolf b/wob/basics.wolf index f8e0598..60ab614 100644 --- a/wob/basics.wolf +++ b/wob/basics.wolf @@ -7,10 +7,63 @@ - see COPYING.AGPL for details --> - +
+ + + + + + + + + +
+ + + + + + + +
+ + + + + + +
+ + + +
+ + + +
+ + + + + + + + + + +
+ + + + + + +
diff --git a/wob/cart.wolf b/wob/cart.wolf new file mode 100644 index 0000000..e36da7e --- /dev/null +++ b/wob/cart.wolf @@ -0,0 +1,40 @@ + + + + + + + + + + + + +
+ + + + + +
+ + + + + +
+ + + + + + + +
+
\ No newline at end of file diff --git a/wob/customer.wolf b/wob/customer.wolf new file mode 100644 index 0000000..05ba216 --- /dev/null +++ b/wob/customer.wolf @@ -0,0 +1,24 @@ + + + + + + //contact data + + + + +
+ + //online login data + + + +
+
\ No newline at end of file diff --git a/wob/event.wolf b/wob/event.wolf new file mode 100644 index 0000000..03fa4d1 --- /dev/null +++ b/wob/event.wolf @@ -0,0 +1,33 @@ + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+
\ No newline at end of file diff --git a/wob/magicsmoke.wolf b/wob/magicsmoke.wolf index f0316be..f53a27b 100644 --- a/wob/magicsmoke.wolf +++ b/wob/magicsmoke.wolf @@ -10,7 +10,7 @@ - + @@ -19,8 +19,9 @@ - + + + + \ No newline at end of file diff --git a/wob/order.wolf b/wob/order.wolf index 12bee92..a3449f0 100644 --- a/wob/order.wolf +++ b/wob/order.wolf @@ -7,6 +7,13 @@ - see COPYING.AGPL for details --> + + + + + + +
diff --git a/woc/phpout.cpp b/woc/phpout.cpp index c8b2150..0a2b8fb 100644 --- a/woc/phpout.cpp +++ b/woc/phpout.cpp @@ -50,6 +50,7 @@ WocPHPServerOut::WocPHPServerOut(QString srcDir,QString subDir,QString ext,bool } m_schema.write(PHPSTART); m_schema.write(SCHEMASTART); + m_schema.write(("\t$this->sversion=\""+WocProcessor::instance()->dbVersion()+"\";\n").toAscii()); addLoad("WobSchema","schema"); } @@ -86,12 +87,45 @@ void WocPHPServerOut::newTable(const WocTable&tbl) code+="public static function getFromDB(...){global $db...;}\n"; //automatic resolution of internal foreign keys //reverse resolution of configured foreign keys + //create enum constants //write table class code+="};\n"; tf.write(code.toAscii()); tf.write(PHPEND); tf.close(); + //extend schema file + //column definitions + QStringList cols=tbl.columns(); + QStringList pcols=tbl.primaryColumns(); + code="\t$this->scheme[\""+tbl.name()+"\"]=array("; + for(int i=0;iarray(\""; + code+=tbl.columnType(cols[i])+"\""; + if(!tbl.columnIsNull(cols[i]))code+=",\"notnull\""; + if(tbl.columnIsForeign(cols[i]))code+=",\"foreignkey:"+tbl.columnForeign(cols[i])+"\""; + if(pcols.size()<2 && tbl.columnIsPrimary(cols[i]))code+=",\"primarykey\""; + if(tbl.columnHasDefault(cols[i]))code+=",\"default:"+tbl.columnDefault(cols[i])+"\""; + if(tbl.columnIsIndexed(cols[i]))code+=",\"index\""; + if(tbl.columnIsUnique(cols[i]))code+=",\"unique\""; + code+=")"; + } + if(pcols.size()>=2){ + code+=",\n\t\t\":primarykey\"=>array("; + for(int i=0;ihaveTable(m_name)){ + qDebug("Error: double definition of table %s.",m_name.toAscii().data()); + m_valid=false; + return; + } + if(!good.exactMatch(m_name)){ + qDebug("Error: table %s does not have a regular name.",m_name.toAscii().data()); + m_valid=false; + return; + } m_backup=str2bool(tbl.attribute("backup","0")); qDebug("Info: parsing table %s",m_name.toAscii().data()); QDomNodeList nl=tbl.elementsByTagName("Column"); @@ -238,8 +273,20 @@ WocTable::WocTable(const QDomElement&tbl) if(el.isNull())continue; s_col cl; cl.name=el.attribute("name"); - //TODO: check name syntax, check it is not doubled + //check name syntax, check it is not doubled + if(!good.exactMatch(cl.name)){ + qDebug("Error: table %s column %s does not have a regular name.",m_name.toAscii().data(),cl.name.toAscii().data()); + m_valid=false; + return; + } + if(haveColumn(cl.name)){ + qDebug("Error: double definition of column %s in table %s.",cl.name.toAscii().data(),m_name.toAscii().data()); + m_valid=false; + return; + } cl.isprime=str2bool(el.attribute("primarykey","0")); + cl.isunique=str2bool(el.attribute("unique","0")); + cl.isindex=str2bool(el.attribute("index","0")); if(el.hasAttribute("null")) cl.isnull=str2bool(el.attribute("null")); else @@ -247,7 +294,25 @@ WocTable::WocTable(const QDomElement&tbl) cl.type=el.attribute("type"); //TODO: validate type cl.foreign=el.attribute("foreignkey"); - //TODO: check foreign key exists + //check foreign key exists + if(cl.foreign!=""){ + QStringList fgn=cl.foreign.split(":"); + if(fgn.size()!=2){ + qDebug("Error: table %s column %s: foreign key definition must use syntax 'table:column'",m_name.toAscii().data(),cl.name.toAscii().data()); + m_valid=false; + return; + } + if(!woc->haveTable(fgn[0])){ + qDebug("Error: table %s column %s: foreign key target table %s does not exist",m_name.toAscii().data(),cl.name.toAscii().data(),fgn[0].toAscii().data()); + m_valid=false; + return; + } + if(!woc->table(fgn[0]).haveColumn(fgn[1])){ + qDebug("Error: table %s column %s: foreign key target table/column %s does not exist",m_name.toAscii().data(),cl.name.toAscii().data(),cl.foreign.toAscii().data()); + m_valid=false; + return; + } + } cl.defaultval=el.attribute("default"); //TODO: validate default against type QDomNodeList nl2=el.elementsByTagName("Value"); @@ -283,5 +348,138 @@ WocTable::WocTable(const QDomElement&tbl) m_valid=false; return; } - //TODO: check that we have a primary key + //check that we have a primary key + if(primaryColumns().size()==0){ + qDebug("Warning: table %s does not have any primary key columns.",m_name.toAscii().data()); + } +} + +QStringList WocTable::columns()const +{ + QStringList r; + for(int i=0;i > WocTable::getEnums()const +{ + QList > r; + for(int i=0;i > getEnums()const; + + QStringList foreigns()const; + QString foreignQuery(QString)const; + bool haveForeign(QString)const; private: bool m_valid,m_backup; QString m_name; struct s_col { QString name,type,foreign,defaultval; - bool isnull,isprime; + bool isnull,isprime,isindex,isunique; QList >enumvals; }; QListm_columns; @@ -81,6 +101,10 @@ class WocProcessor:public QObject QString svnRevision()const{return m_svnRev;} QString dbInst()const{return m_dbInst;} QString dbScheme()const{return m_dbScheme;} + QString dbVersion()const{return m_dbVer;} + + bool haveTable(QString)const; + WocTable table(QString)const; signals: void sfinalize(); void newClass(const WocClass&); @@ -88,7 +112,7 @@ class WocProcessor:public QObject private: QString m_baseDir,m_wobDir,m_verComm,m_verNeedComm,m_verHR; - QString m_svnTarget,m_svnRev,m_svnExe,m_dbInst,m_dbScheme; + QString m_svnTarget,m_svnRev,m_svnExe,m_dbInst,m_dbScheme,m_dbVer; QList m_tables; QList m_classes; diff --git a/www/inc/db/db_scheme.php b/www/inc/db/db_scheme.php index c2af52f..416c0b1 100644 --- a/www/inc/db/db_scheme.php +++ b/www/inc/db/db_scheme.php @@ -1,418 +1,3 @@ sversion="00.02"; - - // //////////////////// - //configuration - $this->scheme["config"]=array( - "ckey"=>array("string:32","primarykey"), - "cval"=>array("string") - ); - $this->preset["config"]=array( - array("ckey"=>"MagicSmokeVersion","cval"=>$this->sversion), - array("ckey"=>"ValidVouchers","cval"=>"1000 2000 2500 5000"), - array("ckey"=>"OrderStop","cval"=>"24"), - array("ckey"=>"SaleStop","cval"=>"0"), - array("ckey"=>"TicketIDChars","cval"=>"10"), - array("ckey"=>"VoucherIDChars","cval"=>"10") - ); - $this->backup[]="config"; - - // //////////////////// - // Machine Interface Stuff - - //clients - $this->scheme["host"]=array( - "hostname"=>array("string:64","primarykey"), - //if hostkey is NULL it is a special host (_any, _anon, _online) - "hostkey"=>array("string") - ); - $this->preset["host"]=array( - array("hostname"=>translate("SpecialHost","_any")), - array("hostname"=>translate("SpecialHost","_anon")), - array("hostname"=>translate("SpecialHost","_online")) - ); - $this->backup[]="host"; - - //client users (ticket sellers, admins, etc.; for customers and web logins see below) - $this->scheme["users"]=array( - "uname" => array("string:64","primarykey"), - "passwd" => array("string","notnull"), - //more detailed data that can be displayed to admins - "description" => array("text") - ); - $this->backup[]="users"; - $this->scheme["userrole"]=array( - "uname" =>array("string:64","notnull","foreignkey:users:uname","index"), - "role" =>array("string:32","notnull"), - ":primarykey"=>array("uname","role") - ); - $this->backup[]="userrole"; - $this->scheme["userhosts"]=array( - "uname" => array("string:64","notnull","foreignkey:users:uname","index"), - "host" => array("string:64","notnull","foreignkey:host:hostname"), - ":primarykey" =>array("uname","host") - ); - $this->backup[]="userhosts"; - //sessions - $this->scheme["session"]=array( - "sessionid" => array("string:64","primarykey"), - //if empty: not authenticated - "user"=>array("string:64"), - //emptied after authentication: - "hchallenge"=>array("string:64"), - "uchallenge"=>array("string:64"), - //unix timestamp at which to delete this session - // this needs to change to 64-bit int in 2038 - "timeout"=>array("int32","notnull") - ); - //templates - $this->scheme["template"]=array( - "filename" => array("string","primarykey"), - "description" =>array("string"), - "content" => array("blob"), - "hash" => array("string:32","notnull") //md5 - ); - $this->backup[]="template"; - - - // ////////////////////// - // Shared Stuff (web & GUI-client) - - //rooms - $this->scheme["room"]=array( - "roomid" => array("string:64","primarykey"), - "capacity" => array("int32","notnull"), - "description" => array("text") - ); - $this->backup[]="room"; - //event - $this->scheme["event"]=array( - "eventid" => array("seq32","primarykey"), - //display data - "title" => array("string","notnull"), - "artist" => array("string","notnull"), - "description" => array("text"), - //timing and location (needs to change to 64bit in 2038) - "starttime" => array("int32","notnull"), - "endtime" => array("int32","notnull"), - "roomid" => array("string:64","foreignkey:room:roomid"), - //initially a copy from room, can be adjusted - "capacity" => array("int32","notnull"), - //default pricing in cents - "defaultprice" => array("int32","notnull"), - //if not null/empty: event has been cancelled - "cancelreason" => array("string") - ); - $this->backup[]="event"; - - //shopping item type -// $this->scheme[""] - - //customer - $this->scheme["customer"]=array( - "customerid" => array("seq32","primarykey"), - //contact data - "name" => array("string","notnull"), - "address" => array("text"), - "contact" => array("string"),//phone or something - "comments" => array("text") - ); - $this->backup[]="customer"; - $this->scheme["webuser"]=array( - //online login data - "email" => array("string","primarykey"), - "customerid" => array("int32","unique","foreignkey:customer:customerid"), - "passwd" => array("string:64"),//salted SHA-1 hash of passwd - ); - $this->backup[]="webuser"; - - //kinds of shipping that are available (templates) - $this->scheme["shipping"]=array( - "shipid" => array("seq32","primarykey"), - "cost" => array("int32","notnull"), //default cost of this shipping type - "canuseweb" => array("bool","defaultbool:false"), //is offered on web interface - "canallusers" => array("bool","defaultbool:true"), //all GUI users may select it - "description" => array("string") //description for the shipping type - ); - $this->backup[]="shipping"; - - //orders by customers - $this->scheme["order"]=array( - "orderid" => array("seq32","primarykey"), - //customer - "customerid" => array("int32","foreignkey:customer:customerid"), - //seller (_online for web forms) - "soldby" => array("string:64","foreignkey:users:uname"), - //if not null/empty: this address for delivery, customer address for invoice - "deliveryaddress" => array("text"), - //if not null/empty: lodge/deposit the tickets at a seller with _deposit flag - "depositat" => array("string:64","foreignkey:users:uname"), - //status, see ORDER_* constants - "status" => array("int32","notnull"), - "ordertime" => array("int32","notnull"), - "senttime" => array("int32"), - //comments made on web form (eg. "urgently needed for dads birthday") - "comments" => array("text"), - //how much has been paid already (including used vouchers) - //this is for comparison with the price fields in ticket and voucher tables - "amountpaid" => array("int32"), - //shipping price - "shippingcosts" => array("int32","defaultint:0"), - //pointer to shipping type (none per default, programmatic default is in config) - "shippingtype" => array("int32","null","foreignkey:shipping:shipid") - ); - $this->backup[]="order"; - //tickets - $this->scheme["ticket"]=array( - //a 8-32 char code (code39: case-insensitive letters+digits) for the ticket - "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"), - //status of ticket (see TICKET_* constants) - "status" => array("int32","notnull"), - //if status is reserved, this contains the reserving seller - "reservedby" => array("string:64","foreignkey:users:uname"), - "reservetimeout" => array("int32"), - //sold to someone (may be NULL for direct sales or reserves) - "orderid" => array("int32","foreignkey:order:orderid") - ); - $this->backup[]="ticket"; - //vouchers and re-imbursments - $this->scheme["voucher"]=array( - //a 8-32 char code (code39: case-insensitive letters+digits) for the voucher - "voucherid" => array("string:32","primarykey"), - //price of the voucher (0 if cancelled) - "price" => array("int32","notnull"), - //order this voucher belongs to - "orderid" => array("int32","foreignkey:order:orderid"), - //marker: voucher has been used to pay something - "isused" => array("bool","defaultbool:false"), - //remaining value in cents (0 for cancelled) - "value" => array("int32","notnull") - ); - $this->backup[]="voucher"; - - //money transaction log - $this->scheme["moneylog"]=array( - "logid" => array("seq64","primarykey"), - "logtime" => array("int64","notnull"), - "uname" => array("string:64","foreignkey:users:uname","null"), - "orderid" => array("int32","foreignkey:order:orderid","null"), - "voucherid" => array("string:32","foreignkey:voucher:voucherid","null"), - "moved" => array("int32","notnull"), - "orderpaid" => array("int32","null"), - "orderdue" => array("int32","null"), - "vouchervalue" => array("int32","null"), - "log" => array("string","notnull") - ); - $this->backup[]="moneylog"; - - - // ///////////////////////// - // Web-Interface Stuff - - //shopping cart - $this->scheme["cart"]=array( - //the cookie for this cart - "cartid" => array("string:32","primarykey"), - //when the cart expires - "timeout" => array("int32","notnull"), - //shipping address during order process - "shippingaddress" => array("text"), - //customer comments during order process - "ordercomments" => array("text") - ); - //buying tickets - $this->scheme["cart_ticket"]=array( - "cartid" => array("string:32","notnull","foreignkey:cart:cartid"), - //tickets in the cart - "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( - "cvid" => array("seq64","primarykey"), - "cartid" => array("string:32","notnull","foreignkey:cart:cartid"), - //voucher value - "value" => array("int32","notnull") - ); - - //web sessions - $this->scheme["websession"]=array( - "sessionid" => array("string:64","primarykey"), - //customer - "customerid" => array("int32","notnull","foreignkey:customer:customerid"), - //unix timestamp at which to delete this session - // this needs to change to 64-bit int in 2038 - "timeout"=>array("int32","notnull") - ); - } - - /**return the version of this scheme*/ - public function version(){return $this->sversion;} - - /**return the tables to be created in order*/ - public function tableNames() - { - return array_keys($this->scheme); - } - - /**returns whether a table exists in the schema*/ - public function haveTable($t) - { - return in_array($t,array_keys($this->scheme)); - } - - /**return the tables that are included in the backup*/ - public function backupTables() - { - return $this->backup; - } - - /**return the full definition of a table, or false if it does not exist*/ - public function tableDefinition($tab) - { - if(!isset($this->scheme[$tab])) - return false; - return $this->scheme[$tab]; - } - - /**return the names of all columns of a table, or false if the table does not exist*/ - public function tableColumns($tab) - { - if(!isset($this->scheme[$tab])) - return false; - $r=array(); - foreach(array_keys($this->scheme[$tab]) as $c) - if(substr($c,0,1)!=":") - $r[]=$c; - return $r; - } - - /**return default lines of the table for the initialization; returns empty array if there are none*/ - public function tableDefaults($tab) - { - if(isset($this->preset[$tab]))return $this->preset[$tab]; - else return array(); - } - - /**return the type of a column, or false if it does not exist*/ - public function columnType($tab,$col) - { - if(!isset($this->scheme[$tab][$col])) - return false; - return $this->scheme[$tab][$col][0]; - } - - /**return the flags of a column, empty array if no flags are set, or false if the column does not exist*/ - public function columnFlags($tab,$col) - { - if(!isset($this->scheme[$tab][$col])) - return false; - $tmp=$this->scheme[$tab][$col]; - unset($tmp[0]); - return array_values($tmp); - } - - /**returns true if the given column is of an integer type*/ - public function isIntColumn($tab,$col) - { - if(!isset($this->scheme[$tab][$col])) - return false; - $tpa=explode(":",$this->scheme[$tab][$col][0]); - switch($tpa[0]){ - case "int32":case "seq32":case "int64":case "seq64": - return true; - default: - return false; - } - } - - /**returns the sequence column name if the table has a sequence, false otherwise*/ - public function hasSequence($tab) - { - if(!isset($this->scheme[$tab])) - return false; - foreach($this->scheme[$tab] as $cl => $def){ - if($def[0] == "seq32" || $def[0] == "seq64") - return $cl; - } - return false; - } - - /**returns true if the given column is of a string type*/ - public function isStringColumn($tab,$col) - { - if(!isset($this->scheme[$tab][$col])) - return false; - $tpa=explode(":",$this->scheme[$tab][$col][0]); - switch($tpa[0]){ - case "string":case "text": - return true; - default: - return false; - } - } - - /**returns true if the given column is of a blob type*/ - public function isBlobColumn($tab,$col) - { - if(!isset($this->scheme[$tab][$col])) - return false; - $tpa=explode(":",$this->scheme[$tab][$col][0]); - switch($tpa[0]){ - case "blob": - return true; - default: - return false; - } - } - - /**returns true if the given column is of a bool type*/ - public function isBoolColumn($tab,$col) - { - if(!isset($this->scheme[$tab][$col])) - return false; - $tpa=explode(":",$this->scheme[$tab][$col][0]); - switch($tpa[0]){ - case "bool": - case "boolean": - return true; - default: - return false; - } - } - - /**returns the names of all primary key columns of the table*/ - public function primaryKeyColumns($tab) - { - $r=array(); - //search for direct mark - foreach($this->scheme[$tab] as $col=>$def) - if(in_array("primarykey",$def)) - $r[]=$col; - //search for special mark - if(isset($this->scheme[$tab][":primarykey"])) - foreach($this->scheme[$tab][":primarykey"] as $col) - if(!in_array($col,$r)) - $r[]=$col; - //return result - return $r; - } -}; -$dbScheme=new DbScheme; +$dbScheme=new WobSchema; ?> \ No newline at end of file diff --git a/www/inc/loader.php b/www/inc/loader.php index f3cfe2a..2e51c6b 100644 --- a/www/inc/loader.php +++ b/www/inc/loader.php @@ -1,6 +1,9 @@ sversion;} + + /**return the tables to be created in order*/ + public function tableNames() + { + return array_keys($this->scheme); + } + + /**returns whether a table exists in the schema*/ + public function haveTable($t) + { + return in_array($t,array_keys($this->scheme)); + } + + /**return the tables that are included in the backup*/ + public function backupTables() + { + return $this->backup; + } + + /**return the full definition of a table, or false if it does not exist*/ + public function tableDefinition($tab) + { + if(!isset($this->scheme[$tab])) + return false; + return $this->scheme[$tab]; + } + + /**return the names of all columns of a table, or false if the table does not exist*/ + public function tableColumns($tab) + { + if(!isset($this->scheme[$tab])) + return false; + $r=array(); + foreach(array_keys($this->scheme[$tab]) as $c) + if(substr($c,0,1)!=":") + $r[]=$c; + return $r; + } + + /**return default lines of the table for the initialization; returns empty array if there are none*/ + public function tableDefaults($tab) + { + if(isset($this->preset[$tab]))return $this->preset[$tab]; + else return array(); + } + + /**return the type of a column, or false if it does not exist*/ + public function columnType($tab,$col) + { + if(!isset($this->scheme[$tab][$col])) + return false; + return $this->scheme[$tab][$col][0]; + } + + /**return the flags of a column, empty array if no flags are set, or false if the column does not exist*/ + public function columnFlags($tab,$col) + { + if(!isset($this->scheme[$tab][$col])) + return false; + $tmp=$this->scheme[$tab][$col]; + unset($tmp[0]); + return array_values($tmp); + } + + /**returns true if the given column is of an integer type*/ + public function isIntColumn($tab,$col) + { + if(!isset($this->scheme[$tab][$col])) + return false; + $tpa=explode(":",$this->scheme[$tab][$col][0]); + switch($tpa[0]){ + case "int32":case "seq32":case "int64":case "seq64": + return true; + default: + return false; + } + } + + /**returns the sequence column name if the table has a sequence, false otherwise*/ + public function hasSequence($tab) + { + if(!isset($this->scheme[$tab])) + return false; + foreach($this->scheme[$tab] as $cl => $def){ + if($def[0] == "seq32" || $def[0] == "seq64") + return $cl; + } + return false; + } + + /**returns true if the given column is of a string type*/ + public function isStringColumn($tab,$col) + { + if(!isset($this->scheme[$tab][$col])) + return false; + $tpa=explode(":",$this->scheme[$tab][$col][0]); + switch($tpa[0]){ + case "string":case "text": + return true; + default: + return false; + } + } + + /**returns true if the given column is of a blob type*/ + public function isBlobColumn($tab,$col) + { + if(!isset($this->scheme[$tab][$col])) + return false; + $tpa=explode(":",$this->scheme[$tab][$col][0]); + switch($tpa[0]){ + case "blob": + return true; + default: + return false; + } + } + + /**returns true if the given column is of a bool type*/ + public function isBoolColumn($tab,$col) + { + if(!isset($this->scheme[$tab][$col])) + return false; + $tpa=explode(":",$this->scheme[$tab][$col][0]); + switch($tpa[0]){ + case "bool": + case "boolean": + return true; + default: + return false; + } + } + + /**returns the names of all primary key columns of the table*/ + public function primaryKeyColumns($tab) + { + $r=array(); + //search for direct mark + foreach($this->scheme[$tab] as $col=>$def) + if(in_array("primarykey",$def)) + $r[]=$col; + //search for special mark + if(isset($this->scheme[$tab][":primarykey"])) + foreach($this->scheme[$tab][":primarykey"] as $col) + if(!in_array($col,$r)) + $r[]=$col; + //return result + return $r; + } +}; +?> \ No newline at end of file -- 1.7.2.5