|
7 | 7 | "io" |
8 | 8 | "os" |
9 | 9 | "sort" |
| 10 | + "strconv" |
10 | 11 | "time" |
11 | 12 |
|
12 | 13 | "github.com/QuickBase/quickbase-cli/qbclient" |
@@ -128,6 +129,7 @@ type ImportOptions struct { |
128 | 129 | func Import(qb *qbclient.Client, opts *ImportOptions) (*qbclient.InsertRecordsOutputMetadata, error) { |
129 | 130 | metadata := &qbclient.InsertRecordsOutputMetadata{ |
130 | 131 | CreatedRecordIDs: []int{}, |
| 132 | + LineErrors: map[string][]string{}, |
131 | 133 | TotalNumberOfRecordsProcessed: 0, |
132 | 134 | UnchangedRecordIDs: []int{}, |
133 | 135 | UpdatedRecordIDs: []int{}, |
@@ -247,13 +249,32 @@ func Import(qb *qbclient.Client, opts *ImportOptions) (*qbclient.InsertRecordsOu |
247 | 249 | } |
248 | 250 |
|
249 | 251 | // Empty the records for the next batch. |
| 252 | + rlen := len(records) |
250 | 253 | records = []map[int]*qbclient.InsertRecordsInputData{} |
251 | 254 |
|
252 | 255 | metadata.CreatedRecordIDs = append(metadata.CreatedRecordIDs, iro.Metadata.CreatedRecordIDs...) |
253 | 256 | metadata.TotalNumberOfRecordsProcessed += iro.Metadata.TotalNumberOfRecordsProcessed |
254 | 257 | metadata.UnchangedRecordIDs = append(metadata.UnchangedRecordIDs, iro.Metadata.UnchangedRecordIDs...) |
255 | 258 | metadata.UpdatedRecordIDs = append(metadata.UpdatedRecordIDs, iro.Metadata.UpdatedRecordIDs...) |
256 | 259 |
|
| 260 | + // Merging the line errors isn't so simple. |
| 261 | + for k, v := range iro.Metadata.LineErrors { |
| 262 | + n, err := strconv.Atoi(k) |
| 263 | + if err != nil { |
| 264 | + return metadata, fmt.Errorf("%s: expecting lineErrors key to be an integer", k) |
| 265 | + } |
| 266 | + |
| 267 | + // This works no matter the batch size, but I have no idea why |
| 268 | + // we have to subtract 1 from n when eof is true. If this is |
| 269 | + // buggy, blame [email protected]. |
| 270 | + n = line - rlen + n |
| 271 | + if eof { |
| 272 | + n-- |
| 273 | + } |
| 274 | + |
| 275 | + metadata.LineErrors[strconv.Itoa(n)] = v |
| 276 | + } |
| 277 | + |
257 | 278 | // Delay before the next API call. |
258 | 279 | if opts.Delay > 0 && !eof { |
259 | 280 | time.Sleep(time.Duration(opts.Delay) * time.Millisecond) |
|
0 commit comments