summaryrefslogtreecommitdiff
path: root/rddb
diff options
context:
space:
mode:
Diffstat (limited to 'rddb')
-rw-r--r--rddb/rddb.go95
1 files changed, 66 insertions, 29 deletions
diff --git a/rddb/rddb.go b/rddb/rddb.go
index 6b78009..6c59578 100644
--- a/rddb/rddb.go
+++ b/rddb/rddb.go
@@ -44,6 +44,7 @@ var (
const (
DB_VERSION = 250
dropboxPseudoStation = "import-dropbox"
+ defaultCartTitle = "[new cart]"
)
type getPasswordResult struct {
@@ -221,34 +222,37 @@ type updateCutCartTitleRequest struct {
}
type DB struct {
- conf *config
- dbh *sql.DB
- passwordCache 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
- getMusicInfoChan chan getMusicInfoRequest
- getMusicInfoStmt *sql.Stmt
- getShowListChan chan getShowListRequest
- getShowListStmt *sql.Stmt
- getShowCartListChan chan getShowCartListRequest
- getCartInfoStmt *sql.Stmt
- getCutInfoStmt *sql.Stmt
- getJingleListChan chan getJingleListRequest
- getJingleListStmt *sql.Stmt
- getJingleCutListChan chan getJingleCutListRequest
- getPoolListChan chan getPoolListRequest
- getPoolListStmt *sql.Stmt
- getPoolCartListChan chan getPoolCartListRequest
- getPoolCartsStmt *sql.Stmt
- updateCutCartTitleChan chan updateCutCartTitleRequest
- quit chan bool
- done chan bool
+ conf *config
+ dbh *sql.DB
+ passwordCache 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
+ getMusicInfoChan chan getMusicInfoRequest
+ getMusicInfoStmt *sql.Stmt
+ getShowListChan chan getShowListRequest
+ getShowListStmt *sql.Stmt
+ getShowCartListChan chan getShowCartListRequest
+ getCartInfoStmt *sql.Stmt
+ getCutInfoStmt *sql.Stmt
+ getJingleListChan chan getJingleListRequest
+ getJingleListStmt *sql.Stmt
+ getJingleCutListChan chan getJingleCutListRequest
+ getPoolListChan chan getPoolListRequest
+ getPoolListStmt *sql.Stmt
+ getPoolCartListChan chan getPoolCartListRequest
+ getPoolCartsStmt *sql.Stmt
+ updateCutCartTitleChan chan updateCutCartTitleRequest
+ getGroupDefaultTitleStmt *sql.Stmt
+ updateCutTitleStmt *sql.Stmt
+ updateCartTitleMaybeStmt *sql.Stmt
+ quit chan bool
+ done chan bool
}
func (db *DB) init() (err error) {
@@ -303,6 +307,15 @@ func (db *DB) init() (err error) {
if db.getPoolCartsStmt, err = db.dbh.Prepare("select CART.NUMBER,CART.ARTIST,CART.TITLE,CART.ALBUM,CUTS.CUT_NAME,CUTS.EVERGREEN,CUTS.DESCRIPTION,CUTS.LENGTH,CUTS.ORIGIN_DATETIME,CUTS.PLAY_COUNTER,CUTS.LAST_PLAY_DATETIME from CUTS,CART where CUTS.CART_NUMBER = CART.NUMBER and CART.GROUP_NAME = ?;"); err != nil {
return
}
+ if db.getGroupDefaultTitleStmt, err = db.dbh.Prepare("select DEFAULT_TITLE from GROUPS where NAME = ?;"); err != nil {
+ return
+ }
+ if db.updateCutTitleStmt, err = db.dbh.Prepare("update CUTS set DESCRIPTION = ? where CUT_NAME = ?;"); err != nil {
+ return
+ }
+ if db.updateCartTitleMaybeStmt, err = db.dbh.Prepare("update CART set TITLE = ? where NUMBER = ? and TITLE = ?;"); err != nil {
+ return
+ }
return
}
@@ -637,7 +650,21 @@ func (db *DB) updateCutCartTitle(cart, cut uint, groupName, sourceFile string) (
ext := strings.TrimLeft(filepath.Ext(filename), ".")
filename = strings.TrimRight(strings.TrimSuffix(filename, ext), ".")
- result.err = fmt.Errorf(" new CUT/CART/GROUP (%d/%d/%s) Title: %%p -> '%s', %%f -> '%s', %%e -> '%s'", cart, cut, groupName, path, filename, ext)
+ groupDefaultTitle := ""
+ result.err = db.getGroupDefaultTitleStmt.QueryRow(groupName).Scan(&groupDefaultTitle)
+ if result.err != nil {
+ return
+ }
+
+ r := strings.NewReplacer("%p", path, "%f", filename, "%e", ext)
+ title := r.Replace(groupDefaultTitle)
+
+ if _, result.err = db.updateCutTitleStmt.Exec(title, fmt.Sprintf("%06d_%03d", cart, cut)); result.err != nil {
+ return
+ }
+ if _, result.err = db.updateCartTitleMaybeStmt.Exec(title, cart, defaultCartTitle); result.err != nil {
+ return
+ }
return
}
@@ -945,6 +972,16 @@ func (db *DB) Cleanup() {
if db.getPoolCartsStmt != nil {
db.getPoolCartsStmt.Close()
}
+ if db.getGroupDefaultTitleStmt != nil {
+ db.getGroupDefaultTitleStmt.Close()
+ }
+ if db.updateCutTitleStmt != nil {
+ db.updateCutTitleStmt.Close()
+ }
+ if db.updateCartTitleMaybeStmt != nil {
+ db.updateCartTitleMaybeStmt.Close()
+ }
+
}
func NewDB(configfile string) (db *DB, err error) {