Skip to content

Commit

Permalink
fix decode number to float64 and int64 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sijms committed Aug 24, 2023
1 parent dc82702 commit c1f4c03
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
24 changes: 19 additions & 5 deletions v2/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,21 @@ func (par *ParameterInfo) decodePrimValue(conn *Connection, udt bool) error {
case RAW:
par.oPrimValue = par.BValue
case NUMBER:
if par.Scale == 0 && par.Precision <= 18 {
if par.Scale == 0 && par.Precision == 0 {
var tempFloat string
tempFloat, err = converters.NumberToString(par.BValue)
if err != nil {
return err
}
if err != nil {
return err
}
if strings.Contains(tempFloat, ".") {
par.oPrimValue, err = strconv.ParseFloat(tempFloat, 64)
} else {
par.oPrimValue, err = strconv.ParseInt(tempFloat, 10, 64)
}
} else if par.Scale == 0 && par.Precision <= 18 {
par.oPrimValue, err = converters.NumberToInt64(par.BValue)
if err != nil {
return err
Expand All @@ -987,20 +1001,20 @@ func (par *ParameterInfo) decodePrimValue(conn *Connection, udt bool) error {
return err
}
} else if par.Scale > 0 {
//par.oPrimValue, err = converters.NumberToString(par.BValue)
var tempFloat string
tempFloat, err = converters.NumberToString(par.BValue)
if err != nil {
return err
}
if err != nil {
return err
}
if strings.Contains(tempFloat, ".") {
par.oPrimValue, err = strconv.ParseFloat(tempFloat, 64)
} else {
par.oPrimValue, err = strconv.ParseInt(tempFloat, 10, 64)
}
//par.oPrimValue, err = converters.NumberToString(par.BValue)
if err != nil {
return err
}
} else {
par.oPrimValue = converters.DecodeNumber(par.BValue)
}
Expand Down
4 changes: 4 additions & 0 deletions v2/parameter_encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ func (par *ParameterInfo) encodeValue(val driver.Value, size int, connection *Co
}
par.MaxLen = par.MaxCharLen * converters.MaxBytePerChar(conv.GetLangID())
}
//if par.DataType == NUMBER {
// par.Precision = 38
// par.Scale = 0xff
//}
if par.DataType == RAW {
if par.MaxLen < size {
par.MaxLen = size
Expand Down

0 comments on commit c1f4c03

Please sign in to comment.