JetCore/__mysql.cpp
2024-09-18 16:52:08 -07:00

45 lines
1.4 KiB
C++

#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);
}
}
}