summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2008-10-03 11:44:20 -0700
committerPixel <pixel@nobis-crew.org>2008-10-03 11:44:20 -0700
commit65430bb471aef183e13c05466a4068e7f1b8d8fc (patch)
tree1d05b3bf8179779ce4548dc89034dcbb7db9b020 /lib
parentd977ac60cf001e9bfa27fc7b2dcc357af9771e6f (diff)
Returning nil on 'FetchRow' if we don't have any more row to return.
Diffstat (limited to 'lib')
-rw-r--r--lib/LuaSQL.cc18
-rw-r--r--lib/SQL.cc2
2 files changed, 13 insertions, 7 deletions
diff --git a/lib/LuaSQL.cc b/lib/LuaSQL.cc
index 2563ff6..a5b2dce 100644
--- a/lib/LuaSQL.cc
+++ b/lib/LuaSQL.cc
@@ -111,13 +111,17 @@ int sLua_SQLConnection::SQLConnection_proceed(Lua * L, int n, SQLConnection * c,
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();
- }
+ if (c->numrows()) {
+ r = c->fetchrow();
+ L->newtable();
+ for (i = r.begin(); i != r.end(); i++) {
+ L->push(i->first);
+ L->push(i->second);
+ L->settable();
+ }
+ } else {
+ L->push();
+ }
break;
case SQLCONNECTION_NUMAFFECTEDROWS:
L->push((lua_Number) c->numaffectedrows());
diff --git a/lib/SQL.cc b/lib/SQL.cc
index ee205b5..e11b78b 100644
--- a/lib/SQL.cc
+++ b/lib/SQL.cc
@@ -100,6 +100,8 @@ AssocArray SQLConnection::fetchrow() {
for (i = 0; i < nf; i++) {
r[fields[i].name] = row[i] ? row[i] : "NULL";
}
+
+ nf--;
}
return r;