@@ -25,6 +25,14 @@ func todo(n pcast.Node) *ast.TODO {
2525 return & ast.TODO {}
2626}
2727
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+
2836func (c * cc ) convertAlterTableStmt (n * pcast.AlterTableStmt ) ast.Node {
2937 alt := & ast.AlterTableStmt {
3038 Table : parseTableName (n .Table ),
@@ -119,7 +127,7 @@ func (c *cc) convertAlterTableStmt(n *pcast.AlterTableStmt) ast.Node {
119127}
120128
121129func (c * cc ) convertAssignment (n * pcast.Assignment ) * ast.ResTarget {
122- name := n .Column .Name .String ()
130+ name := identifier ( n .Column .Name .String () )
123131 return & ast.ResTarget {
124132 Name : & name ,
125133 Val : c .convert (n .Expr ),
@@ -259,12 +267,12 @@ func (c *cc) convertCreateTableStmt(n *pcast.CreateTableStmt) ast.Node {
259267func (c * cc ) convertColumnNameExpr (n * pcast.ColumnNameExpr ) * ast.ColumnRef {
260268 var items []ast.Node
261269 if schema := n .Name .Schema .String (); schema != "" {
262- items = append (items , & ast. String { Str : schema } )
270+ items = append (items , NewIdentifer ( schema ) )
263271 }
264272 if table := n .Name .Table .String (); table != "" {
265- items = append (items , & ast. String { Str : table } )
273+ items = append (items , NewIdentifer ( table ) )
266274 }
267- items = append (items , & ast. String { Str : n .Name .Name .String ()} )
275+ items = append (items , NewIdentifer ( n .Name .Name .String ()) )
268276 return & ast.ColumnRef {
269277 Fields : & ast.List {
270278 Items : items ,
@@ -275,7 +283,7 @@ func (c *cc) convertColumnNameExpr(n *pcast.ColumnNameExpr) *ast.ColumnRef {
275283func (c * cc ) convertColumnNames (cols []* pcast.ColumnName ) * ast.List {
276284 list := & ast.List {Items : []ast.Node {}}
277285 for i := range cols {
278- name := cols [i ].Name .String ()
286+ name := identifier ( cols [i ].Name .String () )
279287 list .Items = append (list .Items , & ast.ResTarget {
280288 Name : & name ,
281289 })
@@ -344,9 +352,9 @@ func (c *cc) convertFuncCallExpr(n *pcast.FuncCallExpr) ast.Node {
344352 // TODO: Deprecate the usage of Funcname
345353 items := []ast.Node {}
346354 if schema != "" {
347- items = append (items , & ast. String { Str : schema } )
355+ items = append (items , NewIdentifer ( schema ) )
348356 }
349- items = append (items , & ast. String { Str : name } )
357+ items = append (items , NewIdentifer ( name ) )
350358
351359 args := & ast.List {}
352360 for _ , arg := range n .Args {
@@ -432,7 +440,8 @@ func (c *cc) convertSelectField(n *pcast.SelectField) *ast.ResTarget {
432440 }
433441 var name * string
434442 if n .AsName .O != "" {
435- name = & n .AsName .O
443+ asname := identifier (n .AsName .O )
444+ name = & asname
436445 }
437446 return & ast.ResTarget {
438447 // TODO: Populate Indirection field
@@ -479,7 +488,7 @@ func (c *cc) convertCommonTableExpression(n *pcast.CommonTableExpression) *ast.C
479488
480489 columns := & ast.List {}
481490 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 ()) )
483492 }
484493
485494 return & ast.CommonTableExpr {
@@ -556,7 +565,7 @@ func (c *cc) convertValueExpr(n *driver.ValueExpr) *ast.A_Const {
556565func (c * cc ) convertWildCardField (n * pcast.WildCardField ) * ast.ColumnRef {
557566 items := []ast.Node {}
558567 if t := n .Table .String (); t != "" {
559- items = append (items , & ast. String { Str : t } )
568+ items = append (items , NewIdentifer ( t ) )
560569 }
561570 items = append (items , & ast.A_Star {})
562571
@@ -579,9 +588,7 @@ func (c *cc) convertAggregateFuncExpr(n *pcast.AggregateFuncExpr) *ast.FuncCall
579588 },
580589 Funcname : & ast.List {
581590 Items : []ast.Node {
582- & ast.String {
583- Str : name ,
584- },
591+ NewIdentifer (name ),
585592 },
586593 },
587594 Args : & ast.List {},
@@ -740,7 +747,7 @@ func (c *cc) convertDropDatabaseStmt(n *pcast.DropDatabaseStmt) ast.Node {
740747 return & ast.DropSchemaStmt {
741748 MissingOk : ! n .IfExists ,
742749 Schemas : []* ast.String {
743- { Str : n .Name } ,
750+ NewIdentifer ( n .Name ) ,
744751 },
745752 }
746753}
@@ -1138,8 +1145,8 @@ func (c *cc) convertSplitRegionStmt(n *pcast.SplitRegionStmt) ast.Node {
11381145}
11391146
11401147func (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 () )
11431150 return & ast.RangeVar {
11441151 Schemaname : & schema ,
11451152 Relname : & rel ,
0 commit comments