[Groonga-mysql-commit] mroonga/mroonga [master] [storage] support fractional seconds in time values.

Back to archive index

null+****@clear***** null+****@clear*****
2012年 2月 3日 (金) 14:17:47 JST


Kouhei Sutou	2012-02-03 14:17:47 +0900 (Fri, 03 Feb 2012)

  New Revision: be45338628f1f33bf937f39ebc2bddd99843fb44

  Log:
    [storage] support fractional seconds in time values.

  Added files:
    test/sql/include/have_fractional_seconds.inc
    test/sql/suite/mroonga_storage/r/column_datetime_fractional_seconds.result
    test/sql/suite/mroonga_storage/t/column_datetime_fractional_seconds.test
  Modified files:
    ha_mroonga.cc

  Modified: ha_mroonga.cc (+2 -2)
===================================================================
--- ha_mroonga.cc    2012-02-03 13:33:04 +0900 (cf476d3)
+++ ha_mroonga.cc    2012-02-03 14:17:47 +0900 (cb5dcf4)
@@ -7184,7 +7184,7 @@ int ha_mroonga::generic_store_bulk_datetime(Field *field, grn_obj *buf)
   date.tm_min = mysql_time.minute;
   date.tm_sec = mysql_time.second;
   int32 seconds = mktime(&date) + mrn_utc_diff_in_seconds;
-  long long int time = GRN_TIME_PACK(seconds, 0);
+  long long int time = GRN_TIME_PACK(seconds, mysql_time.second_part);
   grn_obj_reinit(ctx, buf, GRN_DB_TIME, 0);
   GRN_TIME_SET(ctx, buf, time);
   DBUG_RETURN(error);
@@ -7207,7 +7207,7 @@ int ha_mroonga::generic_store_bulk_datetime2(Field *field, grn_obj *buf)
   date.tm_min = mysql_time.minute;
   date.tm_sec = mysql_time.second;
   int32 seconds = mktime(&date) + mrn_utc_diff_in_seconds;
-  long long int time = GRN_TIME_PACK(seconds, 0);
+  long long int time = GRN_TIME_PACK(seconds, mysql_time.second_part);
   grn_obj_reinit(ctx, buf, GRN_DB_TIME, 0);
   GRN_TIME_SET(ctx, buf, time);
   DBUG_RETURN(error);

  Added: test/sql/include/have_fractional_seconds.inc (+23 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/include/have_fractional_seconds.inc    2012-02-03 14:17:47 +0900 (a13a8ed)
@@ -0,0 +1,23 @@
+# 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
+
+--disable_query_log
+let $fractional_seconds = `SELECT @@global.version >= '5.6'`;
+--enable_query_log
+if (!$fractional_seconds)
+{
+  skip fractional seconds in time values are available in version 5.6 or later;
+}

  Added: test/sql/suite/mroonga_storage/r/column_datetime_fractional_seconds.result (+42 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/r/column_datetime_fractional_seconds.result    2012-02-03 14:17:47 +0900 (08e90d6)
@@ -0,0 +1,42 @@
+DROP TABLE IF EXISTS diaries;
+CREATE TABLE diaries (
+id INT PRIMARY KEY AUTO_INCREMENT,
+title TEXT,
+created_at DATETIME(6),
+updated_at DATETIME(6),
+KEY (updated_at)
+) DEFAULT CHARSET UTF8;
+SHOW CREATE TABLE diaries;
+Table	Create Table
+diaries	CREATE TABLE `diaries` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `title` text,
+  `created_at` datetime(6) DEFAULT NULL,
+  `updated_at` datetime(6) DEFAULT NULL,
+  PRIMARY KEY (`id`),
+  KEY `updated_at` (`updated_at`)
+) ENGINE=mroonga DEFAULT CHARSET=utf8
+INSERT INTO diaries (title, created_at, updated_at)
+VALUES ("clear day",
+"2012-01-29 21:51:01.111111",
+"2012-01-29 21:51:02.222222");
+INSERT INTO diaries (title, created_at, updated_at)
+VALUES ("rainy day",
+"2012-01-30 01:23:45.333",
+"2012-01-30 01:23:46.444");
+INSERT INTO diaries (title, created_at, updated_at)
+VALUES ("cloudy day",
+"2012-01-31 08:32:10.5555",
+"2012-01-31 08:32:11.6666");
+SELECT * FROM diaries;
+id	title	created_at	updated_at
+1	clear day	2012-01-29 21:51:01.111111	2012-01-29 21:51:02.222222
+2	rainy day	2012-01-30 01:23:45.333000	2012-01-30 01:23:46.444000
+3	cloudy day	2012-01-31 08:32:10.555500	2012-01-31 08:32:11.666600
+SELECT * FROM diaries
+WHERE updated_at BETWEEN "2012-01-29 00:00:00.123456" AND
+"2012-01-31 00:00:00.999999";
+id	title	created_at	updated_at
+1	clear day	2012-01-29 21:51:01.111111	2012-01-29 21:51:02.222222
+2	rainy day	2012-01-30 01:23:45.333000	2012-01-30 01:23:46.444000
+DROP TABLE diaries;

  Added: test/sql/suite/mroonga_storage/t/column_datetime_fractional_seconds.test (+54 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/t/column_datetime_fractional_seconds.test    2012-02-03 14:17:47 +0900 (7cabb38)
@@ -0,0 +1,54 @@
+# 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_fractional_seconds.inc
+--source include/have_mroonga.inc
+
+--disable_warnings
+DROP TABLE IF EXISTS diaries;
+--enable_warnings
+
+CREATE TABLE diaries (
+  id INT PRIMARY KEY AUTO_INCREMENT,
+  title TEXT,
+  created_at DATETIME(6),
+  updated_at DATETIME(6),
+  KEY (updated_at)
+) DEFAULT CHARSET UTF8;
+SHOW CREATE TABLE diaries;
+
+INSERT INTO diaries (title, created_at, updated_at)
+       VALUES ("clear day",
+               "2012-01-29 21:51:01.111111",
+               "2012-01-29 21:51:02.222222");
+INSERT INTO diaries (title, created_at, updated_at)
+       VALUES ("rainy day",
+               "2012-01-30 01:23:45.333",
+               "2012-01-30 01:23:46.444");
+INSERT INTO diaries (title, created_at, updated_at)
+       VALUES ("cloudy day",
+               "2012-01-31 08:32:10.5555",
+               "2012-01-31 08:32:11.6666");
+
+SELECT * FROM diaries;
+
+SELECT * FROM diaries
+         WHERE updated_at BETWEEN "2012-01-29 00:00:00.123456" AND
+                                  "2012-01-31 00:00:00.999999";
+
+DROP TABLE diaries;
+
+--source include/have_mroonga_deinit.inc




Groonga-mysql-commit メーリングリストの案内
Back to archive index