func getUpdateColumns(t table.Table, assignList []expression.Assignment, isMultipleTable bool, tblAliasMap map[string]string) ([]*column.Col, []expression.Assignment, error) { // TODO: We should check the validate if assignList in somewhere else. Maybe in building plan. // TODO: We should use field.GetFieldIndex to replace this function. tcols := make([]*column.Col, 0, len(assignList)) tAsgns := make([]expression.Assignment, 0, len(assignList)) tname := t.TableName() for _, asgn := range assignList { if isMultipleTable { if tblAliasMap != nil { if alias, ok := tblAliasMap[asgn.TableName]; ok { if !strings.EqualFold(tname.O, alias) { continue } } } else if !strings.EqualFold(tname.O, asgn.TableName) { continue } } col := column.FindCol(t.Cols(), asgn.ColName) if col == nil { if isMultipleTable { continue } return nil, nil, errors.Errorf("UPDATE: unknown column %s", asgn.ColName) } tcols = append(tcols, col) tAsgns = append(tAsgns, asgn) } return tcols, tAsgns, nil }
func findColumnByName(t table.Table, name string) (*column.Col, error) { _, tableName, colName := field.SplitQualifiedName(name) if len(tableName) > 0 && tableName != t.TableName().O { return nil, errors.Errorf("unknown field %s.%s", tableName, colName) } c := column.FindCol(t.Cols(), colName) if c == nil { return nil, errors.Errorf("unknown field %s", colName) } return c, nil }
func (e *UpdateExec) getTableOffset(t table.Table) int { fields := e.SelectExec.Fields() i := 0 for i < len(fields) { field := fields[i] if field.Table.Name.L == t.TableName().L { return i } i += len(field.Table.Columns) } return 0 }
func getUpdateColumns(t table.Table, assignList []expressions.Assignment, multipleTable bool) ([]*column.Col, error) { // TODO: We should check the validate if assignList in somewhere else. Maybe in building plan. tcols := make([]*column.Col, 0, len(assignList)) tname := t.TableName() for _, asgn := range assignList { if multipleTable { if !strings.EqualFold(tname.O, asgn.TableName) { continue } } col := column.FindCol(t.Cols(), asgn.ColName) if col == nil { if multipleTable { continue } return nil, errors.Errorf("UPDATE: unknown column %s", asgn.ColName) } tcols = append(tcols, col) } return tcols, nil }