MCPcopy Create free account
hub / github.com/documentdb/documentdb / FormatBsonValueForShellLogging

Function FormatBsonValueForShellLogging

pg_documentdb_core/src/io/pgbson.c:363–437  ·  view source on GitHub ↗

* Gets the prefix for bson values of BSON for constructing messages * */

Source from the content-addressed store, hash-verified

361 *
362 */
363const char *
364FormatBsonValueForShellLogging(const bson_value_t *bson)
365{
366 StringInfo str = makeStringInfo();
367 switch (bson->value_type)
368 {
369 case BSON_TYPE_INT32:
370 {
371 appendStringInfo(str, "(%s)%d", "NumberInt", bson->value.v_int32);
372 break;
373 }
374
375 case BSON_TYPE_INT64:
376 {
377 /*
378 * Cast value to "long long int" and use "%lld" to handle different word
379 * sizes in different architectures.
380 */
381 appendStringInfo(str, "(%s)%lld", "NumberLong",
382 (long long int) bson->value.v_int64);
383 break;
384 }
385
386 case BSON_TYPE_DOUBLE:
387 {
388 appendStringInfo(str, "%.1lf", bson->value.v_double);
389 break;
390 }
391
392 case BSON_TYPE_DECIMAL128:
393 {
394 ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
395 errmsg("Decimal 128 operations are currently unsupported")));
396 }
397
398 case BSON_TYPE_DOCUMENT:
399 {
400 bson_iter_t iter;
401 BsonValueInitIterator(bson, &iter);
402 appendStringInfoString(str, "{ ");
403 const char *separator = NULL;
404 while (bson_iter_next(&iter))
405 {
406 const char *key = bson_iter_key(&iter);
407 const bson_value_t *bsonValue = bson_iter_value(&iter);
408
409 if (separator != NULL)
410 {
411 appendStringInfoString(str, separator);
412 }
413
414 const char *bsonValStr = FormatBsonValueForShellLogging(bsonValue);
415 appendStringInfo(str, "%s: %s", key, bsonValStr);
416 separator = ", ";
417 }
418
419 appendStringInfoString(str, " }");
420 break;

Callers 3

PostValidateArrayFiltersFunction · 0.85
HandleUpdateDollarIncFunction · 0.85
HandleUpdateDollarMulFunction · 0.85

Calls 1

BsonValueInitIteratorFunction · 0.85

Tested by

no test coverage detected