[Groonga-commit] groonga/groonga [master] [shcema][table-create] validate key_type.

Back to archive index

null+****@clear***** null+****@clear*****
2011年 12月 19日 (月) 13:28:57 JST


Kouhei Sutou	2011-12-19 04:28:57 +0000 (Mon, 19 Dec 2011)

  New Revision: 92ffd6e852a68ff4cd3aef4aa7134cd70c79cf22

  Log:
    [shcema][table-create] validate key_type.
    
    refs #915
    refs #1210

  Modified files:
    lib/db.c
    test/unit/http/test-http-schema.rb

  Modified: lib/db.c (+20 -11)
===================================================================
--- lib/db.c    2011-12-19 04:13:57 +0000 (69b5020)
+++ lib/db.c    2011-12-19 04:28:57 +0000 (58803a8)
@@ -626,7 +626,16 @@ grn_table_create_validate(grn_ctx *ctx, const char *name, unsigned name_size,
   case GRN_OBJ_TABLE_DAT_KEY :
     break;
   case GRN_OBJ_TABLE_NO_KEY :
-    if (flags & GRN_OBJ_KEY_WITH_SIS) {
+    if (key_type) {
+      int key_name_size;
+      char key_name[GRN_TABLE_MAX_KEY_SIZE];
+      key_name_size = grn_obj_name(ctx, key_type, key_name,
+                                   GRN_TABLE_MAX_KEY_SIZE);
+      ERR(GRN_INVALID_ARGUMENT,
+          "[table][create] "
+          "key isn't available for no key table: <%.*s> (%.*s)",
+          name_size, name, key_name_size, key_name);
+    } else if (flags & GRN_OBJ_KEY_WITH_SIS) {
       ERR(GRN_INVALID_ARGUMENT,
           "[table][create] "
           "key with SIS isn't available for no key table: <%.*s>",
@@ -639,7 +648,16 @@ grn_table_create_validate(grn_ctx *ctx, const char *name, unsigned name_size,
     }
     break;
   case GRN_OBJ_TABLE_VIEW :
-    if (flags & GRN_OBJ_KEY_WITH_SIS) {
+    if (key_type) {
+      int key_name_size;
+      char key_name[GRN_TABLE_MAX_KEY_SIZE];
+      key_name_size = grn_obj_name(ctx, key_type, key_name,
+                                   GRN_TABLE_MAX_KEY_SIZE);
+      ERR(GRN_INVALID_ARGUMENT,
+          "[table][create] "
+          "key isn't available for view table: <%.*s> (%.*s)",
+          name_size, name, key_name_size, key_name);
+    } else if (flags & GRN_OBJ_KEY_WITH_SIS) {
       ERR(GRN_INVALID_ARGUMENT,
           "[table][create] "
           "key with SIS isn't available for view table: <%.*s>",
@@ -685,15 +703,6 @@ grn_table_create(grn_ctx *ctx, const char *name, unsigned name_size,
     GRN_API_RETURN(NULL);
   }
   if (key_type) {
-    if ((flags & GRN_OBJ_TABLE_TYPE_MASK) == GRN_OBJ_TABLE_NO_KEY) {
-      if (name_size > 0) {
-        ERR(GRN_INVALID_ARGUMENT,
-            "key_type assigned for no key table: <%.*s>", name_size, name);
-      } else {
-        ERR(GRN_INVALID_ARGUMENT, "key_type assigned for no key table");
-      }
-      GRN_API_RETURN(NULL);
-    }
     domain = DB_OBJ(key_type)->id;
     switch (key_type->header.type) {
     case GRN_TYPE :

  Modified: test/unit/http/test-http-schema.rb (+7 -3)
===================================================================
--- test/unit/http/test-http-schema.rb    2011-12-19 04:13:57 +0000 (0b57539)
+++ test/unit/http/test-http-schema.rb    2011-12-19 04:28:57 +0000 (d489946)
@@ -549,7 +549,9 @@ class HTTPSchemaTest < Test::Unit::TestCase
                                   :flags => Table::NO_KEY,
                                   :key_type => "ShortText"))
       assert_error_response(Result::INVALID_ARGUMENT,
-                            "key_type assigned for no key table: <users>",
+                            "[table][create] " +
+                              "key isn't available for no key table: " +
+                              "<users> (ShortText)",
                             response,
                             :content_type => "application/json")
 
@@ -642,8 +644,10 @@ class HTTPSchemaTest < Test::Unit::TestCase
                                   :name => "users",
                                   :flags => Table::VIEW,
                                   :key_type => "ShortText"))
-      assert_error_response(Result::UNKNOWN_ERROR,
-                            "key isn't supported",
+      assert_error_response(Result::INVALID_ARGUMENT,
+                            "[table][create] " +
+                              "key isn't available for view table: " +
+                              "<users> (ShortText)",
                             response,
                             :content_type => "application/json")
 




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