From 62453be692c4840096f5302c7fca2d928d5d9a47 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Sun, 26 Jun 2016 21:16:14 +1000 Subject: [PATCH] Let mysql to more searching --- main.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 4f99602..e56ba96 100644 --- a/main.go +++ b/main.go @@ -56,24 +56,19 @@ func check(err error) { } func generateName() string { - s := uniuri.NewLen(LENGTH) + id := uniuri.NewLen(LENGTH) db, err := sql.Open("mysql", DATABASE) check(err) - query, err := db.Query("select id from pastebin") - for query.Next() { - var id string - err := query.Scan(&id) - if err != nil { - - } - if id == s { + query, err := db.Query("select id from pastebin where id=?", id) + if err != sql.ErrNoRows { + for query.Next() { generateName() } } db.Close() - return s + return id } func hash(paste string) string {