insertIntoTable - Insert row of values into the table
(command *ast.InsertCommand)
| 216 | |
| 217 | // insertIntoTable - Insert row of values into the table |
| 218 | func (engine *DbEngine) insertIntoTable(command *ast.InsertCommand) error { |
| 219 | table, exist := engine.Tables[command.Name.Token.Literal] |
| 220 | if !exist { |
| 221 | return &TableDoesNotExistError{command.Name.Token.Literal} |
| 222 | } |
| 223 | |
| 224 | columns := table.Columns |
| 225 | |
| 226 | if len(command.Values) != len(columns) { |
| 227 | return &InvalidNumberOfParametersError{expectedNumber: len(columns), actualNumber: len(command.Values), commandName: command.Token.Literal} |
| 228 | } |
| 229 | |
| 230 | for i := range columns { |
| 231 | expectedToken := tokenMapper(columns[i].Type.Type) |
| 232 | if (expectedToken != command.Values[i].Type) && (command.Values[i].Type != token.NULL) { |
| 233 | return &InvalidValueTypeError{expectedType: string(expectedToken), actualType: string(command.Values[i].Type), commandName: command.Token.Literal} |
| 234 | } |
| 235 | interfaceValue, err := getInterfaceValue(command.Values[i]) |
| 236 | if err != nil { |
| 237 | return err |
| 238 | } |
| 239 | columns[i].Values = append(columns[i].Values, interfaceValue) |
| 240 | } |
| 241 | return nil |
| 242 | } |
| 243 | |
| 244 | func (engine *DbEngine) selectFromProvidedTable(command *ast.SelectCommand, table *Table) (*Table, error) { |
| 245 | columns := table.Columns |
no test coverage detected