summaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
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}()