* BuildResponseMessage builds the response BSON for an insert command. */
| 1443 | * BuildResponseMessage builds the response BSON for an insert command. |
| 1444 | */ |
| 1445 | static pgbson * |
| 1446 | BuildResponseMessage(BatchInsertionResult *batchResult) |
| 1447 | { |
| 1448 | pgbson_writer resultWriter; |
| 1449 | PgbsonWriterInit(&resultWriter); |
| 1450 | PgbsonWriterAppendInt32(&resultWriter, "n", 1, batchResult->rowsInserted); |
| 1451 | PgbsonWriterAppendDouble(&resultWriter, "ok", 2, batchResult->ok); |
| 1452 | |
| 1453 | if (batchResult->writeErrors != NIL) |
| 1454 | { |
| 1455 | pgbson_array_writer writeErrorsArrayWriter; |
| 1456 | PgbsonWriterStartArray(&resultWriter, "writeErrors", 11, &writeErrorsArrayWriter); |
| 1457 | |
| 1458 | ListCell *writeErrorCell = NULL; |
| 1459 | foreach(writeErrorCell, batchResult->writeErrors) |
| 1460 | { |
| 1461 | WriteError *writeError = lfirst(writeErrorCell); |
| 1462 | |
| 1463 | pgbson_writer writeErrorWriter; |
| 1464 | PgbsonArrayWriterStartDocument(&writeErrorsArrayWriter, &writeErrorWriter); |
| 1465 | PgbsonWriterAppendInt32(&writeErrorWriter, "index", 5, writeError->index); |
| 1466 | PgbsonWriterAppendInt32(&writeErrorWriter, "code", 4, writeError->code); |
| 1467 | PgbsonWriterAppendUtf8(&writeErrorWriter, "errmsg", 6, writeError->errmsg); |
| 1468 | PgbsonArrayWriterEndDocument(&writeErrorsArrayWriter, &writeErrorWriter); |
| 1469 | } |
| 1470 | |
| 1471 | PgbsonWriterEndArray(&resultWriter, &writeErrorsArrayWriter); |
| 1472 | } |
| 1473 | |
| 1474 | return PgbsonWriterGetPgbson(&resultWriter); |
| 1475 | } |
| 1476 | |
| 1477 | |
| 1478 | /* |
no test coverage detected