null+****@clear*****
null+****@clear*****
2012年 7月 26日 (木) 13:27:47 JST
Kouhei Sutou 2012-07-26 13:27:47 +0900 (Thu, 26 Jul 2012) New Revision: 04ff66775e1ee67f851fcca86e4e62fa1e136429 https://github.com/mroonga/mroonga/commit/04ff66775e1ee67f851fcca86e4e62fa1e136429 Log: storage: support TINYINT UNSIGNED type Added files: test/sql/suite/mroonga_storage/r/column_unsigned_tinyint_with_index.result test/sql/suite/mroonga_storage/t/column_unsigned_tinyint_with_index.test Modified files: ha_mroonga.cpp Modified: ha_mroonga.cpp (+25 -6) =================================================================== --- ha_mroonga.cpp 2012-07-26 13:16:14 +0900 (17e2b25) +++ ha_mroonga.cpp 2012-07-26 13:27:47 +0900 (aaca03b) @@ -1003,7 +1003,11 @@ static grn_builtin_type mrn_grn_type_from_field(grn_ctx *ctx, Field *field, type = GRN_DB_SHORT_TEXT; // 4Kbytes break; case MYSQL_TYPE_TINY: // TINYINT; 1byte - type = GRN_DB_INT8; // 1byte + if (static_cast<Field_num *>(field)->unsigned_flag) { + type = GRN_DB_UINT8; // 1byte + } else { + type = GRN_DB_INT8; // 1byte + } break; case MYSQL_TYPE_SHORT: // SMALLINT; 2bytes type = GRN_DB_INT16; // 2bytes @@ -8019,10 +8023,17 @@ int ha_mroonga::generic_store_bulk_integer(Field *field, grn_obj *buf) int error = 0; long long value = field->val_int(); uint32 size = field->pack_length(); + Field_num *field_num = static_cast<Field_num *>(field); + bool is_unsigned = field_num->unsigned_flag; switch (size) { case 1: - grn_obj_reinit(ctx, buf, GRN_DB_INT8, 0); - GRN_INT8_SET(ctx, buf, value); + if (is_unsigned) { + grn_obj_reinit(ctx, buf, GRN_DB_UINT8, 0); + GRN_UINT8_SET(ctx, buf, value); + } else { + grn_obj_reinit(ctx, buf, GRN_DB_INT8, 0); + GRN_INT8_SET(ctx, buf, value); + } break; case 2: grn_obj_reinit(ctx, buf, GRN_DB_INT16, 0); @@ -8408,12 +8419,20 @@ void ha_mroonga::storage_store_field_integer(Field *field, const char *value, uint value_length) { + Field_num *field_num = static_cast<Field_num *>(field); + bool is_unsigned = field_num->unsigned_flag; switch (value_length) { case 1: { - char field_value; - field_value = *((char *)value); - field->store(field_value); + if (is_unsigned) { + unsigned char field_value; + field_value = *((unsigned char *)value); + field->store(field_value); + } else { + char field_value; + field_value = *((char *)value); + field->store(field_value); + } break; } case 2: Added: test/sql/suite/mroonga_storage/r/column_unsigned_tinyint_with_index.result (+18 -0) 100644 =================================================================== --- /dev/null +++ test/sql/suite/mroonga_storage/r/column_unsigned_tinyint_with_index.result 2012-07-26 13:27:47 +0900 (90adb04) @@ -0,0 +1,18 @@ +DROP TABLE IF EXISTS items; +CREATE TABLE items ( +name VARCHAR(255), +price TINYINT UNSIGNED KEY +) DEFAULT CHARSET=utf8; +INSERT INTO items VALUES ("hamburger", 255); +INSERT INTO items VALUES ("discount", 0); +INSERT INTO items VALUES ("coke", 100); +SELECT * FROM items; +name price +discount 0 +coke 100 +hamburger 255 +SELECT * FROM items WHERE price <= 100; +name price +discount 0 +coke 100 +DROP TABLE items; Added: test/sql/suite/mroonga_storage/t/column_unsigned_tinyint_with_index.test (+38 -0) 100644 =================================================================== --- /dev/null +++ test/sql/suite/mroonga_storage/t/column_unsigned_tinyint_with_index.test 2012-07-26 13:27:47 +0900 (f3798ce) @@ -0,0 +1,38 @@ +# 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 TINYINT UNSIGNED KEY +) DEFAULT CHARSET=utf8; + +INSERT INTO items VALUES ("hamburger", 255); +INSERT INTO items VALUES ("discount", 0); +INSERT INTO items VALUES ("coke", 100); + +SELECT * FROM items; + +SELECT * FROM items WHERE price <= 100; + +DROP TABLE items; + +--source include/have_mroonga_deinit.inc -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...Download