summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/LuaSQL.cc52
1 files changed, 51 insertions, 1 deletions
diff --git a/lib/LuaSQL.cc b/lib/LuaSQL.cc
index 3ea1465..6a7ca93 100644
--- a/lib/LuaSQL.cc
+++ b/lib/LuaSQL.cc
@@ -5,6 +5,13 @@ LuaSQLConnection::LuaSQLConnection(SQLConnection * _c) : c(_c) { }
enum SQLCONNECTION_methods_t {
SQLCONNECTION_QUERY = 0,
+ SQLCONNECTION_NUMROWS,
+ SQLCONNECTION_NUMFIELDS,
+ SQLCONNECTION_FETCHROW,
+ SQLCONNECTION_NUMAFFECTEDROWS,
+ SQLCONNECTION_INSERTID,
+ SQLCONNECTION_ERRNO,
+ SQLCONNECTION_ERROR,
};
enum SQLCONNECTION_functions_t {
@@ -12,7 +19,14 @@ enum SQLCONNECTION_functions_t {
};
struct lua_functypes_t SQLConnection_methods[] = {
- { SQLCONNECTION_QUERY, "Query", 1, 1, {LUA_STRING} },
+ { SQLCONNECTION_QUERY, "Query", 1, 1, {LUA_STRING} },
+ { SQLCONNECTION_NUMROWS, "NumRows", 0, 0, { } },
+ { SQLCONNECTION_NUMFIELDS, "NumFields", 0, 0, { } },
+ { SQLCONNECTION_FETCHROW, "FetchRow", 0, 0, { } },
+ { SQLCONNECTION_NUMAFFECTEDROWS, "NumAffectedRows", 0, 0, { } },
+ { SQLCONNECTION_INSERTID, "InsertId", 0, 0, { } },
+ { SQLCONNECTION_ERRNO, "ErrNO", 0, 0, { } },
+ { SQLCONNECTION_ERROR, "Error", 0, 0, { } },
{ -1, 0, 0, 0, 0 }
};
@@ -24,6 +38,13 @@ struct lua_functypes_t SQLConnection_functions[] = {
class sLua_SQLConnection : public Base {
public:
DECLARE_METHOD(SQLConnection, SQLCONNECTION_QUERY);
+ DECLARE_METHOD(SQLConnection, SQLCONNECTION_NUMROWS);
+ DECLARE_METHOD(SQLConnection, SQLCONNECTION_NUMFIELDS);
+ DECLARE_METHOD(SQLConnection, SQLCONNECTION_FETCHROW);
+ DECLARE_METHOD(SQLConnection, SQLCONNECTION_NUMAFFECTEDROWS);
+ DECLARE_METHOD(SQLConnection, SQLCONNECTION_INSERTID);
+ DECLARE_METHOD(SQLConnection, SQLCONNECTION_ERRNO);
+ DECLARE_METHOD(SQLConnection, SQLCONNECTION_ERROR);
DECLARE_FUNCTION(SQLConnection, SQLCONNECTION_NEWSQLCONNECTION);
private:
@@ -46,12 +67,41 @@ void LuaSQLConnection::pushstatics(Lua * L) throw (GeneralException) {
int sLua_SQLConnection::SQLConnection_proceed(Lua * L, int n, SQLConnection * c, int caller) {
String s;
+ AssocArray r;
+ AssocArrayIterator i;
switch (caller) {
case SQLCONNECTION_QUERY:
s = L->tostring(2);
L->push((lua_Number) c->query(s));
break;
+ case SQLCONNECTION_NUMROWS:
+ L->push((lua_Number) c->numrows());
+ break;
+ case SQLCONNECTION_NUMFIELDS:
+ L->push((lua_Number) c->numfields());
+ break;
+ case SQLCONNECTION_FETCHROW:
+ r = c->fetchrow();
+ L->newtable();
+ for (i = r->begin(); i != r->end(); i++) {
+ L->push(i->first());
+ L->push(i->second());
+ L->settable();
+ }
+ break;
+ case SQLCONNECTION_NUMAFFECTEDROWS:
+ L->push((lua_Number) c->numaffectedrows());
+ break;
+ case SQLCONNECTION_INSERTID:
+ L->push((lua_Number) c->insertid());
+ break;
+ case SQLCONNECTION_ERRNO:
+ L->push((lua_Number) c->errono());
+ break;
+ case SQLCONNECTION_ERROR:
+ L->push(c->error());
+ break;
}
return 1;