<V col="orderid" val="1"/>
</Preset>
<Foreign method="getRabbit" via="rabbit:rabbitid=eventid"/>
+ <Unique>price,status</Unique>
</Table>
-</pre>
+</pre><p>
+
+The XML Tags are:
+<table frame="1" border="1">
+<tr><td><b>Tag</b></td><td><b>Description</b></td></tr>
+<tr><td>Table</td><td>Encompasses the entire table description.</td></tr>
+<tr><td>Column</td><td>Describes a single column.</td></tr>
+<tr><td> Column/Value</td><td>For enum columns: describes the values that the column can take.</td></tr>
+<tr><td>AuditColumn</td><td>Describes a column that exists in the audit-sub-table only.</td></tr>
+<tr><td>Foreign</td><td>Defines a method that returns rows from a sub-ordinate table via the foreign key relation given.</td></tr>
+<tr><td>Preset</td><td>Defines a row that will be inserted into the table at creation time.</td></tr>
+<tr><td> Preset/V</td><td>Defines a column value for a preset row.</td></tr>
+<tr><td>Unique</td><td>Defines a Unique constraint that spans several columns.</td></tr>
+</table><p>
Table attributes:
<table frame="1" border="1">
<a href="wolf.html">Previous: Overall Format</a><br>
<a href="wolf-comm.html">Next: Communication Layer</a>
-</html>
\ No newline at end of file
+</html>
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
//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
$ret.=")";
return $ret;
}
+
+ ///creates the complex unique constraints; overwrite this to implement DB specific syntax
+ protected function sqlCreateTableUniqueConstraint(array $constraints)
+ {
+ $ret="";
+ for($i=0;$i<count($constraints);$i++){
+ if($i>0)$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)
}
code+=")";
}
+ QStringList ucols=tbl.uniqueConstraints();
+ if(ucols.size()>0){
+ code+=",\n\t\t\":uniqueconstraint\"=>array(";
+ for(int i=0;i<ucols.size();i++){
+ if(i)code+=",";
+ code+="\""+ucols[i]+"\"";
+ }
+ code+=")";
+ }
code+="\n\t);\n";
if(tbl.inBackup()){
code+="\tself::$backup[]=\""+tbl.name()+"\";\n";
QString s=nl.at(i).toElement().text().trimmed();
if(s!="")m_docstrings<<s;
}
+
+ //Complex Unique cols
+ nl=elementsByTagName(tbl,"Unique");
+ for(int i=0;i<nl.size();i++){
+ m_uniquecols<<nl[i].toElement().text().trimmed();
+ }
//sanity checks
//check we have any columns at all
if(primaryColumns().size()==0){
qDebug("Warning: table %s does not have any primary key columns.",m_name.toLatin1().data());
}
+ //check that unique definitions are valid
+ for(QString uniq:m_uniquecols){
+ if(uniq.isEmpty()){
+ qDebug("Error: table %s contains an empty Unique declaration.",m_name.toLatin1().data());
+ m_valid=false;
+ return;
+ }
+ for(QString col:uniq.split(',')){
+ bool found=false;
+ for(auto c:m_columns)
+ if(c.name==col){
+ found=true;
+ break;
+ }
+ if(!found){
+ qDebug("Error: table %s has Unique declaration that refers to unknown column %s.",m_name.toLatin1().data(),col.toLatin1().data());
+ m_valid=false;
+ return;
+ }
+ }
+ }
}
WocTable auditTable()const;
/**returns the names of audit columns (except auditid)*/
QStringList auditColumns()const;
+
+ ///returns all complex Unique constraints (those not defined for a single column)
+ QStringList uniqueConstraints()const{return m_uniquecols;}
/**returns table documentation*/
QStringList docStrings()const{return m_docstrings;}
QList<QMap<QString,QString> >m_presets;
int m_backupsize=-1;
- QStringList m_docstrings;
+ QStringList m_docstrings,m_uniquecols;
QMap<QString,QString>m_fordocs;
//helper method: parses a single column element