From 29089468086e32425f269d6d00c2e22648c5b337 Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Sat, 9 Jul 2016 00:38:42 +0200 Subject: [PATCH] add ability to add complex unique constraints --- doc/wolf-db.html | 18 ++++++++++++++++-- phpbase/db.php | 17 ++++++++++++++++- woc/php/phpdb.cpp | 9 +++++++++ woc/proc/proctable.cpp | 27 +++++++++++++++++++++++++++ woc/proc/proctable.h | 5 ++++- 5 files changed, 72 insertions(+), 4 deletions(-) diff --git a/doc/wolf-db.html b/doc/wolf-db.html index b57e84b..ec239a2 100644 --- a/doc/wolf-db.html +++ b/doc/wolf-db.html @@ -39,8 +39,22 @@ For each database table woc needs a description of that table: <V col="orderid" val="1"/> </Preset> <Foreign method="getRabbit" via="rabbit:rabbitid=eventid"/> + <Unique>price,status</Unique> </Table> - +

+ +The XML Tags are: + + + + + + + + + + +
TagDescription
TableEncompasses the entire table description.
ColumnDescribes a single column.
  Column/ValueFor enum columns: describes the values that the column can take.
AuditColumnDescribes a column that exists in the audit-sub-table only.
ForeignDefines a method that returns rows from a sub-ordinate table via the foreign key relation given.
PresetDefines a row that will be inserted into the table at creation time.
  Preset/VDefines a column value for a preset row.
UniqueDefines a Unique constraint that spans several columns.

Table attributes: @@ -128,4 +142,4 @@ It is then enough to add the audit="yes" tag to each table that will ha Previous: Overall Format
Next: Communication Layer - \ No newline at end of file + diff --git a/phpbase/db.php b/phpbase/db.php index adc9bfa..68747c4 100644 --- a/phpbase/db.php +++ b/phpbase/db.php @@ -177,6 +177,7 @@ abstract class DbEngine const COLUMN_CREATE_KEY = 12; const COLUMN_CREATE_DEFAULT = 16; const COLUMN_CREATE_INDEX = 32; + const COLUMN_CREATE_CONSTRAINT = 64; const COLUMN_CREATE_ALL = 0xffff; ///creates SQL92 part of a statement for creating a single column @@ -186,8 +187,11 @@ abstract class DbEngine //check whether this is a special column if(substr($columnname,0,1)==":"){ if($columnname==":primarykey"){ - if($flag & self::COLUMN_CREATE_PKEY) + if($flags & self::COLUMN_CREATE_PKEY) $ret.=$this->sqlCreateTablePrimaryKey($columndef); + }else if($columnname==":uniqueconstraint"){ + if($flags & self::COLUMN_CREATE_CONSTRAINT) + $ret.=$this->sqlCreateTableUniqueConstraint($columndef); }else die("Unknown special column ".$columnname." while creating table ".$tablename); }else{ //column name @@ -219,6 +223,17 @@ abstract class DbEngine $ret.=")"; return $ret; } + + ///creates the complex unique constraints; overwrite this to implement DB specific syntax + protected function sqlCreateTableUniqueConstraint(array $constraints) + { + $ret=""; + for($i=0;$i0)$ret.=","; + $ret.="UNIQUE (".$constraints[$i].")"; + } + return $ret; + } /**creates a SQL92 statement for selects; overwrite this to implement DB specific syntax; the concrete DB implementation should append "for update" to the select statement if $this->transmode is true and the DB supports it*/ public function sqlSelect($table,$cols,$where,$orderby) diff --git a/woc/php/phpdb.cpp b/woc/php/phpdb.cpp index 472d928..aac07ff 100644 --- a/woc/php/phpdb.cpp +++ b/woc/php/phpdb.cpp @@ -198,6 +198,15 @@ void WocPHPTable::newTable(const WocTable&tbl) } code+=")"; } + QStringList ucols=tbl.uniqueConstraints(); + if(ucols.size()>0){ + code+=",\n\t\t\":uniqueconstraint\"=>array("; + for(int i=0;i >m_presets; int m_backupsize=-1; - QStringList m_docstrings; + QStringList m_docstrings,m_uniquecols; QMapm_fordocs; //helper method: parses a single column element -- 1.7.2.5