(columns []*Column, wantedColumnNames *[]string, tableName string)
| 12 | } |
| 13 | |
| 14 | func extractColumnContent(columns []*Column, wantedColumnNames *[]string, tableName string) (*Table, error) { |
| 15 | selectedTable := &Table{Columns: make([]*Column, 0)} |
| 16 | mappedIndexes := make([]int, 0) |
| 17 | for wantedColumnIndex := range *wantedColumnNames { |
| 18 | for columnNameIndex := range columns { |
| 19 | if columns[columnNameIndex].Name == (*wantedColumnNames)[wantedColumnIndex] { |
| 20 | mappedIndexes = append(mappedIndexes, columnNameIndex) |
| 21 | break |
| 22 | } |
| 23 | if columnNameIndex == len(columns)-1 { |
| 24 | return nil, &ColumnDoesNotExistError{columnName: (*wantedColumnNames)[wantedColumnIndex], tableName: tableName} |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | for i := range mappedIndexes { |
| 30 | selectedTable.Columns = append(selectedTable.Columns, &Column{ |
| 31 | Name: columns[mappedIndexes[i]].Name, |
| 32 | Type: columns[mappedIndexes[i]].Type, |
| 33 | Values: make([]ValueInterface, 0), |
| 34 | }) |
| 35 | } |
| 36 | if len(columns) == 0 { |
| 37 | return selectedTable, nil |
| 38 | } |
| 39 | |
| 40 | rowsCount := len(columns[0].Values) |
| 41 | |
| 42 | for iRow := 0; iRow < rowsCount; iRow++ { |
| 43 | for iColumn := 0; iColumn < len(mappedIndexes); iColumn++ { |
| 44 | selectedTable.Columns[iColumn].Values = |
| 45 | append(selectedTable.Columns[iColumn].Values, columns[mappedIndexes[iColumn]].Values[iRow]) |
| 46 | } |
| 47 | } |
| 48 | return selectedTable, nil |
| 49 | } |
no outgoing calls
no test coverage detected