summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rddb/rddb.go30
1 files changed, 24 insertions, 6 deletions
diff --git a/rddb/rddb.go b/rddb/rddb.go
index f2a44a7..7937dce 100644
--- a/rddb/rddb.go
+++ b/rddb/rddb.go
@@ -412,6 +412,7 @@ type updateCutCartTitleRequest struct {
type db struct {
conf *config
+ readonly bool
dbh *sql.DB
passwordCache map[string]string
getPasswordChan chan getPasswordRequest
@@ -499,11 +500,14 @@ func (d *db) init() (err error) {
if d.getGroupDefaultTitleStmt, err = d.dbh.Prepare("select DEFAULT_TITLE from GROUPS where NAME = ?;"); err != nil {
return
}
- if d.updateCutTitleStmt, err = d.dbh.Prepare("update CUTS set DESCRIPTION = ? where CUT_NAME = ?;"); err != nil {
- return
- }
- if d.updateCartTitleMaybeStmt, err = d.dbh.Prepare("update CART set TITLE = ? where NUMBER = ? and TITLE = ?;"); err != nil {
- return
+
+ if !d.readonly {
+ if d.updateCutTitleStmt, err = d.dbh.Prepare("update CUTS set DESCRIPTION = ? where CUT_NAME = ?;"); err != nil {
+ return
+ }
+ if d.updateCartTitleMaybeStmt, err = d.dbh.Prepare("update CART set TITLE = ? where NUMBER = ? and TITLE = ?;"); err != nil {
+ return
+ }
}
return
@@ -838,6 +842,11 @@ func (d *db) getPoolCartList(pool PoolListEntry) (result getPoolCartListResult)
}
func (d *db) updateCutCartTitle(cart, cut uint, groupName, sourceFile string) (result updateCutCartTitleResult) {
+ if d.readonly {
+ result.err = fmt.Errorf("updating Cut/Cart title prohibited: read-only database connection")
+ return
+ }
+
path, filename := filepath.Split(sourceFile)
ext := strings.TrimLeft(filepath.Ext(filename), ".")
filename = strings.TrimRight(strings.TrimSuffix(filename, ext), ".")
@@ -1185,11 +1194,12 @@ func (d *db) Cleanup() {
}
-func NewDB(configfile string) (d *db, err error) {
+func newDB(configfile string, readonly bool) (d *db, err error) {
d = new(db)
if d.conf, err = newConfig(configfile); err != nil {
return
}
+ d.readonly = readonly
d.quit = make(chan bool)
d.done = make(chan bool)
d.passwordCache = make(map[string]string)
@@ -1213,3 +1223,11 @@ func NewDB(configfile string) (d *db, err error) {
go d.dispatchRequests()
return
}
+
+func NewDB(configfile string) (*db, error) {
+ return newDB(configfile, false)
+}
+
+func NewDBReadOnly(configfile string) (*db, error) {
+ return newDB(configfile, true)
+}