[Groonga-commit] groonga/groonga at d895f22 [master] Add grn_ctx_get_all_types()

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Oct 19 14:31:14 JST 2015


Kouhei Sutou	2015-10-19 14:31:14 +0900 (Mon, 19 Oct 2015)

  New Revision: d895f225c27d5d12939a40a6364a392f056069fd
  https://github.com/groonga/groonga/commit/d895f225c27d5d12939a40a6364a392f056069fd

  Message:
    Add grn_ctx_get_all_types()

  Modified files:
    include/groonga/groonga.h
    lib/db.c

  Modified: include/groonga/groonga.h (+1 -0)
===================================================================
--- include/groonga/groonga.h    2015-10-19 14:28:53 +0900 (531ba38)
+++ include/groonga/groonga.h    2015-10-19 14:31:14 +0900 (236c9df)
@@ -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,

  Modified: lib/db.c (+40 -0)
===================================================================
--- lib/db.c    2015-10-19 14:28:53 +0900 (537292f)
+++ lib/db.c    2015-10-19 14:31:14 +0900 (6edcbcc)
@@ -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);
+}
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index