null+****@clear*****
null+****@clear*****
2012年 2月 3日 (金) 22:05:02 JST
Kouhei Sutou 2012-02-03 22:05:02 +0900 (Fri, 03 Feb 2012)
New Revision: 0baa68b659b60c9ee4c4fa73c502aab7c92d583d
Log:
[storage] use GRN_DB_INT32 for MySQL TIME.
Added files:
test/sql/suite/mroonga_storage/r/column_time.result
test/sql/suite/mroonga_storage/t/column_time.test
Modified files:
ha_mroonga.cc
Modified: ha_mroonga.cc (+14 -29)
===================================================================
--- ha_mroonga.cc 2012-02-03 21:39:03 +0900 (cb5dcf4)
+++ ha_mroonga.cc 2012-02-03 22:05:02 +0900 (434a0fc)
@@ -946,7 +946,11 @@ static grn_builtin_type mrn_grn_type_from_field(grn_ctx *ctx, Field *field,
type = GRN_DB_INT32; // 4bytes
break;
case MYSQL_TYPE_DATE: // DATE; 4bytes
+ type = GRN_DB_TIME; // 8bytes
+ break;
case MYSQL_TYPE_TIME: // TIME; 3bytes
+ type = GRN_DB_INT32; // 4bytes
+ break;
case MYSQL_TYPE_DATETIME: // DATETIME; 8bytes
case MYSQL_TYPE_YEAR: // YEAR; 1byte
case MYSQL_TYPE_NEWDATE: // DATE; 3bytes
@@ -7141,30 +7145,8 @@ int ha_mroonga::generic_store_bulk_time(Field *field, grn_obj *buf)
MRN_DBUG_ENTER_METHOD();
int error = 0;
long long value = field->val_int();
- // FIXME: value isn't epoch time. We should store epoch
- // time to bulk.
- grn_obj_reinit(ctx, buf, GRN_DB_TIME, 0);
- uint32 size = field->pack_length();
- switch (size) {
- case 1:
- case 2:
- case 3:
- case 4:
- case 8:
- GRN_TIME_SET(ctx, buf, value);
- break;
- default:
- // Why!?
- error = HA_ERR_UNSUPPORTED;
- char error_message[MRN_MESSAGE_BUFFER_SIZE];
- snprintf(error_message, MRN_MESSAGE_BUFFER_SIZE,
- "unknown integer value size: <%u>: "
- "available sizes: [1, 2, 3, 4, 8]",
- size);
- push_warning(ha_thd(), Sql_condition::WARN_LEVEL_WARN,
- error, error_message);
- break;
- }
+ grn_obj_reinit(ctx, buf, GRN_DB_INT32, 0);
+ GRN_INT32_SET(ctx, buf, value);
DBUG_RETURN(error);
}
@@ -7469,11 +7451,8 @@ void ha_mroonga::storage_store_field_time(Field *field,
const char *value,
uint value_length)
{
- long long int field_value;
- field_value = *((long long int *)value);
- // FIXME: field_value should be epoch time and convert
- // epoch time to MySQL time. See also
- // ha_mroonga::generic_store_bulk_time().
+ int field_value;
+ field_value = *((int *)value);
field->store(field_value);
}
@@ -7831,6 +7810,12 @@ int ha_mroonga::storage_encode_key(Field *field, const uchar *key,
break;
}
case MYSQL_TYPE_TIME:
+ {
+ int val = (int)sint3korr(ptr);
+ memcpy(buf, &val, 4);
+ *size = 4;
+ break;
+ }
case MYSQL_TYPE_YEAR:
{
long long int val = (long long int) sint8korr(ptr);
Added: test/sql/suite/mroonga_storage/r/column_time.result (+40 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/r/column_time.result 2012-02-03 22:05:02 +0900 (755091f)
@@ -0,0 +1,40 @@
+DROP TABLE IF EXISTS running_records;
+CREATE TABLE running_records (
+id INT PRIMARY KEY AUTO_INCREMENT,
+title TEXT,
+average TIME,
+max TIME,
+KEY (average)
+) DEFAULT CHARSET UTF8;
+SHOW CREATE TABLE running_records;
+Table Create Table
+running_records CREATE TABLE `running_records` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `title` text,
+ `average` time DEFAULT NULL,
+ `max` time DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `average` (`average`)
+) ENGINE=mroonga DEFAULT CHARSET=utf8
+INSERT INTO running_records (title, average, max)
+VALUES ("normal condition", "01:00:00", "01:05:00");
+INSERT INTO running_records (title, average, max)
+VALUES ("bad condition", "12:23:34", "838:59:59");
+INSERT INTO running_records (title, average, max)
+VALUES ("record failure", "-838:59:59", "-838:59:59");
+SELECT * FROM running_records;
+id title average max
+1 normal condition 01:00:00 01:05:00
+2 bad condition 12:23:34 838:59:59
+3 record failure -838:59:59 -838:59:59
+SELECT * FROM running_records
+WHERE average BETWEEN "00:59:59" AND "100:10:10";
+id title average max
+1 normal condition 01:00:00 01:05:00
+2 bad condition 12:23:34 838:59:59
+SELECT * FROM running_records
+WHERE average BETWEEN "-838:59:59" AND "01:00:00";
+id title average max
+3 record failure -838:59:59 -838:59:59
+1 normal condition 01:00:00 01:05:00
+DROP TABLE running_records;
Added: test/sql/suite/mroonga_storage/t/column_time.test (+49 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/t/column_time.test 2012-02-03 22:05:02 +0900 (5323e1c)
@@ -0,0 +1,49 @@
+# 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 running_records;
+--enable_warnings
+
+CREATE TABLE running_records (
+ id INT PRIMARY KEY AUTO_INCREMENT,
+ title TEXT,
+ average TIME,
+ max TIME,
+ KEY (average)
+) DEFAULT CHARSET UTF8;
+SHOW CREATE TABLE running_records;
+
+INSERT INTO running_records (title, average, max)
+ VALUES ("normal condition", "01:00:00", "01:05:00");
+INSERT INTO running_records (title, average, max)
+ VALUES ("bad condition", "12:23:34", "838:59:59");
+INSERT INTO running_records (title, average, max)
+ VALUES ("record failure", "-838:59:59", "-838:59:59");
+
+SELECT * FROM running_records;
+
+SELECT * FROM running_records
+ WHERE average BETWEEN "00:59:59" AND "100:10:10";
+
+SELECT * FROM running_records
+ WHERE average BETWEEN "-838:59:59" AND "01:00:00";
+
+DROP TABLE running_records;
+
+--source include/have_mroonga_deinit.inc