Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #9 from lufeee/feat/check-indent
Browse files Browse the repository at this point in the history
if query has leading whitespace delete indent rune
  • Loading branch information
1uf3 authored May 10, 2022
2 parents e03faf8 + 4f9a162 commit 38646fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion execinquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package execinquery
import (
"go/ast"
"strings"
"unicode"

"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/passes/inspect"
Expand Down Expand Up @@ -76,7 +77,10 @@ func run(pass *analysis.Pass) (interface{}, error) {
return
}

s = strings.Replace(basicLit.Value, "\"", "", -1)
s = strings.TrimLeftFunc(basicLit.Value, func(r rune) bool {
return !unicode.IsLetter(r) && !unicode.IsNumber(r)
})
s = strings.Replace(s, "\"", "", -1)
}

default:
Expand Down
5 changes: 5 additions & 0 deletions testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"testing"
)

const cquery = `
UPDATE * FROM test where test=?
`

func setup() *sql.DB {
db, _ := sql.Open("mysql", "test:test@tcp(test:3306)/test")
return db
Expand All @@ -31,4 +35,5 @@ func f(t *testing.T) {
var query1 string = "UPDATE * FROM test where test=?"
_, _ = db.Query(query, s) // want "It\\'s better to use Execute method instead of Query method to execute `UPDATE` query"
_, _ = db.Query(query1, s) // want "It\\'s better to use Execute method instead of Query method to execute `UPDATE` query"
_, _ = db.Query(cquery, s) // want "It\\'s better to use Execute method instead of Query method to execute `UPDATE` query"
}

0 comments on commit 38646fc

Please sign in to comment.