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

Function UpsertSchemaValidation

pg_documentdb/src/metadata/collection.c:1844–1902  ·  view source on GitHub ↗

* Updates the schema validation information of an existing collection */

Source from the content-addressed store, hash-verified

1842 * Updates the schema validation information of an existing collection
1843 */
1844void
1845UpsertSchemaValidation(Datum databaseDatum,
1846 Datum collectionNameDatum,
1847 const bson_value_t *validator, char *validationLevel,
1848 char *validationAction)
1849{
1850 StringInfo query = makeStringInfo();
1851 appendStringInfo(query, "UPDATE %s.collections set ", ApiCatalogSchemaName);
1852
1853 Oid argsTypes[5] = { TEXTOID, TEXTOID };
1854 Datum argValues[5] = {
1855 databaseDatum, collectionNameDatum
1856 };
1857
1858 int nargs = 2;
1859 char argNulls[5] = { ' ', ' ', 'n', 'n', 'n' };
1860 bool isNullIgnore = false;
1861
1862 bool isFirst = true;
1863
1864 /* todo: add spec validation for validator, like unsupported keywrods, etc. */
1865 if (validator != NULL && validator->value_type != BSON_TYPE_EOD)
1866 {
1867 appendStringInfo(query, "validator = $%d ", ++nargs);
1868 argNulls[nargs - 1] = ' ';
1869 argsTypes[nargs - 1] = BsonTypeId();
1870 argValues[nargs - 1] = PointerGetDatum(PgbsonInitFromDocumentBsonValue(
1871 validator));
1872 isFirst = false;
1873 }
1874 if (!isFirst && validationLevel != NULL)
1875 {
1876 appendStringInfo(query, ", ");
1877 }
1878 if (validationLevel != NULL)
1879 {
1880 appendStringInfo(query, "validation_level = $%d ", ++nargs);
1881 argNulls[nargs - 1] = ' ';
1882 argsTypes[nargs - 1] = TEXTOID;
1883 argValues[nargs - 1] = CStringGetTextDatum(validationLevel);
1884 isFirst = false;
1885 }
1886 if (!isFirst && validationAction != NULL)
1887 {
1888 appendStringInfo(query, ", ");
1889 }
1890 if (validationAction != NULL)
1891 {
1892 appendStringInfo(query, "validation_action = $%d ", ++nargs);
1893 argNulls[nargs - 1] = ' ';
1894 argsTypes[nargs - 1] = TEXTOID;
1895 argValues[nargs - 1] = CStringGetTextDatum(validationAction);
1896 }
1897
1898 appendStringInfo(query, "WHERE database_name = $1 AND collection_name = $2");
1899
1900 RunQueryWithCommutativeWrites(query->data, nargs, argsTypes, argValues, argNulls,
1901 SPI_OK_UPDATE, &isNullIgnore);

Callers 2

command_coll_modFunction · 0.85

Calls 3

BsonTypeIdFunction · 0.85

Tested by

no test coverage detected