Пример #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 ends a session on an Oracle server.
// does not remove Ses from Srv.openSess
func (ses *Ses) close() (err error) {
	ses.mu.Lock()
	defer ses.mu.Unlock()
	ses.log(_drv.cfg.Log.Ses.Close)
	err = ses.checkClosed()
	if err != nil {
		return errE(err)
	}
	errs := _drv.listPool.Get().(*list.List)
	defer func() {
		if value := recover(); value != nil {
			errs.PushBack(errR(value))
		}

		ses.srv = nil
		ses.ocisvcctx = nil
		ses.ocises = nil
		ses.openStmts.clear()
		ses.openTxs.clear()
		_drv.sesPool.Put(ses)

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

	// close transactions
	// close does not rollback or commit any transactions
	// Expect user to make explicit Commit or Rollback.
	// Any open transactions will be timedout by the server
	// if not explicitly committed or rolledback.
	ses.openTxs.closeAll(errs)
	ses.openStmts.closeAll(errs) // close statements

	// close session
	// OCISessionEnd invalidates oci session handle; no need to free session.ocises
	r := C.OCISessionEnd(
		ses.ocisvcctx,      //OCISvcCtx       *svchp,
		ses.srv.env.ocierr, //OCIError        *errhp,
		ses.ocises,         //OCISession      *usrhp,
		C.OCI_DEFAULT)      //ub4             mode );
	if r == C.OCI_ERROR {
		errs.PushBack(errE(ses.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
}