incomplete
This commit is contained in:
parent
06671ae72c
commit
226f56126d
57
sql.go
57
sql.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
@ -108,10 +109,10 @@ func initDB() {
|
|||||||
,attack SMALLINT UNSIGNED NOT NULL
|
,attack SMALLINT UNSIGNED NOT NULL
|
||||||
,defense SMALLINT UNSIGNED NOT NULL
|
,defense SMALLINT UNSIGNED NOT NULL
|
||||||
,gold SMALLINT UNSIGNED NOT NULL
|
,gold SMALLINT UNSIGNED NOT NULL
|
||||||
,stock SMALLINT UNSIGNED NOT NULL
|
,stock MALLINT UNSIGNED NOT NULL
|
||||||
,exp SMALLINT UNSIGNED NOT NULL
|
,exp SMALLINT UNSIGNED NOT NULL
|
||||||
,stamina BOOLEAN NOT NULL
|
,stamina TINYINT NOT NULL
|
||||||
,crit BOOLEAN NOT NULL
|
,crit TINYINT NOT NULL
|
||||||
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
||||||
) ENGINE = InnoDB CHARSET=utf8 COLLATE utf8_unicode_ci;`)
|
) ENGINE = InnoDB CHARSET=utf8 COLLATE utf8_unicode_ci;`)
|
||||||
failOnError(err, "initDB : create table obj_msg_report")
|
failOnError(err, "initDB : create table obj_msg_report")
|
||||||
@ -180,3 +181,53 @@ func getMsg(objId int64) (ChatWarsMessage, error) {
|
|||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getObjSubTypeId(objId int64) (int64, error) {
|
||||||
|
var objSubTypeId int64
|
||||||
|
stmt, err := db.Prepare(`SELECT o.sub_type_id FROM obj o WHERE o.id = ?`)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
defer stmt.Close()
|
||||||
|
|
||||||
|
err = stmt.QueryRow(1).Scan(&objSubTypeId)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return objSubTypeId, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func insertMsgReport(objId int64, war_date int32, atk int32, def int32, exp int32, gold int32, stock int32, crit bool, stamina bool) error {
|
||||||
|
objSubTypeId, err := getObjSubTypeId(objId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if objSubTypeId != objSubTypeMessageUnprocess {
|
||||||
|
return errors.New("Message is not of type Unknown")
|
||||||
|
}
|
||||||
|
|
||||||
|
obj_id BIGINT UNSIGNED NOT NULL
|
||||||
|
,war_date TIMESTAMP NOT NULL
|
||||||
|
,attack SMALLINT UNSIGNED NOT NULL
|
||||||
|
,defense SMALLINT UNSIGNED NOT NULL
|
||||||
|
,gold SMALLINT UNSIGNED NOT NULL
|
||||||
|
,stock MALLINT UNSIGNED NOT NULL
|
||||||
|
,exp SMALLINT UNSIGNED NOT NULL
|
||||||
|
,stamina TINYINT NOT NULL
|
||||||
|
,crit TINYINT NOT NULL
|
||||||
|
|
||||||
|
stmt, err := db.Prepare(`INSERT INTO obj_msg_report (obj_id, war_date, attack, defense, gold, stock, exp, stamina, crit)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?FROM_UNIXTIME(?), ?);`)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer stmt.Close()
|
||||||
|
|
||||||
|
_, err = stmt.Exec(objId, m.ID64, m.ChatID64, m.UserID64, m.SenderUserID64, m.Date, m.Text)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user