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

Function ModifyViewDefinition

pg_documentdb/src/commands/coll_mod.c:1020–1064  ·  view source on GitHub ↗

* Updates the view definition of an existing collection view * With the new view definition provided. * Validates the view definition and ensures it is valid first. * If it is, replaces the view definition in the target collection. */

Source from the content-addressed store, hash-verified

1018 * If it is, replaces the view definition in the target collection.
1019 */
1020static void
1021ModifyViewDefinition(Datum databaseDatum,
1022 const MongoCollection *collection,
1023 const ViewDefinition *viewDefinition,
1024 pgbson_writer *writer)
1025{
1026 if (collection->viewDefinition == NULL)
1027 {
1028 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDOPTIONS),
1029 errmsg("ns %s.%s is a collection, not a view",
1030 collection->name.databaseName,
1031 collection->name.collectionName)));
1032 }
1033
1034 if (viewDefinition->viewSource != NULL &&
1035 viewDefinition->pipeline.value_type == BSON_TYPE_EOD)
1036 {
1037 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDOPTIONS),
1038 errmsg(
1039 "Both 'viewOn' and 'pipeline' must be specified when altering a view while authorization is active")));
1040 }
1041
1042 ValidateViewDefinition(
1043 databaseDatum, collection->name.collectionName, viewDefinition);
1044
1045 /* View definition is valid, now update */
1046 pgbson *viewDefBson = CreateViewDefinition(viewDefinition);
1047
1048 StringInfo query = makeStringInfo();
1049 appendStringInfo(query, "UPDATE %s.collections "
1050 " set view_definition = $3 WHERE database_name = $1 AND collection_name = $2",
1051 ApiCatalogSchemaName);
1052
1053 Oid argsTypes[3] = { TEXTOID, TEXTOID, BsonTypeId() };
1054 Datum argValues[3] = {
1055 databaseDatum, CStringGetTextDatum(collection->name.collectionName),
1056 PointerGetDatum(viewDefBson)
1057 };
1058
1059 int nargs = 3;
1060 char *argNulls = NULL;
1061 bool isNullIgnore = false;
1062 RunQueryWithCommutativeWrites(query->data, nargs, argsTypes, argValues, argNulls,
1063 SPI_OK_UPDATE, &isNullIgnore);
1064}
1065
1066
1067static bool

Callers 1

command_coll_modFunction · 0.85

Calls 4

ValidateViewDefinitionFunction · 0.85
CreateViewDefinitionFunction · 0.85
BsonTypeIdFunction · 0.85

Tested by

no test coverage detected