diff options
-rw-r--r-- | src/helsinki.at/rhimport/rddb.go | 20 |
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) { |