From 2e715a4d085f4ea608d7ac90a1bd4a122f1d75e7 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Tue, 24 Sep 2024 16:27:38 -0700 Subject: [PATCH] Worked on the mysql variable retrieval foundation. --- Global.cpp | 16 ++++++++++++++-- Global.h | 1 + __mysql.cpp | 6 ++++++ __mysql.h | 3 +++ testjet.cpp | 3 +++ 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Global.cpp b/Global.cpp index ebcb3c6..fec7f4e 100644 --- a/Global.cpp +++ b/Global.cpp @@ -1,5 +1,6 @@ #include "Global.h" #include "Exception.h" +#include "__mysql.h" #include 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]; + } + } diff --git a/Global.h b/Global.h index 9c5bf86..e362bad 100644 --- a/Global.h +++ b/Global.h @@ -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 variables; std::map sessions; diff --git a/__mysql.cpp b/__mysql.cpp index 23391de..c9818d9 100644 --- a/__mysql.cpp +++ b/__mysql.cpp @@ -40,5 +40,11 @@ namespace jet { qFields = mysql_num_fields(result); } } + + coreutils::ZString __mysql::getColumnValue(coreutils::ZString column) { + if(column == "#") + return NbrOfRows; + return NbrOfRows; + } } diff --git a/__mysql.h b/__mysql.h index 3d5e746..4151d8e 100644 --- a/__mysql.h +++ b/__mysql.h @@ -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"; }; diff --git a/testjet.cpp b/testjet.cpp index c79c707..f1292dc 100644 --- a/testjet.cpp +++ b/testjet.cpp @@ -9,6 +9,9 @@ int main(int argc, char **argv) { coreutils::ZString data("\n" " This is a comment and should not show up in the output.\n" " \n" + " $[nonexistant]\n" + " $[session.column]\n" + " $[.column]\n" " \n" " \n" " \n"