127 * success = connection:close() |
127 * success = connection:close() |
128 */ |
128 */ |
129 static int connection_close(lua_State *L) { |
129 static int connection_close(lua_State *L) { |
130 connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_DB2_CONNECTION); |
130 connection_t *conn = (connection_t *)luaL_checkudata(L, 1, DBD_DB2_CONNECTION); |
131 int disconnect = 0; |
131 int disconnect = 0; |
132 |
132 SQLRETURN rc = SQL_SUCCESS; |
133 if (conn->db2) { |
133 |
134 SQLRETURN rc = SQL_SUCCESS; |
134 if (conn->db2) { |
135 |
|
136 rollback(conn); |
135 rollback(conn); |
137 |
136 |
138 /* disconnect from the database */ |
137 /* disconnect from the database */ |
139 rc = SQLDisconnect(conn->db2); |
138 rc = SQLDisconnect(conn->db2); |
140 |
139 |
141 /* free connection handle */ |
140 /* free connection handle */ |
142 rc = SQLFreeHandle(SQL_HANDLE_DBC, conn->db2); |
141 rc = SQLFreeHandle(SQL_HANDLE_DBC, conn->db2); |
143 |
142 |
|
143 conn->db2 = 0; |
|
144 } |
|
145 |
|
146 if (conn->env) { |
144 /* free environment handle */ |
147 /* free environment handle */ |
145 rc = SQLFreeHandle(SQL_HANDLE_ENV, conn->env); |
148 rc = SQLFreeHandle(SQL_HANDLE_ENV, conn->env); |
146 |
|
147 conn->db2 = 0; |
|
148 } |
149 } |
149 |
150 |
150 lua_pushboolean(L, disconnect); |
151 lua_pushboolean(L, disconnect); |
151 return 1; |
152 return 1; |
152 } |
153 } |