func checkMetadataForInsert(m gregor.Metadata) error { if m.MsgID() == nil { return fmt.Errorf("bad metadata; nil MsgID") } if m.UID() == nil { return fmt.Errorf("bad metadata: nil UID") } return nil }
func (s *SQLEngine) consumeInBandMessageMetadata(tx *sql.Tx, md gregor.Metadata, t gregor.InBandMsgType) (gregor.Metadata, error) { if err := checkMetadataForInsert(md); err != nil { return nil, err } if t != gregor.InBandMsgTypeUpdate && t != gregor.InBandMsgTypeSync { return nil, fmt.Errorf("bad metadata: unrecognized msg type") } qb := s.newQueryBuilder() qb.Build("INSERT INTO gregor_messages(uid, msgid, mtype, devid, ctime) VALUES(?, ?, ?, ?,", hexEnc(md.UID()), hexEnc(md.MsgID()), int(t), hexEncOrNull(md.DeviceID())) if md.CTime().IsZero() { qb.Now() } else { qb.AddTime(md.CTime()) } qb.Build(")") if err := qb.Exec(tx); err != nil { return nil, err } if !md.CTime().IsZero() { return md, nil } // get the inserted ctime ctime, err := s.ctimeFromMessage(tx, md.UID(), md.MsgID()) if err != nil { return nil, err } return s.objFactory.MakeMetadata(md.UID(), md.MsgID(), md.DeviceID(), ctime, md.InBandMsgType()) }