Finished up whilerow. Added hearder tag.
This commit is contained in:
parent
a09e370e57
commit
3db9227adc
13
Global.cpp
13
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<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 <map>
|
||||
//#include <unordered_map>
|
||||
|
||||
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<coreutils::MString, coreutils::MString> variables;
|
||||
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 "__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 <iostream>
|
||||
|
||||
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();
|
||||
|
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) {
|
||||
if(column == "#")
|
||||
return NbrOfRows;
|
||||
|
@ -16,6 +16,8 @@ namespace jet {
|
||||
~__mysql();
|
||||
|
||||
void query(coreutils::MString query);
|
||||
void nextRow();
|
||||
bool hasRow();
|
||||
coreutils::ZString getColumnValue(coreutils::ZString column);
|
||||
|
||||
private:
|
||||
|
4
__set.h
4
__set.h
@ -1,5 +1,5 @@
|
||||
#ifndef __set_h__
|
||||
#define __set_h__
|
||||
#ifndef ____set_h__
|
||||
#define ____set_h__
|
||||
|
||||
#include "Tag.h"
|
||||
#include "ZString.h"
|
||||
|
@ -1,32 +1,19 @@
|
||||
#include "__whilerow.h"
|
||||
#include "Exception.h"
|
||||
#include "__mysql.h"
|
||||
#include <iostream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -1,14 +1,17 @@
|
||||
#!./jet-2.0
|
||||
<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>
|
||||
<html>
|
||||
$[nonexistant]
|
||||
<comment>
|
||||
<mysql host="localhost" database="barant" user="barant" password="uversa" sessionid="1">
|
||||
<sql sessionid="1">select * from testdata</sql>
|
||||
<whilerow name="index" count="10" sessionid="1">
|
||||
$[1.id] $[1.text] $[1.value]
|
||||
</whilerow>
|
||||
</mysql>
|
||||
</comment>
|
||||
<set name="ix" value="1" />
|
||||
<set name="theexpr" expr="SUBSTRING('abcdefg', 1, 3)" />
|
||||
<set name="theexpr2" expr="5+3" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user