List:Commits« Previous MessageNext Message »
From:Martin Hansson Date:May 18 2011 12:15pm
Subject:bzr commit into mysql-trunk branch (martin.hansson:3100)
View as plain text  
#At file:///data0/martin/bzrroot/bug11746628/mysql-trunk-to-bar/ based on revid:tor.didriksen@stripped

 3100 Martin Hansson	2011-05-18
      Preliminary refactoring patch for set_time().

    modified:
      sql/field.cc
      sql/item_timefunc.cc
      sql/item_timefunc.h
=== modified file 'sql/field.cc'
--- a/sql/field.cc	2011-05-12 12:50:11 +0000
+++ b/sql/field.cc	2011-05-18 12:15:35 +0000
@@ -5032,10 +5032,7 @@ void Field_timestamp::sql_type(String &r
 
 void Field_timestamp::set_time()
 {
-  THD *thd= table ? table->in_use : current_thd;
-  long tmp= (long) thd->query_start();
-  set_notnull();
-  store_timestamp(tmp);
+  Item_func_now_local::store_in(this);  
 }
 
 /****************************************************************************

=== modified file 'sql/item_timefunc.cc'
--- a/sql/item_timefunc.cc	2011-05-18 07:07:52 +0000
+++ b/sql/item_timefunc.cc	2011-05-18 12:15:35 +0000
@@ -1727,15 +1727,59 @@ void Item_func_now::fix_length_and_dec()
 
 
 /**
+   Stores the current time as defined by
+   Item_func_now_local::get_query_start_time() in the field.
+
+   @see Item_func_now_local::get_query_start_time()
+ */
+void Item_func_now_local::store_in(Field *field)
+{
+  THD *thd= field->table != NULL ? field->table->in_use : current_thd;
+  /* 
+     Optimization for the case when the field's storage format is the same as
+     THD::query_start().
+  */
+  if (field->type() == MYSQL_TYPE_TIMESTAMP)
+  {
+    long timestamp= (long) thd->query_start();
+    field->set_notnull();
+    static_cast<Field_timestamp*>(field)->store_timestamp(timestamp);
+    return;
+  }
+  MYSQL_TIME now_time;
+  get_query_start_time(&now_time);
+  field->set_notnull();
+  const int error= field->store_time(&now_time, MYSQL_TIMESTAMP_DATETIME);
+  DBUG_ASSERT(error == 0);
+}
+
+
+/**
+   The start time of the current query in the session's current time zone.
+
+   The current session is asked for the start time of the current query, the
+   time is then converted to the current time zone.
+
+   @note It is unclear exactly what 'start time' is since there is no
+   documentation.
+
+   @param[out] now_time Where the result is stored.
+ */
+void Item_func_now_local::get_query_start_time(MYSQL_TIME *now_time)
+{
+  THD *thd= current_thd;
+  my_time_t query_start= static_cast<my_time_t>(thd->query_start());
+  thd->variables.time_zone->gmt_sec_to_TIME(now_time, query_start);
+  thd->time_zone_used= true;
+}
+
+/**
     Converts current time in my_time_t to MYSQL_TIME represenatation for local
     time zone. Defines time zone (local) used for whole NOW function.
 */
 void Item_func_now_local::store_now_in_TIME(MYSQL_TIME *now_time)
 {
-  THD *thd= current_thd;
-  thd->variables.time_zone->gmt_sec_to_TIME(now_time, 
-                                             (my_time_t)thd->query_start());
-  thd->time_zone_used= 1;
+  get_query_start_time(now_time);
 }
 
 

=== modified file 'sql/item_timefunc.h'
--- a/sql/item_timefunc.h	2011-03-30 07:42:03 +0000
+++ b/sql/item_timefunc.h	2011-05-18 12:15:35 +0000
@@ -627,6 +627,8 @@ public:
 class Item_func_now_local :public Item_func_now
 {
 public:
+  static void store_in(Field *field);
+  static void get_query_start_time(MYSQL_TIME *now_time);
   Item_func_now_local() :Item_func_now() {}
   Item_func_now_local(Item *a) :Item_func_now(a) {}
   const char *func_name() const { return "now"; }


Attachment: [text/bzr-bundle] bzr/martin.hansson@oracle.com-20110518121535-p11x0xvxwdbvizy1.bundle
Thread
bzr commit into mysql-trunk branch (martin.hansson:3100) Martin Hansson19 May