Skip to content

Commit

Permalink
fix struct par number type with pointer will panic
Browse files Browse the repository at this point in the history
  • Loading branch information
sijms committed Oct 10, 2024
1 parent 40067b5 commit 2962e72
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 279 deletions.
105 changes: 0 additions & 105 deletions converters/other_types.go

This file was deleted.

164 changes: 0 additions & 164 deletions converters/other_types_test.go

This file was deleted.

14 changes: 10 additions & 4 deletions v2/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ func (stmt *defaultStmt) read(dataSet *DataSet) (err error) {
// err = stmt.connection.session.GetError()
// return
// }
//
//
// }
// loop = false
// } else if msg == 9 {
Expand Down Expand Up @@ -841,7 +841,7 @@ func (stmt *defaultStmt) read(dataSet *DataSet) (err error) {
} else {
// see if it is re-executed
// if len(dataSet.Cols) == 0 && len(stmt.columns) > 0 {
//
//
// }
// dataSet.Cols = make([]ParameterInfo, len(stmt.columns))
// copy(dataSet.Cols, stmt.columns)
Expand Down Expand Up @@ -1407,12 +1407,18 @@ func (stmt *Stmt) structPar(parValue driver.Value, parIndex int) (processedPars
fieldType = fieldType.Elem()
}
}
// if field is empty ptr create type
//if field.Kind() == reflect.Ptr && field.IsNil() {
// field.Set(reflect.New(fieldType))
//}
// if type mentioned so driver should create a temporary type and then update the current value
typeErr := fmt.Errorf("error passing filed %s as type %s", tempType.Field(fieldIndex).Name, _type)
switch _type {
case "number":
var fieldVal *Number
if !hasNullValue {
if hasNullValue {
fieldVal = &Number{}
} else {
fieldVal, err = NewNumber(fieldValue)
if err != nil {
err = typeErr
Expand Down Expand Up @@ -1669,7 +1675,7 @@ func (stmt *Stmt) _exec(args []driver.NamedValue) (*QueryResult, error) {
// tempVal.Index(arrayIndex).Field(fieldIndex).Kind() == reflect.Array) && tempVal.Index(arrayIndex).Field(fieldIndex).IsNil() {
// arrayValues[arrayIndex] = nil
// } else {
//
//
// }
}
structArrayAsNamedPars = append(structArrayAsNamedPars, driver.NamedValue{Name: name, Value: arrayValues})
Expand Down
12 changes: 6 additions & 6 deletions v2/converters/other_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ INTERVAL_xxx encoding described at https://www.orafaq.com/wiki/Interval
func ConvertIntervalYM_DTY(val []byte) string {
/*
The first 4 bytes gives the number of years, the fifth byte gives the number of months in the following format:
years + 2147483648
years + 0x80000000
months + 60
*/
uyears := binary.BigEndian.Uint32(val)
years := int64(uyears) - 2147483648
years := int64(uyears) - 0x80000000
if years >= 0 {
months := val[4] - 60
return fmt.Sprintf("+%02d-%02d", years, months)
Expand All @@ -92,27 +92,27 @@ func ConvertIntervalDS_DTY(val []byte) string {
/*
The first 4 bytes gives the number of days, the last 4 ones the number of nanoseconds and the 3 in the middle the number of hours, minutes and seconds in the following format:
days + 2147483648
days + 0x80000000
hours + 60
minutes + 60
seconds + 60
nanoseconds
*/
udays := binary.BigEndian.Uint32(val)
days := int64(udays) - 2147483648
days := int64(udays) - 0x80000000
if days >= 0 {
hours := val[4] - 60
mins := val[5] - 60
secs := val[6] - 60
uns := binary.BigEndian.Uint32(val[7:])
ns := (int64(uns) - 2147483648) / 1000
ns := (int64(uns) - 0x80000000) / 1000
return fmt.Sprintf("+%02d %02d:%02d:%02d.%06d", days, hours, mins, secs, ns)
}
days = -days
hours := 60 - val[4]
mins := 60 - val[5]
secs := 60 - val[6]
uns := binary.BigEndian.Uint32(val[7:])
ns := -(int64(uns) - 2147483648) / 1000
ns := -(int64(uns) - 0x80000000) / 1000
return fmt.Sprintf("-%02d %02d:%02d:%02d.%06d", days, hours, mins, secs, ns)
}

0 comments on commit 2962e72

Please sign in to comment.