This commit is contained in:
shoopea 2019-05-06 13:43:15 +08:00
parent bb511ec197
commit 1824dca693

25
sql.go
View File

@ -93,6 +93,7 @@ func initDB() {
obj_id BIGINT UNSIGNED NOT NULL
,msg_id BIGINT NOT NULL
,chat_id BIGINT NOT NULL
,user_id BIGINT NOT NULL
,sender_user_id BIGINT NOT NULL
,date TIMESTAMP NOT NULL
,text VARCHAR(4096) NOT NULL
@ -122,15 +123,15 @@ func initDB() {
failOnError(err, "initDB : populate table code_obj_type")
_, err = db.Exec(`INSERT INTO code_obj_sub_type (id, intl_id, name, obj_type_id)
VALUES (1, "unprocessed", "Unprocessed", 3)
,(2, "unknown", "Unknown", 3)
,(3, "report", "War report", 3)
,(4, "g_report", "Guild War report", 3)
,(5, "quest", "Quest result", 3)
,(6, "fight", "Fight result", 3)
,(7, "hero", "Hero summary", 3)
,(8, "me", "Hero short summary", 3)
,(9, "inv", "Inventory", 3);`)
VALUES (` + strconv.Itoa(objSubTypeMessageUnprocess) + `, "unprocessed", "Unprocessed", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageUnknown) + `, "unknown", "Unknown", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageReport) + `, "report", "War report", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageGReport) + `, "g_report", "Guild War report", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageQuest) + `, "quest", "Quest result", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageFight) + `, "fight", "Fight result", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageHero) + `, "hero", "Hero summary", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageMe) + `, "me", "Hero short summary", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageInventory) + `, "inv", "Inventory", ` + strconv.Itoa(objTypeMessage) + `);`)
failOnError(err, "initDB : populate table code_obj_sub_type")
log.Println("Database set up")
@ -148,14 +149,14 @@ func putUnprocessedMsg(m ChatWarsMessage) (int64, error) {
return 0, err
}
stmt, err := db.Prepare(`INSERT INTO obj_msg (obj_id, msg_id, chat_id, sender_user_id, date , text)
VALUES (?, ?, ?, ?, FROM_UNIXTIME(?), ?);`)
stmt, err := db.Prepare(`INSERT INTO obj_msg (obj_id, msg_id, chat_id, user_id, sender_user_id, date , text)
VALUES (?, ?, ?, ?, ?, FROM_UNIXTIME(?), ?);`)
if err != nil {
return 0, err
}
defer stmt.Close()
_, err = stmt.Exec(objId, m.ID64, m.ChatID64, m.SenderUserID64, m.Date, m.Text)
_, err = stmt.Exec(objId, m.ID64, m.ChatID64, m.UserID64, m.SenderUserID64, m.Date, m.Text)
if err != nil {
return 0, err
}