Some mysql stuff
This commit is contained in:
parent
9e917ece88
commit
4954d5fecb
|
@ -709,9 +709,20 @@ void Application::registerLuaFunctions()
|
||||||
// Database
|
// Database
|
||||||
g_lua.registerClass<Database>();
|
g_lua.registerClass<Database>();
|
||||||
|
|
||||||
|
// DBResult
|
||||||
|
g_lua.registerClass<DBResult>();
|
||||||
|
g_lua.bindClassMemberFunction<DBResult>("getDataInt", &DBResult::getDataInt);
|
||||||
|
g_lua.bindClassMemberFunction<DBResult>("getDataLong", &DBResult::getDataLong);
|
||||||
|
g_lua.bindClassMemberFunction<DBResult>("getDataString", &DBResult::getDataString);
|
||||||
|
//g_lua.bindClassMemberFunction<DBResult>("getDataStream", &DBResult::getDataStream);
|
||||||
|
g_lua.bindClassMemberFunction<DBResult>("next", &DBResult::next);
|
||||||
|
|
||||||
// Mysql
|
// Mysql
|
||||||
g_lua.registerClass<DatabaseMySQL>();
|
g_lua.registerClass<DatabaseMySQL>();
|
||||||
g_lua.bindClassStaticFunction<DatabaseMySQL>("create", []{ return DatabaseMySQLPtr(new DatabaseMySQL); });
|
g_lua.bindClassStaticFunction<DatabaseMySQL>("create", []{ return DatabaseMySQLPtr(new DatabaseMySQL); });
|
||||||
g_lua.bindClassMemberFunction<DatabaseMySQL>("connect", &DatabaseMySQL::connect);
|
g_lua.bindClassMemberFunction<DatabaseMySQL>("connect", &DatabaseMySQL::connect);
|
||||||
|
g_lua.bindClassMemberFunction<DatabaseMySQL>("executeQuery", &DatabaseMySQL::executeQuery);
|
||||||
|
g_lua.bindClassMemberFunction<DatabaseMySQL>("storeQuery", &DatabaseMySQL::storeQuery);
|
||||||
|
g_lua.bindClassMemberFunction<DatabaseMySQL>("escapeString", &DatabaseMySQL::escapeString);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
|
|
||||||
#include <framework/global.h>
|
#include <framework/global.h>
|
||||||
|
|
||||||
|
class DBResult;
|
||||||
class DatabaseMySQL;
|
class DatabaseMySQL;
|
||||||
|
|
||||||
|
typedef stdext::shared_object_ptr<DBResult> DBResultPtr;
|
||||||
typedef stdext::shared_object_ptr<DatabaseMySQL> DatabaseMySQLPtr;
|
typedef stdext::shared_object_ptr<DatabaseMySQL> DatabaseMySQLPtr;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -117,7 +117,7 @@ bool DatabaseMySQL::executeQuery(const std::string &query)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBResult* DatabaseMySQL::storeQuery(const std::string &query)
|
DBResultPtr DatabaseMySQL::storeQuery(const std::string &query)
|
||||||
{
|
{
|
||||||
//LOG_ONDELAY(500);
|
//LOG_ONDELAY(500);
|
||||||
|
|
||||||
|
@ -125,11 +125,11 @@ DBResult* DatabaseMySQL::storeQuery(const std::string &query)
|
||||||
MYSQL_RES *m_res = mysql_store_result(&m_mysqlHandle);
|
MYSQL_RES *m_res = mysql_store_result(&m_mysqlHandle);
|
||||||
|
|
||||||
if(m_res) {
|
if(m_res) {
|
||||||
DBResult* res = new DBResult(m_res);
|
DBResultPtr res = DBResultPtr(new DBResult(m_res));
|
||||||
if(res->next()) {
|
if(res->next()) {
|
||||||
return res;
|
return res;
|
||||||
} else {
|
} else {
|
||||||
delete res;
|
//delete res;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if(mysql_errno(&m_mysqlHandle) != 0) {
|
} else if(mysql_errno(&m_mysqlHandle) != 0) {
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
bool commit();
|
bool commit();
|
||||||
|
|
||||||
bool executeQuery(const std::string &query);
|
bool executeQuery(const std::string &query);
|
||||||
DBResult* storeQuery(const std::string &query);
|
DBResultPtr storeQuery(const std::string &query);
|
||||||
|
|
||||||
uint64_t getLastInsertedRowID();
|
uint64_t getLastInsertedRowID();
|
||||||
|
|
||||||
|
@ -41,15 +41,14 @@ protected:
|
||||||
MYSQL m_mysqlHandle;
|
MYSQL m_mysqlHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DBResult
|
class DBResult : public LuaObject
|
||||||
{
|
{
|
||||||
protected:
|
public:
|
||||||
DBResult(MYSQL_RES* res);
|
DBResult(MYSQL_RES* res);
|
||||||
~DBResult();
|
~DBResult();
|
||||||
|
|
||||||
friend class DatabaseMySQL;
|
friend class DatabaseMySQL;
|
||||||
|
|
||||||
public:
|
|
||||||
int32_t getDataInt(const std::string &s);
|
int32_t getDataInt(const std::string &s);
|
||||||
int64_t getDataLong(const std::string &s);
|
int64_t getDataLong(const std::string &s);
|
||||||
std::string getDataString(const std::string &s);
|
std::string getDataString(const std::string &s);
|
||||||
|
|
Loading…
Reference in New Issue