subject.go 851 B

1234567891011121314151617181920212223242526272829
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/job/main/dm/model"
  6. "go-common/library/database/sql"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _selSubSQL = "SELECT id,oid,type,pid,mid,state,attr,acount,count,mcount,move_count,maxlimit,childpool,ctime,mtime FROM dm_subject_%02d WHERE oid=? AND type=?"
  11. )
  12. // Subject get subject info from db.
  13. func (d *Dao) Subject(c context.Context, tp int32, oid int64) (s *model.Subject, err error) {
  14. s = &model.Subject{}
  15. row := d.dmReader.QueryRow(c, fmt.Sprintf(_selSubSQL, d.hitSubject(oid)), oid, tp)
  16. if err = row.Scan(&s.ID, &s.Oid, &s.Type, &s.Pid, &s.Mid, &s.State, &s.Attr, &s.ACount, &s.Count, &s.MCount, &s.MoveCnt, &s.Maxlimit, &s.Childpool, &s.CTime, &s.MTime); err != nil {
  17. if err == sql.ErrNoRows {
  18. s = nil
  19. err = nil
  20. } else {
  21. log.Error("row.Scan() error(%v)", err)
  22. }
  23. }
  24. return
  25. }