Navigation Menu

Skip to content

Commit

Permalink
storage: support TINYINT UNSIGNED type
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jul 26, 2012
1 parent d94a66a commit 04ff667
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 6 deletions.
31 changes: 25 additions & 6 deletions ha_mroonga.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down
@@ -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;
@@ -0,0 +1,38 @@
# Copyright(C) 2012 Kouhei Sutou <kou@clear-code.com>
#
# 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

0 comments on commit 04ff667

Please sign in to comment.