mysql efforts...
This commit is contained in:
parent
3ba81a7d0a
commit
7453db9bd9
@ -14,7 +14,7 @@ namespace jet {
|
||||
string = op1.string;
|
||||
|
||||
if(in.unparsed().getLength() > 0) {
|
||||
std::cout << "1)" << in.unparsed() << std::endl;
|
||||
std::cout << "1)" << in.unparsed() << "(" << std::endl;
|
||||
if(in.ifNext("+"))
|
||||
operation = (char *)"+";
|
||||
else if(in.ifNext("-"))
|
||||
@ -27,7 +27,9 @@ namespace jet {
|
||||
Operand op2(in);
|
||||
std::cout << op1.string << ":" << operation << ":" << op2.string << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::cout << "Leaving expression string: " << string << std::endl;
|
||||
std::cout << "Unparsed: [" << in.unparsed() << "]" << std::endl;
|
||||
}
|
||||
|
15
Global.cpp
15
Global.cpp
@ -1,4 +1,5 @@
|
||||
#include "Global.h"
|
||||
#include "Exception.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace jet {
|
||||
@ -16,4 +17,18 @@ namespace jet {
|
||||
std::cout << i->first << "=[" << i->second << "]" << std::endl;
|
||||
}
|
||||
|
||||
bool Global::sessionExists(coreutils::MString sessionId) {
|
||||
return sessions.find(sessionId) != sessions.end();
|
||||
}
|
||||
|
||||
void Global::addSession(coreutils::MString sessionId, __mysql *mysql) {
|
||||
if(sessionExists(sessionId))
|
||||
coreutils::Exception("sessionid already exists.");
|
||||
sessions[sessionId] = mysql;
|
||||
}
|
||||
|
||||
void Global::removeSession(coreutils::MString sessionId) {
|
||||
sessions.erase(sessionId);
|
||||
}
|
||||
|
||||
}
|
||||
|
7
Global.h
7
Global.h
@ -6,6 +6,8 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
class __mysql;
|
||||
|
||||
class Global {
|
||||
|
||||
public:
|
||||
@ -13,8 +15,13 @@ namespace jet {
|
||||
virtual ~Global();
|
||||
|
||||
void dump();
|
||||
bool sessionExists(coreutils::MString sessionId);
|
||||
void addSession(coreutils::MString sessionId, __mysql *mysql);
|
||||
void removeSession(coreutils::MString sessionId);
|
||||
void getVariable(ZString variable);
|
||||
|
||||
std::map<coreutils::MString, coreutils::MString> variables;
|
||||
std::map<coreutils::MString, __mysql *> sessions;
|
||||
|
||||
};
|
||||
|
||||
|
@ -11,10 +11,7 @@ namespace jet {
|
||||
Operand(coreutils::ZString &in);
|
||||
|
||||
bool isNumber();
|
||||
bool isInteger();
|
||||
bool isFloat();
|
||||
bool isString();
|
||||
bool isVariable();
|
||||
|
||||
///
|
||||
/// boolean is set by internal processes to return the boolean
|
||||
|
1
Tag.cpp
1
Tag.cpp
@ -3,6 +3,7 @@
|
||||
#include "KeywordValue.h"
|
||||
#include "Log.h"
|
||||
#include "__mysql.h"
|
||||
#include "__sql.h"
|
||||
#include "__comment.h"
|
||||
#include "__for.h"
|
||||
#include "__if.h"
|
||||
|
5
Tag.h
5
Tag.h
@ -26,6 +26,9 @@ namespace jet {
|
||||
void processContainer(coreutils::ZString &container);
|
||||
void copyContainer(coreutils::ZString &in, coreutils::MString &out);
|
||||
|
||||
Global &global;
|
||||
coreutils::MString &parent;
|
||||
|
||||
coreutils::MString out;
|
||||
|
||||
bool output = true;
|
||||
@ -35,8 +38,6 @@ namespace jet {
|
||||
bool cleanWhitespace = false;
|
||||
|
||||
private:
|
||||
Global &global;
|
||||
coreutils::MString &parent;
|
||||
coreutils::ZString splitTagName;
|
||||
|
||||
int skipBlankLine(coreutils::ZString in);
|
||||
|
5
__if.cpp
5
__if.cpp
@ -42,9 +42,8 @@ namespace jet {
|
||||
}
|
||||
if(booleanResult)
|
||||
processContainer(container);
|
||||
else
|
||||
if(hasContainer2)
|
||||
processContainer(container2);
|
||||
else if(hasContainer2)
|
||||
processContainer(container2);
|
||||
|
||||
}
|
||||
|
||||
|
34
__mysql.cpp
34
__mysql.cpp
@ -1,10 +1,44 @@
|
||||
#include "__mysql.h"
|
||||
#include "Exception.h"
|
||||
#include <iostream>
|
||||
|
||||
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.");
|
||||
if(!variableDefined("database"))
|
||||
coreutils::Exception("database must be specified for mysql tag.");
|
||||
if(!variableDefined("user"))
|
||||
coreutils::Exception("user must be specified for mysql tag.");
|
||||
if(!variableDefined("password"))
|
||||
coreutils::Exception("password must be specified for mysql tag.");
|
||||
|
||||
sessionId = variables["sessionid"];
|
||||
|
||||
global.addSession(sessionId, this);
|
||||
|
||||
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() {
|
||||
global.removeSession(sessionId);
|
||||
mysql_free_result(result);
|
||||
mysql_close(mysql);
|
||||
}
|
||||
|
||||
void __mysql::query(coreutils::MString query) {
|
||||
mysql_real_query(mysql, query.getData(), query.getLength());
|
||||
result = mysql_store_result(mysql);
|
||||
if(result) {
|
||||
row = mysql_fetch_row(result);
|
||||
fieldLength = mysql_fetch_lengths(result);
|
||||
qFields = mysql_num_fields(result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
16
__mysql.h
16
__mysql.h
@ -1,10 +1,11 @@
|
||||
#ifndef __mysql_h__
|
||||
#define __mysql_h__
|
||||
#ifndef ____mysql_h__
|
||||
#define ____mysql_h__
|
||||
|
||||
#include "Tag.h"
|
||||
#include "ZString.h"
|
||||
#include "MString.h"
|
||||
#include <sstream>
|
||||
#include <mysql/mysql.h>
|
||||
|
||||
namespace jet {
|
||||
|
||||
@ -12,7 +13,18 @@ namespace jet {
|
||||
|
||||
public:
|
||||
__mysql(coreutils::ZString &in, coreutils::MString &parent, Global &global);
|
||||
~__mysql();
|
||||
|
||||
void query(coreutils::MString query);
|
||||
|
||||
private:
|
||||
MYSQL *mysql;
|
||||
MYSQL_RES *result;
|
||||
MYSQL_ROW row;
|
||||
unsigned long *fieldLength;
|
||||
unsigned int qFields;
|
||||
coreutils::MString sessionId;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
22
__sql.cpp
Normal file
22
__sql.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
#include "__sql.h"
|
||||
#include "Exception.h"
|
||||
#include "MString.h"
|
||||
#include "__mysql.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
namespace jet {
|
||||
|
||||
__sql::__sql(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
17
__sql.h
Normal file
17
__sql.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef ____sql_h__
|
||||
#define ____sql_h__
|
||||
|
||||
#include "Tag.h"
|
||||
|
||||
namespace jet {
|
||||
|
||||
class __sql : public Tag {
|
||||
|
||||
public:
|
||||
__sql(coreutils::ZString &in, coreutils::MString &out, Global &global);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user