summaryrefslogtreecommitdiff
path: root/src/helsinki.at/rhimport/rddb.go
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-13 04:02:43 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-13 04:02:43 (GMT)
commite9ffae4f5f6858a3736136009aff87cb9369a4c1 (patch)
treeed1bf33d5e1336e08ae6381c6e30da95af01383c /src/helsinki.at/rhimport/rddb.go
parent60666c71b666026697f7cfd3e92607e6dc4df67c (diff)
music pool group check works now
Diffstat (limited to 'src/helsinki.at/rhimport/rddb.go')
-rw-r--r--src/helsinki.at/rhimport/rddb.go61
1 files changed, 49 insertions, 12 deletions
diff --git a/src/helsinki.at/rhimport/rddb.go b/src/helsinki.at/rhimport/rddb.go
index 85a3177..52d6e18 100644
--- a/src/helsinki.at/rhimport/rddb.go
+++ b/src/helsinki.at/rhimport/rddb.go
@@ -62,17 +62,29 @@ type getShowInfoRequest struct {
response chan getShowInfoResult
}
+type checkMusicGroupResult struct {
+ ismusic bool
+ err error
+}
+
+type checkMusicGroupRequest struct {
+ group string
+ response chan checkMusicGroupResult
+}
+
type RdDb struct {
- dbh *sql.DB
- password_cache map[string]string
- getPasswordChan chan getPasswordRequest
- getPasswordStmt *sql.Stmt
- getGroupOfCartChan chan getGroupOfCartRequest
- getGroupOfCartStmt *sql.Stmt
- getShowInfoChan chan getShowInfoRequest
- getShowInfoStmt *sql.Stmt
- quit chan bool
- done chan bool
+ dbh *sql.DB
+ password_cache map[string]string
+ getPasswordChan chan getPasswordRequest
+ getPasswordStmt *sql.Stmt
+ getGroupOfCartChan chan getGroupOfCartRequest
+ getGroupOfCartStmt *sql.Stmt
+ getShowInfoChan chan getShowInfoRequest
+ getShowInfoStmt *sql.Stmt
+ checkMusicGroupChan chan checkMusicGroupRequest
+ checkMusicGroupStmt *sql.Stmt
+ quit chan bool
+ done chan bool
}
func (self *RdDb) init(conf *Config) (err error) {
@@ -89,6 +101,9 @@ func (self *RdDb) init(conf *Config) (err error) {
if self.getShowInfoStmt, err = self.dbh.Prepare("select TITLE,MACROS from CART where NUMBER = ?;"); err != nil {
return
}
+ if self.checkMusicGroupStmt, err = self.dbh.Prepare("select count(*) from DROPBOXES where GROUP_NAME = ? and SET_USER_DEFINED like \"M;%\";"); err != nil {
+ return
+ }
return
}
@@ -152,11 +167,25 @@ func (self *RdDb) getShowInfo(showid int) (title string, carts map[int]int, err
}
rhdl.Printf("RdDb: macros for showid '%d' are set to '%s'", showid, macros)
- // TODO: also fetch cart list
+ // TODO: also fetch cart list and import params (norm_level, ...)
carts = make(map[int]int)
return
}
+func (self *RdDb) checkMusicGroup(group string) (ismusic bool, err error) {
+ var cnt int
+ err = self.checkMusicGroupStmt.QueryRow(group).Scan(&cnt)
+ if err != nil {
+ if err == sql.ErrNoRows {
+ err = nil
+ ismusic = false
+ }
+ return
+ }
+ ismusic = cnt > 0
+ return
+}
+
func (self *RdDb) dispatchRequests() {
defer func() { self.done <- true }()
for {
@@ -179,6 +208,10 @@ func (self *RdDb) dispatchRequests() {
rhdl.Println("RdDb: got getShowInfo request for", req.showid)
title, carts, err := self.getShowInfo(req.showid)
req.response <- getShowInfoResult{title, carts, err}
+ case req := <-self.checkMusicGroupChan:
+ rhdl.Println("RdDb: got checkMusicGroup request for", req.group)
+ ismusic, err := self.checkMusicGroup(req.group)
+ req.response <- checkMusicGroupResult{ismusic, err}
}
}
}
@@ -199,7 +232,10 @@ func (self *RdDb) Cleanup() {
self.getGroupOfCartStmt.Close()
}
if self.getShowInfoStmt != nil {
- self.getPasswordStmt.Close()
+ self.getShowInfoStmt.Close()
+ }
+ if self.checkMusicGroupStmt != nil {
+ self.checkMusicGroupStmt.Close()
}
}
@@ -212,6 +248,7 @@ func NewRdDb(conf *Config) (db *RdDb, err error) {
db.getPasswordChan = make(chan getPasswordRequest)
db.getGroupOfCartChan = make(chan getGroupOfCartRequest)
db.getShowInfoChan = make(chan getShowInfoRequest)
+ db.checkMusicGroupChan = make(chan checkMusicGroupRequest)
if err = db.init(conf); err != nil {
return