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 }
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 }
func (bnd *bndTimePtr) bind(value *time.Time, position int, stmt *Stmt) error { bnd.stmt = stmt bnd.value = value r := C.OCIDescriptorAlloc( unsafe.Pointer(bnd.stmt.ses.srv.env.ocienv), //CONST dvoid *parenth, (*unsafe.Pointer)(unsafe.Pointer(&bnd.ociDateTime)), //dvoid **descpp, C.OCI_DTYPE_TIMESTAMP_TZ, //ub4 type, 0, //size_t xtramem_sz, nil) //dvoid **usrmempp); if r == C.OCI_ERROR { return bnd.stmt.ses.srv.env.ociError() } else if r == C.OCI_INVALID_HANDLE { return errNew("unable to allocate oci timestamp handle during bind") } if value == nil { bnd.isNull = C.sb2(-1) } else { zone := zoneOffset(*value, &bnd.zoneBuf) bnd.cZone = C.CString(zone) r = C.OCIDateTimeConstruct( unsafe.Pointer(bnd.stmt.ses.srv.env.ocienv), //dvoid *hndl, bnd.stmt.ses.srv.env.ocierr, //OCIError *err, bnd.ociDateTime, //OCIDateTime *datetime, C.sb2(value.Year()), //sb2 year, C.ub1(int32(value.Month())), //ub1 month, C.ub1(value.Day()), //ub1 day, C.ub1(value.Hour()), //ub1 hour, C.ub1(value.Minute()), //ub1 min, C.ub1(value.Second()), //ub1 sec, C.ub4(value.Nanosecond()), //ub4 fsec, (*C.OraText)(unsafe.Pointer(bnd.cZone)), //OraText *timezone, C.size_t(len(zone))) //size_t timezone_length ); if r == C.OCI_ERROR { return bnd.stmt.ses.srv.env.ociError() } } r = C.OCIBINDBYPOS( bnd.stmt.ocistmt, //OCIStmt *stmtp, (**C.OCIBind)(&bnd.ocibnd), //OCIBind **bindpp, bnd.stmt.ses.srv.env.ocierr, //OCIError *errhp, C.ub4(position), //ub4 position, unsafe.Pointer(&bnd.ociDateTime), //void *valuep, C.LENGTH_TYPE(unsafe.Sizeof(bnd.ociDateTime)), //sb8 value_sz, C.SQLT_TIMESTAMP_TZ, //ub2 dty, unsafe.Pointer(&bnd.isNull), //void *indp, nil, //ub2 *alenp, nil, //ub2 *rcodep, 0, //ub4 maxarr_len, nil, //ub4 *curelep, C.OCI_DEFAULT) //ub4 mode ); if r == C.OCI_ERROR { return bnd.stmt.ses.srv.env.ociError() } return nil }
func (def *defString) value() (value interface{}, err error) { if def.isNullable { oraStringValue := String{IsNull: def.null < C.sb2(0)} if !oraStringValue.IsNull { oraStringValue.Value = string(def.buf[:int(def.rlen)]) } return oraStringValue, nil } if def.null < C.sb2(0) { return "", nil } return string(def.buf[:int(def.rlen)]), nil }
func dateTimeVarSetValue(v *Variable, pos uint, value interface{}) error { x, ok := value.(time.Time) if !ok { a, ok := value.([]time.Time) if !ok { return fmt.Errorf("awaited time.Time or []time.Time, got %T", value) } var err error for i, x := range a { if err = dateTimeVarSetValue(v, pos+uint(i), x); err != nil { return err } } return nil } /* if err := v.environment.CheckStatus( C.OCIDateSetDate(unsafe.Pointer(&v.dataBytes[pos*sizeof_OCIDate]), x.Year(), x.Month(), x.Date()), "OCIDateSetDate"); err != nil { return err } return v.environment.CheckStatus( C.OCIDateSetTime(unsafe.Pointer(&v.dataBytes[pos*sizeof_OCIDate]), x.Hour(), x.Minute(), x.Second()), "OCIDateSetTime") */ C.setDateTime((*C.OCIDate)(v.getHandle(pos)), C.sb2(x.Year()), C.ub1(x.Month()), C.ub1(x.Day()), C.ub1(x.Hour()), C.ub1(x.Minute()), C.ub1(x.Second())) return nil }
func (bnd *bndStringPtr) setPtr() error { if bnd.isNull > C.sb2(-1) { // Buffer is padded with Space char (32) *bnd.value = stringTrimmed(bnd.buf, 32) } return nil }
func (def *defIntervalDS) value() (value interface{}, err error) { intervalDS := IntervalDS{IsNull: def.null < C.sb2(0)} if !intervalDS.IsNull { var day C.sb4 var hour C.sb4 var minute C.sb4 var second C.sb4 var nanosecond C.sb4 r := C.OCIIntervalGetDaySecond( unsafe.Pointer(def.rset.stmt.ses.srv.env.ocienv), //void *hndl, def.rset.stmt.ses.srv.env.ocierr, //OCIError *err, &day, //sb4 *dy, &hour, //sb4 *hr, &minute, //sb4 *mm, &second, //sb4 *ss, &nanosecond, //sb4 *fsec, def.ociInterval) //const OCIInterval *interval ); if r == C.OCI_ERROR { err = def.rset.stmt.ses.srv.env.ociError() } intervalDS.Day = int32(day) intervalDS.Hour = int32(hour) intervalDS.Minute = int32(minute) intervalDS.Second = int32(second) intervalDS.Nanosecond = int32(nanosecond) } return intervalDS, err }
func (def *defLongRaw) value() (value interface{}, err error) { if def.isNullable { bytesValue := Raw{IsNull: def.null < C.sb2(0)} if !bytesValue.IsNull { // Make a slice of length equal to the return length bytesValue.Value = make([]byte, def.returnLength) // Copy returned data copyLength := copy(bytesValue.Value, def.buf) if C.ACTUAL_LENGTH_TYPE(copyLength) != def.returnLength { return nil, errNew("unable to copy LONG RAW result data from buffer") } } value = bytesValue } else { // Make a slice of length equal to the return length result := make([]byte, def.returnLength) // Copy returned data copyLength := copy(result, def.buf) if C.ACTUAL_LENGTH_TYPE(copyLength) != def.returnLength { return nil, errNew("unable to copy LONG RAW result data from buffer") } value = result } return value, err }
func (bnd *bndUint16Ptr) bind(value *uint16, position int, stmt *Stmt) error { bnd.stmt = stmt bnd.value = value if value == nil { bnd.isNull = C.sb2(-1) } else { r := C.OCINumberFromInt( bnd.stmt.ses.srv.env.ocierr, //OCIError *err, unsafe.Pointer(value), //const void *inum, 2, //uword inum_length, C.OCI_NUMBER_UNSIGNED, //uword inum_s_flag, &bnd.ociNumber) //OCINumber *number ); if r == C.OCI_ERROR { return bnd.stmt.ses.srv.env.ociError() } } r := C.OCIBINDBYPOS( bnd.stmt.ocistmt, //OCIStmt *stmtp, (**C.OCIBind)(&bnd.ocibnd), //OCIBind **bindpp, bnd.stmt.ses.srv.env.ocierr, //OCIError *errhp, C.ub4(position), //ub4 position, unsafe.Pointer(&bnd.ociNumber), //void *valuep, C.LENGTH_TYPE(C.sizeof_OCINumber), //sb8 value_sz, C.SQLT_VNU, //ub2 dty, unsafe.Pointer(&bnd.isNull), //void *indp, nil, //ub2 *alenp, nil, //ub2 *rcodep, 0, //ub4 maxarr_len, nil, //ub4 *curelep, C.OCI_DEFAULT) //ub4 mode ); if r == C.OCI_ERROR { return bnd.stmt.ses.srv.env.ociError() } return nil }
func (def *defString) value() (value interface{}, err error) { // Buffer is padded with Space char (32) if def.isNullable { oraStringValue := String{IsNull: def.null < C.sb2(0)} if !oraStringValue.IsNull { oraStringValue.Value = stringTrimmed(def.buf, 32) } value = oraStringValue } else { if def.null < C.sb2(0) { value = "" } else { value = stringTrimmed(def.buf, 32) } } return value, err }
func (bnd *bndStringPtr) setPtr() error { bnd.stmt.logF(_drv.cfg.Log.Stmt.Bind, "StringPtr.setPtr isNull=%d alen=%d", bnd.isNull, bnd.alen[0]) if bnd.isNull > C.sb2(-1) { *bnd.value = string(bnd.buf[:bnd.alen[0]]) } return nil }
func (def *defBool) value() (value interface{}, err error) { //Log.Infof("%v.value", def) if def.isNullable { oraBoolValue := Bool{IsNull: def.null < C.sb2(0)} if !oraBoolValue.IsNull { r, _ := utf8.DecodeRune(def.buf) oraBoolValue.Value = r == def.rset.stmt.cfg.Rset.TrueRune } return oraBoolValue, nil } if def.null > C.sb2(-1) { r, _ := utf8.DecodeRune(def.buf) return r == def.rset.stmt.cfg.Rset.TrueRune, nil } // NULL is false, too return false, nil }
func (def *defLob) value() (value interface{}, err error) { //lob := def.ociLobLocator //Log.Infof("value %p null=%d", lob, def.null) if def.gct == Bin { if def.null > C.sb2(-1) { return def.Reader() } return value, err } if def.null < C.sb2(0) { return Lob{}, nil } var r io.Reader r, err = def.Reader() binValue := Lob{Reader: r} //Log.Infof("value %p returns %#v (%v)", lob, binValue, err) return binValue, err }
func (bnd *bndBoolPtr) setPtr() error { //Log.Infof("%s.setPtr()", bnd) if bnd.isNull > C.sb2(-1) { r, _ := utf8.DecodeRune(bnd.buf) *bnd.value = r == bnd.trueRune } else { bnd.value = nil } return nil }
func (bnd *bndUint64Slice) bindOra(values []Uint64, position int, stmt *Stmt) error { uint64Values := make([]uint64, len(values)) nullInds := make([]C.sb2, len(values)) for n := range values { if values[n].IsNull { nullInds[n] = C.sb2(-1) } else { uint64Values[n] = values[n].Value } } return bnd.bind(uint64Values, nullInds, position, stmt) }
func (def *defTime) value() (value interface{}, err error) { if def.isNullable { oraTimeValue := Time{IsNull: def.null < C.sb2(0)} if !oraTimeValue.IsNull { oraTimeValue.Value, err = getTime(def.rset.stmt.ses.srv.env, def.ociDateTime) } value = oraTimeValue } else { value, err = getTime(def.rset.stmt.ses.srv.env, def.ociDateTime) } return value, err }
func (bnd *bndStringSlice) bindOra(values []String, position int, stmt *Stmt) error { stringValues := make([]string, len(values)) nullInds := make([]C.sb2, len(values)) for n, _ := range values { if values[n].IsNull { nullInds[n] = C.sb2(-1) } else { stringValues[n] = values[n].Value } } return bnd.bind(stringValues, nullInds, position, stmt) }
func (bnd *bndTimeSlice) bindOra(values []Time, position int, stmt *Stmt) error { timeValues := make([]time.Time, len(values)) nullInds := make([]C.sb2, len(values)) for n, _ := range values { if values[n].IsNull { nullInds[n] = C.sb2(-1) } else { timeValues[n] = values[n].Value } } return bnd.bind(timeValues, nullInds, position, stmt) }
func (bnd *bndBinSlice) bindOra(values []Raw, position int, lobBufferSize int, stmt *Stmt) error { binValues := make([][]byte, len(values)) nullInds := make([]C.sb2, len(values)) for i := range values { if values[i].IsNull { nullInds[i] = C.sb2(-1) } else { binValues[i] = values[i].Value } } return bnd.bind(binValues, nullInds, position, lobBufferSize, stmt) }
func (bnd *bndBoolSlice) bindOra(values []Bool, position int, falseRune rune, trueRune rune, stmt *Stmt) error { boolValues := make([]bool, len(values)) nullInds := make([]C.sb2, len(values)) for n, _ := range values { if values[n].IsNull { nullInds[n] = C.sb2(-1) } else { boolValues[n] = values[n].Value } } return bnd.bind(boolValues, nullInds, position, falseRune, trueRune, stmt) }
func (bnd *bndLobSlice) bindOra(values []Lob, position int, lobBufferSize int, stmt *Stmt) error { binValues := make([]io.Reader, len(values)) nullInds := make([]C.sb2, len(values)) for n, _ := range values { if values[n].Reader == nil { nullInds[n] = C.sb2(-1) } else { binValues[n] = values[n].Reader } } return bnd.bindReaders(binValues, nullInds, position, lobBufferSize, stmt) }
func (bnd *bndFloat32Slice) bindOra(values []Float32, position int, stmt *Stmt) error { float32Values := make([]float32, len(values)) nullInds := make([]C.sb2, len(values)) for n := range values { if values[n].IsNull { nullInds[n] = C.sb2(-1) } else { float32Values[n] = values[n].Value } } return bnd.bind(float32Values, nullInds, position, stmt) }
func (bnd *bndInt16Slice) bindOra(values []Int16, position int, stmt *Stmt) error { int16Values := make([]int16, len(values)) nullInds := make([]C.sb2, len(values)) for n := range values { if values[n].IsNull { nullInds[n] = C.sb2(-1) } else { int16Values[n] = values[n].Value } } return bnd.bind(int16Values, nullInds, position, stmt) }
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 }
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 }
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 }
func (bnd *bndStringPtr) bind(value *string, position int, stringPtrBufferSize int, stmt *Stmt) error { bnd.stmt = stmt bnd.value = value var length int if cap(bnd.buf) < stringPtrBufferSize { bnd.buf = make([]byte, 1, stringPtrBufferSize) } if value == nil { bnd.isNull = C.sb2(-1) } else { length = len(*value) } if length == 0 { bnd.buf = bnd.buf[:1] // to be able to address bnd.buf[0] bnd.buf[0] = 0 } else { bnd.buf = bnd.buf[:length] copy(bnd.buf, []byte(*value)) } if cap(bnd.alen) < 1 { bnd.alen = []C.ACTUAL_LENGTH_TYPE{C.ACTUAL_LENGTH_TYPE(length)} } else { bnd.alen = bnd.alen[:1] bnd.alen[0] = C.ACTUAL_LENGTH_TYPE(length) } bnd.stmt.logF(_drv.cfg.Log.Stmt.Bind, "StringPtr.bind(%d) cap=%d len=%d alen=%d", position, cap(bnd.buf), len(bnd.buf), bnd.alen[0]) r := C.OCIBINDBYPOS( bnd.stmt.ocistmt, //OCIStmt *stmtp, (**C.OCIBind)(&bnd.ocibnd), //OCIBind **bindpp, bnd.stmt.ses.srv.env.ocierr, //OCIError *errhp, C.ub4(position), //ub4 position, unsafe.Pointer(&bnd.buf[0]), //void *valuep, C.LENGTH_TYPE(cap(bnd.buf)), //sb8 value_sz, C.SQLT_CHR, //ub2 dty, unsafe.Pointer(&bnd.isNull), //void *indp, &bnd.alen[0], //ub2 *alenp, nil, //ub2 *rcodep, 0, //ub4 maxarr_len, nil, //ub4 *curelep, C.OCI_DEFAULT) //ub4 mode ); if r == C.OCI_ERROR { return bnd.stmt.ses.srv.env.ociError() } return nil }
func (def *defIntervalYM) value() (value interface{}, err error) { intervalYM := IntervalYM{IsNull: def.null < C.sb2(0)} if !intervalYM.IsNull { var year C.sb4 var month C.sb4 r := C.OCIIntervalGetYearMonth( unsafe.Pointer(def.rset.stmt.ses.srv.env.ocienv), //void *hndl, def.rset.stmt.ses.srv.env.ocierr, //OCIError *err, &year, //sb4 *yr, &month, //sb4 *mnth, def.ociInterval) //const OCIInterval *interval ); if r == C.OCI_ERROR { err = def.rset.stmt.ses.srv.env.ociError() } intervalYM.Year = int32(year) intervalYM.Month = int32(month) } return intervalYM, err }
func (bnd *bndNil) bind(position int, sqlt C.ub2, stmt *Stmt) error { bnd.stmt = stmt indp := C.sb2(-1) r := C.OCIBINDBYPOS( bnd.stmt.ocistmt, //OCIStmt *stmtp, (**C.OCIBind)(&bnd.ocibnd), //OCIBind **bindpp, bnd.stmt.ses.srv.env.ocierr, //OCIError *errhp, C.ub4(position), //ub4 position, nil, //void *valuep, 0, //sb8 value_sz, sqlt, //C.SQLT_CHR, //ub2 dty, unsafe.Pointer(&indp), //void *indp, nil, //ub2 *alenp, nil, //ub2 *rcodep, 0, //ub4 maxarr_len, nil, //ub4 *curelep, C.OCI_DEFAULT) //ub4 mode ); if r == C.OCI_ERROR { return bnd.stmt.ses.srv.env.ociError() } return nil }
func (def *defBfile) value() (value interface{}, err error) { var bfileValue Bfile bfileValue.IsNull = def.null < C.sb2(0) if !bfileValue.IsNull { // Get directory alias and filename dLength := C.ub2(len(def.directoryAlias)) fLength := C.ub2(len(def.filename)) r := C.OCILobFileGetName( def.rset.stmt.ses.srv.env.ocienv, //OCIEnv *envhp, def.rset.stmt.ses.srv.env.ocierr, //OCIError *errhp, def.ociLobLocator, //const OCILobLocator *filep, (*C.OraText)(unsafe.Pointer(&def.directoryAlias[0])), //OraText *dir_alias, &dLength, //ub2 *d_length, (*C.OraText)(unsafe.Pointer(&def.filename[0])), //OraText *filename, &fLength) //ub2 *f_length ); if r == C.OCI_ERROR { return value, def.rset.stmt.ses.srv.env.ociError() } bfileValue.DirectoryAlias = string(def.directoryAlias[:int(dLength)]) bfileValue.Filename = string(def.filename[:int(fLength)]) } value = bfileValue return value, err }