Cuidados basicos com erros durante a criacao dos objetos.
This commit is contained in:
parent
195793ac7d
commit
f890247087
10
ls_pg.c
10
ls_pg.c
@ -2,6 +2,7 @@
|
|||||||
** LuaSQL, PostgreSQL driver
|
** LuaSQL, PostgreSQL driver
|
||||||
** Authors: Pedro Rabinovitch, Roberto Ierusalimschy, Carlos Cassino
|
** Authors: Pedro Rabinovitch, Roberto Ierusalimschy, Carlos Cassino
|
||||||
** Tomas Guisasola, Eduardo Quintao
|
** Tomas Guisasola, Eduardo Quintao
|
||||||
|
** $Id: ls_pg.c,v 1.12 2003/05/08 21:43:39 tomas Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -146,13 +147,9 @@ static int cur_close (lua_State *L) {
|
|||||||
/* Nullify structure fields. */
|
/* Nullify structure fields. */
|
||||||
cur->closed = 1;
|
cur->closed = 1;
|
||||||
PQclear(cur->pg_res);
|
PQclear(cur->pg_res);
|
||||||
cur->pg_res = NULL;
|
|
||||||
luaL_unref (L, LUA_REGISTRYINDEX, cur->conn);
|
luaL_unref (L, LUA_REGISTRYINDEX, cur->conn);
|
||||||
cur->conn = LUA_NOREF;
|
|
||||||
luaL_unref (L, LUA_REGISTRYINDEX, cur->colnames);
|
luaL_unref (L, LUA_REGISTRYINDEX, cur->colnames);
|
||||||
cur->colnames = LUA_NOREF;
|
|
||||||
luaL_unref (L, LUA_REGISTRYINDEX, cur->coltypes);
|
luaL_unref (L, LUA_REGISTRYINDEX, cur->coltypes);
|
||||||
cur->coltypes = LUA_NOREF;
|
|
||||||
|
|
||||||
lua_pushnumber(L, 1);
|
lua_pushnumber(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
@ -315,9 +312,7 @@ static int conn_close (lua_State *L) {
|
|||||||
/* Nullify structure fields. */
|
/* Nullify structure fields. */
|
||||||
conn->closed = 1;
|
conn->closed = 1;
|
||||||
luaL_unref (L, LUA_REGISTRYINDEX, conn->env);
|
luaL_unref (L, LUA_REGISTRYINDEX, conn->env);
|
||||||
conn->env = LUA_NOREF;
|
|
||||||
PQfinish(conn->pg_conn);
|
PQfinish(conn->pg_conn);
|
||||||
conn->pg_conn = NULL;
|
|
||||||
lua_pushnumber(L, 1);
|
lua_pushnumber(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -423,10 +418,9 @@ static void notice_processor (void *arg, const char *message) {
|
|||||||
** datasource, username, password, host and port.
|
** datasource, username, password, host and port.
|
||||||
*/
|
*/
|
||||||
static int env_connect (lua_State *L) {
|
static int env_connect (lua_State *L) {
|
||||||
/*env_data *env =*/ getenvironment (L); /* validate environment */
|
|
||||||
const char *sourcename = luaL_checkstring(L, 2);
|
const char *sourcename = luaL_checkstring(L, 2);
|
||||||
PGconn *conn;
|
PGconn *conn;
|
||||||
|
getenvironment (L); /* validate environment */
|
||||||
if ((lua_gettop (L) == 2) && (strchr (sourcename, '=') != NULL))
|
if ((lua_gettop (L) == 2) && (strchr (sourcename, '=') != NULL))
|
||||||
conn = PQconnectdb (luaL_check_string(L, 2));
|
conn = PQconnectdb (luaL_check_string(L, 2));
|
||||||
else {
|
else {
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
** LuaSQL, ODBC driver
|
** LuaSQL, ODBC driver
|
||||||
** Authors: Pedro Rabinovitch, Roberto Ierusalimschy, Diego Nehab,
|
** Authors: Pedro Rabinovitch, Roberto Ierusalimschy, Diego Nehab,
|
||||||
** Tomas Guisasola
|
** Tomas Guisasola
|
||||||
|
** $Id: ls_odbc.c,v 1.10 2003/05/08 21:43:39 tomas Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -293,7 +294,6 @@ static int cur_fetch (lua_State *L) {
|
|||||||
** Closes a cursor.
|
** Closes a cursor.
|
||||||
*/
|
*/
|
||||||
static int cur_close (lua_State *L) {
|
static int cur_close (lua_State *L) {
|
||||||
conn_data *conn;
|
|
||||||
cur_data *cur = (cur_data *) luaL_checkudata (L, 1, LUASQL_CURSOR_ODBC);
|
cur_data *cur = (cur_data *) luaL_checkudata (L, 1, LUASQL_CURSOR_ODBC);
|
||||||
SQLHSTMT hstmt = cur->hstmt;
|
SQLHSTMT hstmt = cur->hstmt;
|
||||||
SQLRETURN ret;
|
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->conn);
|
||||||
luaL_unref (L, LUA_REGISTRYINDEX, cur->colnames);
|
luaL_unref (L, LUA_REGISTRYINDEX, cur->colnames);
|
||||||
luaL_unref (L, LUA_REGISTRYINDEX, cur->coltypes);
|
luaL_unref (L, LUA_REGISTRYINDEX, cur->coltypes);
|
||||||
cur->conn = LUA_NOREF;
|
|
||||||
return pass(L);
|
return pass(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,22 +392,19 @@ static int create_cursor (lua_State *L, conn_data *conn,
|
|||||||
*/
|
*/
|
||||||
static int conn_close (lua_State *L) {
|
static int conn_close (lua_State *L) {
|
||||||
SQLRETURN ret;
|
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)
|
if (conn->closed)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Nullify structure fields. */
|
/* Nullify structure fields. */
|
||||||
conn->closed = 1;
|
conn->closed = 1;
|
||||||
luaL_unref (L, LUA_REGISTRYINDEX, conn->env);
|
luaL_unref (L, LUA_REGISTRYINDEX, conn->env);
|
||||||
conn->env = LUA_NOREF;
|
|
||||||
ret = SQLDisconnect(conn->hdbc);
|
ret = SQLDisconnect(conn->hdbc);
|
||||||
if (error(ret))
|
if (error(ret))
|
||||||
return fail(L, hDBC, conn->hdbc);
|
return fail(L, hDBC, conn->hdbc);
|
||||||
ret = SQLFreeHandle(hDBC, conn->hdbc);
|
ret = SQLFreeHandle(hDBC, conn->hdbc);
|
||||||
if (error(ret))
|
if (error(ret))
|
||||||
return fail(L, hDBC, conn->hdbc);
|
return fail(L, hDBC, conn->hdbc);
|
||||||
conn->hdbc = NULL;
|
|
||||||
return pass(L);
|
return pass(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user