@@ -25,6 +25,14 @@ func todo(n pcast.Node) *ast.TODO {
25
25
return & ast.TODO {}
26
26
}
27
27
28
+ func identifier (id string ) string {
29
+ return strings .ToLower (id )
30
+ }
31
+
32
+ func NewIdentifer (t string ) * ast.String {
33
+ return & ast.String {Str : identifier (t )}
34
+ }
35
+
28
36
func (c * cc ) convertAlterTableStmt (n * pcast.AlterTableStmt ) ast.Node {
29
37
alt := & ast.AlterTableStmt {
30
38
Table : parseTableName (n .Table ),
@@ -119,7 +127,7 @@ func (c *cc) convertAlterTableStmt(n *pcast.AlterTableStmt) ast.Node {
119
127
}
120
128
121
129
func (c * cc ) convertAssignment (n * pcast.Assignment ) * ast.ResTarget {
122
- name := n .Column .Name .String ()
130
+ name := identifier ( n .Column .Name .String () )
123
131
return & ast.ResTarget {
124
132
Name : & name ,
125
133
Val : c .convert (n .Expr ),
@@ -259,12 +267,12 @@ func (c *cc) convertCreateTableStmt(n *pcast.CreateTableStmt) ast.Node {
259
267
func (c * cc ) convertColumnNameExpr (n * pcast.ColumnNameExpr ) * ast.ColumnRef {
260
268
var items []ast.Node
261
269
if schema := n .Name .Schema .String (); schema != "" {
262
- items = append (items , & ast. String { Str : schema } )
270
+ items = append (items , NewIdentifer ( schema ) )
263
271
}
264
272
if table := n .Name .Table .String (); table != "" {
265
- items = append (items , & ast. String { Str : table } )
273
+ items = append (items , NewIdentifer ( table ) )
266
274
}
267
- items = append (items , & ast. String { Str : n .Name .Name .String ()} )
275
+ items = append (items , NewIdentifer ( n .Name .Name .String ()) )
268
276
return & ast.ColumnRef {
269
277
Fields : & ast.List {
270
278
Items : items ,
@@ -275,7 +283,7 @@ func (c *cc) convertColumnNameExpr(n *pcast.ColumnNameExpr) *ast.ColumnRef {
275
283
func (c * cc ) convertColumnNames (cols []* pcast.ColumnName ) * ast.List {
276
284
list := & ast.List {Items : []ast.Node {}}
277
285
for i := range cols {
278
- name := cols [i ].Name .String ()
286
+ name := identifier ( cols [i ].Name .String () )
279
287
list .Items = append (list .Items , & ast.ResTarget {
280
288
Name : & name ,
281
289
})
@@ -344,9 +352,9 @@ func (c *cc) convertFuncCallExpr(n *pcast.FuncCallExpr) ast.Node {
344
352
// TODO: Deprecate the usage of Funcname
345
353
items := []ast.Node {}
346
354
if schema != "" {
347
- items = append (items , & ast. String { Str : schema } )
355
+ items = append (items , NewIdentifer ( schema ) )
348
356
}
349
- items = append (items , & ast. String { Str : name } )
357
+ items = append (items , NewIdentifer ( name ) )
350
358
351
359
args := & ast.List {}
352
360
for _ , arg := range n .Args {
@@ -432,7 +440,8 @@ func (c *cc) convertSelectField(n *pcast.SelectField) *ast.ResTarget {
432
440
}
433
441
var name * string
434
442
if n .AsName .O != "" {
435
- name = & n .AsName .O
443
+ asname := identifier (n .AsName .O )
444
+ name = & asname
436
445
}
437
446
return & ast.ResTarget {
438
447
// TODO: Populate Indirection field
@@ -479,7 +488,7 @@ func (c *cc) convertCommonTableExpression(n *pcast.CommonTableExpression) *ast.C
479
488
480
489
columns := & ast.List {}
481
490
for _ , col := range n .ColNameList {
482
- columns .Items = append (columns .Items , & ast. String { Str : col .String ()} )
491
+ columns .Items = append (columns .Items , NewIdentifer ( col .String ()) )
483
492
}
484
493
485
494
return & ast.CommonTableExpr {
@@ -556,7 +565,7 @@ func (c *cc) convertValueExpr(n *driver.ValueExpr) *ast.A_Const {
556
565
func (c * cc ) convertWildCardField (n * pcast.WildCardField ) * ast.ColumnRef {
557
566
items := []ast.Node {}
558
567
if t := n .Table .String (); t != "" {
559
- items = append (items , & ast. String { Str : t } )
568
+ items = append (items , NewIdentifer ( t ) )
560
569
}
561
570
items = append (items , & ast.A_Star {})
562
571
@@ -579,9 +588,7 @@ func (c *cc) convertAggregateFuncExpr(n *pcast.AggregateFuncExpr) *ast.FuncCall
579
588
},
580
589
Funcname : & ast.List {
581
590
Items : []ast.Node {
582
- & ast.String {
583
- Str : name ,
584
- },
591
+ NewIdentifer (name ),
585
592
},
586
593
},
587
594
Args : & ast.List {},
@@ -740,7 +747,7 @@ func (c *cc) convertDropDatabaseStmt(n *pcast.DropDatabaseStmt) ast.Node {
740
747
return & ast.DropSchemaStmt {
741
748
MissingOk : ! n .IfExists ,
742
749
Schemas : []* ast.String {
743
- { Str : n .Name } ,
750
+ NewIdentifer ( n .Name ) ,
744
751
},
745
752
}
746
753
}
@@ -1138,8 +1145,8 @@ func (c *cc) convertSplitRegionStmt(n *pcast.SplitRegionStmt) ast.Node {
1138
1145
}
1139
1146
1140
1147
func (c * cc ) convertTableName (n * pcast.TableName ) * ast.RangeVar {
1141
- schema := n .Schema .String ()
1142
- rel := n .Name .String ()
1148
+ schema := identifier ( n .Schema .String () )
1149
+ rel := identifier ( n .Name .String () )
1143
1150
return & ast.RangeVar {
1144
1151
Schemaname : & schema ,
1145
1152
Relname : & rel ,
0 commit comments