You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I modified the code for documentation (#38 (comment)) for tried with driver.NullDecimal instead driver.Decimal:
db, err:=sql.Open("hdb", connstring)
iferr!=nil {
log.Fatal(err)
}
deferdb.Close()
query:="select decimal_column from test"rows, err:=db.Query(query)
iferr!=nil {
log.Fatal(err)
}
deferrows.Close()
//The 1 is the columns len returned in queryrecordPointers:=make([]interface{}, 1)
//For Decimal Columnvart driver.NullDecimalrecordPointers[0] =&tforrows.Next() {
// Scan the result into the column pointers...iferr:=rows.Scan(recordPointers...); err!=nil {
log.Fatal(err)
}
for_, v:=rangerecordPointers {
switchx:=v.(type) {
case*driver.NullDecimal:
ifx.Valid {
d:= (*big.Rat)(x.Decimal)
log.Print(d.FloatString(6))
} else {
log.Print("NULL")
}
default:
log.Print("is not Decimal")
}
}
}
When decimal_column is NULL the code return NULL but when is not null return the error: sql: Scan error on column index 0, name "decimal_column": invalid decimal value <nil>
I expect the decimal value.
If driver.Decimal is used then I got the value but when column is NULL then the same error is returned.
The text was updated successfully, but these errors were encountered:
driver.NullDecimal needs to be 'instantiated' with non-nil Decimal attribute, like
var t = driver.NullDecimal{Decimal: new(driver.Decimal)}
The uninitialized Decimal attribute causes the error message you get after scan.
It's arguable why the Decimal isn't created automatically, but full allocation control should be with the user of the client lib - no lib internal magic.
I modified the code for documentation (#38 (comment)) for tried with driver.NullDecimal instead driver.Decimal:
When decimal_column is NULL the code return
NULL
but when is not null return the error:sql: Scan error on column index 0, name "decimal_column": invalid decimal value <nil>
I expect the decimal value.
If driver.Decimal is used then I got the value but when column is NULL then the same error is returned.
The text was updated successfully, but these errors were encountered: