getSelectResponse - Returns Select response basing on ast.OrderByCommand and ast.WhereCommand included in this Select
(selectCommand *ast.SelectCommand)
| 93 | |
| 94 | // getSelectResponse - Returns Select response basing on ast.OrderByCommand and ast.WhereCommand included in this Select |
| 95 | func (engine *DbEngine) getSelectResponse(selectCommand *ast.SelectCommand) (*Table, error) { |
| 96 | var table *Table |
| 97 | var err error |
| 98 | |
| 99 | if selectCommand.HasJoinCommand() { |
| 100 | joinCommand := selectCommand.JoinCommand |
| 101 | table, err = engine.joinTables(joinCommand, selectCommand.Name.Token.Literal) |
| 102 | if err != nil { |
| 103 | return nil, err |
| 104 | } |
| 105 | } else { |
| 106 | var exist bool |
| 107 | table, exist = engine.Tables[selectCommand.Name.Token.Literal] |
| 108 | |
| 109 | if !exist { |
| 110 | return nil, &TableDoesNotExistError{selectCommand.Name.Token.Literal} |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | if selectCommand.HasWhereCommand() { |
| 115 | whereCommand := selectCommand.WhereCommand |
| 116 | if selectCommand.HasOrderByCommand() { |
| 117 | orderByCommand := selectCommand.OrderByCommand |
| 118 | table, err = engine.selectFromTableWithWhereAndOrderBy(selectCommand, whereCommand, orderByCommand, table) |
| 119 | if err != nil { |
| 120 | return nil, err |
| 121 | } |
| 122 | } else { |
| 123 | table, err = engine.selectFromTableWithWhere(selectCommand, whereCommand, table) |
| 124 | if err != nil { |
| 125 | return nil, err |
| 126 | } |
| 127 | } |
| 128 | } else if selectCommand.HasOrderByCommand() { |
| 129 | table, err = engine.selectFromTableWithOrderBy(selectCommand, selectCommand.OrderByCommand, table) |
| 130 | if err != nil { |
| 131 | return nil, err |
| 132 | } |
| 133 | } else { |
| 134 | table, err = engine.selectFromProvidedTable(selectCommand, table) |
| 135 | if err != nil { |
| 136 | return nil, err |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | if selectCommand.HasLimitCommand() || selectCommand.HasOffsetCommand() { |
| 141 | table.applyOffsetAndLimit(selectCommand) |
| 142 | } |
| 143 | |
| 144 | if selectCommand.HasDistinct { |
| 145 | table = table.getDistinctTable() |
| 146 | } |
| 147 | |
| 148 | return table, nil |
| 149 | } |
| 150 | |
| 151 | // createTable - initialize new table in engine with specified name |
| 152 | func (engine *DbEngine) createTable(command *ast.CreateCommand) error { |