Navigation Menu

Skip to content

Commit

Permalink
Add grn_ctx_get_all_types()
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 19, 2015
1 parent 106b564 commit d895f22
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/groonga/groonga.h
Expand Up @@ -441,6 +441,7 @@ GRN_API grn_rc grn_ctx_use(grn_ctx *ctx, grn_obj *db);
GRN_API grn_obj *grn_ctx_db(grn_ctx *ctx);
GRN_API grn_obj *grn_ctx_get(grn_ctx *ctx, const char *name, int name_size);
GRN_API grn_rc grn_ctx_get_all_tables(grn_ctx *ctx, grn_obj *tables_buffer);
GRN_API grn_rc grn_ctx_get_all_types(grn_ctx *ctx, grn_obj *types_buffer);

typedef enum {
GRN_DB_VOID = 0,
Expand Down
40 changes: 40 additions & 0 deletions lib/db.c
Expand Up @@ -13426,3 +13426,43 @@ grn_ctx_get_all_tables(grn_ctx *ctx, grn_obj *tables_buffer)

GRN_API_RETURN(ctx->rc);
}

grn_rc
grn_ctx_get_all_types(grn_ctx *ctx, grn_obj *types_buffer)
{
grn_obj *db;
grn_table_cursor *cursor;
grn_id id;

GRN_API_ENTER;

db = ctx->impl->db;
if (!db) {
ERR(GRN_INVALID_ARGUMENT, "DB isn't associated");
GRN_API_RETURN(ctx->rc);
}

cursor = grn_table_cursor_open(ctx, db, NULL, 0, NULL, 0, 0, -1, 0);
if (!cursor) {
GRN_API_RETURN(ctx->rc);
}

while ((id = grn_table_cursor_next(ctx, cursor)) != GRN_ID_NIL) {
grn_obj *object;

if ((object = grn_ctx_at(ctx, id))) {
if (grn_obj_is_type(ctx, object)) {
GRN_PTR_PUT(ctx, types_buffer, object);
} else {
grn_obj_unlink(ctx, object);
}
} else {
if (ctx->rc != GRN_SUCCESS) {
ERRCLR(ctx);
}
}
}
grn_table_cursor_close(ctx, cursor);

GRN_API_RETURN(ctx->rc);
}

0 comments on commit d895f22

Please sign in to comment.