Skip to content

Commit 58f6c4a

Browse files
committed
refactoring (*textRows).readRow in a more clear way
Fix error returns use utf8mb4 instead of utf8 in TestCharset (#1228) From MySQL 8.0.24, `SELECT @@character_set_connection` reports utf8mb3 or utf8mb4 instead of utf8. Because utf8 is currently an alias for utf8mb3, however at some point utf8 is expected to become a reference to utf8mb4. > ref. https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-24.html#mysqld-8-0-24-bug > Important Note: When a utf8mb3 collation was specified in a CREATE TABLE statement, SHOW CREATE TABLE, DEFAULT CHARSET, > the values of system variables containing character set names, > and the binary log all subsequently displayed the character set as utf8 which is becoming a synonym for utf8mb4. > Now in such cases, utf8mb3 is shown instead, and CREATE TABLE raises the warning 'collation_name' is a collation of the deprecated character set UTF8MB3. > Please consider using UTF8MB4 with an appropriate collation instead. (Bug #27225287, Bug #32085357, Bug #32122844) > > References: See also: Bug #30624990. The document says that we should use utf8mb4 instead of utf8, so we should follow it.
1 parent 21f789c commit 58f6c4a

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

Diff for: driver_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1450,11 +1450,11 @@ func TestCharset(t *testing.T) {
14501450
mustSetCharset("charset=ascii", "ascii")
14511451

14521452
// when the first charset is invalid, use the second
1453-
mustSetCharset("charset=none,utf8", "utf8")
1453+
mustSetCharset("charset=none,utf8mb4", "utf8mb4")
14541454

14551455
// when the first charset is valid, use it
1456-
mustSetCharset("charset=ascii,utf8", "ascii")
1457-
mustSetCharset("charset=utf8,ascii", "utf8")
1456+
mustSetCharset("charset=ascii,utf8mb4", "ascii")
1457+
mustSetCharset("charset=utf8mb4,ascii", "utf8mb4")
14581458
}
14591459

14601460
func TestFailingCharset(t *testing.T) {

Diff for: packets.go

+26-26
Original file line numberDiff line numberDiff line change
@@ -761,40 +761,40 @@ func (rows *textRows) readRow(dest []driver.Value) error {
761761
}
762762

763763
// RowSet Packet
764-
var n int
765-
var isNull bool
766-
pos := 0
764+
var (
765+
n int
766+
isNull bool
767+
pos int = 0
768+
)
767769

768770
for i := range dest {
769771
// Read bytes and convert to string
770772
dest[i], isNull, n, err = readLengthEncodedString(data[pos:])
771773
pos += n
772-
if err == nil {
773-
if !isNull {
774-
if !mc.parseTime {
775-
continue
776-
} else {
777-
switch rows.rs.columns[i].fieldType {
778-
case fieldTypeTimestamp, fieldTypeDateTime,
779-
fieldTypeDate, fieldTypeNewDate:
780-
dest[i], err = parseDateTime(
781-
dest[i].([]byte),
782-
mc.cfg.Loc,
783-
)
784-
if err == nil {
785-
continue
786-
}
787-
default:
788-
continue
789-
}
790-
}
791774

792-
} else {
793-
dest[i] = nil
794-
continue
775+
if err != nil {
776+
return err
777+
}
778+
779+
if isNull {
780+
dest[i] = nil
781+
continue
782+
}
783+
784+
if !mc.parseTime {
785+
continue
786+
}
787+
788+
// Parse time field
789+
switch rows.rs.columns[i].fieldType {
790+
case fieldTypeTimestamp,
791+
fieldTypeDateTime,
792+
fieldTypeDate,
793+
fieldTypeNewDate:
794+
if dest[i], err = parseDateTime(dest[i].([]byte), mc.cfg.Loc); err != nil {
795+
return err
795796
}
796797
}
797-
return err // err != nil
798798
}
799799

800800
return nil

0 commit comments

Comments
 (0)