[Groonga-mysql-commit] mroonga/mroonga [master] [storage] store timestamp value as correct groonga time value.

Back to archive index

null+****@clear***** null+****@clear*****
2012年 1月 29日 (日) 22:10:57 JST


Kouhei Sutou	2012-01-29 22:10:57 +0900 (Sun, 29 Jan 2012)

  New Revision: 48d3b8fdb93d437943d1e6688ad7297a7fd66783

  Log:
    [storage] store timestamp value as correct groonga time value.

  Added files:
    test/sql/suite/mroonga_storage/r/column_timestamp.result
    test/sql/suite/mroonga_storage/t/column_timestamp.test
  Modified files:
    ha_mroonga.cc
    ha_mroonga.h

  Modified: ha_mroonga.cc (+28 -4)
===================================================================
--- ha_mroonga.cc    2012-01-29 21:47:15 +0900 (7f46b6a)
+++ ha_mroonga.cc    2012-01-29 22:10:57 +0900 (d2b987a)
@@ -6913,6 +6913,19 @@ int ha_mroonga::generic_store_bulk_float(Field *field, grn_obj *buf)
   DBUG_RETURN(error);
 }
 
+int ha_mroonga::generic_store_bulk_timestamp(Field *field, grn_obj *buf)
+{
+  MRN_DBUG_ENTER_METHOD();
+  int error = 0;
+  my_bool is_null_value;
+  Field_timestamp *timestamp_field = (Field_timestamp *)field;
+  long seconds = timestamp_field->get_timestamp(&is_null_value);
+  long long int time = GRN_TIME_PACK(seconds, 0);
+  grn_obj_reinit(ctx, buf, GRN_DB_TIME, 0);
+  GRN_TIME_SET(ctx, buf, time);
+  DBUG_RETURN(error);
+}
+
 int ha_mroonga::generic_store_bulk_time(Field *field, grn_obj *buf)
 {
   MRN_DBUG_ENTER_METHOD();
@@ -7005,7 +7018,7 @@ int ha_mroonga::generic_store_bulk(Field *field, grn_obj *buf)
     error = generic_store_bulk_integer(field, buf);
     break;
   case MYSQL_TYPE_TIMESTAMP:
-    error = generic_store_bulk_time(field, buf);
+    error = generic_store_bulk_timestamp(field, buf);
     break;
   case MYSQL_TYPE_LONGLONG:
   case MYSQL_TYPE_INT24:
@@ -7026,7 +7039,7 @@ int ha_mroonga::generic_store_bulk(Field *field, grn_obj *buf)
     break;
 #ifdef MRN_HAVE_MYSQL_TYPE_TIMESTAMP2
   case MYSQL_TYPE_TIMESTAMP2:
-    error = generic_store_bulk_time(field, buf);
+    error = generic_store_bulk_timestamp(field, buf);
     break;
 #endif
 #ifdef MRN_HAVE_MYSQL_TYPE_DATETIME2
@@ -7131,6 +7144,17 @@ void ha_mroonga::storage_store_field_float(Field *field,
   field->store(field_value);
 }
 
+void ha_mroonga::storage_store_field_timestamp(Field *field,
+                                               const char *value,
+                                               uint value_length)
+{
+  long long int time = *((long long int *)value);
+  int32 sec, usec __attribute__((unused));
+  GRN_TIME_UNPACK(time, sec, usec);
+  Field_timestamp *timestamp_field = (Field_timestamp *)field;
+  timestamp_field->store_timestamp(sec);
+}
+
 void ha_mroonga::storage_store_field_time(Field *field,
                                           const char *value,
                                           uint value_length)
@@ -7199,7 +7223,7 @@ void ha_mroonga::storage_store_field(Field *field,
     storage_store_field_integer(field, value, value_length);
     break;
   case MYSQL_TYPE_TIMESTAMP:
-    storage_store_field_time(field, value, value_length);
+    storage_store_field_timestamp(field, value, value_length);
     break;
   case MYSQL_TYPE_LONGLONG:
   case MYSQL_TYPE_INT24:
@@ -7220,7 +7244,7 @@ void ha_mroonga::storage_store_field(Field *field,
     break;
 #ifdef MRN_HAVE_MYSQL_TYPE_TIMESTAMP2
   case MYSQL_TYPE_TIMESTAMP2:
-    storage_store_field_time(field, value, value_length);
+    storage_store_field_timestamp(field, value, value_length);
     break;
 #endif
 #ifdef MRN_HAVE_MYSQL_TYPE_DATETIME2

  Modified: ha_mroonga.h (+3 -0)
===================================================================
--- ha_mroonga.h    2012-01-29 21:47:15 +0900 (a3947d6)
+++ ha_mroonga.h    2012-01-29 22:10:57 +0900 (40a4a9d)
@@ -405,6 +405,7 @@ private:
   int generic_store_bulk_string(Field *field, grn_obj *buf);
   int generic_store_bulk_integer(Field *field, grn_obj *buf);
   int generic_store_bulk_float(Field *field, grn_obj *buf);
+  int generic_store_bulk_timestamp(Field *field, grn_obj *buf);
   int generic_store_bulk_time(Field *field, grn_obj *buf);
   int generic_store_bulk_new_decimal(Field *field, grn_obj *buf);
   int generic_store_bulk_blob(Field *field, grn_obj *buf);
@@ -417,6 +418,8 @@ private:
                                    const char *value, uint value_length);
   void storage_store_field_float(Field *field,
                                  const char *value, uint value_length);
+  void storage_store_field_timestamp(Field *field,
+                                     const char *value, uint value_length);
   void storage_store_field_time(Field *field,
                                 const char *value, uint value_length);
   void storage_store_field_blob(Field *field,

  Added: test/sql/suite/mroonga_storage/r/column_timestamp.result (+35 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/r/column_timestamp.result    2012-01-29 22:10:57 +0900 (1c69668)
@@ -0,0 +1,35 @@
+DROP TABLE IF EXISTS diaries;
+CREATE TABLE diaries (
+id INT PRIMARY KEY AUTO_INCREMENT,
+title TEXT,
+created_at TIMESTAMP,
+updated_at TIMESTAMP,
+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` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+  `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+  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", "2012-01-29 21:51:02");
+INSERT INTO diaries (title, created_at, updated_at)
+VALUES ("rainy day", "2012-01-30 01:23:45", "2012-01-30 01:23:46");
+INSERT INTO diaries (title, created_at, updated_at)
+VALUES ("cloudy day", "2012-01-31 08:32:10", "2012-01-31 08:32:11");
+SELECT * FROM diaries;
+id	title	created_at	updated_at
+1	clear day	2012-01-29 21:51:01	2012-01-29 21:51:02
+2	rainy day	2012-01-30 01:23:45	2012-01-30 01:23:46
+3	cloudy day	2012-01-31 08:32:10	2012-01-31 08:32:11
+SELECT * FROM diaries
+WHERE updated_at BETWEEN "2012-01-29 00:00:00" AND "2012-01-31 00:00:00";
+id	title	created_at	updated_at
+1	clear day	2012-01-29 21:51:01	2012-01-29 21:51:02
+2	rainy day	2012-01-30 01:23:45	2012-01-30 01:23:46
+DROP TABLE diaries;

  Added: test/sql/suite/mroonga_storage/t/column_timestamp.test (+46 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/t/column_timestamp.test    2012-01-29 22:10:57 +0900 (a0dcbff)
@@ -0,0 +1,46 @@
+# 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 diaries;
+--enable_warnings
+
+CREATE TABLE diaries (
+  id INT PRIMARY KEY AUTO_INCREMENT,
+  title TEXT,
+  created_at TIMESTAMP,
+  updated_at TIMESTAMP,
+  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", "2012-01-29 21:51:02");
+INSERT INTO diaries (title, created_at, updated_at)
+       VALUES ("rainy day", "2012-01-30 01:23:45", "2012-01-30 01:23:46");
+INSERT INTO diaries (title, created_at, updated_at)
+       VALUES ("cloudy day", "2012-01-31 08:32:10", "2012-01-31 08:32:11");
+
+SELECT * FROM diaries;
+
+SELECT * FROM diaries
+         WHERE updated_at BETWEEN "2012-01-29 00:00:00" AND "2012-01-31 00:00:00";
+
+DROP TABLE diaries;
+
+--source include/have_mroonga_deinit.inc




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