Example #1
0
// Free deallocates the connection, disconnecting from the database if necessary.
func (conn *Connection) Free() {
	if conn.release {
		// Py_BEGIN_ALLOW_THREADS
		conn.Rollback()
		conn.srvMtx.Lock()
		C.OCISessionRelease(conn.handle, conn.environment.errorHandle, nil,
			0, C.OCI_DEFAULT)
		// Py_END_ALLOW_THREADS
		conn.srvMtx.Unlock()
	} else if !conn.attached {
		if conn.sessionHandle != nil {
			// Py_BEGIN_ALLOW_THREADS
			conn.Rollback()
			conn.srvMtx.Lock()
			C.OCISessionEnd(conn.handle, conn.environment.errorHandle,
				conn.sessionHandle, C.OCI_DEFAULT)
			// Py_END_ALLOW_THREADS
			conn.srvMtx.Unlock()
		}
		if conn.serverHandle != nil {
			C.OCIServerDetach(conn.serverHandle,
				conn.environment.errorHandle, C.OCI_DEFAULT)
		}
	}
}
Example #2
0
// Free deallocates the connection, disconnecting from the database if necessary.
func (conn *Connection) Free(freeEnvironment bool) {
	if conn.release {
		// Py_BEGIN_ALLOW_THREADS
		conn.srvMtx.Lock()
		conn.rollback()
		C.OCISessionRelease(conn.handle, conn.environment.errorHandle, nil,
			0, C.OCI_DEFAULT)
		// Py_END_ALLOW_THREADS
		conn.srvMtx.Unlock()
	} else if !conn.attached {
		conn.srvMtx.Lock()
		if conn.sessionHandle != nil {
			// Py_BEGIN_ALLOW_THREADS
			conn.rollback()
			C.OCISessionEnd(conn.handle, conn.environment.errorHandle,
				conn.sessionHandle, C.OCI_DEFAULT)
			// Py_END_ALLOW_THREADS
		}
		if conn.serverHandle != nil {
			C.OCIServerDetach(conn.serverHandle,
				conn.environment.errorHandle, C.OCI_DEFAULT)
		}
		conn.srvMtx.Unlock()
	}
	if conn.sessionHandle != nil {
		C.OCIHandleFree(unsafe.Pointer(conn.sessionHandle), C.OCI_HTYPE_SESSION)
		conn.sessionHandle = nil
	}
	if conn.handle != nil {
		C.OCIHandleFree(unsafe.Pointer(conn.handle), C.OCI_HTYPE_SVCCTX)
		conn.handle = nil
	}
	if conn.serverHandle != nil {
		C.OCIHandleFree(unsafe.Pointer(conn.serverHandle), C.OCI_HTYPE_SERVER)
		conn.serverHandle = nil
	}
	if freeEnvironment {
		// Free env (Issue #10)
		if conn.environment != nil {
			conn.environment.Free()
			conn.environment = nil
		}
	}
}