--- a/dbd/postgresql/connection.c Sun Nov 23 04:12:04 2008 +0000 +++ b/dbd/postgresql/connection.c Wed Nov 26 10:01:03 2008 +0000 @@ -53,14 +53,15 @@ conn->postgresql = PQsetdbLogin(host, port, options, tty, db, user, password); conn->statement_id = 0; - if (PQstatus(conn->postgresql) == CONNECTION_OK) { - luaL_getmetatable(L, DBD_POSTGRESQL_CONNECTION); - lua_setmetatable(L, -2); - } else { - luaL_error(L, "Failed to connect to database: %s", PQerrorMessage(conn->postgresql)); + if (PQstatus(conn->postgresql) != CONNECTION_OK) { lua_pushnil(L); + lua_pushfstring(L, "Failed to connect to database: %s", PQerrorMessage(conn->postgresql)); + return 2; } + luaL_getmetatable(L, DBD_POSTGRESQL_CONNECTION); + lua_setmetatable(L, -2); + return 1; } @@ -74,6 +75,7 @@ if (conn->postgresql) { PQfinish(conn->postgresql); disconnect = 1; + conn->postgresql = NULL; } lua_pushboolean(L, disconnect); @@ -109,7 +111,8 @@ } lua_pushnil(L); - return 1; + lua_pushstring(L, "Database not available"); + return 2; } /*