// intervalVarSetValue sets the value of the variable. func intervalVarSetValue(v *Variable, pos uint, value interface{}) error { var days, hours, minutes, seconds, microseconds C.sb4 x, ok := value.(time.Duration) if !ok { return fmt.Errorf("requires time.Duration, got %T", value) } days = C.sb4(x.Hours()) / 24 hours = C.sb4(x.Hours()) - days*24 minutes = C.sb4(x.Minutes() - x.Hours()*60) seconds = C.sb4(x.Seconds()-x.Minutes()) * 60 microseconds = C.sb4(float64(x.Nanoseconds()/1000) - x.Seconds()*1000*1000) if CTrace { ctrace("OCIIntervalSetDaySecond(env=%p, err=%p, days=%d, hours=%d, min=%d, sec=%d, micro=%d, handle=%p)", v.environment.handle, v.environment.errorHandle, days, hours, minutes, seconds, microseconds, v.getHandle(pos)) } return v.environment.CheckStatus( C.OCIIntervalSetDaySecond(unsafe.Pointer(v.environment.handle), v.environment.errorHandle, days, hours, minutes, seconds, microseconds, getIntervalHandle(v, pos)), "IntervalSetDaySecond") }
func (bnd *bndIntervalDS) bind(value IntervalDS, position int, stmt *Stmt) error { bnd.stmt = stmt r := C.OCIDescriptorAlloc( unsafe.Pointer(bnd.stmt.ses.srv.env.ocienv), //CONST dvoid *parenth, (*unsafe.Pointer)(unsafe.Pointer(&bnd.ociInterval)), //dvoid **descpp, C.OCI_DTYPE_INTERVAL_DS, //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 interval handle during bind") } r = C.OCIIntervalSetDaySecond( unsafe.Pointer(bnd.stmt.ses.srv.env.ocienv), //void *hndl, bnd.stmt.ses.srv.env.ocierr, //OCIError *err, C.sb4(value.Day), //sb4 dy, C.sb4(value.Hour), //sb4 hr, C.sb4(value.Minute), //sb4 mm, C.sb4(value.Second), //sb4 ss, C.sb4(value.Nanosecond), //sb4 fsec, bnd.ociInterval) //OCIInterval *result ); 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.ociInterval), //void *valuep, C.LENGTH_TYPE(unsafe.Sizeof(bnd.ociInterval)), //sb8 value_sz, C.SQLT_INTERVAL_DS, //ub2 dty, nil, //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 }
// Set the value of the variable. func internalVar_SetValue(v *Variable, pos uint, value interface{}) error { var days, hours, minutes, seconds, microseconds C.sb4 x, ok := value.(time.Duration) if !ok { return fmt.Errorf("requires time.Duration, got %T", value) } days = C.sb4(x.Hours()) / 24 hours = C.sb4(x.Hours()) - days*24 minutes = C.sb4(x.Minutes() - x.Hours()*60) seconds = C.sb4(x.Seconds()-x.Minutes()) * 60 microseconds = C.sb4(float64(x.Nanoseconds()/1000) - x.Seconds()*1000*1000) return v.environment.CheckStatus( C.OCIIntervalSetDaySecond(unsafe.Pointer(v.environment.handle), v.environment.errorHandle, days, hours, minutes, seconds, microseconds, (*C.OCIInterval)(unsafe.Pointer(&v.dataBytes[pos*v.typ.size]))), "IntervalSetDaySecond") }
func (bnd *bndIntervalDSSlice) bind(values []IntervalDS, position int, stmt *Stmt) error { bnd.stmt = stmt bnd.ociIntervals = make([]*C.OCIInterval, len(values)) nullInds := make([]C.sb2, len(values)) alenp := make([]C.ACTUAL_LENGTH_TYPE, len(values)) rcodep := make([]C.ub2, len(values)) for n, value := range values { r := C.OCIDescriptorAlloc( unsafe.Pointer(bnd.stmt.ses.srv.env.ocienv), //CONST dvoid *parenth, (*unsafe.Pointer)(unsafe.Pointer(&bnd.ociIntervals[n])), //dvoid **descpp, C.OCI_DTYPE_INTERVAL_DS, //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 interval handle during bind") } r = C.OCIIntervalSetDaySecond( unsafe.Pointer(bnd.stmt.ses.srv.env.ocienv), //void *hndl, bnd.stmt.ses.srv.env.ocierr, //OCIError *err, C.sb4(value.Day), //sb4 dy, C.sb4(value.Hour), //sb4 hr, C.sb4(value.Minute), //sb4 mm, C.sb4(value.Second), //sb4 ss, C.sb4(value.Nanosecond), //sb4 fsec, bnd.ociIntervals[n]) //OCIInterval *result ); if r == C.OCI_ERROR { return bnd.stmt.ses.srv.env.ociError() } if values[n].IsNull { nullInds[n] = C.sb2(-1) } else { nullInds[n] = C.sb2(0) } alenp[n] = C.ACTUAL_LENGTH_TYPE(unsafe.Sizeof(bnd.ociIntervals[n])) } 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.ociIntervals[0]), //void *valuep, C.LENGTH_TYPE(unsafe.Sizeof(bnd.ociIntervals[0])), //sb8 value_sz, C.SQLT_INTERVAL_DS, //ub2 dty, unsafe.Pointer(&nullInds[0]), //void *indp, &alenp[0], //ub2 *alenp, &rcodep[0], //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() } r = C.OCIBindArrayOfStruct( bnd.ocibnd, bnd.stmt.ses.srv.env.ocierr, C.ub4(unsafe.Sizeof(bnd.ociIntervals[0])), //ub4 pvskip, C.ub4(C.sizeof_sb2), //ub4 indskip, C.ub4(C.sizeof_ub4), //ub4 alskip, C.ub4(C.sizeof_ub2)) //ub4 rcskip if r == C.OCI_ERROR { return bnd.stmt.ses.srv.env.ociError() } return nil }