From b480eae069140e01ae5ffdd1114ab3493d5c5847 Mon Sep 17 00:00:00 2001 From: konrad Date: Mon, 2 Feb 2009 18:19:55 +0000 Subject: [PATCH] first steps on implementing DB table wrapper in woc git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@259 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- README | 19 ++++---- doc/prog_woc.html | 4 ++ wob/basics.wolf | 8 +++ wob/magicsmoke.wolf | 14 ++++-- wob/order.wolf | 8 +++ wob/user.wolf | 8 +++ woc/phpout.cpp | 90 ++++++++++++++++++++++++++++++++++++- woc/phpout.h | 10 ++++- woc/processor.cpp | 105 ++++++++++++++++++++++++++++++++++++++----- woc/processor.h | 28 ++++++++++++ woc/qtout.cpp | 1 + woc/qtout.h | 1 + www/inc/wbase/autoload.php | 4 +- www/inc/wbase/table.php | 4 +- 14 files changed, 271 insertions(+), 33 deletions(-) diff --git a/README b/README index b8c9ce7..d334a34 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ -Magic Smoke Ticketing System - README -======================================= +Magic Smoke Ticket Sale System - README +======================================== Magic Smoke was written to keep track of tickets for events (like concerts or theatric plays), sell them online or through retailers. It does not keep @@ -23,22 +23,23 @@ invariant sections, but will be relicensed when SFDL is released by the FSF. See COPYING.FDL for details. (COPYING.SFDL contains the current draft of SFDL as a preview, but is currently not binding.) -Directory src: +Directories src, woc, mkdist: The CPP-source files are licensed under GPLv3 or at your option any newer version of the license. See COPYING.GPL for details. -Directory src/zip -The ZIP code used by this program was copied from LinTouch and are licensed +Directory zip +The ZIP code used by this program was copied from LinTouch and is licensed under LGPL v.2.1. See src/zip/README and src/zip/COPYING for details. The source has been adapted by Konrad Rosenbaum to work with Qt 4.x instead of Qt 3.x. -Directory www: -The web-code (PHP files) is licensed under GNU AGPLv3 (see COPYING.AGPL for -details). This excludes the template sub-directory. +Directory www, wob: +The web-code (PHP files) and object meta files (*.wolf) are licensed under +GNU AGPLv3 (see COPYING.AGPL for details). This excludes the www/template +sub-directory. Directories www/template and examples: -Templates for web-pages (www/template) and examples for ODT and ticket templates +Templates for web-pages (www/template) and examples for ODF and ticket templates (examples) are in the public domain. Which means eg. they can be freely modified and then put under any license when you create your own web-site using this software. diff --git a/doc/prog_woc.html b/doc/prog_woc.html index d2e8dbc..ca6f426 100644 --- a/doc/prog_woc.html +++ b/doc/prog_woc.html @@ -18,6 +18,10 @@ The Web Object Compiler (woc) helps implementing these three-tier architecture i Three Tier Architecture

+

Overall File Format

+ +Woc translates Web Object Language Files (*.wolf) into PHP or C++/Qt code. The wolf files are simple XML syntax. +

Database Abstraction Layer

The Database Abstraction Layer is the servers lower bound towards the database. It is a simple translation of the database structure into usable PHP objects. diff --git a/wob/basics.wolf b/wob/basics.wolf index de63028..f8e0598 100644 --- a/wob/basics.wolf +++ b/wob/basics.wolf @@ -1,3 +1,11 @@ + + diff --git a/wob/magicsmoke.wolf b/wob/magicsmoke.wolf index 4073733..f0316be 100644 --- a/wob/magicsmoke.wolf +++ b/wob/magicsmoke.wolf @@ -1,14 +1,20 @@ + + - - - + - + diff --git a/wob/order.wolf b/wob/order.wolf index 027a336..12bee92 100644 --- a/wob/order.wolf +++ b/wob/order.wolf @@ -1,3 +1,11 @@ + +
diff --git a/wob/user.wolf b/wob/user.wolf index e1e68d1..d01ac53 100644 --- a/wob/user.wolf +++ b/wob/user.wolf @@ -1,3 +1,11 @@ + + diff --git a/woc/phpout.cpp b/woc/phpout.cpp index e911c0d..c8b2150 100644 --- a/woc/phpout.cpp +++ b/woc/phpout.cpp @@ -12,6 +12,92 @@ #include "phpout.h" -WocPHPServerOut::WocPHPServerOut(QString srcDir,QString subDir,QString ext,QString loader){} -void WocPHPServerOut::finalize(){} +#include + +static const QByteArray PHPSTART(""); + +static const QByteArray SCHEMASTART("class WobSchema extends WobSchemaBase\n{\nfunction __construct(){\n"); +static const QByteArray SCHEMAEND("}};\n"); + +WocPHPServerOut::WocPHPServerOut(QString srcDir,QString subDir,QString ext,bool clean) +{ + qDebug("Info: creating PHP Server Output Generator."); + m_basedir=WocProcessor::instance()->baseDir()+"/"+srcDir; + m_subdir=subDir; + m_fileext=ext; + //cleanup directory (remove normal files, assume remainder is harmless) + QDir d(m_basedir+"/"+m_subdir); + if(d.exists() && clean){ + QStringList ent=d.entryList(QDir::Files); + for(int i=0;i + #include "processor.h" class WocPHPServerOut:public WocOutput { public: - WocPHPServerOut(QString srcDir,QString subDir,QString ext,QString loader); + WocPHPServerOut(QString srcDir,QString subDir,QString ext,bool clean); protected: virtual void finalize(); virtual void newClass(const WocClass&); + virtual void newTable(const WocTable&); + private: + QString m_basedir,m_subdir,m_fileext; + QFile m_loader,m_schema; + + void addLoad(QString,QString); }; #endif diff --git a/woc/processor.cpp b/woc/processor.cpp index c1caa05..c21bbb0 100644 --- a/woc/processor.cpp +++ b/woc/processor.cpp @@ -22,6 +22,17 @@ #include #include + +static inline bool str2bool(QString s) +{ + bool b; + int i=s.toInt(&b,0); + if(b)return i?true:false; + s=s.toLower(); + if(s=="yes"||s=="y"||s=="on"||s=="true"||s=="t")return true; + return false; +} + WocProcessor* WocProcessor::inst=0; WocProcessor::WocProcessor() @@ -72,9 +83,18 @@ bool WocProcessor::processFile(QString fn) QString tn=el.tagName(); if(tn=="Class"){ WocClass cls(el); - if(cls.isValid()) + if(cls.isValid()){ + m_classes.append(cls); emit newClass(cls); - else + }else + return false; + }else + if(tn=="Table"){ + WocTable tbl(el); + if(tbl.isValid()){ + m_tables.append(tbl); + emit newTable(tbl); + }else return false; }else if(tn=="Project"){ @@ -97,7 +117,7 @@ bool WocProcessor::processFile(QString fn) new WocQtClientOut(el.attribute("sourceDir","."), el.attribute("subDir","qtwob"), el.attribute("priInclude","qtwob.pri")); }else if(tn=="PHPServerOutput"){ - new WocPHPServerOut(el.attribute("sourceDir","."), el.attribute("subDir","phpwob"), el.attribute("extension",".inc"), el.attribute("loader","")); + new WocPHPServerOut(el.attribute("sourceDir","."), el.attribute("subDir","phpwob"), el.attribute("extension",".inc"), str2bool(el.attribute("clean","0"))); }else if(tn=="Version"){ if(el.hasAttribute("comm")) @@ -106,16 +126,11 @@ bool WocProcessor::processFile(QString fn) m_verNeedComm=el.attribute("needcomm"); if(el.hasAttribute("humanReadable")) m_verHR=el.attribute("humanReadable"); - QDomNodeList nl2=el.elementsByTagName("Svn"); - for(int j=0;j0)callSvn(); + if(el.hasAttribute("svnTarget")) + m_svnTarget=el.attribute("target"); + if(el.hasAttribute("svnExe")) + m_svnExe=el.attribute("exe"); + callSvn(); } else{ qDebug("Warning: file %s has unknown element '%s' at line %i column %i", fn.toLocal8Bit().data(), tn.toLocal8Bit().data(), el.lineNumber(), el.columnNumber()); @@ -196,6 +211,7 @@ WocOutput::WocOutput() { connect(WocProcessor::instance(),SIGNAL(sfinalize()),this,SLOT(finalize())); connect(WocProcessor::instance(),SIGNAL(newClass(const WocClass&)),this,SLOT(newClass(const WocClass&))); + connect(WocProcessor::instance(),SIGNAL(newTable(const WocTable&)),this,SLOT(newTable(const WocTable&))); } WocOutput::~WocOutput(){} @@ -206,3 +222,66 @@ WocClass::WocClass(const QDomElement&cls) qDebug("not really parsing class %s",cls.attribute("name").toAscii().data()); } + +WocTable::WocTable(const QDomElement&tbl) +{ + m_valid=true; + //parse XML + m_name=tbl.attribute("name"); + //TODO: check name syntax, check it does not exist yet + m_backup=str2bool(tbl.attribute("backup","0")); + qDebug("Info: parsing table %s",m_name.toAscii().data()); + QDomNodeList nl=tbl.elementsByTagName("Column"); + //Columns + for(int i=0;i(n,nxval)); + nxval++; + } + m_columns.append(cl); + } + //Foreign getter methods + nl=tbl.elementsByTagName("Foreign"); + for(int i=0;i(el.attribute("method"),el.attribute("via"))); + //TODO: validate foreign getter + } + + //sanity checks + //check we have any columns at all + if(m_columns.size()==0){ + qDebug("Error: table %s does not have any columns.",m_name.toAscii().data()); + m_valid=false; + return; + } + //TODO: check that we have a primary key +} diff --git a/woc/processor.h b/woc/processor.h index 4ac09a3..55ca722 100644 --- a/woc/processor.h +++ b/woc/processor.h @@ -13,7 +13,9 @@ #ifndef WOC_PROCESSOR_H #define WOC_PROCESSOR_H +#include #include +#include class QDomElement; @@ -27,6 +29,27 @@ class WocClass bool m_valid; }; +class WocTable +{ + public: + WocTable(const QDomElement&); + + bool isValid()const{return m_valid;} + + QString name()const{return m_name;} + bool inBackup()const{return m_backup;} + private: + bool m_valid,m_backup; + QString m_name; + struct s_col { + QString name,type,foreign,defaultval; + bool isnull,isprime; + QList >enumvals; + }; + QListm_columns; + QList >m_foreign; +}; + class WocOutput:public QObject { Q_OBJECT @@ -37,6 +60,7 @@ class WocOutput:public QObject protected slots: virtual void finalize()=0; virtual void newClass(const WocClass&)=0; + virtual void newTable(const WocTable&)=0; }; class WocProcessor:public QObject @@ -60,11 +84,15 @@ class WocProcessor:public QObject signals: void sfinalize(); void newClass(const WocClass&); + void newTable(const WocTable&); private: QString m_baseDir,m_wobDir,m_verComm,m_verNeedComm,m_verHR; QString m_svnTarget,m_svnRev,m_svnExe,m_dbInst,m_dbScheme; + QList m_tables; + QList m_classes; + static WocProcessor*inst; void callSvn(); diff --git a/woc/qtout.cpp b/woc/qtout.cpp index 151848c..31fd52b 100644 --- a/woc/qtout.cpp +++ b/woc/qtout.cpp @@ -15,3 +15,4 @@ WocQtClientOut::WocQtClientOut(QString srcDir,QString subDir,QString prifile){} void WocQtClientOut::finalize(){} void WocQtClientOut::newClass(const WocClass&){} +void WocQtClientOut::newTable(const WocTable&){} \ No newline at end of file diff --git a/woc/qtout.h b/woc/qtout.h index ced1e88..1a50ef4 100644 --- a/woc/qtout.h +++ b/woc/qtout.h @@ -22,6 +22,7 @@ class WocQtClientOut:public WocOutput protected: virtual void finalize(); virtual void newClass(const WocClass&); + virtual void newTable(const WocTable&); }; #endif diff --git a/www/inc/wbase/autoload.php b/www/inc/wbase/autoload.php index daa9778..ba642c7 100644 --- a/www/inc/wbase/autoload.php +++ b/www/inc/wbase/autoload.php @@ -9,13 +9,13 @@ // +---------------------------------------------------------------------- // -$AUTOCLASS["WobTable"]="wbase/table.php"; +$AUTOCLASS["WobTable"]="inc/wbase/table.php"; function __autoload($cname) { global $AUTOCLASS; if(isset($AUTOCLASS[$cname])) - require_once 'inc/'.$AUTOCLASS[$cname]; + require_once $AUTOCLASS[$cname]; } ?> diff --git a/www/inc/wbase/table.php b/www/inc/wbase/table.php index b339c4e..afa6ef5 100644 --- a/www/inc/wbase/table.php +++ b/www/inc/wbase/table.php @@ -40,12 +40,12 @@ class WobTable public function __isset($name) { - //verify name and return true on existence + //verify name and return true on existence AND notnull } public function __unset($name) { - //ignore those fools! + //reset to null } /**insert the object under a new primary key value into the DB (implicitly calls newKey)*/ -- 1.7.2.5