// Frees environment handle -- calling this will make the lodbc package unusable because all setup is performed in init() func FreeEnvironment() error { ret := odbc.SQLFreeHandle(odbc.SQL_HANDLE_ENV, envHandle) if isError(ret) { return errorEnvironment(envHandle) } return nil }
func (stmt *statement) Close() error { //Verify that stmtHandle is valid if stmt.handle == 0 { return nil } //Verify that statement has not already been closed if stmt.isClosed { return nil } var err error //Close any open rows if stmt.rows != nil { err = stmt.rows.Close() } //Clear any bind values stmt.bindValues = nil //Free the statement handle ret := odbc.SQLFreeHandle(odbc.SQL_HANDLE_STMT, stmt.handle) if isError(ret) { err = errorStatement(stmt.handle, stmt.sqlStmt) } //Mark the statement as closed with the connection stmt.conn.closeStatement(stmt) //Clear the handles stmt.handle = 0 stmt.stmtDescHandle = 0 //Clear the finalizer runtime.SetFinalizer(stmt, nil) //Mark the rows as closed stmt.isClosed = true //Return any error if err != nil { return err } return nil }
// Close invalidates and potentially stops any current // prepared statements and transactions, marking this // connection as no longer in use. func (c *connection) Close() error { // Verify that connHandle is valid if c.handle == 0 { return nil } // Verify that connection has not already been closed if c.isClosed { return nil } var err error // Close all of the statements owned by the connection for key, _ := range c.statements { // Skip the statement if it is already nil if isNil(key) { continue } key.Close() } c.statements = nil // If the transaction is active, roll it back if c.isTransactionActive { ret := odbc.SQLEndTran(odbc.SQL_HANDLE_DBC, c.handle, odbc.SQL_ROLLBACK) if isError(ret) { err = errorConnection(c.handle) } //Turn AutoCommit back on ret = odbc.SQLSetConnectAttr(c.handle, odbc.SQL_ATTR_AUTOCOMMIT, odbc.SQLPOINTER(odbc.SQL_AUTOCOMMIT_ON), 0, nil) if isError(ret) { err = errorConnection(c.handle) } } // Disconnect connection ret := odbc.SQLDisconnect(c.handle) if isError(ret) { err = errorConnection(c.handle) } // Deallocate connection ret = odbc.SQLFreeHandle(odbc.SQL_HANDLE_DBC, c.handle) if isError(ret) { err = errorConnection(c.handle) } // Clear the handle c.handle = 0 // Set connection to closed c.isClosed = true //Clear the finalizer runtime.SetFinalizer(c, nil) // Return any error if err != nil { return err } return nil }