From b5f572860a2a8d94103d2b27a7f170243f885e97 Mon Sep 17 00:00:00 2001 From: raylu Date: Tue, 9 Aug 2011 01:53:58 -0700 Subject: fix 2 bugs related to empty playlists --- main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index de39411..761a895 100644 --- a/main.go +++ b/main.go @@ -70,7 +70,9 @@ func add(w http.ResponseWriter, r *http.Request) { http.Error(w, err.String(), http.StatusInternalServerError) return } - maxOrder, err := queryInt(db, "SELECT MAX(`order`) FROM `song` WHERE pid = ?", pid) + // unfortunately, MAX(`order`) returns NULL when there is nothing + // so query for COUNT(`sid`) + count, err := queryInt(db, "SELECT COUNT(`sid`) FROM `song` WHERE `pid` = ?", pid) if err != nil { db.Rollback() http.Error(w, err.String(), http.StatusInternalServerError) @@ -78,7 +80,7 @@ func add(w http.ResponseWriter, r *http.Request) { } _, err = prepare(db, "INSERT INTO `song` (`pid`,`yid`,`title`,`user`,`order`) VALUES(?, ?, ?, ?, ?)", - pid, q.Get("yid"), q.Get("title"), q.Get("user"), maxOrder + 1) + pid, q.Get("yid"), q.Get("title"), q.Get("user"), count) if err != nil { db.Rollback() http.Error(w, err.String(), http.StatusInternalServerError) @@ -222,7 +224,7 @@ func move(w http.ResponseWriter, r *http.Request) { func poll(w http.ResponseWriter, r *http.Request) { q := r.URL.Query() timestamp := q.Get("timestamp") - if timestamp == "0" { + if timestamp == "-1" { db := <-dbPool defer func () {dbPool <- db}() -- cgit v1.2.3