Skip to content

Commit

Permalink
Fixed staticcheck reports
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
  • Loading branch information
kozlovic committed Aug 8, 2018
1 parent 8a14dda commit 0dc2bf6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
15 changes: 6 additions & 9 deletions stores/sqlstore.go
Expand Up @@ -17,8 +17,8 @@ import (
"database/sql"
"encoding/json"
"fmt"
"regexp"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -683,21 +683,18 @@ func initSQLStmtsTable(driver string) {
switch driver {
case driverPostgres:
// Replace ? with $1, $2, etc...
reg := regexp.MustCompile(`\?`)
for i, stmt := range sqlStmts {
n := 0
stmt := reg.ReplaceAllStringFunc(stmt, func(string) string {
for strings.IndexByte(stmt, '?') != -1 {
n++
return "$" + strconv.Itoa(n)
})
param := "$" + strconv.Itoa(n)
stmt = strings.Replace(stmt, "?", param, 1)
}
sqlStmts[i] = stmt
}
// Replace `row` with row
reg = regexp.MustCompile("`row`")
for i, stmt := range sqlStmts {
stmt := reg.ReplaceAllStringFunc(stmt, func(string) string {
return "row"
})
stmt := strings.Replace(stmt, "`row`", "row", -1)
sqlStmts[i] = stmt
}
// OVER (PARTITION ...) is not supported in older MySQL servers.
Expand Down
7 changes: 2 additions & 5 deletions stores/sqlstore_test.go
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"math/rand"
"reflect"
"regexp"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -197,16 +196,14 @@ func TestSQLPostgresDriverInit(t *testing.T) {
initSQLStmtsTable(driverPostgres)

// Make sure there is not ? but $ in the statements
reg := regexp.MustCompile(`\?`)
for _, stmt := range sqlStmts {
if reg.FindString(stmt) != "" {
if strings.IndexByte(stmt, '?') != -1 {
t.Fatalf("Statement %q incorrect for Postgres driver", stmt)
}
}
// Make sure there is not `row` in the statements
reg = regexp.MustCompile("`row`")
for _, stmt := range sqlStmts {
if reg.FindString(stmt) != "" {
if strings.Contains(stmt, "`row`") {
t.Fatalf("Statement %q incorrect for Postgres driver", stmt)
}
}
Expand Down

0 comments on commit 0dc2bf6

Please sign in to comment.