diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-01-29 22:01:38 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-01-29 22:01:38 (GMT) |
commit | 780cfc0c66303ac301b88502a0f15723b3e92e98 (patch) | |
tree | 7e65e30b3798fc374999c8d39d0bb01831824b15 /rddb | |
parent | eb1a8f480dfe94e934e207f17843e9f3370af6fb (diff) |
added getShowList command
Diffstat (limited to 'rddb')
-rw-r--r-- | rddb/rddb.go | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/rddb/rddb.go b/rddb/rddb.go index 74cef83..29a87af 100644 --- a/rddb/rddb.go +++ b/rddb/rddb.go @@ -39,7 +39,8 @@ var ( ) const ( - DB_VERSION = 245 + DB_VERSION = 245 + dropboxPseudoStation = "import-dropbox" ) type getPasswordResult struct { @@ -98,6 +99,22 @@ type getMusicInfoRequest struct { response chan<- getMusicInfoResult } +type ShowListEntry struct { + ID uint + Title string + Carts []uint +} + +type getShowListResult struct { + shows []ShowListEntry + err error +} + +type getShowListRequest struct { + username string + response chan<- getShowListResult +} + type DB struct { conf *config dbh *sql.DB @@ -112,6 +129,8 @@ type DB struct { checkMusicGroupStmt *sql.Stmt getMusicInfoChan chan getMusicInfoRequest getMusicInfoStmt *sql.Stmt + getShowListChan chan getShowListRequest + getShowListStmt *sql.Stmt quit chan bool done chan bool } @@ -150,6 +169,10 @@ func (db *DB) init() (err error) { if db.getMusicInfoStmt, err = db.dbh.Prepare("select NORMALIZATION_LEVEL,AUTOTRIM_LEVEL from DROPBOXES where DROPBOXES.GROUP_NAME = ?;"); err != nil { return } + 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 + } + return } @@ -271,6 +294,31 @@ func (db *DB) getMusicInfo(group string) (result getMusicInfoResult) { return } +func (db *DB) getShowList(username string) (result getShowListResult) { + var rows *sql.Rows + if rows, result.err = db.getShowListStmt.Query(username, dropboxPseudoStation); result.err != nil { + return + } + defer rows.Close() + + for rows.Next() { + var show ShowListEntry + var macros, params, desc string + var lowCart, highCart int + + if result.err = rows.Scan(&show.Title, ¯os, &show.ID, ¶ms, &lowCart, &highCart, &desc); result.err != nil { + return + } + + show.Carts, result.err = db.getShowCarts(showMacroRe.FindStringSubmatch(macros)[1], lowCart, highCart) + + result.shows = append(result.shows, show) + } + result.err = rows.Err() + return + +} + func (db *DB) dispatchRequests() { defer func() { db.done <- true }() for { @@ -287,6 +335,8 @@ func (db *DB) dispatchRequests() { req.response <- db.checkMusicGroup(req.group) case req := <-db.getMusicInfoChan: req.response <- db.getMusicInfo(req.group) + case req := <-db.getShowListChan: + req.response <- db.getShowList(req.username) } } } @@ -300,6 +350,7 @@ type DBChan struct { getShowInfoChan chan<- getShowInfoRequest checkMusicGroupChan chan<- checkMusicGroupRequest getMusicInfoChan chan<- getMusicInfoRequest + getShowListChan chan<- getShowListRequest } func (db *DBChan) GetPassword(username string, cached bool) (string, error) { @@ -400,6 +451,20 @@ func (db *DBChan) GetMusicInfo(groupname string) (int, int, error) { return res.normLvl, res.trimLvl, nil } +func (db *DBChan) GetShowList(username string) ([]ShowListEntry, error) { + resCh := make(chan getShowListResult) + req := getShowListRequest{} + req.username = username + req.response = resCh + db.getShowListChan <- req + + res := <-resCh + if res.err != nil { + return nil, res.err + } + return res.shows, nil +} + func (db *DB) GetInterface() *DBChan { ch := &DBChan{} ch.getPasswordChan = db.getPasswordChan @@ -407,6 +472,7 @@ func (db *DB) GetInterface() *DBChan { ch.getShowInfoChan = db.getShowInfoChan ch.checkMusicGroupChan = db.checkMusicGroupChan ch.getMusicInfoChan = db.getMusicInfoChan + ch.getShowListChan = db.getShowListChan return ch } @@ -434,6 +500,9 @@ func (db *DB) Cleanup() { if db.getMusicInfoStmt != nil { db.getMusicInfoStmt.Close() } + if db.getShowListStmt != nil { + db.getShowListStmt.Close() + } } func NewDB(configfile string) (db *DB, err error) { @@ -449,6 +518,7 @@ func NewDB(configfile string) (db *DB, err error) { db.getShowInfoChan = make(chan getShowInfoRequest, 10) db.checkMusicGroupChan = make(chan checkMusicGroupRequest, 10) db.getMusicInfoChan = make(chan getMusicInfoRequest, 10) + db.getShowListChan = make(chan getShowListRequest, 10) if err = db.init(); err != nil { return |