Evaluate - it takes sequences, map them to specific implementation and then process it in SQL engine
(sequences *ast.Sequence)
| 25 | |
| 26 | // Evaluate - it takes sequences, map them to specific implementation and then process it in SQL engine |
| 27 | func (engine *DbEngine) Evaluate(sequences *ast.Sequence) (string, error) { |
| 28 | commands := sequences.Commands |
| 29 | |
| 30 | result := "" |
| 31 | for _, command := range commands { |
| 32 | |
| 33 | switch mappedCommand := command.(type) { |
| 34 | case *ast.WhereCommand: |
| 35 | continue |
| 36 | case *ast.OrderByCommand: |
| 37 | continue |
| 38 | case *ast.LimitCommand: |
| 39 | continue |
| 40 | case *ast.OffsetCommand: |
| 41 | continue |
| 42 | case *ast.JoinCommand: |
| 43 | continue |
| 44 | case *ast.CreateCommand: |
| 45 | err := engine.createTable(mappedCommand) |
| 46 | if err != nil { |
| 47 | return "", err |
| 48 | } |
| 49 | result += "Table '" + mappedCommand.Name.GetToken().Literal + "' has been created\n" |
| 50 | continue |
| 51 | case *ast.InsertCommand: |
| 52 | err := engine.insertIntoTable(mappedCommand) |
| 53 | if err != nil { |
| 54 | return "", err |
| 55 | } |
| 56 | result += "Data Inserted\n" |
| 57 | continue |
| 58 | case *ast.SelectCommand: |
| 59 | selectOutput, err := engine.getSelectResponse(mappedCommand) |
| 60 | if err != nil { |
| 61 | return "", err |
| 62 | } |
| 63 | result += selectOutput.ToString() + "\n" |
| 64 | continue |
| 65 | case *ast.DeleteCommand: |
| 66 | deleteCommand := command.(*ast.DeleteCommand) |
| 67 | if deleteCommand.HasWhereCommand() { |
| 68 | err := engine.deleteFromTable(mappedCommand, deleteCommand.WhereCommand) |
| 69 | if err != nil { |
| 70 | return "", err |
| 71 | } |
| 72 | } |
| 73 | result += "Data from '" + mappedCommand.Name.GetToken().Literal + "' has been deleted\n" |
| 74 | continue |
| 75 | case *ast.DropCommand: |
| 76 | engine.dropTable(mappedCommand) |
| 77 | result += "Table: '" + mappedCommand.Name.GetToken().Literal + "' has been dropped\n" |
| 78 | continue |
| 79 | case *ast.UpdateCommand: |
| 80 | err := engine.updateTable(mappedCommand) |
| 81 | if err != nil { |
| 82 | return "", err |
| 83 | } |
| 84 | result += "Table: '" + mappedCommand.Name.GetToken().Literal + "' has been updated\n" |