* CreateCollection is a C wrapper around create_collection. It returns * whether a new collection was created (in case of a race, another * transaction may have created it). */
| 1611 | * transaction may have created it). |
| 1612 | */ |
| 1613 | bool |
| 1614 | CreateCollection(Datum dbNameDatum, Datum collectionNameDatum) |
| 1615 | { |
| 1616 | char *collectionNameStr = TextDatumGetCString(collectionNameDatum); |
| 1617 | if (collectionNameStr != NULL && strlen(collectionNameStr) == 0) |
| 1618 | { |
| 1619 | ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INVALIDNAMESPACE), |
| 1620 | errmsg("An invalid and empty namespace has been specified"))); |
| 1621 | } |
| 1622 | |
| 1623 | const char *cmdStr = FormatSqlQuery("SELECT %s.create_collection($1, $2)", |
| 1624 | ApiSchemaName); |
| 1625 | |
| 1626 | Oid argTypes[CREATE_COLLECTION_FUNC_NARGS] = { TEXTOID, TEXTOID }; |
| 1627 | Datum argValues[CREATE_COLLECTION_FUNC_NARGS] = { |
| 1628 | dbNameDatum, |
| 1629 | collectionNameDatum, |
| 1630 | }; |
| 1631 | |
| 1632 | /* all args are non-null */ |
| 1633 | char *argNulls = NULL; |
| 1634 | |
| 1635 | bool isNull = true; |
| 1636 | bool readOnly = false; |
| 1637 | Datum resultDatum = ExtensionExecuteQueryWithArgsViaSPI(cmdStr, |
| 1638 | CREATE_COLLECTION_FUNC_NARGS, |
| 1639 | argTypes, argValues, argNulls, |
| 1640 | readOnly, SPI_OK_SELECT, |
| 1641 | &isNull); |
| 1642 | if (isNull) |
| 1643 | { |
| 1644 | ereport(ERROR, (errmsg("create_collection unexpectedly " |
| 1645 | "returned NULL datum"))); |
| 1646 | } |
| 1647 | |
| 1648 | return DatumGetBool(resultDatum); |
| 1649 | } |
| 1650 | |
| 1651 | |
| 1652 | /* |
no test coverage detected