(row []interface{})
| 149 | } |
| 150 | |
| 151 | func (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 | |
| 197 | type WhereContext struct { |
| 198 | Where string |
no test coverage detected