fill in null columns with empty strings

This commit is contained in:
Ted Unangst 2020-09-02 16:31:02 -04:00
parent 3702ab34ef
commit 333006817e
2 changed files with 15 additions and 4 deletions

View File

@ -880,7 +880,7 @@ func preparetodie(db *sql.DB, s string) *sql.Stmt {
func prepareStatements(db *sql.DB) {
stmtHonkers = preparetodie(db, "select honkerid, userid, name, xid, flavor, combos, meta from honkers where userid = ? and (flavor = 'presub' or flavor = 'sub' or flavor = 'peep' or flavor = 'unsub') order by name")
stmtSaveHonker = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos, owner, meta) values (?, ?, ?, ?, ?, ?, ?)")
stmtSaveHonker = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos, owner, meta, folxid) values (?, ?, ?, ?, ?, ?, ?, '')")
stmtUpdateFlavor = preparetodie(db, "update honkers set flavor = ? where userid = ? and xid = ? and name = ? and flavor = ?")
stmtUpdateHonker = preparetodie(db, "update honkers set name = ?, combos = ?, meta = ? where honkerid = ? and userid = ?")
stmtOneHonker = preparetodie(db, "select xid from honkers where name = ? and userid = ?")
@ -927,7 +927,7 @@ func prepareStatements(db *sql.DB) {
stmtFindFile = preparetodie(db, "select fileid, xid from filemeta where url = ? and local = 1")
stmtUserByName = preparetodie(db, "select userid, username, displayname, about, pubkey, seckey, options from users where username = ? and userid > 0")
stmtUserByNumber = preparetodie(db, "select userid, username, displayname, about, pubkey, seckey, options from users where userid = ?")
stmtSaveDub = preparetodie(db, "insert into honkers (userid, name, xid, flavor) values (?, ?, ?, ?)")
stmtSaveDub = preparetodie(db, "insert into honkers (userid, name, xid, flavor, combos, owner, meta, folxid) values (?, ?, ?, ?, '', '', '', '')")
stmtAddDoover = preparetodie(db, "insert into doovers (dt, tries, userid, rcpt, msg) values (?, ?, ?, ?, ?)")
stmtGetDoovers = preparetodie(db, "select dooverid, dt from doovers")
stmtLoadDoover = preparetodie(db, "select tries, userid, rcpt, msg from doovers where dooverid = ?")

View File

@ -23,9 +23,13 @@ import (
"time"
)
var myVersion = 37
var myVersion = 38
func doordie(db *sql.DB, s string, args ...interface{}) {
type dbexecer interface {
Exec(query string, args ...interface{}) (sql.Result, error)
}
func doordie(db dbexecer, s string, args ...interface{}) {
_, err := db.Exec(s, args...)
if err != nil {
log.Fatalf("can't run %s: %s", s, err)
@ -153,6 +157,13 @@ func upgradedb() {
doordie(db, "update config set value = 37 where key = 'dbversion'")
fallthrough
case 37:
doordie(db, "update honkers set combos = '' where combos is null")
doordie(db, "update honkers set owner = '' where owner is null")
doordie(db, "update honkers set meta = '' where meta is null")
doordie(db, "update honkers set folxid = '' where folxid is null")
doordie(db, "update config set value = 38 where key = 'dbversion'")
fallthrough
case 38:
default:
log.Fatalf("can't upgrade unknown version %d", dbversion)