Skip to content

Commit

Permalink
refactoring (*textRows).readRow in a more clear way (#1230)
Browse files Browse the repository at this point in the history
  • Loading branch information
zihengCat committed Jul 12, 2021
1 parent a34e090 commit 75d09ac
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions packets.go
Expand Up @@ -761,40 +761,40 @@ func (rows *textRows) readRow(dest []driver.Value) error {
}

// RowSet Packet
var n int
var isNull bool
pos := 0
var (
n int
isNull bool
pos int = 0
)

for i := range dest {
// Read bytes and convert to string
dest[i], isNull, n, err = readLengthEncodedString(data[pos:])
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
continue
if err != nil {
return err
}

if isNull {
dest[i] = nil
continue
}

if !mc.parseTime {
continue
}

// Parse time field
switch rows.rs.columns[i].fieldType {
case fieldTypeTimestamp,
fieldTypeDateTime,
fieldTypeDate,
fieldTypeNewDate:
if dest[i], err = parseDateTime(dest[i].([]byte), mc.cfg.Loc); err != nil {
return err
}
}
return err // err != nil
}

return nil
Expand Down

0 comments on commit 75d09ac

Please sign in to comment.