-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Refactor textRows.readRow to improve readability #1123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -761,40 +761,37 @@ func (rows *textRows) readRow(dest []driver.Value) error { | |
} | ||
|
||
// RowSet Packet | ||
var n int | ||
var isNull bool | ||
pos := 0 | ||
|
||
for i := range dest { | ||
// Read bytes and convert to string | ||
dest[i], isNull, n, err = readLengthEncodedString(data[pos:]) | ||
b, isNull, n, err := readLengthEncodedString(data[pos:]) | ||
if err != nil { | ||
return err | ||
} | ||
pos += n | ||
if err == nil { | ||
if !isNull { | ||
if !mc.parseTime { | ||
continue | ||
} else { | ||
switch rows.rs.columns[i].fieldType { | ||
case fieldTypeTimestamp, fieldTypeDateTime, | ||
fieldTypeDate, fieldTypeNewDate: | ||
dest[i], err = parseDateTime( | ||
dest[i].([]byte), | ||
mc.cfg.Loc, | ||
) | ||
if err == nil { | ||
continue | ||
} | ||
default: | ||
continue | ||
} | ||
} | ||
|
||
} else { | ||
dest[i] = nil | ||
if isNull { | ||
dest[i] = nil | ||
continue | ||
} | ||
if !mc.parseTime { | ||
dest[i] = b // type: []byte | ||
continue | ||
} | ||
|
||
switch rows.rs.columns[i].fieldType { | ||
case fieldTypeTimestamp, fieldTypeDateTime, | ||
fieldTypeDate, fieldTypeNewDate: | ||
|
||
t, err := parseDateTime(b, mc.cfg.Loc) | ||
if err == nil { | ||
dest[i] = t // type: time.Time | ||
continue | ||
} | ||
// If parseDateTime failed, leave as []byte | ||
} | ||
return err // err != nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't err ignored now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I just saw the comment above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it looks like I misunderstood the original code. And this shows that it must be refactored to make it easier to follow 😉 . I will fix my code once the test suite is extended to cover that case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This still must be changed before I can approve this change. |
||
|
||
dest[i] = b // type: []byte | ||
} | ||
|
||
return nil | ||
|
Uh oh!
There was an error while loading. Please reload this page.