Let sql do the searching

This commit is contained in:
Eliot Whalan 2016-06-26 21:14:12 +10:00
parent f562758f35
commit 3c4a9e0032
No known key found for this signature in database
GPG Key ID: C0A42175139840D6
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)
sha := hash(raw)
query, err := db.Query("select id, title, hash, data, delkey from pastebin")
for query.Next() {
var id, title, hash, paste, delkey string
err := query.Scan(&id, &title, &hash, &paste, &delkey)
check(err)
if hash == sha {
query, err := db.Query("select id, title, hash, data, delkey from pastebin where hash=?", sha)
if err != sql.ErrNoRows {
for query.Next() {
var id, title, hash, paste, delkey string
err := query.Scan(&id, &title, &hash, &paste, &delkey)
check(err)
url := ADDRESS + "/p/" + id
return []string{id, title, hash, url, paste, delkey}
}