Let sql do the searching

This commit is contained in:
Eliot Whalan 2016-06-26 21:14:12 +10:00
parent 672ce0d77a
commit a1d4ee2287
1 changed files with 6 additions and 6 deletions

12
main.go
View File

@ -89,12 +89,12 @@ func save(raw string, lang string, title string, expiry string) []string {
check(err) check(err)
sha := hash(raw) sha := hash(raw)
query, err := db.Query("select id, title, hash, data, delkey from pastebin") query, err := db.Query("select id, title, hash, data, delkey from pastebin where hash=?", sha)
for query.Next() { if err != sql.ErrNoRows {
var id, title, hash, paste, delkey string for query.Next() {
err := query.Scan(&id, &title, &hash, &paste, &delkey) var id, title, hash, paste, delkey string
check(err) err := query.Scan(&id, &title, &hash, &paste, &delkey)
if hash == sha { check(err)
url := ADDRESS + "/p/" + id url := ADDRESS + "/p/" + id
return []string{id, title, hash, url, paste, delkey} return []string{id, title, hash, url, paste, delkey}
} }