Worked on the mysql variable retrieval foundation.

This commit is contained in:
Brad Arant 2024-09-24 16:27:38 -07:00
parent 933c400922
commit 2e715a4d08
5 changed files with 27 additions and 2 deletions

View File

@ -1,5 +1,6 @@
#include "Global.h"
#include "Exception.h"
#include "__mysql.h"
#include <iostream>
namespace jet {
@ -41,7 +42,11 @@ namespace jet {
} if(variable.ifNext("@")) {
// TODO: should only allow environment variables. Allow substitution.
} else {
return variables[renderVariableName(name, variable)];
coreutils::MString splitName = renderVariableName(name, variable);
splitName.split(".");
if(splitName.getList().size() == 1)
return variables[splitName[0]];
return getSessionVariable(splitName);
}
throw coreutils::Exception("expected variable name or type designator.");
} if(variable.ifNext("#[")) {
@ -64,5 +69,12 @@ namespace jet {
renderVariableName(name, variable);
return name;
}
coreutils::ZString Global::getSessionVariable(coreutils::MString &splitName) {
if(sessions.find(splitName[0]) == sessions.end())
throw coreutils::Exception("requested session is not available in variable.");
sessions[splitName[0]]->getColumnValue(splitName[1]);
return splitName[1];
}
}

View File

@ -20,6 +20,7 @@ namespace jet {
void removeSession(coreutils::MString sessionId);
coreutils::ZString getVariable(coreutils::ZString &variable);
coreutils::MString renderVariableName(coreutils::MString &name, coreutils::ZString &variable);
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
std::map<coreutils::MString, coreutils::MString> variables;
std::map<coreutils::MString, __mysql *> sessions;

View File

@ -40,5 +40,11 @@ namespace jet {
qFields = mysql_num_fields(result);
}
}
coreutils::ZString __mysql::getColumnValue(coreutils::ZString column) {
if(column == "#")
return NbrOfRows;
return NbrOfRows;
}
}

View File

@ -16,6 +16,7 @@ namespace jet {
~__mysql();
void query(coreutils::MString query);
coreutils::ZString getColumnValue(coreutils::ZString column);
private:
MYSQL *mysql;
@ -24,6 +25,8 @@ namespace jet {
unsigned long *fieldLength;
unsigned int qFields;
coreutils::MString sessionId;
coreutils::MString NbrOfRows = "0";
};

View File

@ -9,6 +9,9 @@ int main(int argc, char **argv) {
coreutils::ZString data("<jet name1=\"localname\" filterblanklines=\"true\" trimlines=\"true\">\n"
" <comment>This is a comment and should not show up in the output.</comment>\n"
" <html>\n"
" $[nonexistant]\n"
" $[session.column]\n"
" $[.column]\n"
" <set name=\"ix\" value=\"1\" />\n"
" <set name=\"theexpr\" expr=\"SUBSTRING('abcdefg', 1, 3)\" />\n"
" <set name=\"theexpr2\" expr=\"5+3\" />\n"