diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/LuaSQL.cc | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/LuaSQL.cc b/lib/LuaSQL.cc new file mode 100644 index 0000000..3ea1465 --- /dev/null +++ b/lib/LuaSQL.cc @@ -0,0 +1,84 @@ +#include <mysql.h> +#include "LuaSQL.h" + +LuaSQLConnection::LuaSQLConnection(SQLConnection * _c) : c(_c) { } + +enum SQLCONNECTION_methods_t { + SQLCONNECTION_QUERY = 0, +}; + +enum SQLCONNECTION_functions_t { + SQLCONNECTION_NEWSQLCONNECTION = 0, +}; + +struct lua_functypes_t SQLConnection_methods[] = { + { SQLCONNECTION_QUERY, "Query", 1, 1, {LUA_STRING} }, + { -1, 0, 0, 0, 0 } +}; + +struct lua_functypes_t SQLConnection_functions[] = { + { SQLCONNECTION_NEWSQLCONNECTION, "SQLConnection" , 4, 7, {LUA_STRING, LUA_STRING, LUA_STRING, LUA_STRING, LUA_NUMBER, LUA_STRING, LUA_NUMBER } }, + { -1, 0, 0, 0, 0 } +}; + +class sLua_SQLConnection : public Base { + public: + DECLARE_METHOD(SQLConnection, SQLCONNECTION_QUERY); + + DECLARE_FUNCTION(SQLConnection, SQLCONNECTION_NEWSQLCONNECTION); + private: + static int SQLConnection_proceed(Lua * L, int n, SQLConnection * obj, int caller); + static int SQLConnection_proceed_statics(Lua * L, int n, int caller); +}; + +void LuaSQLConnection::pushmembers(Lua * L) { + pushme(L, c); + + PUSH_METHOD(SQLConnection, SQLCONNECTION_QUERY); +} + +void LuaSQLConnection::pushstatics(Lua * L) throw (GeneralException) { + CHECK_METHODS(SQLConnection); + CHECK_FUNCTIONS(SQLConnection); + + PUSH_FUNCTION(SQLConnection, SQLCONNECTION_NEWSQLCONNECTION); +} + +int sLua_SQLConnection::SQLConnection_proceed(Lua * L, int n, SQLConnection * c, int caller) { + String s; + + switch (caller) { + case SQLCONNECTION_QUERY: + s = L->tostring(2); + L->push((lua_Number) c->query(s)); + break; + } + + return 1; +} + +int sLua_SQLConnection::SQLConnection_proceed_statics(Lua * L, int n, int caller) { + String host, user, passwd, db, socket = ""; + int port = 3306, cflags = 0; + + switch (caller) { + case SQLCONNECTION_NEWSQLCONNECTION: + host = L->tostring(1); + user = L->tostring(2); + passwd = L->tostring(3); + db = L->tostring(4); + if (n >= 5) + port = L->tonumber(5); + if (n >= 6) + socket = L->tostring(6); + if (n >= 7) + cflags = L->tonumber(7); + { + LuaSQLConnection c(new SQLConnection(host, user, passwd, db, port, socket, cflags)); + c.pushdestruct(L); + } + break; + } + + return 1; +} |