Skip to content

Commit

Permalink
fix: handle error on some failing casts
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
kmpm committed Nov 11, 2019
1 parent 920d3da commit fd9ced4
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions reader/dbReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@ func DbValueToString(colData interface{}, dataType string) *string {
bytes[3], bytes[2], bytes[1], bytes[0], bytes[5], bytes[4], bytes[7], bytes[6], bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15])
// === //
case dataType == "numeric": // sqlite - best type for number. needs casting for pg
stringValue = fmt.Sprintf("%v", colData.(float64))
if f, ok := colData.(float64); ok {
stringValue = fmt.Sprintf("%v", f)
} else {
log.Printf("Error casting '%T' to 'float64' for datatype %s", colData, dataType)
stringValue = fmt.Sprintf("Type Error! %T", colData)
}
case dataType == "varbinary":
fallthrough
case dataType == "blob":
Expand Down Expand Up @@ -228,8 +233,17 @@ func DbValueToString(colData interface{}, dataType string) *string {
// === //
case strings.Contains(dataType, "text"): // mssql // todo: expensive, optimise for supported values
// https://stackoverflow.com/a/18615786/10245
bytes := colData.([]uint8)
stringValue = fmt.Sprintf("%s", bytes)
switch v := colData.(type) {
case string:
stringValue = v
default:
if bytes, ok := colData.([]uint8); ok {
stringValue = fmt.Sprintf("%s", bytes)
} else {
log.Printf("Error casting '%T' to '[]uint8' for datatype %s", colData, dataType)
stringValue = fmt.Sprintf("Type Error! %T", colData)
}
}
// === // unknown ...
default:
//log.Printf("unknown data type %s", dataType)
Expand Down

0 comments on commit fd9ced4

Please sign in to comment.