* Validation function that ensures that the database/collections created in * documentdb_api are valid. */
| 1727 | * documentdb_api are valid. |
| 1728 | */ |
| 1729 | void |
| 1730 | ValidateDatabaseCollection(Datum databaseDatum, Datum collectionDatum) |
| 1731 | { |
| 1732 | text *databaseName = DatumGetTextP(databaseDatum); |
| 1733 | text *collectionName = DatumGetTextP(collectionDatum); |
| 1734 | |
| 1735 | StringView databaseView = { |
| 1736 | .length = VARSIZE_ANY_EXHDR(databaseName), .string = VARDATA_ANY(databaseName) |
| 1737 | }; |
| 1738 | StringView collectionView = { |
| 1739 | .length = VARSIZE_ANY_EXHDR(collectionName), .string = VARDATA_ANY(collectionName) |
| 1740 | }; |
| 1741 | |
| 1742 | if (databaseView.length >= MAX_DATABASE_NAME_LENGTH) |
| 1743 | { |
| 1744 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), |
| 1745 | errmsg("Database %.*s must be less than 64 characters", |
| 1746 | databaseView.length, databaseView.string))); |
| 1747 | } |
| 1748 | |
| 1749 | for (int i = 0; i < CharactersNotAllowedInDatabaseNamesLength; i++) |
| 1750 | { |
| 1751 | if (StringViewContains(&databaseView, CharactersNotAllowedInDatabaseNames[i])) |
| 1752 | { |
| 1753 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), |
| 1754 | errmsg("Database %.*s has an invalid character %c", |
| 1755 | databaseView.length, databaseView.string, |
| 1756 | CharactersNotAllowedInDatabaseNames[i]))); |
| 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | if (collectionView.string == NULL || collectionView.length == 0) |
| 1761 | { |
| 1762 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), |
| 1763 | errmsg("The specified namespace provided '%.*s.' is invalid.", |
| 1764 | databaseView.length, databaseView.string))); |
| 1765 | } |
| 1766 | |
| 1767 | if (StringViewStartsWith(&collectionView, '.')) |
| 1768 | { |
| 1769 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), |
| 1770 | errmsg( |
| 1771 | "Collection names must not begin with the '.' character: %.*s", |
| 1772 | collectionView.length, collectionView.string))); |
| 1773 | } |
| 1774 | |
| 1775 | for (int i = 0; i < CharactersNotAllowedInCollectionNamesLength; i++) |
| 1776 | { |
| 1777 | if (StringViewContains(&collectionView, CharactersNotAllowedInCollectionNames[i])) |
| 1778 | { |
| 1779 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), |
| 1780 | errmsg("Collection name provided is invalid: %.*s", |
| 1781 | collectionView.length, collectionView.string))); |
| 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | if (databaseView.length + collectionView.length + 1 > MaxDatabaseCollectionLength) |
| 1786 | { |
no test coverage detected