summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-12-13 23:54:44 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2015-12-13 23:54:44 (GMT)
commit7c58b88bd5cdfc667b8e5d30733e4eb7ce1a02c6 (patch)
treef91462f52614751bc4e8fd32f3ee58c40753aacb
parentc870bfae31ac530488b5a97498b21825de6f7faa (diff)
implemented DB version check
-rw-r--r--rddb.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/rddb.go b/rddb.go
index e945483..03553b9 100644
--- a/rddb.go
+++ b/rddb.go
@@ -36,6 +36,10 @@ var (
showMacroRe = regexp.MustCompile(`^LL 1 ([^ ]+) 0\!$`)
)
+const (
+ DB_VERSION = 245
+)
+
type getPasswordResult struct {
password string
err error
@@ -96,11 +100,21 @@ type RdDb struct {
}
func (self *RdDb) init(conf *Config) (err error) {
- dsn := fmt.Sprintf("%s:%s@tcp(%s:3306)/%s", conf.db_user, conf.db_passwd, conf.db_host, conf.db_db)
+ dsn := fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8", conf.db_user, conf.db_passwd, conf.db_host, conf.db_db)
if self.dbh, err = sql.Open("mysql", dsn); err != nil {
return
}
- //TODO: check if we have a compatible DB version
+
+ var dbver int
+ err = self.dbh.QueryRow("select DB from VERSION;").Scan(&dbver)
+ if err != nil {
+ err = fmt.Errorf("fetching version: %s", err)
+ return
+ }
+ if dbver != DB_VERSION {
+ err = fmt.Errorf("version mismatch is %d, should be %d", dbver, DB_VERSION)
+ return
+ }
if self.getPasswordStmt, err = self.dbh.Prepare("select PASSWORD from USERS where LOGIN_NAME = ?;"); err != nil {
return
@@ -167,7 +181,7 @@ func (self *RdDb) getGroupOfCart(cart uint) (group string, err error) {
}
func (self *RdDb) getLogTableName(log string) string {
- return strings.Replace(log, " ", "_", -1) + "_LOG" // TODO: this should get escaped fir mySQL but golang doesn't support it!!!
+ return strings.Replace(log, " ", "_", -1) + "_LOG" // TODO: this should get escaped for mySQL but golang doesn't support it!!!
}
func (self *RdDb) getShowCarts(log string, low_cart, high_cart int) (carts []int, err error) {