Ejemplo n.º 1
0
func (def *defUint64) value() (value interface{}, err error) {
	if def.isNullable {
		oraUint64Value := Uint64{IsNull: def.null < C.sb2(0)}
		if !oraUint64Value.IsNull {
			r := C.OCINumberToInt(
				def.rset.stmt.ses.srv.env.ocierr,      //OCIError              *err,
				&def.ociNumber,                        //const OCINumber       *number,
				C.uword(8),                            //uword                 rsl_length,
				C.OCI_NUMBER_UNSIGNED,                 //uword                 rsl_flag,
				unsafe.Pointer(&oraUint64Value.Value)) //void                  *rsl );
			if r == C.OCI_ERROR {
				err = def.rset.stmt.ses.srv.env.ociError()
			}
		}
		value = oraUint64Value
	} else {
		if def.null > C.sb2(-1) {
			var uint64Value uint64
			r := C.OCINumberToInt(
				def.rset.stmt.ses.srv.env.ocierr, //OCIError              *err,
				&def.ociNumber,                   //const OCINumber       *number,
				C.uword(8),                       //uword                 rsl_length,
				C.OCI_NUMBER_UNSIGNED,            //uword                 rsl_flag,
				unsafe.Pointer(&uint64Value))     //void                  *rsl );
			if r == C.OCI_ERROR {
				err = def.rset.stmt.ses.srv.env.ociError()
			}
			value = uint64Value
		}
	}
	return value, err
}
Ejemplo n.º 2
0
func numAsInt(v *Variable, num *C.OCINumber) (intVal int32, err error) {
	if err = v.environment.CheckStatus(
		C.OCINumberToInt(v.environment.errorHandle,
			//(*C.OCINumber)(v.getHandle(pos)),
			num,
			4, C.OCI_NUMBER_SIGNED, unsafe.Pointer(&intVal)),
		"numberToInt"); err != nil {
		return -1, errgo.Mask(err)
	}
	return
}
Ejemplo n.º 3
0
func (bnd *bndUint16Ptr) setPtr() error {
	if bnd.isNull > C.sb2(-1) {
		r := C.OCINumberToInt(
			bnd.stmt.ses.srv.env.ocierr, //OCIError              *err,
			&bnd.ociNumber,              //const OCINumber       *number,
			C.uword(2),                  //uword                 rsl_length,
			C.OCI_NUMBER_UNSIGNED,       //uword                 rsl_flag,
			unsafe.Pointer(bnd.value))   //void                  *rsl );
		if r == C.OCI_ERROR {
			return bnd.stmt.ses.srv.env.ociError()
		}
	}
	return nil
}
Ejemplo n.º 4
0
func (bnd *bndInt32Ptr) setPtr() error {
	if bnd.isNull > C.sb2(-1) {
		r := C.OCINumberToInt(
			bnd.stmt.ses.srv.env.ocierr, //OCIError              *err,
			&bnd.ociNumber,              //const OCINumber       *number,
			C.uword(4),                  //uword                 rsl_length,
			C.OCI_NUMBER_SIGNED,         //uword                 rsl_flag,
			unsafe.Pointer(bnd.value))   //void                  *rsl );
		if r == C.OCI_ERROR {
			return bnd.stmt.ses.srv.env.ociError()
		}
		bnd.stmt.logF(_drv.cfg.Log.Stmt.Bind,
			"Int32Ptr.setPtr number=%#v => value=%d", bnd.ociNumber, *bnd.value)
	}
	return nil
}
Ejemplo n.º 5
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
}