[Groonga-commit] droonga/droonga-engine at afef6a4 [master] Allow to delete records in tables with integer key_type.

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Dec 2 11:22:47 JST 2014


YUKI Hiroshi	2014-12-02 11:22:47 +0900 (Tue, 02 Dec 2014)

  New Revision: afef6a43437f4b65af01728786e2938e7e282a2e
  https://github.com/droonga/droonga-engine/commit/afef6a43437f4b65af01728786e2938e7e282a2e

  Message:
    Allow to delete records in tables with integer key_type.
    
    It is reported at http://sourceforge.jp/projects/groonga/lists/archive/dev/2014-December/002995.html

  Modified files:
    lib/droonga/plugins/groonga/delete.rb
    test/unit/plugins/groonga/test_delete.rb

  Modified: lib/droonga/plugins/groonga/delete.rb (+13 -0)
===================================================================
--- lib/droonga/plugins/groonga/delete.rb    2014-12-01 00:19:15 +0900 (40e244a)
+++ lib/droonga/plugins/groonga/delete.rb    2014-12-02 11:22:47 +0900 (5453b16)
@@ -69,10 +69,23 @@ module Droonga
           end
 
           def delete_record_by_key(table, key)
+            key = normalize_record_key(key, table)
             record = table[key]
             record.delete unless record.nil?
           end
 
+          def normalize_record_key(key, table)
+            case table.domain.name
+            when "Int8",  "UInt8",
+                 "Int16", "UInt16",
+                 "Int32", "UInt32",
+                 "Int64", "UInt64"
+              key.to_i
+            else
+              key
+            end
+          end
+
           def delete_record_by_id(table, id)
             record = table[id.to_i]
             record.delete if record and record.valid_id?

  Modified: test/unit/plugins/groonga/test_delete.rb (+45 -6)
===================================================================
--- test/unit/plugins/groonga/test_delete.rb    2014-12-01 00:19:15 +0900 (53b90f0)
+++ test/unit/plugins/groonga/test_delete.rb    2014-12-02 11:22:47 +0900 (d00a48e)
@@ -79,12 +79,10 @@ class DeleteTest < GroongaHandlerTest
     )
   end
 
-  class DeleteTest < self
-    def test_key
-      Groonga::Schema.define do |schema|
-        schema.create_table("Books", :type => :hash)
-      end
-      Groonga::Context.default["Books"].add("sample")
+  class DeleteKeyTest < self
+    def test_string
+      setup_table_with_key_type("ShortText")
+      table.add("sample")
       process(:delete,
               {"table" => "Books", "key" => "sample"})
       assert_equal(<<-DUMP, dump)
@@ -92,6 +90,47 @@ table_create Books TABLE_HASH_KEY ShortText
       DUMP
     end
 
+    data do
+      data_set = {}
+      [
+        "Int8",
+        "UInt8",
+        "Int16",
+        "UInt16",
+        "Int32",
+        "UInt32",
+        "Int64",
+        "UInt64",
+      ].each do |key_type|
+        data_set[key_type] = key_type
+      end
+      data_set
+    end
+    def test_integer(key_type)
+      setup_table_with_key_type(key_type)
+      table.add(1)
+      process(:delete,
+              {"table" => "Books", "key" => "1"})
+      assert_equal(<<-DUMP, dump)
+table_create Books TABLE_HASH_KEY #{key_type}
+      DUMP
+    end
+
+    private
+    def setup_table_with_key_type(key_type)
+      Groonga::Schema.define do |schema|
+        schema.create_table("Books",
+                            :type     => :hash,
+                            :key_type => key_type)
+      end
+    end
+
+    def table
+      Groonga::Context.default["Books"]
+    end
+  end
+
+  class DeleteTest < self
     def test_id
       Groonga::Schema.define do |schema|
         schema.create_table("Ages", :type => :array)
-------------- next part --------------
HTML����������������������������...
Télécharger 



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