Exemplo n.º 1
0
func (def *defFloat32) value() (value interface{}, err error) {
	if def.isNullable {
		oraFloat32Value := Float32{IsNull: def.null < C.sb2(0)}
		if !oraFloat32Value.IsNull {
			var float32Value float32
			r := C.OCINumberToReal(
				def.rset.stmt.ses.srv.env.ocierr,       //OCIError              *err,
				&def.ociNumber,                         //const OCINumber     *number,
				C.uword(4),                             //uword               rsl_length,
				unsafe.Pointer(&oraFloat32Value.Value)) //void                *rsl );
			if r == C.OCI_ERROR {
				err = def.rset.stmt.ses.srv.env.ociError()
			}
			value = float32Value
		}
		value = oraFloat32Value
	} else {
		if def.null > C.sb2(-1) {
			var float32Value float32
			r := C.OCINumberToReal(
				def.rset.stmt.ses.srv.env.ocierr, //OCIError              *err,
				&def.ociNumber,                   //const OCINumber     *number,
				C.uword(4),                       //uword               rsl_length,
				unsafe.Pointer(&float32Value))    //void                *rsl );
			if r == C.OCI_ERROR {
				err = def.rset.stmt.ses.srv.env.ociError()
			}
			value = float32Value
		}
	}
	return value, err
}
Exemplo n.º 2
0
func (bnd *bndFloat64Ptr) setPtr() error {
	if bnd.isNull > C.sb2(-1) {
		r := C.OCINumberToReal(
			bnd.stmt.ses.srv.env.ocierr, //OCIError              *err,
			&bnd.ociNumber,              //const OCINumber     *number,
			C.uword(8),                  //uword               rsl_length,
			unsafe.Pointer(bnd.value))   //void                *rsl );
		if r == C.OCI_ERROR {
			return bnd.stmt.ses.srv.env.ociError()
		}
	}
	return nil
}
Exemplo n.º 3
0
// Returns the value stored at the given array position.
func numberVarGetValue(v *Variable, pos uint) (interface{}, error) {
	if v.dataFloats != nil {
		// log.Printf("getting pos=%d from %+v", pos, v.dataFloats)
		return v.dataFloats[pos], nil
	}
	if v.dataInts != nil {
		// log.Printf("getting pos=%d from %+v", pos, v.dataInts)
		return v.dataInts[pos], nil
	}

	num := (*C.OCINumber)(v.getHandle(pos))
	buf := make([]byte, 64)
	size := C.ub4(len(buf))
	if err := v.environment.CheckStatus(
		C.OCINumberToText(v.environment.errorHandle,
			num,
			(*C.oratext)(unsafe.Pointer(&v.environment.numberToStringFormatBuffer[0])),
			C.ub4(len(v.environment.numberToStringFormatBuffer)), nil, 0,
			&size, (*C.oratext)(&buf[0])),
		"NumberToText",
	); err != nil {
		var floatVal float64
		_ = v.environment.CheckStatus(
			C.OCINumberToReal(v.environment.errorHandle,
				num,
				C.sizeof_double, unsafe.Pointer(&floatVal)),
			"numberToFloat")
		log.Printf("floatVal=%f format=%q len=%d num=%p (%d) size=%p buf=%p",
			floatVal,
			v.environment.numberToStringFormatBuffer,
			len(v.environment.numberToStringFormatBuffer),
			num, *((*byte)(unsafe.Pointer(num))),
			&size, &buf[0])
		return 0, errgo.Notef(err, "want string (%f)", floatVal)
	}
	numS := strings.Replace(
		v.environment.FromEncodedString(buf[:int(size)]),
		",", ".", -1)
	if v.typ == NumberAsStringVarType {
		return numS, nil
	}

	if len(numS) <= 9 && strings.IndexByte(numS, '.') < 0 {
		intVal, err := numAsInt(v, num)
		return intVal, errgo.Mask(err)
	}
	return numS, nil
}
Exemplo n.º 4
0
// Returns the value stored at the given array position.
func numberVarGetValue(v *Variable, pos uint) (interface{}, error) {
	if v.dataFloats != nil {
		// log.Printf("getting pos=%d from %+v", pos, v.dataFloats)
		return v.dataFloats[pos], nil
	}
	if v.dataInts != nil {
		// log.Printf("getting pos=%d from %+v", pos, v.dataInts)
		return v.dataInts[pos], nil
	}
	if v.typ == NumberAsStringVarType {
		buf := make([]byte, 200)
		var size C.ub4
		if err := v.environment.CheckStatus(
			C.OCINumberToText(v.environment.errorHandle,
				(*C.OCINumber)(v.getHandle(pos)),
				(*C.oratext)(unsafe.Pointer(&v.environment.numberToStringFormatBuffer[0])),
				C.ub4(len(v.environment.numberToStringFormatBuffer)), nil, 0,
				&size, (*C.oratext)(&buf[0])),
			"NumberToText"); err != nil {
			return 0, err
		}
		return v.environment.FromEncodedString(buf[:int(size)]), nil
	}
	// log.Printf("v=%s IsInteger?%s", v.typ, v.typ.IsInteger())
	if v.typ.IsInteger() {
		intVal := int64(0)
		if err := v.environment.CheckStatus(
			C.OCINumberToInt(v.environment.errorHandle,
				(*C.OCINumber)(v.getHandle(pos)),
				C.sizeof_long, C.OCI_NUMBER_SIGNED, unsafe.Pointer(&intVal)),
			"numberToInt"); err != nil {
			return -1, err
		}
		if v.typ == BooleanVarType {
			return intVal > 0, nil
		}
		return intVal, nil
	}

	floatVal := float64(0)
	err := v.environment.CheckStatus(
		C.OCINumberToReal(v.environment.errorHandle,
			(*C.OCINumber)(v.getHandle(pos)),
			C.sizeof_double, unsafe.Pointer(&floatVal)),
		"numberToFloat")
	return floatVal, err
}