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

Method updateTable

engine/engine.go:171–215  ·  view source on GitHub ↗
(command *ast.UpdateCommand)

Source from the content-addressed store, hash-verified

169}
170
171func (engine *DbEngine) updateTable(command *ast.UpdateCommand) error {
172 table, exist := engine.Tables[command.Name.Token.Literal]
173
174 if !exist {
175 return &TableDoesNotExistError{command.Name.Token.Literal}
176 }
177
178 columns := table.Columns
179
180 // TODO: This could be optimized
181 mappedChanges := make(map[int]ast.Anonymitifier)
182 for updatedCol, newValue := range command.Changes {
183 for colIndex := 0; colIndex < len(columns); colIndex++ {
184 if columns[colIndex].Name == updatedCol.Literal {
185 mappedChanges[colIndex] = newValue
186 break
187 }
188 if colIndex == len(columns)-1 {
189 return &ColumnDoesNotExistError{tableName: command.Name.GetToken().Literal, columnName: updatedCol.Literal}
190 }
191 }
192 }
193
194 numberOfRows := len(columns[0].Values)
195 for rowIndex := 0; rowIndex < numberOfRows; rowIndex++ {
196 if command.HasWhereCommand() {
197 fulfilledFilters, err := isFulfillingFilters(getRow(table, rowIndex), command.WhereCommand.Expression, command.WhereCommand.Token.Literal)
198 if err != nil {
199 return err
200 }
201 if !fulfilledFilters {
202 continue
203 }
204 }
205 for colIndex, value := range mappedChanges {
206 interfaceValue, err := getInterfaceValue(value.GetToken())
207 if err != nil {
208 return err
209 }
210 table.Columns[colIndex].Values[rowIndex] = interfaceValue
211 }
212 }
213
214 return nil
215}
216
217// insertIntoTable - Insert row of values into the table
218func (engine *DbEngine) insertIntoTable(command *ast.InsertCommand) error {

Callers 1

EvaluateMethod · 0.95

Calls 5

isFulfillingFiltersFunction · 0.85
getRowFunction · 0.85
getInterfaceValueFunction · 0.85
GetTokenMethod · 0.65
HasWhereCommandMethod · 0.45

Tested by

no test coverage detected