Пример #1
0
// Close the connection, disconnecting from the database.
func (conn *Connection) Close() (err error) {
	if !conn.IsConnected() {
		return nil //?
	}

	conn.srvMtx.Lock()
	// perform a rollback
	conn.rollback()

	// logoff of the server
	if conn.handle != nil && conn.sessionHandle != nil {
		// Py_BEGIN_ALLOW_THREADS
		err = conn.environment.CheckStatus(C.OCISessionEnd((conn.handle),
			conn.environment.errorHandle, conn.sessionHandle,
			C.OCI_DEFAULT), "Close[end session]")
	}
	if conn.serverHandle != nil {
		if err2 := conn.environment.CheckStatus(
			C.OCIServerDetach(conn.serverHandle, conn.environment.errorHandle, C.OCI_DEFAULT),
			"Close[server detach]"); err2 != nil && err == nil {
			err = err2
		}
	}
	conn.srvMtx.Unlock()
	conn.Free(true)
	return err
}
Пример #2
0
// Close the connection, disconnecting from the database.
func (conn *Connection) Close() (err error) {
	if !conn.IsConnected() {
		return nil //?
	}

	// perform a rollback
	if err = conn.Rollback(); err != nil {
		setErrAt(err, "Close[rollback]")
		return
	}
	conn.srvMtx.Lock()
	defer conn.srvMtx.Unlock()

	// logoff of the server
	if conn.sessionHandle != nil {
		// Py_BEGIN_ALLOW_THREADS
		if err = conn.environment.CheckStatus(C.OCISessionEnd((conn.handle),
			conn.environment.errorHandle, conn.sessionHandle,
			C.OCI_DEFAULT), "Close[end session]"); err != nil {
			return
		}
		C.OCIHandleFree(unsafe.Pointer(conn.handle), C.OCI_HTYPE_SVCCTX)
	}
	conn.handle = nil
	if conn.serverHandle != nil {
		if err = conn.environment.CheckStatus(
			C.OCIServerDetach(conn.serverHandle, conn.environment.errorHandle, C.OCI_DEFAULT),
			"Close[server detach]"); err != nil {
			return
		}
		conn.serverHandle = nil
	}
	return nil
}
Пример #3
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)
		}
	}
}
Пример #4
0
// Close disconnects from an Oracle server.
//
// Any open sessions associated with the server are closed.
//
// Calling Close will cause Srv.IsOpen to return false. Once closed, a server cannot
// be re-opened. Call Env.OpenSrv to open a new server.
func (srv *Srv) Close() (err error) {
	srv.mu.Lock()
	defer srv.mu.Unlock()
	srv.log(_drv.cfg.Log.Srv.Close)
	err = srv.checkClosed()
	if err != nil {
		return errE(err)
	}
	errs := _drv.listPool.Get().(*list.List)
	defer func() {
		if value := recover(); value != nil {
			errs.PushBack(errR(value))
		}
		env := srv.env
		env.openSrvs.Remove(srv.elem)
		srv.openSess.Init()
		srv.env = nil
		srv.ocisrv = nil
		srv.ocisvcctx = nil
		srv.elem = nil
		_drv.srvPool.Put(srv)

		multiErr := newMultiErrL(errs)
		if multiErr != nil {
			err = errE(*multiErr)
		}
		errs.Init()
		_drv.listPool.Put(errs)
	}()

	// close sessions
	for e := srv.openSess.Front(); e != nil; e = e.Next() {
		err = e.Value.(*Ses).Close()
		if err != nil {
			errs.PushBack(errE(err))
		}
	}
	// detach server
	// OCIServerDetach invalidates oci server handle; no need to free server.ocisvr
	// OCIServerDetach invalidates oci service context handle; no need to free server.ocisvcctx
	r := C.OCIServerDetach(
		srv.ocisrv,     //OCIServer   *srvhp,
		srv.env.ocierr, //OCIError    *errhp,
		C.OCI_DEFAULT)  //ub4         mode );
	if r == C.OCI_ERROR {
		errs.PushBack(errE(srv.env.ociError()))
	}
	return nil
}
Пример #5
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
		}
	}
}
Пример #6
0
func (conn *OCI8Conn) Close() error {
	//TODO: add C.OCITransRollback()
	C.OCISessionEnd(
		(*C.OCISvcCtx)(conn.svc),
		(*C.OCIError)(conn.err),
		(*C.OCISession)(conn.usr),
		C.OCI_DEFAULT)
	C.OCIServerDetach(
		(*C.OCIServer)(conn.srv),
		(*C.OCIError)(conn.err),
		C.OCI_DEFAULT)
	C.OCIHandleFree(
		conn.env,
		C.OCI_HTYPE_ENV)

	conn.srv = nil
	conn.svc = nil
	conn.env = nil
	conn.err = nil
	return nil
}