File tree 3 files changed +43
-2
lines changed
3 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ Jian Zhen <zhenjl at gmail.com>
32
32
Joshua Prunier <joshua.prunier at gmail.com>
33
33
Julien Lefevre <julien.lefevr at gmail.com>
34
34
Julien Schmidt <go-sql-driver at julienschmidt.com>
35
+ Justin Nuß <nuss.justin at gmail.com>
35
36
Kamil Dziedzic <kamil at klecza.pl>
36
37
Kevin Malachowski <kevin at chowski.com>
37
38
Lennart Rudolph <lrudolph at hmc.edu>
Original file line number Diff line number Diff line change @@ -1916,3 +1916,36 @@ func TestInterruptBySignal(t *testing.T) {
1916
1916
}
1917
1917
})
1918
1918
}
1919
+
1920
+ func TestColumnsReusesSlice (t * testing.T ) {
1921
+ rows := mysqlRows {
1922
+ rs : resultSet {
1923
+ columns : []mysqlField {
1924
+ {
1925
+ tableName : "test" ,
1926
+ name : "A" ,
1927
+ },
1928
+ {
1929
+ tableName : "test" ,
1930
+ name : "B" ,
1931
+ },
1932
+ },
1933
+ },
1934
+ }
1935
+
1936
+ allocs := testing .AllocsPerRun (1 , func () {
1937
+ cols := rows .Columns ()
1938
+
1939
+ if len (cols ) != 2 {
1940
+ t .Fatalf ("expected 2 columns, got %d" , len (cols ))
1941
+ }
1942
+ })
1943
+
1944
+ if allocs != 0 {
1945
+ t .Fatalf ("expected 0 allocations, got %d" , int (allocs ))
1946
+ }
1947
+
1948
+ if rows .rs .columnNames == nil {
1949
+ t .Fatalf ("expected columnNames to be set, got nil" )
1950
+ }
1951
+ }
Original file line number Diff line number Diff line change @@ -22,8 +22,9 @@ type mysqlField struct {
22
22
}
23
23
24
24
type resultSet struct {
25
- columns []mysqlField
26
- done bool
25
+ columns []mysqlField
26
+ columnNames []string
27
+ done bool
27
28
}
28
29
29
30
type mysqlRows struct {
@@ -40,6 +41,10 @@ type textRows struct {
40
41
}
41
42
42
43
func (rows * mysqlRows ) Columns () []string {
44
+ if rows .rs .columnNames != nil {
45
+ return rows .rs .columnNames
46
+ }
47
+
43
48
columns := make ([]string , len (rows .rs .columns ))
44
49
if rows .mc != nil && rows .mc .cfg .ColumnsWithAlias {
45
50
for i := range columns {
@@ -54,6 +59,8 @@ func (rows *mysqlRows) Columns() []string {
54
59
columns [i ] = rows .rs .columns [i ].name
55
60
}
56
61
}
62
+
63
+ rows .rs .columnNames = columns
57
64
return columns
58
65
}
59
66
You can’t perform that action at this time.
0 commit comments