Use instr for substring test in SQL query

There is no longer a need for the EscapeGlob function.
This commit is contained in:
Cheer Xiao 2015-02-24 16:04:07 +01:00
parent 37186a41d4
commit e8299a6e7c
2 changed files with 1 additions and 13 deletions

View File

@ -1,11 +0,0 @@
package store
import "strings"
var globEscaper = strings.NewReplacer("\\", "\\\\", "?", "\\?", "*", "\\*")
// EscapeGlob escapes s to be suitable as an argument to SQLite's GLOB
// operator.
func EscapeGlob(s string) string {
return globEscaper.Replace(s)
}

View File

@ -51,8 +51,7 @@ func convertVisitedDirs(rows *sql.Rows) ([]VisitedDir, error) {
func (s *Store) FindVisitedDirs(p string) ([]VisitedDir, error) {
rows, err := s.db.Query(
"select path, score from visited_dir where path glob ? order by score desc",
"*"+EscapeGlob(p)+"*")
"select path, score from visited_dir where instr(path, ?) > 0 order by score desc", p)
if err != nil {
return nil, err
}