Skip to content

Commit e91a9ab

Browse files
fix: Myriad string formatting changes (#2558)
1 parent 4a18cc2 commit e91a9ab

File tree

7 files changed

+28
-29
lines changed

7 files changed

+28
-29
lines changed

internal/codegen/golang/field.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TagsToString(tags map[string]string) string {
3434
}
3535
tagParts := make([]string, 0, len(tags))
3636
for key, val := range tags {
37-
tagParts = append(tagParts, fmt.Sprintf("%s:\"%s\"", key, val))
37+
tagParts = append(tagParts, fmt.Sprintf("%s:%q", key, val))
3838
}
3939
sort.Strings(tagParts)
4040
return strings.Join(tagParts, " ")

internal/codegen/golang/imports.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ type ImportSpec struct {
2121

2222
func (s ImportSpec) String() string {
2323
if s.ID != "" {
24-
return fmt.Sprintf("%s \"%s\"", s.ID, s.Path)
24+
return fmt.Sprintf("%s %q", s.ID, s.Path)
2525
} else {
26-
return fmt.Sprintf("\"%s\"", s.Path)
26+
return fmt.Sprintf("%q", s.Path)
2727
}
2828
}
2929

internal/compiler/output_columns.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,14 +639,14 @@ func outputColumnRefs(res *ast.ResTarget, tables []*Table, node *ast.ColumnRef)
639639
if found == 0 {
640640
return nil, &sqlerr.Error{
641641
Code: "42703",
642-
Message: fmt.Sprintf("column \"%s\" does not exist", name),
642+
Message: fmt.Sprintf("column %q does not exist", name),
643643
Location: res.Location,
644644
}
645645
}
646646
if found > 1 {
647647
return nil, &sqlerr.Error{
648648
Code: "42703",
649-
Message: fmt.Sprintf("column reference \"%s\" is ambiguous", name),
649+
Message: fmt.Sprintf("column reference %q is ambiguous", name),
650650
Location: res.Location,
651651
}
652652
}
@@ -702,14 +702,14 @@ func findColumnForRef(ref *ast.ColumnRef, tables []*Table, targetList *ast.List)
702702
if found == 0 {
703703
return &sqlerr.Error{
704704
Code: "42703",
705-
Message: fmt.Sprintf("column reference \"%s\" not found", name),
705+
Message: fmt.Sprintf("column reference %q not found", name),
706706
Location: ref.Location,
707707
}
708708
}
709709
if found > 1 {
710710
return &sqlerr.Error{
711711
Code: "42703",
712-
Message: fmt.Sprintf("column reference \"%s\" is ambiguous", name),
712+
Message: fmt.Sprintf("column reference %q is ambiguous", name),
713713
Location: ref.Location,
714714
}
715715
}

internal/compiler/resolve.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
188188
if !located {
189189
return nil, &sqlerr.Error{
190190
Code: "42703",
191-
Message: fmt.Sprintf("table alias \"%s\" does not exist", alias),
191+
Message: fmt.Sprintf("table alias %q does not exist", alias),
192192
Location: node.Location,
193193
}
194194
}
@@ -231,14 +231,14 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
231231
if found == 0 {
232232
return nil, &sqlerr.Error{
233233
Code: "42703",
234-
Message: fmt.Sprintf("column \"%s\" does not exist", key),
234+
Message: fmt.Sprintf("column %q does not exist", key),
235235
Location: node.Location,
236236
}
237237
}
238238
if found > 1 {
239239
return nil, &sqlerr.Error{
240240
Code: "42703",
241-
Message: fmt.Sprintf("column reference \"%s\" is ambiguous", key),
241+
Message: fmt.Sprintf("column reference %q is ambiguous", key),
242242
Location: node.Location,
243243
}
244244
}
@@ -471,7 +471,7 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
471471
} else {
472472
return nil, &sqlerr.Error{
473473
Code: "42703",
474-
Message: fmt.Sprintf("column \"%s\" does not exist", key),
474+
Message: fmt.Sprintf("column %q does not exist", key),
475475
Location: n.Location,
476476
}
477477
}
@@ -587,20 +587,20 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar,
587587
if found == 0 {
588588
return nil, &sqlerr.Error{
589589
Code: "42703",
590-
Message: fmt.Sprintf("396: column \"%s\" does not exist", key),
590+
Message: fmt.Sprintf("396: column %q does not exist", key),
591591
Location: location,
592592
}
593593
}
594594
if found > 1 {
595595
return nil, &sqlerr.Error{
596596
Code: "42703",
597-
Message: fmt.Sprintf("in same name column reference \"%s\" is ambiguous", key),
597+
Message: fmt.Sprintf("in same name column reference %q is ambiguous", key),
598598
Location: location,
599599
}
600600
}
601601

602602
default:
603-
fmt.Printf("unsupported reference type: %T", n)
603+
fmt.Printf("unsupported reference type: %T\n", n)
604604
}
605605
}
606606
return a, nil

internal/sql/catalog/table.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (c *Catalog) createTable(stmt *ast.CreateTableStmt) error {
267267
seen[col.Name] = notNull || col.IsNotNull
268268
if a, ok := coltype[col.Name]; ok {
269269
if !sameType(&a, &col.Type) {
270-
return fmt.Errorf("column \"%s\" has a type conflict", col.Name)
270+
return fmt.Errorf("column %q has a type conflict", col.Name)
271271
}
272272
}
273273
continue
@@ -298,7 +298,7 @@ func (c *Catalog) createTable(stmt *ast.CreateTableStmt) error {
298298
seen[col.Colname] = notNull || col.IsNotNull
299299
if a, ok := coltype[col.Colname]; ok {
300300
if !sameType(&a, col.TypeName) {
301-
return fmt.Errorf("column \"%s\" has a type conflict", col.Colname)
301+
return fmt.Errorf("column %q has a type conflict", col.Colname)
302302
}
303303
}
304304
continue

internal/sql/sqlerr/errors.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,77 +35,77 @@ func ColumnExists(rel, col string) *Error {
3535
return &Error{
3636
Err: Exists,
3737
Code: "42701",
38-
Message: fmt.Sprintf("column \"%s\" of relation \"%s\"", col, rel),
38+
Message: fmt.Sprintf("column %q of relation %q", col, rel),
3939
}
4040
}
4141

4242
func ColumnNotFound(rel, col string) *Error {
4343
return &Error{
4444
Err: NotFound,
4545
Code: "42703",
46-
Message: fmt.Sprintf("column \"%s\" of relation \"%s\"", col, rel),
46+
Message: fmt.Sprintf("column %q of relation %q", col, rel),
4747
}
4848
}
4949

5050
func RelationExists(rel string) *Error {
5151
return &Error{
5252
Err: Exists,
5353
Code: "42P07",
54-
Message: fmt.Sprintf("relation \"%s\"", rel),
54+
Message: fmt.Sprintf("relation %q", rel),
5555
}
5656
}
5757

5858
func RelationNotFound(rel string) *Error {
5959
return &Error{
6060
Err: NotFound,
6161
Code: "42P01",
62-
Message: fmt.Sprintf("relation \"%s\"", rel),
62+
Message: fmt.Sprintf("relation %q", rel),
6363
}
6464
}
6565

6666
func SchemaExists(name string) *Error {
6767
return &Error{
6868
Err: Exists,
6969
Code: "42P06",
70-
Message: fmt.Sprintf("schema \"%s\"", name),
70+
Message: fmt.Sprintf("schema %q", name),
7171
}
7272
}
7373

7474
func SchemaNotFound(sch string) *Error {
7575
return &Error{
7676
Err: NotFound,
7777
Code: "3F000",
78-
Message: fmt.Sprintf("schema \"%s\"", sch),
78+
Message: fmt.Sprintf("schema %q", sch),
7979
}
8080
}
8181

8282
func TypeExists(typ string) *Error {
8383
return &Error{
8484
Err: Exists,
8585
Code: "42710",
86-
Message: fmt.Sprintf("type \"%s\"", typ),
86+
Message: fmt.Sprintf("type %q", typ),
8787
}
8888
}
8989

9090
func TypeNotFound(typ string) *Error {
9191
return &Error{
9292
Err: NotFound,
9393
Code: "42704",
94-
Message: fmt.Sprintf("type \"%s\"", typ),
94+
Message: fmt.Sprintf("type %q", typ),
9595
}
9696
}
9797

9898
func FunctionNotFound(fun string) *Error {
9999
return &Error{
100100
Err: NotFound,
101101
Code: "42704",
102-
Message: fmt.Sprintf("function \"%s\"", fun),
102+
Message: fmt.Sprintf("function %q", fun),
103103
}
104104
}
105105

106106
func FunctionNotUnique(fn string) *Error {
107107
return &Error{
108108
Err: NotUnique,
109-
Message: fmt.Sprintf("function name \"%s\"", fn),
109+
Message: fmt.Sprintf("function name %q", fn),
110110
}
111111
}

internal/tools/sqlc-pg-gen/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"strings"
1414
"text/template"
1515

16-
pgx "github.com/jackc/pgx/v4"
16+
"github.com/jackc/pgx/v4"
1717
)
1818

1919
// https://dba.stackexchange.com/questions/255412/how-to-select-functions-that-belong-in-a-given-extension-in-postgresql
@@ -308,8 +308,7 @@ func run(ctx context.Context) error {
308308
funcName += strings.Title(part)
309309
}
310310

311-
_, err := conn.Exec(ctx, fmt.Sprintf("CREATE EXTENSION IF NOT EXISTS \"%s\"", extension))
312-
if err != nil {
311+
if _, err := conn.Exec(ctx, fmt.Sprintf("CREATE EXTENSION IF NOT EXISTS %q", extension)); err != nil {
313312
return fmt.Errorf("error creating %s: %s", extension, err)
314313
}
315314

0 commit comments

Comments
 (0)