[Groonga-commit] groonga/groonga [master] grn_column_name() supports accessor.

Back to archive index

null+****@clear***** null+****@clear*****
2010年 8月 13日 (金) 12:36:28 JST


Kouhei Sutou	2010-08-13 03:36:28 +0000 (Fri, 13 Aug 2010)

  New Revision: 9581521b7672dcc259b41c7e2f67cfd1b799eef0

  Log:
    grn_column_name() supports accessor.

  Modified files:
    lib/db.c
    test/unit/core/Makefile.am

  Modified: lib/db.c (+34 -0)
===================================================================
--- lib/db.c    2010-08-12 11:34:19 +0000 (514f348)
+++ lib/db.c    2010-08-13 03:36:28 +0000 (23638ef)
@@ -6035,6 +6035,7 @@ grn_column_name(grn_ctx *ctx, grn_obj *obj, char *namebuf, int buf_size)
 {
   int len = 0;
   char buf[GRN_TABLE_MAX_KEY_SIZE];
+  if (!obj) { return len; }
   GRN_API_ENTER;
   if (GRN_DB_OBJP(obj)) {
     if (DB_OBJ(obj)->id && DB_OBJ(obj)->id < GRN_ID_MAX) {
@@ -6052,6 +6053,39 @@ grn_column_name(grn_ctx *ctx, grn_obj *obj, char *namebuf, int buf_size)
         }
       }
     }
+  } else if (obj->header.type == GRN_ACCESSOR) {
+    const char *name = NULL;
+    grn_accessor *a;
+    for (a = (grn_accessor *)obj; a; a = a->next) {
+      switch (a->action) {
+      case GRN_ACCESSOR_GET_ID :
+        name = "_id";
+        break;
+      case GRN_ACCESSOR_GET_KEY :
+        name = "_key";
+        break;
+      case GRN_ACCESSOR_GET_VALUE :
+        name = "_value";
+        break;
+      case GRN_ACCESSOR_GET_SCORE :
+        name = "_score";
+        break;
+      case GRN_ACCESSOR_GET_NSUBRECS :
+        name = "_nsubrecs";
+        break;
+      case GRN_ACCESSOR_GET_COLUMN_VALUE :
+      case GRN_ACCESSOR_GET_DB_OBJ :
+      case GRN_ACCESSOR_LOOKUP :
+      case GRN_ACCESSOR_FUNCALL :
+        break;
+      }
+    }
+    if (name) {
+      len = strlen(name);
+      if (len <= buf_size) {
+        memcpy(namebuf, name, len);
+      }
+    }
   }
   GRN_API_RETURN(len);
 }

  Modified: test/unit/core/Makefile.am (+3 -1)
===================================================================
--- test/unit/core/Makefile.am    2010-08-12 11:34:19 +0000 (d69bb5f)
+++ test/unit/core/Makefile.am    2010-08-13 03:36:28 +0000 (e78914e)
@@ -46,7 +46,8 @@ noinst_LTLIBRARIES =				\
 	test-command-select-prefix-search.la	\
 	test-command-cache-limit.la		\
 	test-command-delete.la			\
-	test-geo.la
+	test-geo.la				\
+	test-accessor.la
 endif
 
 INCLUDES =			\
@@ -117,3 +118,4 @@ test_command_select_prefix_search_la_SOURCES	= test-command-select-prefix-search
 test_command_cache_limit_la_SOURCES	= test-command-cache-limit.c
 test_command_delete_la_SOURCES		= test-command-delete.c
 test_geo_la_SOURCES			= test-geo.c
+test_accessor_la_SOURCES		= test-accessor.c




Groonga-commit メーリングリストの案内
Back to archive index