*processor: make determination of table null/notnull more logical
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 10 Jan 2010 13:08:56 +0000 (13:08 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 10 Jan 2010 13:08:56 +0000 (13:08 +0000)
*php: make db-retrievals more resilient
*qt: translated right names

git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@411 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

woc/phpout.cpp
woc/processor.cpp
woc/qtout.cpp

index 0a0adb9..5ccb84b 100644 (file)
@@ -162,18 +162,23 @@ void WocPHPServerOut::newTable(const WocTable&tbl)
        //static get instance
        QStringList cols=tbl.columns();
        QStringList pcols=tbl.primaryColumns();
+        //header
        code+="public static function getFromDB(";
        for(int i=0;i<pcols.size();i++){
                if(i)code+=",";
                code+="$"+pcols[i];
        }
        QString dbi="$"+woc->dbInst();
+        //DB query
        code+="){\n\tglobal "+dbi+";\n\t$res="+dbi+"->select(\""+tbl.name()+"\",\"*\",\"";
        for(int i=0;i<pcols.size();i++){
                if(i)code+=" AND ";
                code+=pcols[i]+"=\"."+dbi+"->escapeColumn(\""+tbl.name()+"\",\""+pcols[i]+"\",$"+pcols[i]+").\"";
        }
-       code+="\");\n\tif($res!==false && count($res)<1)return false;\n\telse return new WT"+tbl.name()+"($res[0],true);\n}\n\n";
+       code+="\");\n";
+        //check result
+       code+="\tif($res===false)return false;\n\tif(count($res)<1)return false;\n\telse return new WT"+tbl.name()+"($res[0],true);\n}\n\n";
+       
        //static get selection
        code+="public static function selectFromDB($where=\"\",$orderby=\"\"){\n\tglobal "+dbi+";\n\t$res="+dbi+"->select(\""+tbl.name()+"\",\"*\",$where,$orderby);\n\tif($res===false || count($res)<1)return array();\n\t";
        code+="$r=array();\n\tforeach($res as $row)\n\t\t$r[]=new WT"+tbl.name()+"($row,true);\n\treturn $r;\n}\n\n";
@@ -715,6 +720,7 @@ QString WocPHPServerOut::classMappings(const WocClass&cls)
                WocTable tab=WocProcessor::instance()->table(k[i]);
                //single object mapping
                code+="\nstatic public function fromTable"+k[i]+"($table){\n";
+               code+="\tif($table === false)return false;\n";
                code+="\t$data=new WO"+cls.name()+"();\n";
                QMap<QString,QString>map=cls.mapping(k[i]);
                QStringList mapk=cls.mappingProperties(k[i]);
index 279a93c..8da690c 100644 (file)
@@ -773,9 +773,11 @@ QPair<bool,WocTable::s_col> WocTable::parseColumn(const QDomElement&el,QString m
        cl.isprime=str2bool(el.attribute("primarykey","0"));
        cl.isunique=str2bool(el.attribute("unique","0"));
        cl.isindex=str2bool(el.attribute("index","0"));
+       if(cl.isprime)cl.isnull=false;
+       else cl.isnull=true;
        if(el.hasAttribute("null"))
                cl.isnull=str2bool(el.attribute("null"));
-       else
+       else if(el.hasAttribute("notnull"))
                cl.isnull=!str2bool(el.attribute("notnull","0"));
        cl.type=el.attribute("type");
        //TODO: validate type
index beb2e85..3762836 100644 (file)
@@ -737,6 +737,7 @@ void WocQtClientOut::trnList()
                code+=",\n    P"+pp[i].replace(':',"_");
        code+="\n  };\n";
        code+="  static QString rightToString(Right);\n";
+       code+="  static QString rightToLocalString(Right);\n";
        code+="  static Right stringToRight(QString);\n";
        code+="  static QStringList allKnownRightsString();\n";
        code+="  static QList<Right> allKnownRights();\n";
@@ -748,6 +749,12 @@ void WocQtClientOut::trnList()
        for(int i=0;i<p.size();i++)
                code+="\t\tcase P"+pp[i]+":return \""+p[i]+"\";\n";
        code+="\t\tdefault:return \"\";\n\t}\n}\n";
+       code+="QString "+m_prefix+"Interface::rightToLocalString(Right r)\n{\n\tswitch(r){\n";
+       for(int i=0;i<r.size();i++)
+               code+="\t\tcase R"+r[i]+":return tr(\""+r[i]+"\");\n";
+       for(int i=0;i<p.size();i++)
+               code+="\t\tcase P"+pp[i]+":return tr(\""+p[i]+"\");\n";
+       code+="\t\tdefault:return \"\";\n\t}\n}\n";
        code+=m_prefix+"Interface::Right "+m_prefix+"Interface::stringToRight(QString s)\n{\n";
        for(int i=0;i<r.size();i++)
                code+="\tif(s==\""+r[i]+"\")return R"+r[i]+";else\n";