Skip to content

Commit

Permalink
box: introduce box_space_id_by_name
Browse files Browse the repository at this point in the history
Part of #3273.
  • Loading branch information
kshcherbatov committed May 31, 2018
1 parent ddf2fbf commit 95c32aa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/box/box.cc
Expand Up @@ -877,7 +877,7 @@ box_return_tuple(box_function_ctx_t *ctx, box_tuple_t *tuple)

/* schema_find_id()-like method using only public API */
uint32_t
box_space_id_by_name(const char *name, uint32_t len)
space_id_by_name(uint32_t system_space_id, const char *name, uint32_t len)
{
if (len > BOX_NAME_MAX)
return BOX_ID_NIL;
Expand All @@ -892,7 +892,7 @@ box_space_id_by_name(const char *name, uint32_t len)

/* NOTE: error and missing key cases are indistinguishable */
box_tuple_t *tuple;
if (box_index_get(BOX_VSPACE_ID, 2, begin, end, &tuple) != 0)
if (box_index_get(system_space_id, 2, begin, end, &tuple) != 0)
return BOX_ID_NIL;
if (tuple == NULL)
return BOX_ID_NIL;
Expand All @@ -901,6 +901,12 @@ box_space_id_by_name(const char *name, uint32_t len)
return result;
}

uint32_t
box_space_id_by_name(const char *name, uint32_t len)
{
return space_id_by_name(BOX_VSPACE_ID, name, len);
}

uint32_t
box_index_id_by_name(uint32_t space_id, const char *name, uint32_t len)
{
Expand Down
14 changes: 14 additions & 0 deletions src/box/box.h
Expand Up @@ -219,6 +219,20 @@ typedef struct box_function_ctx box_function_ctx_t;
API_EXPORT int
box_return_tuple(box_function_ctx_t *ctx, box_tuple_t *tuple);

/**
* Find space id by name in specified system space.
*
* This function performs SELECT request to _vspace system space.
* \param system_space_id space to lookup name.
* \param name space name
* \param len length of \a name
* \retval BOX_ID_NIL on error or if not found (check box_error_last())
* \retval space_id otherwise
* \sa box_index_id_by_name
*/
uint32_t
space_id_by_name(uint32_t system_space_id, const char *name, uint32_t len);

/**
* Find space id by name.
*
Expand Down

0 comments on commit 95c32aa

Please sign in to comment.