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

Function command_validate

pg_documentdb/src/commands/validate.c:86–195  ·  view source on GitHub ↗

* command_validate is the implementation of the internal logic for * 'validate' database diagnostic command. */

Source from the content-addressed store, hash-verified

84 * 'validate' database diagnostic command.
85 */
86Datum
87command_validate(PG_FUNCTION_ARGS)
88{
89 ValidateSpec validateSpec = { 0 };
90
91 if (PG_ARGISNULL(1))
92 {
93 ereport(ERROR, (errmsg("The provided namespace value is not valid.")));
94 }
95
96 pgbson *validationBsonSpec = PG_GETARG_PGBSON(1);
97 Datum databaseNameDatum = PG_ARGISNULL(0) ? (Datum) 0 : PG_GETARG_DATUM(0);
98
99 bson_iter_t validateIter;
100 PgbsonInitIterator(validationBsonSpec, &validateIter);
101
102 while (bson_iter_next(&validateIter))
103 {
104 StringView keyView = bson_iter_key_string_view(&validateIter);
105 const bson_value_t *value = bson_iter_value(&validateIter);
106
107 if (StringViewEqualsCString(&keyView, "validate"))
108 {
109 if (bson_iter_type(&validateIter) == BSON_TYPE_DOCUMENT)
110 {
111 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE),
112 errmsg(
113 "Collection name contains an invalid object type")));
114 }
115 EnsureTopLevelFieldType("validate", &validateIter, BSON_TYPE_UTF8);
116 validateSpec.collectionName = value->value.v_utf8.str;
117 }
118 else if (StringViewEqualsCString(&keyView, "$db"))
119 {
120 ValidateOrExtractDatabaseNameFromSpec(&validateIter, &databaseNameDatum);
121 }
122 else if (StringViewEqualsCString(&keyView, "full"))
123 {
124 validateSpec.full = BsonValueAsBool(value);
125 }
126 else if (StringViewEqualsCString(&keyView, "repair"))
127 {
128 validateSpec.repair = BsonValueAsBool(value);
129 }
130 else if (StringViewEqualsCString(&keyView, "metadata"))
131 {
132 validateSpec.metadata = BsonValueAsBool(value);
133 }
134 }
135
136 if (databaseNameDatum == (Datum) 0)
137 {
138 ereport(ERROR, (errmsg("Database name must not be NULL")));
139 }
140 validateSpec.databaseName = TextDatumGetCString(databaseNameDatum);
141
142 if (validateSpec.collectionName == NULL || strlen(validateSpec.collectionName) == 0)
143 {

Callers

nothing calls this directly

Calls 10

PgbsonInitIteratorFunction · 0.85
StringViewEqualsCStringFunction · 0.85
EnsureTopLevelFieldTypeFunction · 0.85
BsonValueAsBoolFunction · 0.85
ReportFeatureUsageFunction · 0.85
validateCollectionFunction · 0.85
BuildResponseMessageFunction · 0.70

Tested by

no test coverage detected