* BuildInsertionList iterates over an array of documents in an insert spec and * returns a list of pgbson documents to insert. */
| 462 | * returns a list of pgbson documents to insert. |
| 463 | */ |
| 464 | static List * |
| 465 | BuildInsertionList(bson_iter_t *insertArrayIter, bool *hasSkippedDocuments) |
| 466 | { |
| 467 | List *documents = NIL; |
| 468 | *hasSkippedDocuments = false; |
| 469 | |
| 470 | while (bson_iter_next(insertArrayIter)) |
| 471 | { |
| 472 | StringInfo fieldNameStr = makeStringInfo(); |
| 473 | int arrIdx = list_length(documents); |
| 474 | appendStringInfo(fieldNameStr, "insert.documents.%d", arrIdx); |
| 475 | |
| 476 | EnsureTopLevelFieldType(fieldNameStr->data, insertArrayIter, BSON_TYPE_DOCUMENT); |
| 477 | const bson_value_t *docValue = bson_iter_value(insertArrayIter); |
| 478 | if (ValidateAndCheckShouldInsertDocument(docValue)) |
| 479 | { |
| 480 | bson_value_t *clonedValue = palloc(sizeof(bson_value_t)); |
| 481 | *clonedValue = *docValue; |
| 482 | documents = lappend(documents, clonedValue); |
| 483 | } |
| 484 | else |
| 485 | { |
| 486 | *hasSkippedDocuments = true; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | return documents; |
| 491 | } |
| 492 | |
| 493 | |
| 494 | /* |
no test coverage detected