InCondition.go 648 B

1234567891011121314151617181920212223242526272829303132
  1. package DB
  2. import "TsDB2/DB/types"
  3. type InCondition struct {
  4. Field string
  5. Values []interface{}
  6. Type types.FieldType
  7. }
  8. func In(field string, values []interface{}, typ types.FieldType) Condition {
  9. return InCondition{Field: field, Values: values, Type: typ}
  10. }
  11. func (c InCondition) Fields() []string {
  12. return []string{c.Field}
  13. }
  14. func (c InCondition) Match(row []byte, table *Table) bool {
  15. fieldIdx := table.findFieldIndex(c.Field)
  16. if fieldIdx < 0 {
  17. return false
  18. }
  19. offset := table.calcFieldOffset(fieldIdx)
  20. for _, value := range c.Values {
  21. if table.compareValue(row, offset, c.Type, value) {
  22. return true
  23. }
  24. }
  25. return false
  26. }