summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO2
-rw-r--r--include/LuaSQL.h17
-rw-r--r--lib/LuaSQL.cc84
3 files changed, 102 insertions, 1 deletions
diff --git a/TODO b/TODO
index e498aca..ccc2e27 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
-) Add timeouts in HttpServ and HttpClient.
-) Add logging support in HttpServ.
-) Remove hardcoded skin, and create the HtmlSkin class.
--) Add LuaMysql.
+-) Improving LuaSQL.
diff --git a/include/LuaSQL.h b/include/LuaSQL.h
new file mode 100644
index 0000000..bec0260
--- /dev/null
+++ b/include/LuaSQL.h
@@ -0,0 +1,17 @@
+#ifndef __LUASQL_H__
+#define __LUASQL_H__
+
+#include <Exceptions.h>
+#include <SQL.h>
+#include <BLua.h>
+
+class LuaSQLConnection : public LuaObject {
+ public:
+ static void pushstatics(Lua *) throw (GeneralException);
+ LuaSQLConnection(SQLConnection *);
+ protected:
+ virtual void pushmembers(Lua *);
+ SQLConnection * c;
+};
+
+#endif
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;
+}