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 "Global.h"
#include "Exception.h" #include "Exception.h"
#include "__mysql.h"
#include <iostream> #include <iostream>
namespace jet { namespace jet {
@ -41,7 +42,11 @@ namespace jet {
} if(variable.ifNext("@")) { } if(variable.ifNext("@")) {
// TODO: should only allow environment variables. Allow substitution. // TODO: should only allow environment variables. Allow substitution.
} else { } 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."); throw coreutils::Exception("expected variable name or type designator.");
} if(variable.ifNext("#[")) { } if(variable.ifNext("#[")) {
@ -65,4 +70,11 @@ namespace jet {
return name; 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); void removeSession(coreutils::MString sessionId);
coreutils::ZString getVariable(coreutils::ZString &variable); coreutils::ZString getVariable(coreutils::ZString &variable);
coreutils::MString renderVariableName(coreutils::MString &name, 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, coreutils::MString> variables;
std::map<coreutils::MString, __mysql *> sessions; std::map<coreutils::MString, __mysql *> sessions;

View File

@ -41,4 +41,10 @@ namespace jet {
} }
} }
coreutils::ZString __mysql::getColumnValue(coreutils::ZString column) {
if(column == "#")
return NbrOfRows;
return NbrOfRows;
}
} }

View File

@ -16,6 +16,7 @@ namespace jet {
~__mysql(); ~__mysql();
void query(coreutils::MString query); void query(coreutils::MString query);
coreutils::ZString getColumnValue(coreutils::ZString column);
private: private:
MYSQL *mysql; MYSQL *mysql;
@ -25,6 +26,8 @@ namespace jet {
unsigned int qFields; unsigned int qFields;
coreutils::MString sessionId; 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" 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" " <comment>This is a comment and should not show up in the output.</comment>\n"
" <html>\n" " <html>\n"
" $[nonexistant]\n"
" $[session.column]\n"
" $[.column]\n"
" <set name=\"ix\" value=\"1\" />\n" " <set name=\"ix\" value=\"1\" />\n"
" <set name=\"theexpr\" expr=\"SUBSTRING('abcdefg', 1, 3)\" />\n" " <set name=\"theexpr\" expr=\"SUBSTRING('abcdefg', 1, 3)\" />\n"
" <set name=\"theexpr2\" expr=\"5+3\" />\n" " <set name=\"theexpr2\" expr=\"5+3\" />\n"