summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.go8
-rw-r--r--static/script.js4
2 files changed, 8 insertions, 4 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}()
diff --git a/static/script.js b/static/script.js
index bc05fad..bcb531b 100644
--- a/static/script.js
+++ b/static/script.js
@@ -4,7 +4,7 @@ var player;
var litColor = '#eee';
var dimmedColor = '#555';
var interval;
-var timestamp = '0';
+var timestamp = '-1';
$(document).ready(function () {
$('body').click(function (e) {
@@ -68,6 +68,8 @@ function handleUpdates(data) {
break;
}
}
+ if (timestamp == '-1')
+ timestamp = '0';
getUpdates();
}