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) {
|
||||
std::cout << "sessionId: " << sessionId << std::endl;
|
||||
if(sessionExists(sessionId))
|
||||
coreutils::Exception("sessionid already exists.");
|
||||
sessions[sessionId] = mysql;
|
||||
|
||||
std::cout << "::count: " << sessions.size() << std::endl;
|
||||
std::cout << "::" << sessionId << std::endl;
|
||||
}
|
||||
|
||||
void Global::removeSession(coreutils::MString sessionId) {
|
||||
@ -70,6 +74,14 @@ namespace jet {
|
||||
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) {
|
||||
if(sessions.find(splitName[0]) == sessions.end())
|
||||
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);
|
||||
coreutils::ZString getVariable(coreutils::ZString &variable);
|
||||
coreutils::MString renderVariableName(coreutils::MString &name, coreutils::ZString &variable);
|
||||
__mysql * getSession(coreutils::MString sessionId);
|
||||
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
||||
|
||||
std::map<coreutils::MString, coreutils::MString> variables;
|
||||
|
3
Tag.cpp
3
Tag.cpp
@ -113,6 +113,9 @@ namespace jet {
|
||||
} else if(ifTagName(in, "comment")) {
|
||||
__comment _comment(in, out, global);
|
||||
continue;
|
||||
} else if(ifTagName(in, "sql")) {
|
||||
__sql _sql(in, out, global);
|
||||
continue;
|
||||
} else if(ifTagName(in, "for")) {
|
||||
__for _for(in, out, global);
|
||||
continue;
|
||||
|
4
__if.h
4
__if.h
@ -1,5 +1,5 @@
|
||||
#ifndef __if_h__
|
||||
#define __if_h__
|
||||
#ifndef ____if_h__
|
||||
#define ____if_h__
|
||||
|
||||
#include "Tag.h"
|
||||
#include "ZString.h"
|
||||
|
20
__mysql.cpp
20
__mysql.cpp
@ -5,16 +5,15 @@
|
||||
namespace jet {
|
||||
|
||||
__mysql::__mysql(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
|
||||
processContainer(container);
|
||||
|
||||
|
||||
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"))
|
||||
coreutils::Exception("database must be specified for mysql tag.");
|
||||
throw coreutils::Exception("database must be specified for mysql tag.");
|
||||
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"))
|
||||
coreutils::Exception("password must be specified for mysql tag.");
|
||||
throw coreutils::Exception("password must be specified for mysql tag.");
|
||||
|
||||
sessionId = variables["sessionid"];
|
||||
|
||||
@ -22,6 +21,10 @@ namespace jet {
|
||||
|
||||
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);
|
||||
|
||||
std::cout << "mysql: " << mysql << std::endl;
|
||||
|
||||
processContainer(container);
|
||||
|
||||
}
|
||||
|
||||
@ -32,8 +35,11 @@ namespace jet {
|
||||
}
|
||||
|
||||
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);
|
||||
std::cout << "result: " << result << std::endl;
|
||||
if(result) {
|
||||
row = mysql_fetch_row(result);
|
||||
fieldLength = mysql_fetch_lengths(result);
|
||||
|
@ -10,12 +10,15 @@
|
||||
namespace jet {
|
||||
|
||||
__sql::__sql(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
||||
output = false;
|
||||
if(!hasContainer)
|
||||
throw coreutils::Exception("sql tag must have a container.");
|
||||
if(!global.sessionExists(variables["sessionid"]))
|
||||
coreutils::Exception("sessionid does not exist.");
|
||||
|
||||
global.sessions[variables["sessionid"]]->query(container);
|
||||
throw coreutils::Exception("sessionid does not exist.");
|
||||
std::cout << "cont: " << container << std::endl;
|
||||
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"
|
||||
" <html>\n"
|
||||
" $[nonexistant]\n"
|
||||
" $[session.column]\n"
|
||||
" $[.column]\n"
|
||||
" <mysql host=\"localhost\" database=\"barant\" user=\"barant\" password=\"uversa\" sessionid=\"1\">\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=\"theexpr\" expr=\"SUBSTRING('abcdefg', 1, 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=\"test$[ix$[ix1]]$[iz]\" value=\"0123456789\" />\n"
|
||||
" $[test$[ix$[ix1]]$[iz]]\n"
|
||||
" <mysql key=\"uu\">\n"
|
||||
" <if value1=\"X\" value2=\"Y\" type=\"ne\">\n"
|
||||
" 789\n"
|
||||
" <if expr=\"false\">\n"
|
||||
@ -36,7 +38,6 @@ int main(int argc, char **argv) {
|
||||
" 456\n"
|
||||
" </if>\n"
|
||||
" </if>\n"
|
||||
" </mysql>\n"
|
||||
" <for name=\"ix\" start=\"1\" end=\"5\" step=\"1\">\n"
|
||||
" -->#[ix]<--\n"
|
||||
" </for>\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user