* BuildResponseMessage returns a bson object that can be sent to the client * based on given FindAndModifyResult. */
| 622 | * based on given FindAndModifyResult. |
| 623 | */ |
| 624 | static pgbson * |
| 625 | BuildResponseMessage(FindAndModifyResult *result) |
| 626 | { |
| 627 | pgbson_writer lastErrorObjectWriter; |
| 628 | PgbsonWriterInit(&lastErrorObjectWriter); |
| 629 | |
| 630 | PgbsonWriterAppendInt32(&lastErrorObjectWriter, "n", strlen("n"), |
| 631 | result->lastErrorObject.n); |
| 632 | |
| 633 | if (result->isUpdateCommand) |
| 634 | { |
| 635 | PgbsonWriterAppendBool(&lastErrorObjectWriter, "updatedExisting", |
| 636 | strlen("updatedExisting"), |
| 637 | result->lastErrorObject.updatedExisting); |
| 638 | |
| 639 | if (result->lastErrorObject.upsertedObjectId != NULL) |
| 640 | { |
| 641 | pgbsonelement idElement; |
| 642 | PgbsonToSinglePgbsonElement(result->lastErrorObject.upsertedObjectId, |
| 643 | &idElement); |
| 644 | PgbsonWriterAppendValue(&lastErrorObjectWriter, "upserted", |
| 645 | strlen("upserted"), |
| 646 | &idElement.bsonValue); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | pgbson_writer resultWriter; |
| 651 | PgbsonWriterInit(&resultWriter); |
| 652 | |
| 653 | PgbsonWriterAppendDocument(&resultWriter, "lastErrorObject", |
| 654 | strlen("lastErrorObject"), |
| 655 | PgbsonWriterGetPgbson(&lastErrorObjectWriter)); |
| 656 | if (result->value == NULL) |
| 657 | { |
| 658 | PgbsonWriterAppendNull(&resultWriter, "value", strlen("value")); |
| 659 | } |
| 660 | else |
| 661 | { |
| 662 | PgbsonWriterAppendDocument(&resultWriter, "value", strlen("value"), |
| 663 | result->value); |
| 664 | } |
| 665 | |
| 666 | PgbsonWriterAppendDouble(&resultWriter, "ok", strlen("ok"), result->ok); |
| 667 | |
| 668 | return PgbsonWriterGetPgbson(&resultWriter); |
| 669 | } |
no test coverage detected