dbd/db2/connection.c

changeset 26
cf847efefdb5
parent 24
abb9499bef51
child 32
03ed0ca09837
--- a/dbd/db2/connection.c	Sat Dec 20 23:53:07 2008 +0000
+++ b/dbd/db2/connection.c	Mon Dec 22 07:36:54 2008 +0000
@@ -129,10 +129,9 @@
 static int connection_close(lua_State *L) {
     connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_DB2_CONNECTION);
     int disconnect = 0;   
+    SQLRETURN rc = SQL_SUCCESS;
 
     if (conn->db2) {
-	SQLRETURN rc = SQL_SUCCESS;
-
 	rollback(conn);
 
 	/* disconnect from the database */
@@ -141,10 +140,12 @@
 	/* free connection handle */
 	rc = SQLFreeHandle(SQL_HANDLE_DBC, conn->db2);
 
+	conn->db2 = 0;
+    }
+
+    if (conn->env) {
 	/* free environment handle */
 	rc = SQLFreeHandle(SQL_HANDLE_ENV, conn->env);
-
-	conn->db2 = 0;
     }
 
     lua_pushboolean(L, disconnect);

mercurial