diff --git a/src/processor.go b/src/processor.go index e550cf9..6f3d763 100644 --- a/src/processor.go +++ b/src/processor.go @@ -22,59 +22,54 @@ func (p LineProcessor) ProcessLine(s string) string { } stmt, _ := sqlparser.Parse(s) + insert := stmt.(*sqlparser.Insert) - switch stmt := stmt.(type) { - case *sqlparser.Insert: + table := insert.Table.Name.String() - table := stmt.Table.Name.String() + processor := p.Config.ProcessTable(table) - processor := p.Config.ProcessTable(table) - - switch processor { - case "": - // This table doesn't need to be processed - return s - case "table": - // "Classic" processing - rows := stmt.Rows.(sqlparser.Values) - for _, vt := range rows { - for i, e := range vt { - column := stmt.Columns[i].String() + switch processor { + case "": + // This table doesn't need to be processed + return s + case "table": + // "Classic" processing + rows := insert.Rows.(sqlparser.Values) + for _, vt := range rows { + for i, e := range vt { + column := insert.Columns[i].String() - result, dataType := p.Config.ProcessColumn(table, column) + result, dataType := p.Config.ProcessColumn(table, column) - if !result { - continue - } + if !result { + continue + } - e.(*sqlparser.SQLVal).Val = []byte(p.Provider.Get(dataType)) + e.(*sqlparser.SQLVal).Val = []byte(p.Provider.Get(dataType)) - } } - return sqlparser.String(stmt) + ";\n" - case "eav": - // EAV processing - var attributeId string - rows := stmt.Rows.(sqlparser.Values) - for _, vt := range rows { - for i, e := range vt { - column := stmt.Columns[i].String() - if column == "attribute_id" { - switch v := e.(type) { - case *sqlparser.SQLVal: - switch v.Type { - default: - attributeId = string(v.Val) - } + } + return sqlparser.String(insert) + ";\n" + case "eav": + // EAV processing + var attributeId string + rows := insert.Rows.(sqlparser.Values) + for _, vt := range rows { + for i, e := range vt { + column := insert.Columns[i].String() + if column == "attribute_id" { + switch v := e.(type) { + case *sqlparser.SQLVal: + switch v.Type { + default: + attributeId = string(v.Val) } } } } - - return "FOOO" + attributeId + "\n" - default: - return s } + + return "FOOO" + attributeId + "\n" default: return s }