summaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorraylu <raylu@mixpanel.com>2011-08-09 01:53:58 -0700
committerraylu <raylu@mixpanel.com>2011-08-09 01:53:58 -0700
commitb5f572860a2a8d94103d2b27a7f170243f885e97 (patch)
tree2e09d28beaa44fcdfbffb1cba5b82746147fb12c /main.go
parentc37572b1dc72fb604bd57ffe27d3f1a7d45cdc0e (diff)
downloadaudioaxis-b5f572860a2a8d94103d2b27a7f170243f885e97.tar.xz
fix 2 bugs related to empty playlists
Diffstat (limited to 'main.go')
-rw-r--r--main.go8
1 files changed, 5 insertions, 3 deletions
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}()