예제 #1
0
// Free temporary LOBs prior to fetch.
func lobVar_PreFetch(v *Variable) error {
	var isTemporary C.boolean

	var err error
	for i := uint(0); i < v.allocatedElements; i++ {
		if v.dataBytes != nil && uint(len(v.dataBytes)) > i && v.dataBytes[i] != 0 {
			if err = v.environment.CheckStatus(
				C.OCILobIsTemporary(v.environment.handle,
					v.environment.errorHandle,
					(*C.OCILobLocator)(unsafe.Pointer(&v.dataBytes[i])),
					&isTemporary),
				"LobIsTemporary"); err != nil {
				return err
			}
			if isTemporary == C.TRUE {
				// Py_BEGIN_ALLOW_THREADS
				if err = v.environment.CheckStatus(
					C.OCILobFreeTemporary(v.connection.handle,
						v.environment.errorHandle,
						(*C.OCILobLocator)(unsafe.Pointer(&v.dataBytes[i]))),
					"LobFreeTemporary"); err != nil {
					return err
				}
				// Py_END_ALLOW_THREADS
			}
		}
	}

	return nil
}
예제 #2
0
// Sets the value stored at the given array position.
func lobVarSetValue(v *Variable, pos uint, value interface{}) error {
	x, ok := value.([]byte)
	if !ok {
		return errgo.Newf("requires []byte, got %T", value)
	}
	var (
		isTemporary C.boolean
		lobType     C.ub1
	)

	hndl, err := v.getLobLoc(pos)
	if err != nil {
		return err
	}
	// make sure have temporary LOBs set up
	if err = v.environment.CheckStatus(
		C.OCILobIsTemporary(v.environment.handle, v.environment.errorHandle,
			hndl, &isTemporary),
		"LobIsTemporary"); err != nil {
		if CTrace {
			ctrace("OCILobIsTemporary(env=%p, err=%p, handle=%p, dst=%p): %v",
				v.environment.handle, v.environment.errorHandle, hndl, &isTemporary, err)
		}
		return errgo.Mask(err)
	}
	if isTemporary != C.TRUE {
		if v.typ.oracleType == C.SQLT_BLOB {
			lobType = C.OCI_TEMP_BLOB
		} else {
			lobType = C.OCI_TEMP_CLOB
		}
		// Py_BEGIN_ALLOW_THREADS
		if err = v.environment.CheckStatus(
			C.OCILobCreateTemporary(v.connection.handle,
				v.environment.errorHandle,
				hndl,
				C.OCI_DEFAULT, v.typ.charsetForm, lobType, C.FALSE,
				C.OCI_DURATION_SESSION),
			"LobCreateTemporary"); err != nil {
			// Py_END_ALLOW_THREADS
			return errgo.Mask(err)
		}
	}

	// trim the current value
	// Py_BEGIN_ALLOW_THREADS
	if err = v.environment.CheckStatus(
		C.OCILobTrim(v.connection.handle, v.environment.errorHandle, hndl, 0),
		"LobTrim"); err != nil {
		return errgo.Mask(

			// Py_END_ALLOW_THREADS
			err)
	}

	// set the current value
	// func (v *Variable) lobVarWrite(data []byte, pos uint, off int64) (amount int, err error) {
	_, err = v.lobVarWrite(x, pos, 0)
	return err
}
예제 #3
0
파일: lobvar.go 프로젝트: viney/goracle
// Sets the value stored at the given array position.
func lobVarSetValue(v *Variable, pos uint, value interface{}) error {
	x, ok := value.([]byte)
	if !ok {
		return fmt.Errorf("requires []byte, got %T", value)
	}
	var (
		isTemporary C.boolean
		lobType     C.ub1
		err         error
	)
	j := pos * v.typ.size

	// make sure have temporary LOBs set up
	if err = v.environment.CheckStatus(
		C.OCILobIsTemporary(v.environment.handle,
			v.environment.errorHandle,
			(*C.OCILobLocator)(unsafe.Pointer(&v.dataBytes[j])), &isTemporary),
		"LobIsTemporary"); err != nil {
		return err
	}
	if isTemporary != C.TRUE {
		if v.typ.oracleType == C.SQLT_BLOB {
			lobType = C.OCI_TEMP_BLOB
		} else {
			lobType = C.OCI_TEMP_CLOB
		}
		// Py_BEGIN_ALLOW_THREADS
		if err = v.environment.CheckStatus(
			C.OCILobCreateTemporary(v.connection.handle,
				v.environment.errorHandle,
				(*C.OCILobLocator)(unsafe.Pointer(&v.dataBytes[j])),
				C.OCI_DEFAULT, v.typ.charsetForm, lobType, C.FALSE,
				C.OCI_DURATION_SESSION),
			"LobCreateTemporary"); err != nil {
			// Py_END_ALLOW_THREADS
			return err
		}
	}

	// trim the current value
	// Py_BEGIN_ALLOW_THREADS
	if err = v.environment.CheckStatus(
		C.OCILobTrim(v.connection.handle,
			v.environment.errorHandle,
			(*C.OCILobLocator)(unsafe.Pointer(&v.dataBytes[j])), 0),
		"LobTrim"); err != nil {
		return err
	}
	// Py_END_ALLOW_THREADS

	// set the current value
	// func (v *Variable) lobVarWrite(data []byte, pos uint, off int64) (amount int, err error) {
	_, err = v.lobVarWrite(x, pos, 0)
	return err
}
예제 #4
0
// Free temporary LOBs prior to fetch.
func lobVarPreFetch(v *Variable) (err error) {
	if v.dataBytes == nil {
		return
	}

	var (
		isTemporary C.boolean
		hndl        *C.OCILobLocator
	)
	for i := uint(0); i < v.allocatedElements; i++ {
		//hndl = (*C.OCILobLocator)(v.getHandle(i))
		if hndl, err = v.getLobLoc(i); err != nil {
			return
		}
		if hndl == nil {
			continue
		}
		if err = v.environment.CheckStatus(
			C.OCILobIsTemporary(v.environment.handle,
				v.environment.errorHandle, hndl,
				&isTemporary),
			"LobIsTemporary"); err != nil {
			return
		}
		if isTemporary == C.TRUE {
			// Py_BEGIN_ALLOW_THREADS
			if err = v.environment.CheckStatus(
				C.OCILobFreeTemporary(v.connection.handle,
					v.environment.errorHandle,
					hndl),
				"LobFreeTemporary"); err != nil {
				return
			}
			// Py_END_ALLOW_THREADS
		}
	}

	return
}