func (bnd *bndBool) bind(value bool, position int, c StmtCfg, stmt *Stmt) (err error) { //Log.Infof("%s.bind(%t, %d)", bnd, value, position) bnd.stmt = stmt var str string if value { str, err = strconv.Unquote(strconv.QuoteRune(c.TrueRune)) } else { str, err = strconv.Unquote(strconv.QuoteRune(c.FalseRune)) } if err != nil { return err } bnd.cString = C.CString(str) 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.cString), //void *valuep, C.LENGTH_TYPE(1), //sb8 value_sz, C.SQLT_AFC, //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 }
func (bnd *bndBoolPtr) bind(value *bool, position int, trueRune rune, stmt *Stmt) error { //Log.Infof("%v.bind(%t, %d)", bnd, value, position) bnd.stmt = stmt bnd.value = value bnd.trueRune = trueRune if cap(bnd.buf) < 2 { bnd.buf = make([]byte, 2) } 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(len(bnd.buf)), //sb8 value_sz, C.SQLT_CHR, //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 (bnd *bndStringPtr) bind(value *string, position int, stringPtrBufferSize int, stmt *Stmt) error { bnd.stmt = stmt bnd.value = value if cap(bnd.buf) < stringPtrBufferSize { bnd.buf = make([]byte, stringPtrBufferSize) } 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(len(bnd.buf)), //sb8 value_sz, C.SQLT_CHR, //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 (bnd *bndFloat64Ptr) bind(value *float64, position int, stmt *Stmt) error { bnd.stmt = stmt bnd.value = value if value == nil { bnd.isNull = C.sb2(-1) } else { r := C.OCINumberFromReal( bnd.stmt.ses.srv.env.ocierr, //OCIError *err, unsafe.Pointer(value), //const void *rnum, 8, //uword rnum_length, &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 *defRowid) define(position int, rset *Rset) error { def.rset = rset // using a character host variable of width between 19 // (18 bytes plus the null-terminator) and 4001 as the // host bind variable for universal ROWID. if len(def.buf) < 4001 { def.buf = make([]byte, 4001) } r := C.OCIDEFINEBYPOS( def.rset.ocistmt, //OCIStmt *stmtp, &def.ocidef, //OCIDefine **defnpp, def.rset.stmt.ses.srv.env.ocierr, //OCIError *errhp, C.ub4(position), //ub4 position, unsafe.Pointer(&def.buf[0]), //void *valuep, C.LENGTH_TYPE(len(def.buf)), //sb8 value_sz, C.SQLT_STR, //ub2 dty, nil, //void *indp, nil, //ub2 *rlenp, nil, //ub2 *rcodep, C.OCI_DEFAULT) //ub4 mode ); if r == C.OCI_ERROR { return def.rset.stmt.ses.srv.env.ociError() } return nil }
func (bnd *bndInt32) bind(value int32, position int, stmt *Stmt) error { bnd.stmt = stmt r := C.OCINumberFromInt( bnd.stmt.ses.srv.env.ocierr, //OCIError *err, unsafe.Pointer(&value), //const void *inum, 4, //uword inum_length, C.OCI_NUMBER_SIGNED, //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, 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 }
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") } 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 *defBool) define(position int, columnSize int, isNullable bool, rset *Rset) error { def.rset = rset def.isNullable = isNullable if cap(def.buf) < columnSize { def.buf = make([]byte, columnSize) } //Log.Infof("defBool.define(position=%d, columnSize=%d)", position, columnSize) // Create oci define handle r := C.OCIDEFINEBYPOS( def.rset.ocistmt, //OCIStmt *stmtp, &def.ocidef, //OCIDefine **defnpp, def.rset.stmt.ses.srv.env.ocierr, //OCIError *errhp, C.ub4(position), //ub4 position, unsafe.Pointer(&def.buf[0]), //void *valuep, C.LENGTH_TYPE(columnSize), //sb8 value_sz, C.SQLT_AFC, //ub2 dty, unsafe.Pointer(&def.null), //void *indp, nil, //ub2 *rlenp, nil, //ub2 *rcodep, C.OCI_DEFAULT) //ub4 mode ); if r == C.OCI_ERROR { return def.rset.stmt.ses.srv.env.ociError() } return nil }
func (bnd *bndStringSlice) bind(values []string, nullInds []C.sb2, position int, stmt *Stmt) (err error) { bnd.stmt = stmt if nullInds == nil { nullInds = make([]C.sb2, len(values)) } alenp := make([]C.ACTUAL_LENGTH_TYPE, len(values)) rcodep := make([]C.ub2, len(values)) var maxLen int for _, str := range values { strLen := len(str) if strLen > maxLen { maxLen = strLen } } for m := 0; m < len(values); m++ { _, err = bnd.buf.WriteString(values[m]) if err != nil { return err } // pad to make equal to max len if necessary padLen := maxLen - len(values[m]) for n := 0; n < padLen; n++ { _, err = bnd.buf.WriteRune('0') if err != nil { return err } } alenp[m] = C.ACTUAL_LENGTH_TYPE(len(values[m])) } bnd.bytes = bnd.buf.Bytes() 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.bytes[0]), //void *valuep, C.LENGTH_TYPE(maxLen), //sb8 value_sz, C.SQLT_CHR, //ub2 dty, unsafe.Pointer(&nullInds[0]), //void *indp, &alenp[0], //ub4 *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(maxLen), //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 }
func (bnd *bndBfile) bind(value Bfile, position int, stmt *Stmt) error { // DirectoryAlias must be specified to avoid error "ORA-24801: illegal parameter value in OCI lob function" // Raising a driver error clarifies the user error if value.DirectoryAlias == "" { return errNew("DirectoryAlias must be specified when binding a non-null Bfile") } // Filename must be specified to avoid error "ORA-24801: illegal parameter value in OCI lob function" // Raising a driver error clarifies the user error if value.Filename == "" { return errNew("Filename must be specified when binding a non-null Bfile") } bnd.stmt = stmt // Allocate lob locator handle r := C.OCIDescriptorAlloc( unsafe.Pointer(bnd.stmt.ses.srv.env.ocienv), //CONST dvoid *parenth, (*unsafe.Pointer)(unsafe.Pointer(&bnd.ociLobLocator)), //dvoid **descpp, C.OCI_DTYPE_FILE, //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 lob handle during bind") } bnd.cDirectoryAlias = C.CString(value.DirectoryAlias) bnd.cFilename = C.CString(value.Filename) r = C.OCILobFileSetName( bnd.stmt.ses.srv.env.ocienv, //OCIEnv *envhp, bnd.stmt.ses.srv.env.ocierr, //OCIError *errhp, &bnd.ociLobLocator, //OCILobLocator **filepp, (*C.OraText)(unsafe.Pointer(bnd.cDirectoryAlias)), //const OraText *dir_alias, C.ub2(len(value.DirectoryAlias)), //ub2 d_length, (*C.OraText)(unsafe.Pointer(bnd.cFilename)), //const OraText *filename, C.ub2(len(value.Filename))) //ub2 f_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.ociLobLocator), //void *valuep, C.LENGTH_TYPE(unsafe.Sizeof(bnd.ociLobLocator)), //sb8 value_sz, C.SQLT_FILE, //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 }
func (bnd *bndBinSlice) bind(values [][]byte, nullInds []C.sb2, position int, lobBufferSize int, stmt *Stmt) error { bnd.stmt = stmt if nullInds == nil { nullInds = make([]C.sb2, len(values)) } alenp := make([]C.ACTUAL_LENGTH_TYPE, len(values)) rcodep := make([]C.ub2, len(values)) var maxLen int for _, b := range values { if len(b) > maxLen { maxLen = len(b) } } n := maxLen * len(values) if cap(bnd.buf) < n { bnd.buf = make([]byte, n) } else { bnd.buf = bnd.buf[:n] // reset buffer for i := range bnd.buf { bnd.buf[i] = 0 } } for i, b := range values { copy(bnd.buf[i*maxLen:], b) alenp[i] = C.ACTUAL_LENGTH_TYPE(len(b)) } 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(maxLen), //sb8 value_sz, C.SQLT_LBI, //ub2 dty, unsafe.Pointer(&nullInds[0]), //void *indp, &alenp[0], //ub4 *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(maxLen), //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 }
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 (bnd *bndBoolSlice) bind(values []bool, nullInds []C.sb2, position int, falseRune rune, trueRune rune, stmt *Stmt) (err error) { bnd.stmt = stmt if nullInds == nil { nullInds = make([]C.sb2, len(values)) } alenp := make([]C.ACTUAL_LENGTH_TYPE, len(values)) rcodep := make([]C.ub2, len(values)) var maxLen int = 1 for n, bValue := range values { if bValue { _, err = bnd.buf.WriteRune(trueRune) if err != nil { return err } } else { _, err = bnd.buf.WriteRune(falseRune) if err != nil { return err } } alenp[n] = 1 } bnd.bytes = bnd.buf.Bytes() 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.bytes[0]), //void *valuep, C.LENGTH_TYPE(maxLen), //sb8 value_sz, C.SQLT_CHR, //ub2 dty, unsafe.Pointer(&nullInds[0]), //void *indp, &alenp[0], //ub4 *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, //OCIBind *bindp, bnd.stmt.ses.srv.env.ocierr, //OCIError *errhp, C.ub4(maxLen), //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 }
func (bnd *bndInt16Slice) bind(values []int16, nullInds []C.sb2, position int, stmt *Stmt) error { bnd.stmt = stmt if nullInds == nil { nullInds = make([]C.sb2, len(values)) } alenp := make([]C.ACTUAL_LENGTH_TYPE, len(values)) rcodep := make([]C.ub2, len(values)) bnd.ociNumbers = make([]C.OCINumber, len(values)) for n := range values { alenp[n] = C.ACTUAL_LENGTH_TYPE(C.sizeof_OCINumber) r := C.OCINumberFromInt( bnd.stmt.ses.srv.env.ocierr, //OCIError *err, unsafe.Pointer(&values[n]), //const void *inum, 2, //uword inum_length, C.OCI_NUMBER_SIGNED, //uword inum_s_flag, &bnd.ociNumbers[n]) //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.ociNumbers[0]), //void *valuep, C.LENGTH_TYPE(C.sizeof_OCINumber), //sb8 value_sz, C.SQLT_VNU, //ub2 dty, unsafe.Pointer(&nullInds[0]), //void *indp, &alenp[0], //ub4 *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(C.sizeof_OCINumber), //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 }
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 (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 }
func (def *defBfile) define(position int, rset *Rset) error { def.rset = rset r := C.OCIDEFINEBYPOS( def.rset.ocistmt, //OCIStmt *stmtp, &def.ocidef, //OCIDefine **defnpp, def.rset.stmt.ses.srv.env.ocierr, //OCIError *errhp, C.ub4(position), //ub4 position, unsafe.Pointer(&def.ociLobLocator), //void *valuep, C.LENGTH_TYPE(unsafe.Sizeof(def.ociLobLocator)), //sb8 value_sz, C.SQLT_FILE, //ub2 dty, unsafe.Pointer(&def.null), //void *indp, nil, //ub4 *rlenp, nil, //ub2 *rcodep, C.OCI_DEFAULT) //ub4 mode ); if r == C.OCI_ERROR { return def.rset.stmt.ses.srv.env.ociError() } return nil }
func (def *defUint64) define(position int, isNullable bool, rset *Rset) error { def.rset = rset def.isNullable = isNullable r := C.OCIDEFINEBYPOS( def.rset.ocistmt, //OCIStmt *stmtp, &def.ocidef, //OCIDefine **defnpp, def.rset.stmt.ses.srv.env.ocierr, //OCIError *errhp, C.ub4(position), //ub4 position, unsafe.Pointer(&def.ociNumber), //void *valuep, C.LENGTH_TYPE(C.sizeof_OCINumber), //sb8 value_sz, C.SQLT_VNU, //ub2 dty, unsafe.Pointer(&def.null), //void *indp, nil, //ub2 *rlenp, nil, //ub2 *rcodep, C.OCI_DEFAULT) //ub4 mode ); if r == C.OCI_ERROR { return def.rset.stmt.ses.srv.env.ociError() } return nil }
func (def *defString) define(position int, columnSize int, isNullable bool, rset *Rset) error { def.rset = rset def.isNullable = isNullable //Log.Infof("defString position=%d columnSize=%d", position, columnSize) n := columnSize // AL32UTF8: one db "char" can be 4 bytes on wire, esp. if the database's // character set is not AL32UTF8 (e.g. some 8bit fixed width charset), and // the column is VARCHAR2 with byte semantics. // // For example when the db's charset is EE8ISO8859P2, then a VARCHAR2(1) can // contain an "ű", which is 2 bytes AL32UTF8. if !rset.stmt.ses.srv.dbIsUTF8 { n *= 2 } if n == 0 { n = 2 } if n%2 != 0 { n++ } if def.buf == nil || cap(def.buf) < n { def.buf = make([]byte, n) } // Create oci define handle r := C.OCIDEFINEBYPOS( def.rset.ocistmt, //OCIStmt *stmtp, &def.ocidef, //OCIDefine **defnpp, def.rset.stmt.ses.srv.env.ocierr, //OCIError *errhp, C.ub4(position), //ub4 position, unsafe.Pointer(&def.buf[0]), //void *valuep, C.LENGTH_TYPE(n), //sb8 value_sz, C.SQLT_CHR, //ub2 dty, unsafe.Pointer(&def.null), //void *indp, nil, //ub2 *rlenp, nil, //ub2 *rcodep, C.OCI_DEFAULT) //ub4 mode ); if r == C.OCI_ERROR { return def.rset.stmt.ses.srv.env.ociError() } return nil }
func (bnd *bndLob) bindByPos(position int) error { 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.ociLobLocator), //void *valuep, C.LENGTH_TYPE(unsafe.Sizeof(bnd.ociLobLocator)), //sb8 value_sz, C.SQLT_BLOB, //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 }
func (bnd *bndBin) bind(value []byte, position int, stmt *Stmt) (err error) { bnd.stmt = stmt 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(&value[0]), //void *valuep, C.LENGTH_TYPE(len(value)), //sb8 value_sz, C.SQLT_LBI, //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 }
func (bnd *bndUint8Ptr) bind(value *uint8, position int, stmt *Stmt) error { bnd.stmt = stmt bnd.value = value 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 *defLongRaw) define(position int, bufSize uint32, isNullable bool, rset *Rset) error { def.rset = rset def.isNullable = isNullable def.buf = make([]byte, int(bufSize)) //logF(true, "position %v, def.buf %v", position, len(def.buf)) r := C.OCIDEFINEBYPOS( def.rset.ocistmt, //OCIStmt *stmtp, &def.ocidef, //OCIDefine **defnpp, def.rset.stmt.ses.srv.env.ocierr, //OCIError *errhp, C.ub4(position), //ub4 position, unsafe.Pointer(&def.buf[0]), //void *valuep, C.LENGTH_TYPE(len(def.buf)), //sb8 value_sz, C.SQLT_LBI, //ub2 dty, unsafe.Pointer(&def.null), //void *indp, &def.returnLength, //ub4 *rlenp, nil, //ub2 *rcodep, C.OCI_DEFAULT) //ub4 mode ); if r == C.OCI_ERROR { return def.rset.stmt.ses.srv.env.ociError() } return nil }
func (bnd *bndInt32Ptr) bind(value *int32, 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, 4, //uword inum_length, C.OCI_NUMBER_SIGNED, //uword inum_s_flag, &bnd.ociNumber) //OCINumber *number if r == C.OCI_ERROR { return bnd.stmt.ses.srv.env.ociError() } bnd.stmt.logF(_drv.cfg.Log.Stmt.Bind, "Int32Ptr.bind(%d) value=%d => number=%#v", position, *value, bnd.ociNumber) } 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 *defLob) define(position int, charsetForm C.ub1, sqlt C.ub2, gct GoColumnType, rset *Rset) error { def.rset = rset def.gct = gct def.sqlt = sqlt def.charsetForm = charsetForm def.ociLobLocator = nil r := C.OCIDEFINEBYPOS( def.rset.ocistmt, //OCIStmt *stmtp, &def.ocidef, //OCIDefine **defnpp, def.rset.stmt.ses.srv.env.ocierr, //OCIError *errhp, C.ub4(position), //ub4 position, unsafe.Pointer(&def.ociLobLocator), //void *valuep, C.LENGTH_TYPE(unsafe.Sizeof(def.ociLobLocator)), //sb8 value_sz, sqlt, //ub2 dty, unsafe.Pointer(&def.null), //void *indp, nil, //ub2 *rlenp, nil, //ub2 *rcodep, C.OCI_DEFAULT) //ub4 mode ); if r != C.OCI_SUCCESS { return def.rset.stmt.ses.srv.env.ociError() } prefetchLength := C.boolean(C.TRUE) return def.rset.stmt.ses.srv.env.setAttr(unsafe.Pointer(def.ocidef), C.OCI_HTYPE_DEFINE, unsafe.Pointer(&prefetchLength), 0, C.OCI_ATTR_LOBPREFETCH_LENGTH) }
func (bnd *bndLobSlice) bindReaders( values []io.Reader, nullInds []C.sb2, position int, lobBufferSize int, stmt *Stmt, ) ( err error, ) { bnd.stmt = stmt bnd.ociLobLocators = make([]*C.OCILobLocator, len(values)) if nullInds == nil { nullInds = make([]C.sb2, len(values)) } alenp := make([]C.ACTUAL_LENGTH_TYPE, len(values)) rcodep := make([]C.ub2, len(values)) if len(bnd.buf) < lobBufferSize { bnd.buf = make([]byte, lobBufferSize) } finishers := make([]func(), len(values)) defer func() { if err == nil { return } for _, finish := range finishers { if finish == nil { continue } finish() } }() for i, r := range values { bnd.ociLobLocators[i], finishers[i], err = allocTempLob(bnd.stmt) if err != nil { return err } alenp[i] = C.ACTUAL_LENGTH_TYPE(unsafe.Sizeof(bnd.ociLobLocators[i])) if nullInds[i] <= C.sb2(-1) { continue } if err = writeLob(bnd.ociLobLocators[i], bnd.stmt, r, lobBufferSize); err != nil { bnd.stmt.ses.Break() return err } } 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.ociLobLocators[0]), //void *valuep, C.LENGTH_TYPE(unsafe.Sizeof(bnd.ociLobLocators[0])), //sb8 value_sz, C.SQLT_BLOB, //ub2 dty, unsafe.Pointer(&nullInds[0]), //void *indp, &alenp[0], //ub4 *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.ociLobLocators[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 }
func (bnd *bndTimeSlice) bind(values []time.Time, nullInds []C.sb2, position int, stmt *Stmt) error { bnd.stmt = stmt bnd.ociDateTimes = make([]*C.OCIDateTime, len(values)) if nullInds == nil { nullInds = make([]C.sb2, len(values)) } alenp := make([]C.ACTUAL_LENGTH_TYPE, len(values)) rcodep := make([]C.ub2, len(values)) for n, timeValue := range values { timezoneStr := zoneOffset(timeValue, &bnd.zoneBuf) cTimezoneStr := C.CString(timezoneStr) defer func() { C.free(unsafe.Pointer(cTimezoneStr)) }() r := C.OCIDescriptorAlloc( unsafe.Pointer(bnd.stmt.ses.srv.env.ocienv), //CONST dvoid *parenth, (*unsafe.Pointer)(unsafe.Pointer(&bnd.ociDateTimes[n])), //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") } r = C.OCIDateTimeConstruct( unsafe.Pointer(bnd.stmt.ses.srv.env.ocienv), //dvoid *hndl, bnd.stmt.ses.srv.env.ocierr, //OCIError *err, bnd.ociDateTimes[n], //OCIDateTime *datetime, C.sb2(timeValue.Year()), //sb2 year, C.ub1(int32(timeValue.Month())), //ub1 month, C.ub1(timeValue.Day()), //ub1 day, C.ub1(timeValue.Hour()), //ub1 hour, C.ub1(timeValue.Minute()), //ub1 min, C.ub1(timeValue.Second()), //ub1 sec, C.ub4(timeValue.Nanosecond()), //ub4 fsec, (*C.OraText)(unsafe.Pointer(cTimezoneStr)), //OraText *timezone, C.size_t(len(timezoneStr))) //size_t timezone_length ); if r == C.OCI_ERROR { return bnd.stmt.ses.srv.env.ociError() } alenp[n] = C.ACTUAL_LENGTH_TYPE(unsafe.Sizeof(bnd.ociDateTimes[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.ociDateTimes[0]), //void *valuep, C.LENGTH_TYPE(unsafe.Sizeof(bnd.ociDateTimes[0])), //sb8 value_sz, C.SQLT_TIMESTAMP_TZ, //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.ociDateTimes[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 }
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 }