fix obj name

This commit is contained in:
shoopea 2020-04-18 21:09:26 +08:00
parent dadc20279b
commit aa34353a9e

22
obj.go
View File

@ -265,12 +265,28 @@ func setObjSubTypeId(objId int64, objSubTypeID64 int64) error {
} }
func objAddName(objID64 int64, name string) error { func objAddName(objID64 int64, name string) error {
stmt, err := db.Prepare(`INSERT INTO obj_name (obj_id, name, priority) var priority int64
SELECT ? obj_id, ? name, (SELECT count(*) FROM obj_name WHERE obj_id = ?) priority FROM DUAL;`)
_, err = stmt.Exec(objID64, name, objID64) stmt, err := db.Prepare(`SELECT COUNT(*) FROM obj_name on WHERE on.obj_id = ?`)
if err != nil {
return err
}
defer stmt.Close() defer stmt.Close()
err = stmt.QueryRow(objID64).Scan(&priority)
if err != nil {
return err
}
stmt2, err := db.Prepare(`INSERT INTO obj_name (obj_id, name, priority)
VALUES (?, ?, ?);`)
if err != nil {
return err
}
defer stmt2.Close()
_, err = stmt2.Exec(objID64, name, priority)
return err return err
} }