MCPcopy Index your code
hub / github.com/LissaGreense/GO4SQL / insertIntoTable

Method insertIntoTable

engine/engine.go:218–242  ·  view source on GitHub ↗

insertIntoTable - Insert row of values into the table

(command *ast.InsertCommand)

Source from the content-addressed store, hash-verified

216
217// insertIntoTable - Insert row of values into the table
218func (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
244func (engine *DbEngine) selectFromProvidedTable(command *ast.SelectCommand, table *Table) (*Table, error) {
245 columns := table.Columns

Callers 1

EvaluateMethod · 0.95

Calls 2

tokenMapperFunction · 0.85
getInterfaceValueFunction · 0.85

Tested by

no test coverage detected