Example #1
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
}
Example #2
0
// Trim the LOB variable to the specified length.
func (lv *ExternalLobVar) Trim(newSize int) error {
	var (
		err error
	)

	if err = lv.Verify(); err != nil {
		return errgo.Mask(

			// Py_BEGIN_ALLOW_THREADS
			err)
	}

	if CTrace {
		ctrace("OCILobTrim(conn=%p, lob=%x, newSize=%d)",
			lv.lobVar.connection.handle, lv.getHandleBytes(), newSize)
	}
	if err = lv.lobVar.environment.CheckStatus(
		C.OCILobTrim(lv.lobVar.connection.handle,
			lv.lobVar.environment.errorHandle,
			lv.getHandle(), C.ub4(newSize)),
		"LobTrim"); err != nil {
		return errgo.Mask(

			// Py_END_ALLOW_THREADS
			err)
	}

	return nil
}
Example #3
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 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
}
Example #4
0
// Trim the LOB variable to the specified length.
func (lv *ExternalLobVar) Trim(newSize int) error {
	var (
		err error
	)

	if err = lv.Verify(); err != nil {
		return err
	}
	// Py_BEGIN_ALLOW_THREADS
	if err = lv.lobVar.environment.CheckStatus(
		C.OCILobTrim(lv.lobVar.connection.handle,
			lv.lobVar.environment.errorHandle,
			(*C.OCILobLocator)(unsafe.Pointer(&lv.lobVar.dataBytes[lv.pos*lv.lobVar.size])),
			C.ub4(newSize)),
		"LobTrim"); err != nil {
		return err
	}
	// Py_END_ALLOW_THREADS
	return nil
}