Navigation Menu

Skip to content

Commit

Permalink
storage: support MEDIUMINT UNSIGNED type
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jul 26, 2012
1 parent 438a139 commit 2b2cda6
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 6 deletions.
27 changes: 21 additions & 6 deletions ha_mroonga.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down
@@ -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;
@@ -0,0 +1,42 @@
# 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 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

0 comments on commit 2b2cda6

Please sign in to comment.