@@ -4,14 +4,15 @@ import (
44 "fmt"
55 "strings"
66
7+ "github.com/kyleconroy/sqlc/internal/config"
78 "github.com/kyleconroy/sqlc/internal/source"
89 "github.com/kyleconroy/sqlc/internal/sql/ast"
910 "github.com/kyleconroy/sqlc/internal/sql/ast/pg"
1011 "github.com/kyleconroy/sqlc/internal/sql/astutils"
1112 "github.com/kyleconroy/sqlc/internal/sql/lang"
1213)
1314
14- func expand (qc * QueryCatalog , raw * ast.RawStmt ) ([]source.Edit , error ) {
15+ func ( c * Compiler ) expand (qc * QueryCatalog , raw * ast.RawStmt ) ([]source.Edit , error ) {
1516 list := astutils .Search (raw , func (node ast.Node ) bool {
1617 switch node .(type ) {
1718 case * pg.DeleteStmt :
@@ -28,7 +29,7 @@ func expand(qc *QueryCatalog, raw *ast.RawStmt) ([]source.Edit, error) {
2829 }
2930 var edits []source.Edit
3031 for _ , item := range list .Items {
31- edit , err := expandStmt (qc , raw , item )
32+ edit , err := c . expandStmt (qc , raw , item )
3233 if err != nil {
3334 return nil , err
3435 }
@@ -37,14 +38,20 @@ func expand(qc *QueryCatalog, raw *ast.RawStmt) ([]source.Edit, error) {
3738 return edits , nil
3839}
3940
40- func quoteIdent (ident string ) string {
41+ func (c * Compiler ) quoteIdent (ident string ) string {
42+ // TODO: Add a method to the parser / engine for this instead
4143 if lang .IsReservedKeyword (ident ) {
42- return "\" " + ident + "\" "
44+ switch c .conf .Engine {
45+ case config .EngineMySQL , config .EngineXDolphin :
46+ return "`" + ident + "`"
47+ default :
48+ return "\" " + ident + "\" "
49+ }
4350 }
4451 return ident
4552}
4653
47- func expandStmt (qc * QueryCatalog , raw * ast.RawStmt , node ast.Node ) ([]source.Edit , error ) {
54+ func ( c * Compiler ) expandStmt (qc * QueryCatalog , raw * ast.RawStmt , node ast.Node ) ([]source.Edit , error ) {
4855 tables , err := sourceTables (qc , node )
4956 if err != nil {
5057 return nil , err
@@ -103,14 +110,14 @@ func expandStmt(qc *QueryCatalog, raw *ast.RawStmt, node ast.Node) ([]source.Edi
103110 if scope != "" && scope != t .Rel .Name {
104111 continue
105112 }
106- tableName := quoteIdent (t .Rel .Name )
107- scopeName := quoteIdent (scope )
108- for _ , c := range t .Columns {
109- cname := c .Name
113+ tableName := c . quoteIdent (t .Rel .Name )
114+ scopeName := c . quoteIdent (scope )
115+ for _ , column := range t .Columns {
116+ cname := column .Name
110117 if res .Name != nil {
111118 cname = * res .Name
112119 }
113- cname = quoteIdent (cname )
120+ cname = c . quoteIdent (cname )
114121 if scope != "" {
115122 cname = scopeName + "." + cname
116123 }
@@ -122,7 +129,7 @@ func expandStmt(qc *QueryCatalog, raw *ast.RawStmt, node ast.Node) ([]source.Edi
122129 }
123130 var old []string
124131 for _ , p := range parts {
125- old = append (old , quoteIdent (p ))
132+ old = append (old , c . quoteIdent (p ))
126133 }
127134 edits = append (edits , source.Edit {
128135 Location : res .Location - raw .StmtLocation ,
0 commit comments