作者:optimus
项目:or
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
}
作者:optimus
项目:or
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
}
作者:rjammal
项目:or
func (bnd *bndRset) bind(value *Rset, position int, stmt *Stmt) error {
bnd.stmt = stmt
bnd.value = value
// Allocate a statement handle
ocistmt, err := bnd.stmt.ses.srv.env.allocOciHandle(C.OCI_HTYPE_STMT)
bnd.ocistmt = (*C.OCIStmt)(ocistmt)
if err != nil {
return err
}
r := C.OCIBINDBYPOS(
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.ocistmt), //void *valuep,
0, //sb8 value_sz,
C.SQLT_RSET, //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
}
作者:optimus
项目:or
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
}
作者:optimus
项目:or
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
}
作者:optimus
项目:or
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
}
作者:ricsmani
项目:or
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
}
作者:optimus
项目:or
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
}
作者:optimus
项目:or
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
}
作者:optimus
项目:or
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
}
作者:ricsmani
项目:or
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
}
作者:optimus
项目:or
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
}
作者:optimus
项目:or
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
}
作者:ricsmani
项目:or
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
}
作者:optimus
项目:or
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
}
作者:optimus
项目:or
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
}
作者:optimus
项目:or
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
}
作者:optimus
项目:or
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
}
作者:optimus
项目:or
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
}
作者:ricsmani
项目:or
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
}