Skip to content

Commit

Permalink
Extract table columns inspection code
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jun 19, 2013
1 parent 3c1a47f commit c081f89
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions lib/util.c
Expand Up @@ -521,9 +521,35 @@ grn_table_key_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj)
}

static grn_rc
grn_table_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj)
grn_table_columns_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj)
{
grn_hash *cols;

GRN_TEXT_PUTS(ctx, buf, "columns:[");
if ((cols = grn_hash_create(ctx, NULL, sizeof(grn_id), 0,
GRN_OBJ_TABLE_HASH_KEY|GRN_HASH_TINY))) {
if (grn_table_columns(ctx, obj, "", 0, (grn_obj *)cols)) {
int i = 0;
grn_id *key;
GRN_HASH_EACH(ctx, cols, id, &key, NULL, NULL, {
grn_obj *col = grn_ctx_at(ctx, *key);
if (col) {
if (i++ > 0) { GRN_TEXT_PUTS(ctx, buf, ", "); }
grn_column_name_(ctx, col, buf);
grn_obj_unlink(ctx, col);
}
});
}
grn_hash_close(ctx, cols);
}
GRN_TEXT_PUTS(ctx, buf, "]");

return GRN_SUCCESS;
}

static grn_rc
grn_table_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj)
{
grn_id range_id;
grn_obj *range;

Expand Down Expand Up @@ -552,24 +578,8 @@ grn_table_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj)
GRN_TEXT_PUTS(ctx, buf, " size:");
grn_text_lltoa(ctx, buf, grn_table_size(ctx, obj));

GRN_TEXT_PUTS(ctx, buf, " columns:[");
if ((cols = grn_hash_create(ctx, NULL, sizeof(grn_id), 0,
GRN_OBJ_TABLE_HASH_KEY|GRN_HASH_TINY))) {
if (grn_table_columns(ctx, obj, "", 0, (grn_obj *)cols)) {
int i = 0;
grn_id *key;
GRN_HASH_EACH(ctx, cols, id, &key, NULL, NULL, {
grn_obj *col = grn_ctx_at(ctx, *key);
if (col) {
if (i++ > 0) { GRN_TEXT_PUTS(ctx, buf, ", "); }
grn_column_name_(ctx, col, buf);
grn_obj_unlink(ctx, col);
}
});
}
grn_hash_close(ctx, cols);
}
GRN_TEXT_PUTS(ctx, buf, "]");
GRN_TEXT_PUTS(ctx, buf, " ");
grn_table_columns_inspect(ctx, buf, obj);

if (obj->header.type == GRN_TABLE_NO_KEY) {
grn_table_cursor *tc;
Expand Down

0 comments on commit c081f89

Please sign in to comment.