示例#1
0
文件: driver.go 项目: hlife/goci
func ociGetError(err unsafe.Pointer) error {
	var errcode C.sb4
	var errbuff [512]C.char
	C.OCIErrorGet(err, 1, nil, &errcode, (*C.OraText)(unsafe.Pointer(&errbuff[0])), 512, C.OCI_HTYPE_ERROR)
	s := C.GoString(&errbuff[0])
	return errors.New(s)
}
示例#2
0
文件: env.go 项目: optimuse/ora
// getOciError gets an error returned by an Oracle server. No locking occurs.
func (env *Env) ociError() error {
	var errcode C.sb4
	C.OCIErrorGet(
		unsafe.Pointer(env.ocierr),
		1, nil,
		&errcode,
		(*C.OraText)(unsafe.Pointer(&env.errBuf[0])),
		C.ub4(len(env.errBuf)),
		C.OCI_HTYPE_ERROR)
	return er(C.GoString(&env.errBuf[0]))
}
示例#3
0
文件: oci8.go 项目: kwargs/go-oci8
func ociGetError(err unsafe.Pointer, context string) *OCIError {
	var errcode C.sb4
	var errbuff [512]C.char
	if rv := C.OCIErrorGet(
		err,
		1,
		nil,
		&errcode,
		(*C.OraText)(unsafe.Pointer(&errbuff[0])),
		512,
		C.OCI_HTYPE_ERROR); rv != C.OCI_SUCCESS {
		return &OCIError{0, "no oracle error?", ""}
	}

	s := C.GoString(&errbuff[0])
	return &OCIError{int(errcode), s, context}
}
示例#4
0
// Check for an error in the last call and if an error has occurred,
// retrieve the error message from the database environment
func (env *Environment) CheckStatus(status C.sword, at string) error {
	// if status != C.OCI_SUCCESS {
	// log.Printf("CheckStatus(%d (%s), %s)", status, status == C.OCI_SUCCESS, at)
	// }
	if status == C.OCI_SUCCESS || status == C.OCI_SUCCESS_WITH_INFO {
		// log.Printf("CheckStatus(%d): OK", status)
		return nil
	}
	if err := checkStatus(status, true); err != nil {
		if err != NoDataFound {
			log.Printf("CheckStatus(%d): ERR=%s", status, err)
		}
		return err
	}
	var (
		errorcode int
		ec        C.sb4
		errbuf    = make([]byte, 2001)
		i         = C.ub4(0)
		errstat   C.sword
		message   = make([]byte, 0, 2000)
	)
	for {
		i++
		errstat = C.OCIErrorGet(unsafe.Pointer(env.errorHandle), i, nil,
			&ec, (*C.OraText)(&errbuf[0]), C.ub4(len(errbuf)-1),
			C.OCI_HTYPE_ERROR)
		if ec != 0 && errorcode == 0 {
			errorcode = int(ec)
		}
		message = append(message, errbuf[:bytes.IndexByte(errbuf, 0)]...)
		if errstat == C.OCI_NO_DATA {
			break
		}
	}
	err := &Error{Code: errorcode,
		Message: fmt.Sprintf("[%d] %s", status, message),
		At:      at}
	// log.Printf("CheckStatus(%d) ERR=%v", err)
	return err
}
示例#5
0
// CheckStatus checks for an error in the last call and if an error has occurred,
// retrieve the error message from the database environment
func (env *Environment) CheckStatus(status C.sword, at string) error {
	// if status != C.OCI_SUCCESS {
	// Log.Debug("CheckStatus", "status", status, "success?", status == C.OCI_SUCCESS, "at", at)
	// }
	if status == C.OCI_SUCCESS || status == C.OCI_SUCCESS_WITH_INFO {
		// Log.Debug("CheckStatus: OK", "status", status)
		return nil
	}
	if err := checkStatus(status, true); err != nil {
		if err != NoDataFound {
			Log.Error("CheckStatus", "status", status, "at", at, "error", err, "stackTrace", getStackTrace())
		}
		return err
	}
	var (
		errorcode int
		ec        C.sb4
		errbuf    = make([]byte, 2001)
		i         = C.ub4(0)
		errstat   C.sword
		message   = make([]byte, 0, 2000)
	)
	for {
		i++
		errstat = C.OCIErrorGet(unsafe.Pointer(env.errorHandle), i, nil,
			&ec, (*C.OraText)(&errbuf[0]), C.ub4(len(errbuf)-1),
			C.OCI_HTYPE_ERROR)
		if ec != 0 && errorcode == 0 {
			errorcode = int(ec)
		}
		message = append(message, errbuf[:bytes.IndexByte(errbuf, 0)]...)
		if errstat == C.OCI_NO_DATA {
			break
		}
	}
	return NewErrorAt(errorcode, fmt.Sprintf("[%d] %s", status, message), at)
}