diff --git a/Global.cpp b/Global.cpp index 0fca745..1316345 100644 --- a/Global.cpp +++ b/Global.cpp @@ -87,5 +87,16 @@ namespace jet { throw coreutils::Exception("requested session is not available in variable."); return sessions[splitName[0]]->getColumnValue(splitName[1]); } - + + void Global::outputHeaders() { + if(headers.size() > 0) { + for(std::map::iterator header = headers.begin(); + header != headers.end(); + ++header) { + std::cout << header->first << ": " << header->second << std::endl; + } + std::cout << std::endl; + } + } + } diff --git a/Global.h b/Global.h index 83d6de6..c183589 100644 --- a/Global.h +++ b/Global.h @@ -3,6 +3,7 @@ #include "MString.h" #include +//#include namespace jet { @@ -22,10 +23,11 @@ namespace jet { coreutils::MString renderVariableName(coreutils::MString &name, coreutils::ZString &variable); __mysql * getSession(coreutils::MString sessionId); coreutils::ZString getSessionVariable(coreutils::MString &splitName); + void outputHeaders(); std::map variables; std::map sessions; - + std::map headers; }; diff --git a/Tag.cpp b/Tag.cpp index 4437df8..c1a23ed 100644 --- a/Tag.cpp +++ b/Tag.cpp @@ -4,6 +4,7 @@ #include "Log.h" #include "__mysql.h" #include "__sql.h" +#include "__whilerow.h" #include "__comment.h" #include "__for.h" #include "__if.h" @@ -14,6 +15,7 @@ #include "__system.h" #include "__jet.h" #include "__while.h" +#include "__header.h" #include namespace jet { @@ -116,6 +118,9 @@ namespace jet { } else if(ifTagName(in, "sql")) { __sql _sql(in, out, global); continue; + } else if(ifTagName(in, "whilerow")) { + __whilerow _whilerow(in, out, global); + continue; } else if(ifTagName(in, "for")) { __for _for(in, out, global); continue; @@ -143,6 +148,9 @@ namespace jet { } else if(ifTagName(in, "while")) { __while _while(in, out, global); continue; + } else if(ifTagName(in, "header")) { + __header _header(in, out, global); + continue; } else { out.write(in.charAt(0)); in.nextChar(); diff --git a/__header.cpp b/__header.cpp new file mode 100644 index 0000000..54599ff --- /dev/null +++ b/__header.cpp @@ -0,0 +1,35 @@ +#include "__header.h" +#include "Exception.h" +#include "Expression.h" +#include + +namespace jet { + + __header::__header(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) { + output = false; + if(!variableDefined("name")) + throw coreutils::Exception("header tag must have name defined."); + if(!variableDefined("expr") && variableDefined("value") && hasContainer) + throw coreutils::Exception("header tag cannot have both value and a container."); + if(variableDefined("expr") && !variableDefined("value") && hasContainer) + throw coreutils::Exception("header tag cannot have both expr and a container."); + if(variableDefined("expr") && variableDefined("value") && !hasContainer) + throw coreutils::Exception("header tag cannot have both expr and value."); + if(!variableDefined("expr") && !variableDefined("value") && !hasContainer) + throw coreutils::Exception("header tag must have a value, expr or a container."); + if(variableDefined("expr")) { + if(variableDefined("eval")) + throw coreutils::Exception("Cannot use eval with expr."); + global.headers[variables["name"]] = Expression(variables["expr"]).string; + } else if(hasContainer) { + processContainer(container); + if(evaluate) { + global.headers[variables["name"]] = out; + } else { + global.headers[variables["name"]] = container; + } + } else + global.headers[variables["name"]] = variables["value"]; + + } +} diff --git a/__header.h b/__header.h new file mode 100644 index 0000000..8a67180 --- /dev/null +++ b/__header.h @@ -0,0 +1,22 @@ +#ifndef ____header_h__ +#define ____header_h__ + +#include "Tag.h" +#include "ZString.h" +#include "MString.h" +#include + +namespace jet { + + class __header : public Tag { + + public: + __header(coreutils::ZString &in, coreutils::MString &parent, Global &global); + + protected: + + }; + +} + +#endif diff --git a/__mysql.cpp b/__mysql.cpp index d641b55..ab94b86 100644 --- a/__mysql.cpp +++ b/__mysql.cpp @@ -50,6 +50,15 @@ namespace jet { } } + void __mysql::nextRow() { + row = mysql_fetch_row(result); + fieldLength = mysql_fetch_lengths(result); + } + + bool __mysql::hasRow() { + return row != NULL; + } + coreutils::ZString __mysql::getColumnValue(coreutils::ZString column) { if(column == "#") return NbrOfRows; diff --git a/__mysql.h b/__mysql.h index 4151d8e..d59689f 100644 --- a/__mysql.h +++ b/__mysql.h @@ -16,6 +16,8 @@ namespace jet { ~__mysql(); void query(coreutils::MString query); + void nextRow(); + bool hasRow(); coreutils::ZString getColumnValue(coreutils::ZString column); private: diff --git a/__set.h b/__set.h index 8ea39c7..7f6e78a 100644 --- a/__set.h +++ b/__set.h @@ -1,5 +1,5 @@ -#ifndef __set_h__ -#define __set_h__ +#ifndef ____set_h__ +#define ____set_h__ #include "Tag.h" #include "ZString.h" diff --git a/__whilerow.cpp b/__whilerow.cpp index e38cae0..be9bb9b 100644 --- a/__whilerow.cpp +++ b/__whilerow.cpp @@ -1,32 +1,19 @@ #include "__whilerow.h" #include "Exception.h" +#include "__mysql.h" #include namespace jet { __whilerow::__whilerow(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) { - if(!variableDefined("host")) - throw coreutils::Exception("host must be specified for mysql tag."); - if(!variableDefined("database")) - throw coreutils::Exception("database must be specified for mysql tag."); - if(!variableDefined("user")) - throw coreutils::Exception("user must be specified for mysql tag."); - if(!variableDefined("password")) - throw coreutils::Exception("password must be specified for mysql tag."); - - while ((count != 0) && sql[sqlsession].row) { - processContainer(container); - - sql[sqlsession].row = mysql_fetch_row (sql[sqlsession].result); - sql[sqlsession].fieldlen = mysql_fetch_lengths (sql[sqlsession].result); - - --count; - } - - + int count = variables["count"].asInteger(); - + while ((count != 0) && global.getSession(variables["sessionid"])->hasRow()) { + processContainer(container); + global.getSession(variables["sessionid"])->nextRow(); + --count; + } } diff --git a/jet-2.0 b/jet-2.0 index 476ab51..af3ad69 100755 Binary files a/jet-2.0 and b/jet-2.0 differ diff --git a/jet-2.0.cpp b/jet-2.0.cpp index 2efcf7a..802efca 100644 --- a/jet-2.0.cpp +++ b/jet-2.0.cpp @@ -17,7 +17,9 @@ int main(int argc, char **argv) { coreutils::MString out; jet::__jet *jet = new jet::__jet(data, out, global); delete jet; - std::cout << "----------------------\n" << out; + std::cout << "----------------------" << std::endl; + global.outputHeaders(); + std::cout << out; } catch(coreutils::Exception e) { std::cout << "Error caught: " << e.text << std::endl; diff --git a/testjet.jet b/testjet.jet index 8a3e218..f45ab0c 100755 --- a/testjet.jet +++ b/testjet.jet @@ -1,14 +1,17 @@ #!./jet-2.0 +
This is a comment and should not show up in the output. $[nonexistant] + select * from testdata $[1.id] $[1.text] $[1.value] +