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

Back to archive index

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


Kouhei Sutou	2012-07-26 13:46:50 +0900 (Thu, 26 Jul 2012)

  New Revision: 2b2cda6f0d09310aa4ae4ba20bb527b2016b9a06
  https://github.com/mroonga/mroonga/commit/2b2cda6f0d09310aa4ae4ba20bb527b2016b9a06

  Log:
    storage: support MEDIUMINT UNSIGNED type

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

  Modified: ha_mroonga.cpp (+21 -6)
===================================================================
--- ha_mroonga.cpp    2012-07-26 13:37:24 +0900 (2fa3f71)
+++ ha_mroonga.cpp    2012-07-26 13:46:50 +0900 (16a1623)
@@ -1033,7 +1033,11 @@ static grn_builtin_type mrn_grn_type_from_field(grn_ctx *ctx, Field *field,
     type = GRN_DB_INT64;        // 8bytes
     break;
   case MYSQL_TYPE_INT24:        // MEDIUMINT; 3bytes
-    type = GRN_DB_INT32;        // 4bytes
+    if (static_cast<Field_num *>(field)->unsigned_flag) {
+      type = GRN_DB_UINT32;     // 4bytes
+    } else {
+      type = GRN_DB_INT32;      // 4bytes
+    }
     break;
   case MYSQL_TYPE_DATE:         // DATE; 4bytes
   case MYSQL_TYPE_TIME:         // TIME; 3bytes
@@ -8050,8 +8054,13 @@ int ha_mroonga::generic_store_bulk_integer(Field *field, grn_obj *buf)
     break;
   case 3:
   case 4:
-    grn_obj_reinit(ctx, buf, GRN_DB_INT32, 0);
-    GRN_INT32_SET(ctx, buf, value);
+    if (is_unsigned) {
+      grn_obj_reinit(ctx, buf, GRN_DB_UINT32, 0);
+      GRN_UINT32_SET(ctx, buf, value);
+    } else {
+      grn_obj_reinit(ctx, buf, GRN_DB_INT32, 0);
+      GRN_INT32_SET(ctx, buf, value);
+    }
     break;
   case 8:
     grn_obj_reinit(ctx, buf, GRN_DB_INT64, 0);
@@ -8459,9 +8468,15 @@ void ha_mroonga::storage_store_field_integer(Field *field,
     }
   case 4:
     {
-      int field_value;
-      field_value = *((int *)value);
-      field->store(field_value);
+      if (is_unsigned) {
+        unsigned int field_value;
+        field_value = *((unsigned int *)value);
+        field->store(field_value);
+      } else {
+        int field_value;
+        field_value = *((int *)value);
+        field->store(field_value);
+      }
       break;
     }
   case 8:

  Added: test/sql/suite/mroonga_storage/r/column_unsigned_mediumint_with_index.result (+28 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/r/column_unsigned_mediumint_with_index.result    2012-07-26 13:46:50 +0900 (2825aad)
@@ -0,0 +1,28 @@
+DROP TABLE IF EXISTS items;
+CREATE TABLE items (
+name VARCHAR(255),
+price MEDIUMINT UNSIGNED KEY
+) DEFAULT CHARSET=utf8;
+INSERT INTO items VALUES ("car", 16777215);
+INSERT INTO items VALUES ("note PC", 32767);
+INSERT INTO items VALUES ("discount", 0);
+INSERT INTO items VALUES ("coke", 100);
+INSERT INTO items VALUES ("bike", 8388607);
+SELECT * FROM items;
+name	price
+discount	0
+coke	100
+note PC	32767
+bike	8388607
+car	16777215
+SELECT * FROM items WHERE price <= 8388608;
+name	price
+discount	0
+coke	100
+note PC	32767
+bike	8388607
+SELECT * FROM items WHERE price >= 8388607;
+name	price
+bike	8388607
+car	16777215
+DROP TABLE items;

  Added: test/sql/suite/mroonga_storage/t/column_unsigned_mediumint_with_index.test (+42 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/t/column_unsigned_mediumint_with_index.test    2012-07-26 13:46:50 +0900 (6754d28)
@@ -0,0 +1,42 @@
+# 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 MEDIUMINT UNSIGNED KEY
+) DEFAULT CHARSET=utf8;
+
+INSERT INTO items VALUES ("car", 16777215);
+INSERT INTO items VALUES ("note PC", 32767);
+INSERT INTO items VALUES ("discount", 0);
+INSERT INTO items VALUES ("coke", 100);
+INSERT INTO items VALUES ("bike", 8388607);
+
+SELECT * FROM items;
+
+SELECT * FROM items WHERE price <= 8388608;
+
+SELECT * FROM items WHERE price >= 8388607;
+
+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