MCPcopy Create free account
hub / github.com/actiontech/dtle / WhereTrue

Method WhereTrue

driver/common/tabletypes.go:151–195  ·  view source on GitHub ↗
(row []interface{})

Source from the content-addressed store, hash-verified

149}
150
151func (t *TableContext) WhereTrue(row []interface{}) (bool, error) {
152 var m = make(map[string]interface{})
153 for field, idx := range t.WhereCtx.FieldsMap {
154 nCols := len(row)
155 if idx >= nCols {
156 return false, fmt.Errorf("cannot eval 'where' predicate: no enough columns (%v < %v). table %v.%v",
157 nCols, idx, t.Table.TableSchema, t.Table.TableName)
158 }
159
160 //fmt.Printf("**** type of %v %T\n", field, *values.ValuesPointers[idx])
161 rawValue := row[idx]
162 var value interface{}
163 if rawValue == nil {
164 value = rawValue
165 } else {
166 switch t.Table.OriginalTableColumns.ColumnList()[idx].Type {
167 case mysqlconfig.TextColumnType:
168 bs, ok := rawValue.([]byte)
169 if !ok {
170 return false,
171 fmt.Errorf("where_predicate. expect []byte for TextColumnType, but got %T. table %v.%v",
172 rawValue, t.Table.TableSchema, t.Table.TableName)
173 }
174 value = string(bs)
175 default:
176 value = rawValue
177 }
178 }
179
180 m[field] = value
181 }
182 ctx := datasource.NewContextSimpleNative(m)
183 val, ok := vm.Eval(ctx, t.WhereCtx.Ast)
184 if !ok {
185 return false, fmt.Errorf("cannot eval 'where' predicate with the row value. %v.%v %v",
186 t.Table.TableSchema, t.Table.TableName, t.WhereCtx.Where)
187 }
188 r, ok := val.Value().(bool)
189 if !ok {
190 return false, fmt.Errorf("'where' predicate does not eval to bool. %v.%v %v",
191 t.Table.TableSchema, t.Table.TableName, t.WhereCtx.Where)
192 }
193
194 return r, nil
195}
196
197type WhereContext struct {
198 Where string

Callers 1

handleRowsEventMethod · 0.80

Calls 1

ColumnListMethod · 0.80

Tested by

no test coverage detected