SAP / go-ase

SAP ASE Database Client for Go
Apache License 2.0
25 stars 14 forks source link

nullable numeric field not scanned correctly #204

Closed hqin closed 2 years ago

hqin commented 3 years ago

Description

nullable numeric field not scanned into *asetypes.Decimal correctly

Expected behaviour asetypes.Decimal needs to have a way to represent NULL. Otherwise a new type such as asetypes.NullDecimal needs to be created.

Current behaviour

*asetypes.Decimal does not have a way to represent a NULL. a null numeric field is scanned to a zero value

Steps to Reproduce

Steps to reproduce the behavior: create table DATATYPE_DECIMAL_TEST(Id int primary key, DecimalFld decimal(32,5) NULL, NumericFld numeric(32,10) NULL, NumericP10S0Fld numeric(10,0) NOT NULL) go insert into DATATYPE_DECIMAL_TEST(Id, NumericP10S0Fld) values(3, 333) go

export environment variables DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_HOSTNAME, DB_PORT

  1. Run the attached code using go-ase driver DB_DRIVER=ase go run decimal_validate.go Connected to database using ase driver select NumericFld, NumericP10S0Fld from DATATYPE_DECIMAL_TEST where Id=3 column[0] column name: NumericFld type: NUMN length = 15 (presion, scale) = (32, 10) nullable = true scan type: asetypes.Decimal column[1] column name: NumericP10S0Fld type: NUMN length = 6 (presion, scale) = (10, 0) nullable = false scan type: asetypes.Decimal numericFld: &asetypes.Decimal{Precision:32, Scale:10, i:(big.Int)(0xc0000d33e0)}, numericP10S0Fld: &asetypes.Decimal{Precision:10, Scale:0, i:(big.Int)(0xc0000d3400)} numericFld value :0.0 numericP10S0Fld value :333.0

Environment

Client: OS: centos-7 go version: go1.16.3 linux/amd64 go-ase version / commit hash: v0.0.0-20210611100756-1778dda08c18

integer_validate.go.gz go-dblib version / commit hash: v0.0.0-20210610133137-f25b0f0fced0

Server: OS: centos-7 ASE version: 16.0_SP03PL09_EBF29247

decimal_validate.go.gz

frewilhelm commented 2 years ago

Solved in https://github.com/SAP/go-ase/pull/210