Work on mysql and sql.
This commit is contained in:
parent
2e715a4d08
commit
387203f4b3
12
Global.cpp
12
Global.cpp
@ -23,9 +23,13 @@ namespace jet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Global::addSession(coreutils::MString sessionId, __mysql *mysql) {
|
void Global::addSession(coreutils::MString sessionId, __mysql *mysql) {
|
||||||
|
std::cout << "sessionId: " << sessionId << std::endl;
|
||||||
if(sessionExists(sessionId))
|
if(sessionExists(sessionId))
|
||||||
coreutils::Exception("sessionid already exists.");
|
coreutils::Exception("sessionid already exists.");
|
||||||
sessions[sessionId] = mysql;
|
sessions[sessionId] = mysql;
|
||||||
|
|
||||||
|
std::cout << "::count: " << sessions.size() << std::endl;
|
||||||
|
std::cout << "::" << sessionId << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Global::removeSession(coreutils::MString sessionId) {
|
void Global::removeSession(coreutils::MString sessionId) {
|
||||||
@ -70,6 +74,14 @@ namespace jet {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__mysql * Global::getSession(coreutils::MString sessionId) {
|
||||||
|
std::cout << "sessionId: " << sessionId << std::endl;
|
||||||
|
std::cout << "count: " << sessions.size() << std::endl;
|
||||||
|
if(sessions.find(sessionId) == sessions.end())
|
||||||
|
throw coreutils::Exception("requested session is not available.");
|
||||||
|
return sessions[sessionId];
|
||||||
|
}
|
||||||
|
|
||||||
coreutils::ZString Global::getSessionVariable(coreutils::MString &splitName) {
|
coreutils::ZString Global::getSessionVariable(coreutils::MString &splitName) {
|
||||||
if(sessions.find(splitName[0]) == sessions.end())
|
if(sessions.find(splitName[0]) == sessions.end())
|
||||||
throw coreutils::Exception("requested session is not available in variable.");
|
throw coreutils::Exception("requested session is not available in variable.");
|
||||||
|
1
Global.h
1
Global.h
@ -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);
|
||||||
|
__mysql * getSession(coreutils::MString sessionId);
|
||||||
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
||||||
|
|
||||||
std::map<coreutils::MString, coreutils::MString> variables;
|
std::map<coreutils::MString, coreutils::MString> variables;
|
||||||
|
3
Tag.cpp
3
Tag.cpp
@ -113,6 +113,9 @@ namespace jet {
|
|||||||
} else if(ifTagName(in, "comment")) {
|
} else if(ifTagName(in, "comment")) {
|
||||||
__comment _comment(in, out, global);
|
__comment _comment(in, out, global);
|
||||||
continue;
|
continue;
|
||||||
|
} else if(ifTagName(in, "sql")) {
|
||||||
|
__sql _sql(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;
|
||||||
|
4
__if.h
4
__if.h
@ -1,5 +1,5 @@
|
|||||||
#ifndef __if_h__
|
#ifndef ____if_h__
|
||||||
#define __if_h__
|
#define ____if_h__
|
||||||
|
|
||||||
#include "Tag.h"
|
#include "Tag.h"
|
||||||
#include "ZString.h"
|
#include "ZString.h"
|
||||||
|
18
__mysql.cpp
18
__mysql.cpp
@ -5,16 +5,15 @@
|
|||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
__mysql::__mysql(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
|
__mysql::__mysql(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
|
||||||
processContainer(container);
|
|
||||||
|
|
||||||
if(!variableDefined("host"))
|
if(!variableDefined("host"))
|
||||||
coreutils::Exception("host must be specified for mysql tag.");
|
throw coreutils::Exception("host must be specified for mysql tag.");
|
||||||
if(!variableDefined("database"))
|
if(!variableDefined("database"))
|
||||||
coreutils::Exception("database must be specified for mysql tag.");
|
throw coreutils::Exception("database must be specified for mysql tag.");
|
||||||
if(!variableDefined("user"))
|
if(!variableDefined("user"))
|
||||||
coreutils::Exception("user must be specified for mysql tag.");
|
throw coreutils::Exception("user must be specified for mysql tag.");
|
||||||
if(!variableDefined("password"))
|
if(!variableDefined("password"))
|
||||||
coreutils::Exception("password must be specified for mysql tag.");
|
throw coreutils::Exception("password must be specified for mysql tag.");
|
||||||
|
|
||||||
sessionId = variables["sessionid"];
|
sessionId = variables["sessionid"];
|
||||||
|
|
||||||
@ -23,6 +22,10 @@ namespace jet {
|
|||||||
mysql = mysql_init(NULL);
|
mysql = mysql_init(NULL);
|
||||||
mysql = mysql_real_connect(mysql, variables["host"].c_str(), variables["user"].c_str(), variables["password"].c_str(), variables["database"].c_str(), 0, NULL, 0);
|
mysql = mysql_real_connect(mysql, variables["host"].c_str(), variables["user"].c_str(), variables["password"].c_str(), variables["database"].c_str(), 0, NULL, 0);
|
||||||
|
|
||||||
|
std::cout << "mysql: " << mysql << std::endl;
|
||||||
|
|
||||||
|
processContainer(container);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__mysql::~__mysql() {
|
__mysql::~__mysql() {
|
||||||
@ -32,8 +35,11 @@ namespace jet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __mysql::query(coreutils::MString query) {
|
void __mysql::query(coreutils::MString query) {
|
||||||
mysql_real_query(mysql, query.getData(), query.getLength());
|
std::cout << "q: " << query << std::endl;
|
||||||
|
int rc = mysql_real_query(mysql, query.getData(), query.getLength());
|
||||||
|
std::cout << "rc: " << rc << std::endl;
|
||||||
result = mysql_store_result(mysql);
|
result = mysql_store_result(mysql);
|
||||||
|
std::cout << "result: " << result << std::endl;
|
||||||
if(result) {
|
if(result) {
|
||||||
row = mysql_fetch_row(result);
|
row = mysql_fetch_row(result);
|
||||||
fieldLength = mysql_fetch_lengths(result);
|
fieldLength = mysql_fetch_lengths(result);
|
||||||
|
@ -10,12 +10,15 @@
|
|||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
__sql::__sql(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
__sql::__sql(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
||||||
|
output = false;
|
||||||
if(!hasContainer)
|
if(!hasContainer)
|
||||||
throw coreutils::Exception("sql tag must have a container.");
|
throw coreutils::Exception("sql tag must have a container.");
|
||||||
if(!global.sessionExists(variables["sessionid"]))
|
if(!global.sessionExists(variables["sessionid"]))
|
||||||
coreutils::Exception("sessionid does not exist.");
|
throw coreutils::Exception("sessionid does not exist.");
|
||||||
|
std::cout << "cont: " << container << std::endl;
|
||||||
global.sessions[variables["sessionid"]]->query(container);
|
processContainer(container);
|
||||||
|
std::cout << "out: " << out << std::endl;
|
||||||
|
global.getSession(variables["sessionid"])->query(out);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,8 +10,11 @@ int main(int argc, char **argv) {
|
|||||||
" <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"
|
" $[nonexistant]\n"
|
||||||
" $[session.column]\n"
|
" <mysql host=\"localhost\" database=\"barant\" user=\"barant\" password=\"uversa\" sessionid=\"1\">\n"
|
||||||
" $[.column]\n"
|
" <sql sessionid=\"1\">select * from testdata</sql>\n"
|
||||||
|
" $[1.text]\n"
|
||||||
|
" $[1.value]\n"
|
||||||
|
" </mysql>\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"
|
||||||
@ -27,7 +30,6 @@ int main(int argc, char **argv) {
|
|||||||
" <set name=\"ix1\" value=\"1\" />\n"
|
" <set name=\"ix1\" value=\"1\" />\n"
|
||||||
" <set name=\"test$[ix$[ix1]]$[iz]\" value=\"0123456789\" />\n"
|
" <set name=\"test$[ix$[ix1]]$[iz]\" value=\"0123456789\" />\n"
|
||||||
" $[test$[ix$[ix1]]$[iz]]\n"
|
" $[test$[ix$[ix1]]$[iz]]\n"
|
||||||
" <mysql key=\"uu\">\n"
|
|
||||||
" <if value1=\"X\" value2=\"Y\" type=\"ne\">\n"
|
" <if value1=\"X\" value2=\"Y\" type=\"ne\">\n"
|
||||||
" 789\n"
|
" 789\n"
|
||||||
" <if expr=\"false\">\n"
|
" <if expr=\"false\">\n"
|
||||||
@ -36,7 +38,6 @@ int main(int argc, char **argv) {
|
|||||||
" 456\n"
|
" 456\n"
|
||||||
" </if>\n"
|
" </if>\n"
|
||||||
" </if>\n"
|
" </if>\n"
|
||||||
" </mysql>\n"
|
|
||||||
" <for name=\"ix\" start=\"1\" end=\"5\" step=\"1\">\n"
|
" <for name=\"ix\" start=\"1\" end=\"5\" step=\"1\">\n"
|
||||||
" -->#[ix]<--\n"
|
" -->#[ix]<--\n"
|
||||||
" </for>\n"
|
" </for>\n"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user