[Groonga-commit] groonga/groonga [master] grn_table_get: support grn_db. fixes #1242

Back to archive index

null+****@clear***** null+****@clear*****
2012年 1月 13日 (金) 11:17:54 JST


Kouhei Sutou	2012-01-13 11:17:54 +0900 (Fri, 13 Jan 2012)

  New Revision: a9886d008d549ddb48738e5719965b64e5571ed3

  Log:
    grn_table_get: support grn_db. fixes #1242

  Modified files:
    include/groonga.h
    lib/db.c
    test/unit/core/test-database.c

  Modified: include/groonga.h (+6 -3)
===================================================================
--- include/groonga.h    2012-01-13 17:31:29 +0900 (c305ed5)
+++ include/groonga.h    2012-01-13 11:17:54 +0900 (f108759)
@@ -708,10 +708,13 @@ GRN_API grn_id grn_table_add(grn_ctx *ctx, grn_obj *table,
 
 /**
  * grn_table_get:
- * @table: 対象table
- * @key: 検索key
+ * @table: The table or database
+ * @key: The record or object key to be found
  *
- * tableからkeyに対応するrecordを検索し、対応するIDを返す。
+ * It finds a record that has @key and returns ID of the
+ * found record. If @table is a database, it finds an object
+ * (table, column and so on) that has @key and returns ID of
+ * the found object.
  **/
 GRN_API grn_id grn_table_get(grn_ctx *ctx, grn_obj *table,
                              const void *key, unsigned int key_size);

  Modified: lib/db.c (+6 -0)
===================================================================
--- lib/db.c    2012-01-13 17:31:29 +0900 (bafafb7)
+++ lib/db.c    2012-01-13 11:17:54 +0900 (397c752)
@@ -1280,6 +1280,12 @@ grn_table_get(grn_ctx *ctx, grn_obj *table, const void *key, unsigned int key_si
   GRN_API_ENTER;
   if (table) {
     switch (table->header.type) {
+    case GRN_DB :
+      {
+        grn_db *db = (grn_db *)table;
+        id = grn_table_get(ctx, db->keys, key, key_size);
+      }
+      break;
     case GRN_TABLE_PAT_KEY :
       WITH_NORMALIZE((grn_pat *)table, key, key_size, {
         id = grn_pat_get(ctx, (grn_pat *)table, key, key_size, NULL);

  Modified: test/unit/core/test-database.c (+15 -1)
===================================================================
--- test/unit/core/test-database.c    2012-01-13 17:31:29 +0900 (a47781b)
+++ test/unit/core/test-database.c    2012-01-13 11:17:54 +0900 (3c28af4)
@@ -1,6 +1,6 @@
 /* -*- c-basic-offset: 2; coding: utf-8 -*- */
 /*
-  Copyright (C) 2009-2011  Kouhei Sutou <kou****@clear*****>
+  Copyright (C) 2009-2012  Kouhei Sutou <kou****@clear*****>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -31,6 +31,7 @@ void test_recreate_temporary_object_on_opened_database(void);
 void test_size(void);
 void test_expire_cache_on_recreate(void);
 void test_expression_lifetime_over_database(void);
+void test_get(void);
 
 static gchar *tmp_directory;
 
@@ -281,3 +282,16 @@ test_expression_lifetime_over_database(void)
   g_free(context);
   context = NULL;
 }
+
+void
+test_get(void)
+{
+  const gchar *short_text_type_name = "ShortText";
+
+  database = grn_db_create(context, NULL, NULL);
+  grn_test_assert_equal_id(context,
+                           GRN_DB_SHORT_TEXT,
+                           grn_table_get(context, database,
+                                         short_text_type_name,
+                                         strlen(short_text_type_name)));
+}




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