Skip to content

Commit 5fcbc08

Browse files
authored
Merge pull request #1860 from testwill/fmt
chore: unnecessary use of fmt.Sprintf
2 parents f11523c + 122eef4 commit 5fcbc08

File tree

14 files changed

+33
-34
lines changed

14 files changed

+33
-34
lines changed

enginetest/enginetests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5943,7 +5943,7 @@ func TestPersist(t *testing.T, harness Harness, newPersistableSess func(ctx *sql
59435943
_, res, _ := sql.SystemVariables.GetGlobal("max_connections")
59445944
require.Equal(t, tt.ExpectedGlobal, res)
59455945

5946-
showGlobalVarsQuery := fmt.Sprintf("SHOW GLOBAL VARIABLES LIKE 'max_connections'")
5946+
showGlobalVarsQuery := "SHOW GLOBAL VARIABLES LIKE 'max_connections'"
59475947
TestQueryWithContext(t, ctx, e, harness, showGlobalVarsQuery, []sql.Row{{"max_connections", tt.ExpectedGlobal}}, nil, nil)
59485948
}
59495949

enginetest/spatial_index_tests.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package enginetest
1616

1717
import (
18-
"fmt"
1918
"testing"
2019

2120
"github.com/stretchr/testify/require"
@@ -399,12 +398,12 @@ func evalSpatialIndexPlanTest(t *testing.T, harness Harness, e *sqle.Engine, que
399398
return true
400399
})
401400

402-
require.True(t, hasFilter, fmt.Sprintf("filter node was missing from plan"))
401+
require.True(t, hasFilter, "filter node was missing from plan")
403402
if noIdx {
404-
require.False(t, hasIndex, fmt.Sprintf("indextableaccess should not be in plan"))
403+
require.False(t, hasIndex, "indextableaccess should not be in plan")
405404
} else {
406-
require.True(t, hasIndex, fmt.Sprintf("indextableaccess node was missing from plan"))
407-
require.True(t, hasRightOrder, fmt.Sprintf("filter node was not above indextableaccess"))
405+
require.True(t, hasIndex, "indextableaccess node was missing from plan")
406+
require.True(t, hasRightOrder, "filter node was not above indextableaccess")
408407
}
409408
})
410409
}
@@ -523,12 +522,12 @@ func evalSpatialIndexPlanTestPrepared(t *testing.T, harness Harness, e *sqle.Eng
523522
return true
524523
})
525524

526-
require.True(t, hasFilter, fmt.Sprintf("filter node was missing from plan"))
525+
require.True(t, hasFilter, "filter node was missing from plan")
527526
if noIdx {
528-
require.False(t, hasIndex, fmt.Sprintf("indextableaccess should not be in plan"))
527+
require.False(t, hasIndex, "indextableaccess should not be in plan")
529528
} else {
530-
require.True(t, hasIndex, fmt.Sprintf("indextableaccess node was missing from plan"))
531-
require.True(t, hasRightOrder, fmt.Sprintf("filter node was not above indextableaccess"))
529+
require.True(t, hasIndex, "indextableaccess node was missing from plan")
530+
require.True(t, hasRightOrder, "filter node was not above indextableaccess")
532531
}
533532
})
534533
}

sql/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type EventDetails struct {
6161

6262
// CreateEventStatement returns a CREATE EVENT statement for this event.
6363
func (e *EventDetails) CreateEventStatement() string {
64-
stmt := fmt.Sprintf("CREATE")
64+
stmt := "CREATE"
6565
if e.Definer != "" {
6666
stmt = fmt.Sprintf("%s DEFINER = %s", stmt, e.Definer)
6767
}

sql/expression/div.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (d *Div) div(ctx *sql.Context, lval, rval interface{}) (interface{}, error)
236236
switch r := rval.(type) {
237237
case float32:
238238
if r == 0 {
239-
arithmeticWarning(ctx, ERDivisionByZero, fmt.Sprintf("Division by 0"))
239+
arithmeticWarning(ctx, ERDivisionByZero, "Division by 0")
240240
return nil, nil
241241
}
242242
return l / r, nil
@@ -245,7 +245,7 @@ func (d *Div) div(ctx *sql.Context, lval, rval interface{}) (interface{}, error)
245245
switch r := rval.(type) {
246246
case float64:
247247
if r == 0 {
248-
arithmeticWarning(ctx, ERDivisionByZero, fmt.Sprintf("Division by 0"))
248+
arithmeticWarning(ctx, ERDivisionByZero, "Division by 0")
249249
return nil, nil
250250
}
251251
return l / r, nil
@@ -254,7 +254,7 @@ func (d *Div) div(ctx *sql.Context, lval, rval interface{}) (interface{}, error)
254254
switch r := rval.(type) {
255255
case decimal.Decimal:
256256
if r.Equal(decimal.NewFromInt(0)) {
257-
arithmeticWarning(ctx, ERDivisionByZero, fmt.Sprintf("Division by 0"))
257+
arithmeticWarning(ctx, ERDivisionByZero, "Division by 0")
258258
return nil, nil
259259
}
260260

@@ -743,7 +743,7 @@ func intDiv(ctx *sql.Context, lval, rval interface{}) (interface{}, error) {
743743
switch r := rval.(type) {
744744
case uint64:
745745
if r == 0 {
746-
arithmeticWarning(ctx, ERDivisionByZero, fmt.Sprintf("Division by 0"))
746+
arithmeticWarning(ctx, ERDivisionByZero, "Division by 0")
747747
return nil, nil
748748
}
749749
return l / r, nil
@@ -752,7 +752,7 @@ func intDiv(ctx *sql.Context, lval, rval interface{}) (interface{}, error) {
752752
switch r := rval.(type) {
753753
case int64:
754754
if r == 0 {
755-
arithmeticWarning(ctx, ERDivisionByZero, fmt.Sprintf("Division by 0"))
755+
arithmeticWarning(ctx, ERDivisionByZero, "Division by 0")
756756
return nil, nil
757757
}
758758
return l / r, nil
@@ -761,7 +761,7 @@ func intDiv(ctx *sql.Context, lval, rval interface{}) (interface{}, error) {
761761
switch r := rval.(type) {
762762
case float64:
763763
if r == 0 {
764-
arithmeticWarning(ctx, ERDivisionByZero, fmt.Sprintf("Division by 0"))
764+
arithmeticWarning(ctx, ERDivisionByZero, "Division by 0")
765765
return nil, nil
766766
}
767767
res := l / r
@@ -771,7 +771,7 @@ func intDiv(ctx *sql.Context, lval, rval interface{}) (interface{}, error) {
771771
switch r := rval.(type) {
772772
case decimal.Decimal:
773773
if r.Equal(decimal.NewFromInt(0)) {
774-
arithmeticWarning(ctx, ERDivisionByZero, fmt.Sprintf("Division by 0"))
774+
arithmeticWarning(ctx, ERDivisionByZero, "Division by 0")
775775
return nil, nil
776776
}
777777

sql/expression/function/time.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ func NewCurrTimestamp(args ...sql.Expression) (sql.Expression, error) {
14581458

14591459
func (c *CurrTimestamp) String() string {
14601460
if len(c.Args) == 0 {
1461-
return fmt.Sprintf("CURRENT_TIMESTAMP()")
1461+
return "CURRENT_TIMESTAMP()"
14621462
}
14631463
return fmt.Sprintf("CURRENT_TIMESTAMP(%s)", c.Args[0].String())
14641464
}

sql/expression/mod.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func mod(ctx *sql.Context, lval, rval interface{}) (interface{}, error) {
165165
switch r := rval.(type) {
166166
case float32:
167167
if r == 0 {
168-
arithmeticWarning(ctx, ERDivisionByZero, fmt.Sprintf("Division by 0"))
168+
arithmeticWarning(ctx, ERDivisionByZero, "Division by 0")
169169
return nil, nil
170170
}
171171
return math.Mod(float64(l), float64(r)), nil
@@ -175,7 +175,7 @@ func mod(ctx *sql.Context, lval, rval interface{}) (interface{}, error) {
175175
switch r := rval.(type) {
176176
case float64:
177177
if r == 0 {
178-
arithmeticWarning(ctx, ERDivisionByZero, fmt.Sprintf("Division by 0"))
178+
arithmeticWarning(ctx, ERDivisionByZero, "Division by 0")
179179
return nil, nil
180180
}
181181
return math.Mod(l, r), nil
@@ -184,7 +184,7 @@ func mod(ctx *sql.Context, lval, rval interface{}) (interface{}, error) {
184184
switch r := rval.(type) {
185185
case decimal.Decimal:
186186
if r.Equal(decimal.NewFromInt(0)) {
187-
arithmeticWarning(ctx, ERDivisionByZero, fmt.Sprintf("Division by 0"))
187+
arithmeticWarning(ctx, ERDivisionByZero, "Division by 0")
188188
return nil, nil
189189
}
190190

sql/information_schema/columns_table.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func getRowFromColumn(ctx *sql.Context, curOrdPos int, col *sql.Column, dbName,
217217
extra := col.Extra
218218
// If extra is not defined, fill it here.
219219
if extra == "" && !col.Default.IsLiteral() {
220-
extra = fmt.Sprintf("DEFAULT_GENERATED")
220+
extra = "DEFAULT_GENERATED"
221221
}
222222

223223
var curColPrivStr []string

sql/parse/parse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ func convertShow(ctx *sql.Context, s *sqlparser.Show, query string) (sql.Node, e
914914
return node, nil
915915
case sqlparser.KeywordString(sqlparser.WARNINGS):
916916
if s.CountStar {
917-
unsupportedShow := fmt.Sprintf("SHOW COUNT(*) WARNINGS")
917+
unsupportedShow := "SHOW COUNT(*) WARNINGS"
918918
return nil, sql.ErrUnsupportedFeature.New(unsupportedShow)
919919
}
920920
var node sql.Node
@@ -1420,7 +1420,7 @@ func convertDBDDL(ctx *sql.Context, c *sqlparser.DBDDL) (sql.Node, error) {
14201420
ctx.Session.Warn(&sql.Warning{
14211421
Level: "Warning",
14221422
Code: mysql.ERNotSupportedYet,
1423-
Message: fmt.Sprintf("Setting CHARACTER SET, COLLATION and ENCRYPTION are not supported yet"),
1423+
Message: "Setting CHARACTER SET, COLLATION and ENCRYPTION are not supported yet",
14241424
})
14251425
}
14261426
}

sql/plan/alter_event.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func NewAlterEvent(
106106

107107
// String implements the sql.Node interface.
108108
func (a *AlterEvent) String() string {
109-
stmt := fmt.Sprintf("ALTER")
109+
stmt := "ALTER"
110110

111111
if a.Definer != "" {
112112
stmt = fmt.Sprintf("%s DEFINER = %s", stmt, a.Definer)
@@ -416,7 +416,7 @@ func (c *alterEventIter) Next(ctx *sql.Context) (sql.Row, error) {
416416
ctx.Session.Warn(&sql.Warning{
417417
Level: "Note",
418418
Code: 1544,
419-
Message: fmt.Sprintf("Event execution time is in the past. Event has been disabled"),
419+
Message: "Event execution time is in the past. Event has been disabled",
420420
})
421421
} else {
422422
return nil, fmt.Errorf("Event execution time is in the past and ON COMPLETION NOT PRESERVE is set. The event was not changed. Specify a time in the future.")

sql/plan/ddl_event.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (c *CreateEvent) String() string {
148148

149149
onCompletion := ""
150150
if !c.OnCompPreserve {
151-
onCompletion = fmt.Sprintf(" ON COMPLETION NOT PRESERVE")
151+
onCompletion = " ON COMPLETION NOT PRESERVE"
152152
}
153153

154154
comment := ""
@@ -355,7 +355,7 @@ func (c *createEventIter) Next(ctx *sql.Context) (sql.Row, error) {
355355
ctx.Session.Warn(&sql.Warning{
356356
Level: "Note",
357357
Code: 1544,
358-
Message: fmt.Sprintf("Event execution time is in the past. Event has been disabled"),
358+
Message: "Event execution time is in the past. Event has been disabled",
359359
})
360360
} else {
361361
// If ON COMPLETION NOT PRESERVE is defined, the event is dropped immediately after creation.
@@ -366,7 +366,7 @@ func (c *createEventIter) Next(ctx *sql.Context) (sql.Row, error) {
366366
ctx.Session.Warn(&sql.Warning{
367367
Level: "Note",
368368
Code: 1588,
369-
Message: fmt.Sprintf("Event execution time is in the past and ON COMPLETION NOT PRESERVE is set. The event was dropped immediately after creation."),
369+
Message: "Event execution time is in the past and ON COMPLETION NOT PRESERVE is set. The event was dropped immediately after creation.",
370370
})
371371
}
372372
return sql.Row{types.NewOkResult(0)}, nil

0 commit comments

Comments
 (0)