* BuildResponseMessage builds the response BSON for a delete command. */
| 1864 | * BuildResponseMessage builds the response BSON for a delete command. |
| 1865 | */ |
| 1866 | static pgbson * |
| 1867 | BuildResponseMessage(BatchDeletionResult *batchResult) |
| 1868 | { |
| 1869 | pgbson_writer resultWriter; |
| 1870 | PgbsonWriterInit(&resultWriter); |
| 1871 | PgbsonWriterAppendInt32(&resultWriter, "n", 1, batchResult->rowsDeleted); |
| 1872 | PgbsonWriterAppendDouble(&resultWriter, "ok", 2, batchResult->ok); |
| 1873 | |
| 1874 | if (batchResult->writeErrors != NIL) |
| 1875 | { |
| 1876 | pgbson_array_writer writeErrorsArrayWriter; |
| 1877 | PgbsonWriterStartArray(&resultWriter, "writeErrors", 11, &writeErrorsArrayWriter); |
| 1878 | |
| 1879 | ListCell *writeErrorCell = NULL; |
| 1880 | foreach(writeErrorCell, batchResult->writeErrors) |
| 1881 | { |
| 1882 | WriteError *writeError = lfirst(writeErrorCell); |
| 1883 | |
| 1884 | pgbson_writer writeErrorWriter; |
| 1885 | PgbsonArrayWriterStartDocument(&writeErrorsArrayWriter, &writeErrorWriter); |
| 1886 | PgbsonWriterAppendInt32(&writeErrorWriter, "index", 5, writeError->index); |
| 1887 | PgbsonWriterAppendInt32(&writeErrorWriter, "code", 4, writeError->code); |
| 1888 | PgbsonWriterAppendUtf8(&writeErrorWriter, "errmsg", 6, writeError->errmsg); |
| 1889 | PgbsonArrayWriterEndDocument(&writeErrorsArrayWriter, &writeErrorWriter); |
| 1890 | } |
| 1891 | |
| 1892 | PgbsonWriterEndArray(&resultWriter, &writeErrorsArrayWriter); |
| 1893 | } |
| 1894 | |
| 1895 | return PgbsonWriterGetPgbson(&resultWriter); |
| 1896 | } |
no test coverage detected