summaryrefslogtreecommitdiff
path: root/src
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)
commit377fe22c006a992a2b547bf5bab894161afb7ab6 (patch)
treeb0c0a47d8e5cc316e6f6ba8505757f5c9c75e246 /src
parenta39efd1c76e53cf7c09b899a9724c66fbcb01f00 (diff)
implemented DB version check
Diffstat (limited to 'src')
-rw-r--r--src/helsinki.at/rhimport/rddb.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/helsinki.at/rhimport/rddb.go b/src/helsinki.at/rhimport/rddb.go
index e945483..03553b9 100644
--- a/src/helsinki.at/rhimport/rddb.go
+++ b/src/helsinki.at/rhimport/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) {