Cuidados basicos com erros durante a criacao dos objetos.

This commit is contained in:
tomas 2003-05-08 21:43:39 +00:00
parent 195793ac7d
commit f890247087
2 changed files with 4 additions and 14 deletions

10
ls_pg.c
View File

@ -2,6 +2,7 @@
** LuaSQL, PostgreSQL driver
** Authors: Pedro Rabinovitch, Roberto Ierusalimschy, Carlos Cassino
** Tomas Guisasola, Eduardo Quintao
** $Id: ls_pg.c,v 1.12 2003/05/08 21:43:39 tomas Exp $
*/
#include <assert.h>
@ -146,13 +147,9 @@ static int cur_close (lua_State *L) {
/* Nullify structure fields. */
cur->closed = 1;
PQclear(cur->pg_res);
cur->pg_res = NULL;
luaL_unref (L, LUA_REGISTRYINDEX, cur->conn);
cur->conn = LUA_NOREF;
luaL_unref (L, LUA_REGISTRYINDEX, cur->colnames);
cur->colnames = LUA_NOREF;
luaL_unref (L, LUA_REGISTRYINDEX, cur->coltypes);
cur->coltypes = LUA_NOREF;
lua_pushnumber(L, 1);
return 1;
@ -315,9 +312,7 @@ static int conn_close (lua_State *L) {
/* Nullify structure fields. */
conn->closed = 1;
luaL_unref (L, LUA_REGISTRYINDEX, conn->env);
conn->env = LUA_NOREF;
PQfinish(conn->pg_conn);
conn->pg_conn = NULL;
lua_pushnumber(L, 1);
return 1;
}
@ -423,10 +418,9 @@ static void notice_processor (void *arg, const char *message) {
** datasource, username, password, host and port.
*/
static int env_connect (lua_State *L) {
/*env_data *env =*/ getenvironment (L); /* validate environment */
const char *sourcename = luaL_checkstring(L, 2);
PGconn *conn;
getenvironment (L); /* validate environment */
if ((lua_gettop (L) == 2) && (strchr (sourcename, '=') != NULL))
conn = PQconnectdb (luaL_check_string(L, 2));
else {

View File

@ -2,6 +2,7 @@
** LuaSQL, ODBC driver
** Authors: Pedro Rabinovitch, Roberto Ierusalimschy, Diego Nehab,
** Tomas Guisasola
** $Id: ls_odbc.c,v 1.10 2003/05/08 21:43:39 tomas Exp $
*/
#include <assert.h>
@ -293,7 +294,6 @@ static int cur_fetch (lua_State *L) {
** Closes a cursor.
*/
static int cur_close (lua_State *L) {
conn_data *conn;
cur_data *cur = (cur_data *) luaL_checkudata (L, 1, LUASQL_CURSOR_ODBC);
SQLHSTMT hstmt = cur->hstmt;
SQLRETURN ret;
@ -311,7 +311,6 @@ static int cur_close (lua_State *L) {
luaL_unref (L, LUA_REGISTRYINDEX, cur->conn);
luaL_unref (L, LUA_REGISTRYINDEX, cur->colnames);
luaL_unref (L, LUA_REGISTRYINDEX, cur->coltypes);
cur->conn = LUA_NOREF;
return pass(L);
}
@ -393,22 +392,19 @@ static int create_cursor (lua_State *L, conn_data *conn,
*/
static int conn_close (lua_State *L) {
SQLRETURN ret;
env_data *env;
conn_data *conn = (conn_data *) luaL_checkudata (L, 1, LUASQL_CONNECTION_ODBC);
conn_data *conn = (conn_data *)luaL_checkudata(L,1,LUASQL_CONNECTION_ODBC);
if (conn->closed)
return 0;
/* Nullify structure fields. */
conn->closed = 1;
luaL_unref (L, LUA_REGISTRYINDEX, conn->env);
conn->env = LUA_NOREF;
ret = SQLDisconnect(conn->hdbc);
if (error(ret))
return fail(L, hDBC, conn->hdbc);
ret = SQLFreeHandle(hDBC, conn->hdbc);
if (error(ret))
return fail(L, hDBC, conn->hdbc);
conn->hdbc = NULL;
return pass(L);
}