File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -1246,6 +1246,30 @@ func TestCollation(t *testing.T) {
1246
1246
}
1247
1247
}
1248
1248
1249
+ func TestColumnsWithAlias (t * testing.T ) {
1250
+ runTests (t , dsn + "&columnsWithAlias=true" , func (dbt * DBTest ) {
1251
+ rows := dbt .mustQuery ("SELECT 1 AS A" )
1252
+ defer rows .Close ()
1253
+ cols , _ := rows .Columns ()
1254
+ if len (cols ) != 1 {
1255
+ t .Fatalf ("expected 1 column, got %d" , len (cols ))
1256
+ }
1257
+ if cols [0 ] != "A" {
1258
+ t .Fatalf ("expected column name \" A\" , got \" %s\" " , cols [0 ])
1259
+ }
1260
+ rows .Close ()
1261
+
1262
+ rows = dbt .mustQuery ("SELECT * FROM (SELECT 1 AS one) AS A" )
1263
+ cols , _ = rows .Columns ()
1264
+ if len (cols ) != 1 {
1265
+ t .Fatalf ("expected 1 column, got %d" , len (cols ))
1266
+ }
1267
+ if cols [0 ] != "A.one" {
1268
+ t .Fatalf ("expected column name \" A.one\" , got \" %s\" " , cols [0 ])
1269
+ }
1270
+ })
1271
+ }
1272
+
1249
1273
func TestRawBytesResultExceedsBuffer (t * testing.T ) {
1250
1274
runTests (t , dsn , func (dbt * DBTest ) {
1251
1275
// defaultBufSize from buffer.go
Original file line number Diff line number Diff line change @@ -40,7 +40,11 @@ func (rows *mysqlRows) Columns() []string {
40
40
columns := make ([]string , len (rows .columns ))
41
41
if rows .mc .cfg .columnsWithAlias {
42
42
for i := range columns {
43
- columns [i ] = rows .columns [i ].tableName + "." + rows .columns [i ].name
43
+ if tableName := rows .columns [i ].tableName ; len (tableName ) > 0 {
44
+ columns [i ] = tableName + "." + rows .columns [i ].name
45
+ } else {
46
+ columns [i ] = rows .columns [i ].name
47
+ }
44
48
}
45
49
} else {
46
50
for i := range columns {
You can’t perform that action at this time.
0 commit comments