summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rddb/rddb.go81
1 files changed, 72 insertions, 9 deletions
diff --git a/rddb/rddb.go b/rddb/rddb.go
index 638c360..847e865 100644
--- a/rddb/rddb.go
+++ b/rddb/rddb.go
@@ -28,6 +28,7 @@ import (
"database/sql"
"fmt"
"regexp"
+ "strconv"
"strings"
"time"
@@ -102,17 +103,19 @@ type getMusicInfoRequest struct {
type CutListEntry struct {
Number uint
+ Evergreen bool
Description string
+ Duration time.Duration
+ // Imported time.Time
+ NumPlayed uint
+ // LastPlayed time.Time
}
type CartListEntry struct {
- Number uint
- Title string
- Duration time.Duration
- Imported time.Time
- NumPlayed uint
- LastPlayed time.Time
- Cuts []*CutListEntry
+ Number uint
+ Exists bool
+ Title string
+ Cuts []*CutListEntry
}
type ShowListEntry struct {
@@ -147,6 +150,8 @@ type DB struct {
getMusicInfoStmt *sql.Stmt
getShowListChan chan getShowListRequest
getShowListStmt *sql.Stmt
+ getCartInfoStmt *sql.Stmt
+ getCutInfoStmt *sql.Stmt
quit chan bool
done chan bool
}
@@ -188,6 +193,13 @@ func (db *DB) init() (err error) {
if db.getShowListStmt, err = db.dbh.Prepare("select CART.TITLE,CART.MACROS,DROPBOXES.TO_CART,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from CART, USER_PERMS, DROPBOXES, GROUPS where CART.NUMBER = DROPBOXES.TO_CART and USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME = USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME = GROUPS.NAME and DROPBOXES.STATION_NAME = ?;"); err != nil {
return
}
+ if db.getCartInfoStmt, err = db.dbh.Prepare("select TITLE from CART where TYPE=1 and NUMBER = ?"); err != nil {
+ return
+ }
+ // if db.getCutInfoStmt, err = db.dbh.Prepare("select CUT_NAME, EVERGREEN, DESCRIPTION, LENGTH, ORIGIN_DATETIME, PLAY_COUNTER, LAST_PLAY_DATETIME from CUTS where CART_NUMBER = ?"); err != nil {
+ if db.getCutInfoStmt, err = db.dbh.Prepare("select CUT_NAME, EVERGREEN, DESCRIPTION, LENGTH, PLAY_COUNTER from CUTS where CART_NUMBER = ?"); err != nil {
+ return
+ }
return
}
@@ -310,10 +322,62 @@ func (db *DB) getMusicInfo(group string) (result getMusicInfoResult) {
return
}
+func (db *DB) getCutInfo(cart uint) (cuts []*CutListEntry, err error) {
+ var rows *sql.Rows
+ if rows, err = db.getCutInfoStmt.Query(cart); err != nil {
+ return
+ }
+ defer rows.Close()
+
+ for rows.Next() {
+ var cut = &CutListEntry{}
+ var cutName, evergreen string
+ var length uint
+
+ // if err = rows.Scan(&cutName, &evergreen, &cut.Description, &length, &cut.Imported, &cut.NumPlayed, &cut.LastPlayed); err != nil {
+ if err = rows.Scan(&cutName, &evergreen, &cut.Description, &length, &cut.NumPlayed); err != nil {
+ return
+ }
+
+ parts := strings.Split(cutName, "_")
+ if len(parts) == 2 {
+ if cn, converr := strconv.ParseUint(parts[1], 10, 32); converr != nil {
+ continue
+ } else {
+ cut.Number = uint(cn)
+ }
+ } else {
+ continue
+ }
+ switch evergreen {
+ case "Y":
+ cut.Evergreen = true
+ default:
+ cut.Evergreen = false
+ }
+ cut.Duration = time.Duration(length) * time.Millisecond
+
+ cuts = append(cuts, cut)
+ }
+ err = rows.Err()
+ return
+}
+
func (db *DB) getCartInfo(cart uint) (c *CartListEntry, err error) {
c = &CartListEntry{}
c.Number = cart
- c.Title = fmt.Sprintf("Title of Cart: %d", cart)
+ c.Exists = true
+ err = db.getCartInfoStmt.QueryRow(cart).Scan(&c.Title)
+ if err != nil {
+ if err == sql.ErrNoRows {
+ err = nil
+ c.Exists = false
+ }
+ return
+ }
+ if c.Cuts, err = db.getCutInfo(cart); err != nil {
+ return
+ }
return
}
@@ -350,7 +414,6 @@ func (db *DB) getShowList(username string) (result getShowListResult) {
}
result.err = rows.Err()
return
-
}
func (db *DB) dispatchRequests() {