Skip to content

Commit

Permalink
Nullable output parameters for String, Int*, Float*
Browse files Browse the repository at this point in the history
  • Loading branch information
Дутка Вячеслав Станиславович authored and tgulacsi committed May 23, 2017
1 parent 0df5121 commit fa34ede
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 64 deletions.
17 changes: 12 additions & 5 deletions bndFloat32Ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ import (
)

type bndFloat32Ptr struct {
stmt *Stmt
ocibnd *C.OCIBind
ociNumber [1]C.OCINumber
value *float32
stmt *Stmt
ocibnd *C.OCIBind
ociNumber [1]C.OCINumber
value *float32
valueIsNull *bool
nullp
}

func (bnd *bndFloat32Ptr) bind(value *float32, position namedPos, stmt *Stmt) error {
func (bnd *bndFloat32Ptr) bind(value *float32, valueIsNull *bool, position namedPos, stmt *Stmt) error {
bnd.stmt = stmt
bnd.value = value
bnd.valueIsNull = valueIsNull
bnd.nullp.Set(value == nil)
if value != nil {
if err := bnd.stmt.ses.srv.env.OCINumberFromFloat(&bnd.ociNumber[0], float64(*value), byteWidth32); err != nil {
Expand Down Expand Up @@ -57,11 +59,15 @@ func (bnd *bndFloat32Ptr) bind(value *float32, position namedPos, stmt *Stmt) er
}

func (bnd *bndFloat32Ptr) setPtr() error {
if bnd.valueIsNull != nil {
*bnd.valueIsNull = bnd.nullp.IsNull()
}
if bnd.nullp.IsNull() {
return nil
}
f, err := bnd.stmt.ses.srv.env.OCINumberToFloat(&bnd.ociNumber[0], byteWidth32)
*bnd.value = float32(f)

return err
}

Expand All @@ -76,6 +82,7 @@ func (bnd *bndFloat32Ptr) close() (err error) {
bnd.stmt = nil
bnd.ocibnd = nil
bnd.value = nil
bnd.valueIsNull = nil
bnd.nullp.Free()
stmt.putBnd(bndIdxFloat32Ptr, bnd)
return nil
Expand Down
17 changes: 12 additions & 5 deletions bndFloat64Ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ import (
)

type bndFloat64Ptr struct {
stmt *Stmt
ocibnd *C.OCIBind
ociNumber [1]C.OCINumber
value *float64
stmt *Stmt
ocibnd *C.OCIBind
ociNumber [1]C.OCINumber
value *float64
valueIsNull *bool
nullp
}

func (bnd *bndFloat64Ptr) bind(value *float64, position namedPos, stmt *Stmt) error {
func (bnd *bndFloat64Ptr) bind(value *float64, valueIsNull *bool, position namedPos, stmt *Stmt) error {
bnd.stmt = stmt
bnd.value = value
bnd.valueIsNull = valueIsNull
bnd.nullp.Set(value == nil)
if value != nil {
if err := bnd.stmt.ses.srv.env.OCINumberFromFloat(&bnd.ociNumber[0], floatSixtyFour(*value), byteWidth64); err != nil {
Expand Down Expand Up @@ -57,11 +59,15 @@ func (bnd *bndFloat64Ptr) bind(value *float64, position namedPos, stmt *Stmt) er
}

func (bnd *bndFloat64Ptr) setPtr() error {
if bnd.valueIsNull != nil {
*bnd.valueIsNull = bnd.nullp.IsNull()
}
if bnd.nullp.IsNull() {
return nil
}
f, err := bnd.stmt.ses.srv.env.OCINumberToFloat(&bnd.ociNumber[0], byteWidth64)
*bnd.value = float64(f)

return err
}

Expand All @@ -76,6 +82,7 @@ func (bnd *bndFloat64Ptr) close() (err error) {
bnd.stmt = nil
bnd.ocibnd = nil
bnd.value = nil
bnd.valueIsNull = nil
bnd.nullp.Free()
stmt.putBnd(bndIdxFloat64Ptr, bnd)
return nil
Expand Down
17 changes: 12 additions & 5 deletions bndInt16Ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ import "C"
import "unsafe"

type bndInt16Ptr struct {
stmt *Stmt
ocibnd *C.OCIBind
ociNumber [1]C.OCINumber
value *int16
stmt *Stmt
ocibnd *C.OCIBind
ociNumber [1]C.OCINumber
value *int16
valueIsNull *bool
nullp
}

func (bnd *bndInt16Ptr) bind(value *int16, position namedPos, stmt *Stmt) error {
func (bnd *bndInt16Ptr) bind(value *int16, valueIsNull *bool, position namedPos, stmt *Stmt) error {
//bnd.stmt.logF(_drv.Cfg().Log.Stmt.Bind, "Int16Ptr.bind(%d) value=%#v => number=%#v", position, value, bnd.ociNumber[0])
bnd.stmt = stmt
bnd.value = value
bnd.valueIsNull = valueIsNull
bnd.nullp.Set(value == nil)
if value != nil {
if err := bnd.stmt.ses.srv.env.OCINumberFromInt(&bnd.ociNumber[0], int64(*value), byteWidth16); err != nil {
Expand Down Expand Up @@ -59,11 +61,15 @@ func (bnd *bndInt16Ptr) bind(value *int16, position namedPos, stmt *Stmt) error
}

func (bnd *bndInt16Ptr) setPtr() error {
if bnd.valueIsNull != nil {
*bnd.valueIsNull = bnd.nullp.IsNull()
}
if bnd.nullp.IsNull() {
return nil
}
i, err := bnd.stmt.ses.srv.env.OCINumberToInt(&bnd.ociNumber[0], byteWidth16)
*bnd.value = int16(i)

return err
}

Expand All @@ -78,6 +84,7 @@ func (bnd *bndInt16Ptr) close() (err error) {
bnd.stmt = nil
bnd.ocibnd = nil
bnd.value = nil
bnd.valueIsNull = nil
bnd.nullp.Free()
stmt.putBnd(bndIdxInt16Ptr, bnd)
return nil
Expand Down
17 changes: 12 additions & 5 deletions bndInt32Ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ import "C"
import "unsafe"

type bndInt32Ptr struct {
stmt *Stmt
ocibnd *C.OCIBind
ociNumber [1]C.OCINumber
value *int32
stmt *Stmt
ocibnd *C.OCIBind
ociNumber [1]C.OCINumber
value *int32
valueIsNull *bool
nullp
}

func (bnd *bndInt32Ptr) bind(value *int32, position namedPos, stmt *Stmt) error {
func (bnd *bndInt32Ptr) bind(value *int32, valueIsNull *bool, position namedPos, stmt *Stmt) error {
//bnd.stmt.logF(_drv.Cfg().Log.Stmt.Bind, "Int32Ptr.bind(%d) value=%#v => number=%#v", position, value, bnd.ociNumber[0])
bnd.stmt = stmt
bnd.value = value
bnd.valueIsNull = valueIsNull
bnd.nullp.Set(value == nil)
if value != nil {
if err := bnd.stmt.ses.srv.env.OCINumberFromInt(&bnd.ociNumber[0], int64(*value), byteWidth32); err != nil {
Expand Down Expand Up @@ -59,11 +61,15 @@ func (bnd *bndInt32Ptr) bind(value *int32, position namedPos, stmt *Stmt) error
}

func (bnd *bndInt32Ptr) setPtr() error {
if bnd.valueIsNull != nil {
*bnd.valueIsNull = bnd.nullp.IsNull()
}
if bnd.nullp.IsNull() {
return nil
}
i, err := bnd.stmt.ses.srv.env.OCINumberToInt(&bnd.ociNumber[0], byteWidth32)
*bnd.value = int32(i)

return err
}

Expand All @@ -78,6 +84,7 @@ func (bnd *bndInt32Ptr) close() (err error) {
bnd.stmt = nil
bnd.ocibnd = nil
bnd.value = nil
bnd.valueIsNull = nil
bnd.nullp.Free()
stmt.putBnd(bndIdxInt32Ptr, bnd)
return nil
Expand Down
17 changes: 12 additions & 5 deletions bndInt64Ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ import "C"
import "unsafe"

type bndInt64Ptr struct {
stmt *Stmt
ocibnd *C.OCIBind
ociNumber [1]C.OCINumber
value *int64
stmt *Stmt
ocibnd *C.OCIBind
ociNumber [1]C.OCINumber
value *int64
valueIsNull *bool
nullp
}

func (bnd *bndInt64Ptr) bind(value *int64, position namedPos, stmt *Stmt) error {
func (bnd *bndInt64Ptr) bind(value *int64, valueIsNull *bool, position namedPos, stmt *Stmt) error {
//bnd.stmt.logF(_drv.Cfg().Log.Stmt.Bind, "Int64Ptr.bind(%d) value=%#v => number=%#v", position, value, bnd.ociNumber[0])
bnd.stmt = stmt
bnd.value = value
bnd.valueIsNull = valueIsNull
bnd.nullp.Set(value == nil)
if value != nil {
if err := bnd.stmt.ses.srv.env.OCINumberFromInt(&bnd.ociNumber[0], intSixtyFour(*value), byteWidth64); err != nil {
Expand Down Expand Up @@ -59,11 +61,15 @@ func (bnd *bndInt64Ptr) bind(value *int64, position namedPos, stmt *Stmt) error
}

func (bnd *bndInt64Ptr) setPtr() error {
if bnd.valueIsNull != nil {
*bnd.valueIsNull = bnd.nullp.IsNull()
}
if bnd.nullp.IsNull() {
return nil
}
i, err := bnd.stmt.ses.srv.env.OCINumberToInt(&bnd.ociNumber[0], byteWidth64)
*bnd.value = int64(i)

return err
}

Expand All @@ -78,6 +84,7 @@ func (bnd *bndInt64Ptr) close() (err error) {
bnd.stmt = nil
bnd.ocibnd = nil
bnd.value = nil
bnd.valueIsNull = nil
bnd.nullp.Free()
stmt.putBnd(bndIdxInt64Ptr, bnd)
return nil
Expand Down
17 changes: 12 additions & 5 deletions bndInt8Ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@ import "C"
import "unsafe"

type bndInt8Ptr struct {
stmt *Stmt
ocibnd *C.OCIBind
ociNumber [1]C.OCINumber
value *int8
stmt *Stmt
ocibnd *C.OCIBind
ociNumber [1]C.OCINumber
value *int8
valueIsNull *bool
nullp
}

func (bnd *bndInt8Ptr) bind(value *int8, position namedPos, stmt *Stmt) error {
func (bnd *bndInt8Ptr) bind(value *int8, valueIsNull *bool, position namedPos, stmt *Stmt) error {
//bnd.stmt.logF(_drv.Cfg().Log.Stmt.Bind, "Int8Ptr.bind(%d) value=%#v => number=%#v", position, value, bnd.ociNumber[0])
bnd.stmt = stmt
bnd.value = value
bnd.valueIsNull = valueIsNull
bnd.nullp.Set(value == nil)
if value != nil {
if err := bnd.stmt.ses.srv.env.OCINumberFromInt(&bnd.ociNumber[0], int64(*value), byteWidth8); err != nil {
Expand Down Expand Up @@ -59,11 +61,15 @@ func (bnd *bndInt8Ptr) bind(value *int8, position namedPos, stmt *Stmt) error {
}

func (bnd *bndInt8Ptr) setPtr() error {
if bnd.valueIsNull != nil {
*bnd.valueIsNull = bnd.nullp.IsNull()
}
if bnd.nullp.IsNull() {
return nil
}
i, err := bnd.stmt.ses.srv.env.OCINumberToInt(&bnd.ociNumber[0], byteWidth8)
*bnd.value = int8(i)

return err
}

Expand All @@ -78,6 +84,7 @@ func (bnd *bndInt8Ptr) close() (err error) {
bnd.stmt = nil
bnd.ocibnd = nil
bnd.value = nil
bnd.valueIsNull = nil
bnd.nullp.Free()
stmt.putBnd(bndIdxInt8Ptr, bnd)
return nil
Expand Down
19 changes: 13 additions & 6 deletions bndStringPtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ import "unsafe"
const maxStringLength = 32767

type bndStringPtr struct {
stmt *Stmt
ocibnd *C.OCIBind
value *string
buf []byte
alen [1]C.ACTUAL_LENGTH_TYPE
stmt *Stmt
ocibnd *C.OCIBind
value *string
valueIsNull *bool
buf []byte
alen [1]C.ACTUAL_LENGTH_TYPE
nullp
}

func (bnd *bndStringPtr) bind(value *string, position namedPos, stringPtrBufferSize int, stmt *Stmt) error {
func (bnd *bndStringPtr) bind(value *string, valueIsNull *bool, position namedPos, stringPtrBufferSize int, stmt *Stmt) error {
bnd.stmt = stmt
bnd.value = value
bnd.valueIsNull = valueIsNull
if stringPtrBufferSize < 2 {
stringPtrBufferSize = 2
} else if stringPtrBufferSize%2 == 1 {
Expand Down Expand Up @@ -101,11 +103,15 @@ func (bnd *bndStringPtr) bind(value *string, position namedPos, stringPtrBufferS
}

func (bnd *bndStringPtr) setPtr() error {
if bnd.valueIsNull != nil {
*bnd.valueIsNull = bnd.nullp.IsNull()
}
if bnd.value == nil {
return nil
}
bnd.stmt.logF(_drv.Cfg().Log.Stmt.Bind,
"StringPtr.setPtr isNull=%t alen=%d", bnd.nullp.IsNull(), bnd.alen[0])

if !bnd.nullp.IsNull() {
*bnd.value = string(bnd.buf[:bnd.alen[0]])
} else {
Expand All @@ -127,6 +133,7 @@ func (bnd *bndStringPtr) close() (err error) {
bnd.stmt = nil
bnd.ocibnd = nil
bnd.value = nil
bnd.valueIsNull = nil
bnd.alen[0] = 0
bytesPool.Put(bnd.buf)
bnd.buf = nil
Expand Down
Loading

0 comments on commit fa34ede

Please sign in to comment.