File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 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) {
12461246 }
12471247}
12481248
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+
12491273func TestRawBytesResultExceedsBuffer (t * testing.T ) {
12501274 runTests (t , dsn , func (dbt * DBTest ) {
12511275 // defaultBufSize from buffer.go
Original file line number Diff line number Diff line change @@ -40,7 +40,11 @@ func (rows *mysqlRows) Columns() []string {
4040 columns := make ([]string , len (rows .columns ))
4141 if rows .mc .cfg .columnsWithAlias {
4242 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+ }
4448 }
4549 } else {
4650 for i := range columns {
You can’t perform that action at this time.
0 commit comments