From 2a48617d23eb93890c17be87161787b998430c48 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 18 Feb 2016 18:00:02 +0100 Subject: fetching pool list works now diff --git a/rddb/rddb.go b/rddb/rddb.go index a645fa2..c889dff 100644 --- a/rddb/rddb.go +++ b/rddb/rddb.go @@ -178,6 +178,23 @@ type getJingleCutListRequest struct { response chan<- getJingleCutListResult } +type PoolListEntry struct { + Group string + Description string +} + +type PoolList map[string]PoolListEntry + +type getPoolListResult struct { + pools PoolList + err error +} + +type getPoolListRequest struct { + username string + response chan<- getPoolListResult +} + type DB struct { conf *config dbh *sql.DB @@ -200,6 +217,8 @@ type DB struct { getJingleListChan chan getJingleListRequest getJingleListStmt *sql.Stmt getJingleCutListChan chan getJingleCutListRequest + getPoolListChan chan getPoolListRequest + getPoolListStmt *sql.Stmt quit chan bool done chan bool } @@ -250,6 +269,9 @@ func (db *DB) init() (err error) { if db.getJingleListStmt, err = db.dbh.Prepare("select GROUPS.NAME,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where 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.getPoolListStmt, err = db.dbh.Prepare("select GROUPS.NAME,DROPBOXES.SET_USER_DEFINED,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where 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 } @@ -505,6 +527,30 @@ func (db *DB) getJingleCutList(jingle JingleListEntry) (result getJingleCutListR return } +func (db *DB) getPoolList(username string) (result getPoolListResult) { + var rows *sql.Rows + if rows, result.err = db.getPoolListStmt.Query(username, dropboxPseudoStation); result.err != nil { + return + } + defer rows.Close() + + result.pools = make(map[string]PoolListEntry) + for rows.Next() { + var pool PoolListEntry + var params string + + if result.err = rows.Scan(&pool.Group, ¶ms, &pool.Description); result.err != nil { + return + } + if params[0] != 'M' { + continue + } + result.pools[pool.Group] = pool + } + result.err = rows.Err() + return +} + func (db *DB) dispatchRequests() { defer func() { db.done <- true }() for { @@ -529,6 +575,8 @@ func (db *DB) dispatchRequests() { req.response <- db.getJingleList(req.username) case req := <-db.getJingleCutListChan: req.response <- db.getJingleCutList(req.jingle) + case req := <-db.getPoolListChan: + req.response <- db.getPoolList(req.username) } } } @@ -546,6 +594,7 @@ type DBChan struct { getShowCartListChan chan<- getShowCartListRequest getJingleListChan chan<- getJingleListRequest getJingleCutListChan chan<- getJingleCutListRequest + getPoolListChan chan<- getPoolListRequest } func (db *DBChan) GetPassword(username string, cached bool) (string, error) { @@ -699,6 +748,20 @@ func (db *DBChan) GetJingleCutList(jingle JingleListEntry) (CartListEntry, CartL return res.active, res.inactive, res.err } +func (db *DBChan) GetPoolList(username string) (PoolList, error) { + resCh := make(chan getPoolListResult) + req := getPoolListRequest{} + req.username = username + req.response = resCh + db.getPoolListChan <- req + + res := <-resCh + if res.err != nil { + return nil, res.err + } + return res.pools, nil +} + func (db *DB) GetInterface() *DBChan { ch := &DBChan{} ch.getPasswordChan = db.getPasswordChan @@ -710,6 +773,7 @@ func (db *DB) GetInterface() *DBChan { ch.getShowCartListChan = db.getShowCartListChan ch.getJingleListChan = db.getJingleListChan ch.getJingleCutListChan = db.getJingleCutListChan + ch.getPoolListChan = db.getPoolListChan return ch } @@ -749,6 +813,9 @@ func (db *DB) Cleanup() { if db.getJingleListStmt != nil { db.getJingleListStmt.Close() } + if db.getPoolListStmt != nil { + db.getPoolListStmt.Close() + } } func NewDB(configfile string) (db *DB, err error) { @@ -768,6 +835,7 @@ func NewDB(configfile string) (db *DB, err error) { db.getShowCartListChan = make(chan getShowCartListRequest, 10) db.getJingleListChan = make(chan getJingleListRequest, 10) db.getJingleCutListChan = make(chan getJingleCutListRequest, 10) + db.getPoolListChan = make(chan getPoolListRequest, 10) if err = db.init(); err != nil { return -- cgit v0.10.2