[Groonga-mysql-commit] mroonga/mroonga [master] storage: support SMALLINT UNSIGNED type

Back to archive index

null+****@clear***** null+****@clear*****
2012年 7月 26日 (木) 13:37:24 JST


Kouhei Sutou	2012-07-26 13:37:24 +0900 (Thu, 26 Jul 2012)

  New Revision: 438a139cbfe420f2b286fc28620772ce7d298e98
  https://github.com/mroonga/mroonga/commit/438a139cbfe420f2b286fc28620772ce7d298e98

  Log:
    storage: support SMALLINT UNSIGNED type

  Added files:
    test/sql/suite/mroonga_storage/r/column_unsigned_smallint_with_index.result
    test/sql/suite/mroonga_storage/t/column_unsigned_smallint_with_index.test
  Modified files:
    ha_mroonga.cpp

  Modified: ha_mroonga.cpp (+21 -6)
===================================================================
--- ha_mroonga.cpp    2012-07-26 13:27:47 +0900 (aaca03b)
+++ ha_mroonga.cpp    2012-07-26 13:37:24 +0900 (2fa3f71)
@@ -1010,7 +1010,11 @@ static grn_builtin_type mrn_grn_type_from_field(grn_ctx *ctx, Field *field,
     }
     break;
   case MYSQL_TYPE_SHORT:        // SMALLINT; 2bytes
-    type = GRN_DB_INT16;        // 2bytes
+    if (static_cast<Field_num *>(field)->unsigned_flag) {
+      type = GRN_DB_UINT16;     // 2bytes
+    } else {
+      type = GRN_DB_INT16;      // 2bytes
+    }
     break;
   case MYSQL_TYPE_LONG:         // INT; 4bytes
     type = GRN_DB_INT32;        // 4bytes
@@ -8036,8 +8040,13 @@ int ha_mroonga::generic_store_bulk_integer(Field *field, grn_obj *buf)
     }
     break;
   case 2:
-    grn_obj_reinit(ctx, buf, GRN_DB_INT16, 0);
-    GRN_INT16_SET(ctx, buf, value);
+    if (is_unsigned) {
+      grn_obj_reinit(ctx, buf, GRN_DB_UINT16, 0);
+      GRN_UINT16_SET(ctx, buf, value);
+    } else {
+      grn_obj_reinit(ctx, buf, GRN_DB_INT16, 0);
+      GRN_INT16_SET(ctx, buf, value);
+    }
     break;
   case 3:
   case 4:
@@ -8437,9 +8446,15 @@ void ha_mroonga::storage_store_field_integer(Field *field,
     }
   case 2:
     {
-      short field_value;
-      field_value = *((short *)value);
-      field->store(field_value);
+      if (is_unsigned) {
+        unsigned short field_value;
+        field_value = *((unsigned short *)value);
+        field->store(field_value);
+      } else {
+        short field_value;
+        field_value = *((short *)value);
+        field->store(field_value);
+      }
       break;
     }
   case 4:

  Added: test/sql/suite/mroonga_storage/r/column_unsigned_smallint_with_index.result (+25 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/r/column_unsigned_smallint_with_index.result    2012-07-26 13:37:24 +0900 (8586d09)
@@ -0,0 +1,25 @@
+DROP TABLE IF EXISTS items;
+CREATE TABLE items (
+name VARCHAR(255),
+price SMALLINT UNSIGNED KEY
+) DEFAULT CHARSET=utf8;
+INSERT INTO items VALUES ("note PC", 65535);
+INSERT INTO items VALUES ("discount", 0);
+INSERT INTO items VALUES ("coke", 100);
+INSERT INTO items VALUES ("tablet PC", 32767);
+SELECT * FROM items;
+name	price
+discount	0
+coke	100
+tablet PC	32767
+note PC	65535
+SELECT * FROM items WHERE price <= 32768;
+name	price
+discount	0
+coke	100
+tablet PC	32767
+SELECT * FROM items WHERE price >= 32767;
+name	price
+tablet PC	32767
+note PC	65535
+DROP TABLE items;

  Added: test/sql/suite/mroonga_storage/t/column_unsigned_smallint_with_index.test (+41 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/t/column_unsigned_smallint_with_index.test    2012-07-26 13:37:24 +0900 (a84a1f5)
@@ -0,0 +1,41 @@
+# Copyright(C) 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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+--source include/have_mroonga.inc
+
+--disable_warnings
+DROP TABLE IF EXISTS items;
+--enable_warnings
+
+CREATE TABLE items (
+  name VARCHAR(255),
+  price SMALLINT UNSIGNED KEY
+) DEFAULT CHARSET=utf8;
+
+INSERT INTO items VALUES ("note PC", 65535);
+INSERT INTO items VALUES ("discount", 0);
+INSERT INTO items VALUES ("coke", 100);
+INSERT INTO items VALUES ("tablet PC", 32767);
+
+SELECT * FROM items;
+
+SELECT * FROM items WHERE price <= 32768;
+
+SELECT * FROM items WHERE price >= 32767;
+
+DROP TABLE items;
+
+--source include/have_mroonga_deinit.inc
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Descargar 



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