From 65430bb471aef183e13c05466a4068e7f1b8d8fc Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 3 Oct 2008 11:44:20 -0700 Subject: Returning nil on 'FetchRow' if we don't have any more row to return. --- lib/LuaSQL.cc | 18 +++++++++++------- lib/SQL.cc | 2 ++ 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; -- cgit v1.2.3