Finished up whilerow. Added hearder tag.
This commit is contained in:
parent
a09e370e57
commit
3db9227adc
11
Global.cpp
11
Global.cpp
@ -88,4 +88,15 @@ namespace jet {
|
|||||||
return sessions[splitName[0]]->getColumnValue(splitName[1]);
|
return sessions[splitName[0]]->getColumnValue(splitName[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Global::outputHeaders() {
|
||||||
|
if(headers.size() > 0) {
|
||||||
|
for(std::map<coreutils::MString, coreutils::MString>::iterator header = headers.begin();
|
||||||
|
header != headers.end();
|
||||||
|
++header) {
|
||||||
|
std::cout << header->first << ": " << header->second << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
4
Global.h
4
Global.h
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "MString.h"
|
#include "MString.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
//#include <unordered_map>
|
||||||
|
|
||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
@ -22,10 +23,11 @@ namespace jet {
|
|||||||
coreutils::MString renderVariableName(coreutils::MString &name, coreutils::ZString &variable);
|
coreutils::MString renderVariableName(coreutils::MString &name, coreutils::ZString &variable);
|
||||||
__mysql * getSession(coreutils::MString sessionId);
|
__mysql * getSession(coreutils::MString sessionId);
|
||||||
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
||||||
|
void outputHeaders();
|
||||||
|
|
||||||
std::map<coreutils::MString, coreutils::MString> variables;
|
std::map<coreutils::MString, coreutils::MString> variables;
|
||||||
std::map<coreutils::MString, __mysql *> sessions;
|
std::map<coreutils::MString, __mysql *> sessions;
|
||||||
|
std::map<coreutils::MString, coreutils::MString> headers;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
8
Tag.cpp
8
Tag.cpp
@ -4,6 +4,7 @@
|
|||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "__mysql.h"
|
#include "__mysql.h"
|
||||||
#include "__sql.h"
|
#include "__sql.h"
|
||||||
|
#include "__whilerow.h"
|
||||||
#include "__comment.h"
|
#include "__comment.h"
|
||||||
#include "__for.h"
|
#include "__for.h"
|
||||||
#include "__if.h"
|
#include "__if.h"
|
||||||
@ -14,6 +15,7 @@
|
|||||||
#include "__system.h"
|
#include "__system.h"
|
||||||
#include "__jet.h"
|
#include "__jet.h"
|
||||||
#include "__while.h"
|
#include "__while.h"
|
||||||
|
#include "__header.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace jet {
|
namespace jet {
|
||||||
@ -116,6 +118,9 @@ namespace jet {
|
|||||||
} else if(ifTagName(in, "sql")) {
|
} else if(ifTagName(in, "sql")) {
|
||||||
__sql _sql(in, out, global);
|
__sql _sql(in, out, global);
|
||||||
continue;
|
continue;
|
||||||
|
} else if(ifTagName(in, "whilerow")) {
|
||||||
|
__whilerow _whilerow(in, out, global);
|
||||||
|
continue;
|
||||||
} else if(ifTagName(in, "for")) {
|
} else if(ifTagName(in, "for")) {
|
||||||
__for _for(in, out, global);
|
__for _for(in, out, global);
|
||||||
continue;
|
continue;
|
||||||
@ -143,6 +148,9 @@ namespace jet {
|
|||||||
} else if(ifTagName(in, "while")) {
|
} else if(ifTagName(in, "while")) {
|
||||||
__while _while(in, out, global);
|
__while _while(in, out, global);
|
||||||
continue;
|
continue;
|
||||||
|
} else if(ifTagName(in, "header")) {
|
||||||
|
__header _header(in, out, global);
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
out.write(in.charAt(0));
|
out.write(in.charAt(0));
|
||||||
in.nextChar();
|
in.nextChar();
|
||||||
|
35
__header.cpp
Normal file
35
__header.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#include "__header.h"
|
||||||
|
#include "Exception.h"
|
||||||
|
#include "Expression.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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"];
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
22
__header.h
Normal file
22
__header.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef ____header_h__
|
||||||
|
#define ____header_h__
|
||||||
|
|
||||||
|
#include "Tag.h"
|
||||||
|
#include "ZString.h"
|
||||||
|
#include "MString.h"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace jet {
|
||||||
|
|
||||||
|
class __header : public Tag {
|
||||||
|
|
||||||
|
public:
|
||||||
|
__header(coreutils::ZString &in, coreutils::MString &parent, Global &global);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -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) {
|
coreutils::ZString __mysql::getColumnValue(coreutils::ZString column) {
|
||||||
if(column == "#")
|
if(column == "#")
|
||||||
return NbrOfRows;
|
return NbrOfRows;
|
||||||
|
@ -16,6 +16,8 @@ namespace jet {
|
|||||||
~__mysql();
|
~__mysql();
|
||||||
|
|
||||||
void query(coreutils::MString query);
|
void query(coreutils::MString query);
|
||||||
|
void nextRow();
|
||||||
|
bool hasRow();
|
||||||
coreutils::ZString getColumnValue(coreutils::ZString column);
|
coreutils::ZString getColumnValue(coreutils::ZString column);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
4
__set.h
4
__set.h
@ -1,5 +1,5 @@
|
|||||||
#ifndef __set_h__
|
#ifndef ____set_h__
|
||||||
#define __set_h__
|
#define ____set_h__
|
||||||
|
|
||||||
#include "Tag.h"
|
#include "Tag.h"
|
||||||
#include "ZString.h"
|
#include "ZString.h"
|
||||||
|
@ -1,33 +1,20 @@
|
|||||||
#include "__whilerow.h"
|
#include "__whilerow.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
|
#include "__mysql.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
__whilerow::__whilerow(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
|
__whilerow::__whilerow(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
|
||||||
|
|
||||||
if(!variableDefined("host"))
|
int count = variables["count"].asInteger();
|
||||||
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) {
|
while ((count != 0) && global.getSession(variables["sessionid"])->hasRow()) {
|
||||||
processContainer(container);
|
processContainer(container);
|
||||||
|
global.getSession(variables["sessionid"])->nextRow();
|
||||||
sql[sqlsession].row = mysql_fetch_row (sql[sqlsession].result);
|
--count;
|
||||||
sql[sqlsession].fieldlen = mysql_fetch_lengths (sql[sqlsession].result);
|
|
||||||
|
|
||||||
--count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@ int main(int argc, char **argv) {
|
|||||||
coreutils::MString out;
|
coreutils::MString out;
|
||||||
jet::__jet *jet = new jet::__jet(data, out, global);
|
jet::__jet *jet = new jet::__jet(data, out, global);
|
||||||
delete jet;
|
delete jet;
|
||||||
std::cout << "----------------------\n" << out;
|
std::cout << "----------------------" << std::endl;
|
||||||
|
global.outputHeaders();
|
||||||
|
std::cout << out;
|
||||||
}
|
}
|
||||||
catch(coreutils::Exception e) {
|
catch(coreutils::Exception e) {
|
||||||
std::cout << "Error caught: " << e.text << std::endl;
|
std::cout << "Error caught: " << e.text << std::endl;
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
#!./jet-2.0
|
#!./jet-2.0
|
||||||
<jet name1="localname" filterblanklines="true" trimlines="true">
|
<jet name1="localname" filterblanklines="true" trimlines="true">
|
||||||
|
<header name="Content-Type" value="text/html" />
|
||||||
<comment>This is a comment and should not show up in the output.</comment>
|
<comment>This is a comment and should not show up in the output.</comment>
|
||||||
<html>
|
<html>
|
||||||
$[nonexistant]
|
$[nonexistant]
|
||||||
|
<comment>
|
||||||
<mysql host="localhost" database="barant" user="barant" password="uversa" sessionid="1">
|
<mysql host="localhost" database="barant" user="barant" password="uversa" sessionid="1">
|
||||||
<sql sessionid="1">select * from testdata</sql>
|
<sql sessionid="1">select * from testdata</sql>
|
||||||
<whilerow name="index" count="10" sessionid="1">
|
<whilerow name="index" count="10" sessionid="1">
|
||||||
$[1.id] $[1.text] $[1.value]
|
$[1.id] $[1.text] $[1.value]
|
||||||
</whilerow>
|
</whilerow>
|
||||||
</mysql>
|
</mysql>
|
||||||
|
</comment>
|
||||||
<set name="ix" value="1" />
|
<set name="ix" value="1" />
|
||||||
<set name="theexpr" expr="SUBSTRING('abcdefg', 1, 3)" />
|
<set name="theexpr" expr="SUBSTRING('abcdefg', 1, 3)" />
|
||||||
<set name="theexpr2" expr="5+3" />
|
<set name="theexpr2" expr="5+3" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user