~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/time/now.cc

  • Committer: Stewart Smith
  • Author(s): Marko Mäkelä, Stewart Smith
  • Date: 2010-11-17 05:52:09 UTC
  • mto: (2021.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1971.
  • Revision ID: stewart@flamingspork.com-20101117055209-69m035q6h7e1txrc
Merge Revision revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg from MySQL InnoDB

Original revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg

Original Authors: Marko Mkel <marko.makela@oracle.com>
Original commit message:
Bug#52199 utf32: mbminlen=4, mbmaxlen=4, type->mbminlen=0, type->mbmaxlen=4

Merge and adjust a forgotten change to fix this bug.
rb://393 approved by Jimmy Yang
  ------------------------------------------------------------------------
  r3794 | marko | 2009-01-07 14:14:53 +0000 (Wed, 07 Jan 2009) | 18 lines

  branches/6.0: Allow the minimum length of a multi-byte character to be
  up to 4 bytes. (Bug #35391)

  dtype_t, dict_col_t: Replace mbminlen:2, mbmaxlen:3 with mbminmaxlen:5.
  In this way, the 5 bits can hold two values of 0..4, and the storage size
  of the fields will not cross the 64-bit boundary.  Encode the values as
  DATA_MBMAX * mbmaxlen + mbminlen.  Define the auxiliary macros
  DB_MBMINLEN(mbminmaxlen), DB_MBMAXLEN(mbminmaxlen), and
  DB_MINMAXLEN(mbminlen, mbmaxlen).

  Try to trim and pad UTF-16 and UTF-32 with spaces as appropriate.

  Alexander Barkov suggested the use of cs->cset->fill(cs, buff, len, 0x20).
  ha_innobase::store_key_val_for_row() now does that, but the added function
  row_mysql_pad_col() does not, because it doesn't have the MySQL TABLE object.

  rb://49 approved by Heikki Tuuri
  ------------------------------------------------------------------------

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
31
31
{
32
32
  assert(fixed == 1);
33
33
  str_value.set(buff, buff_length, &my_charset_bin);
34
 
 
35
34
  return &str_value;
36
35
}
37
36
 
41
40
  decimals= DATETIME_DEC;
42
41
  collation.set(&my_charset_bin);
43
42
  
44
 
  ltime.reset();
45
 
 
46
 
  ltime.time_type= type::DRIZZLE_TIMESTAMP_DATETIME;
47
 
 
48
 
  store_now_in_TIME(ltime);
49
 
 
50
 
  ltime.convert(value);
51
 
 
52
 
  size_t length= type::Time::MAX_STRING_LENGTH;
53
 
  ltime.convert(buff, length);
54
 
 
55
 
  max_length= buff_length= length;
 
43
  memset(&ltime, 0, sizeof(DRIZZLE_TIME));
 
44
 
 
45
  ltime.time_type= DRIZZLE_TIMESTAMP_DATETIME;
 
46
 
 
47
  store_now_in_TIME(&ltime);
 
48
  value= (int64_t) TIME_to_uint64_t_datetime(&ltime);
 
49
 
 
50
  buff_length= (uint) my_datetime_to_str(&ltime, buff);
 
51
  max_length= buff_length;
56
52
}
57
53
 
58
54
/**
59
 
    Converts current time in time_t to type::Time represenatation for local
 
55
    Converts current time in time_t to DRIZZLE_TIME represenatation for local
60
56
    time zone. Defines time zone (local) used for whole NOW function.
61
57
*/
62
 
void Item_func_now_local::store_now_in_TIME(type::Time &now_time)
 
58
void Item_func_now_local::store_now_in_TIME(DRIZZLE_TIME *now_time)
63
59
{
64
60
  Session *session= current_session;
65
 
  uint32_t fractional_seconds= 0;
66
 
  time_t tmp= session->getCurrentTimestampEpoch(fractional_seconds);
67
 
 
68
 
#if 0
69
 
  now_time->store(tmp, fractional_seconds, true);
70
 
#endif
71
 
  now_time.store(tmp, fractional_seconds);
 
61
  time_t tmp= session->query_start();
 
62
 
 
63
  (void) cached_temporal.from_time_t(tmp);
 
64
 
 
65
  now_time->year= cached_temporal.years();
 
66
  now_time->month= cached_temporal.months();
 
67
  now_time->day= cached_temporal.days();
 
68
  now_time->hour= cached_temporal.hours();
 
69
  now_time->minute= cached_temporal.minutes();
 
70
  now_time->second= cached_temporal.seconds();
72
71
}
73
72
 
74
73
 
75
74
/**
76
 
    Converts current time in time_t to type::Time represenatation for UTC
 
75
    Converts current time in time_t to DRIZZLE_TIME represenatation for UTC
77
76
    time zone. Defines time zone (UTC) used for whole UTC_TIMESTAMP function.
78
77
*/
79
 
void Item_func_now_utc::store_now_in_TIME(type::Time &now_time)
 
78
void Item_func_now_utc::store_now_in_TIME(DRIZZLE_TIME *now_time)
80
79
{
81
80
  Session *session= current_session;
82
 
  uint32_t fractional_seconds= 0;
83
 
  time_t tmp= session->getCurrentTimestampEpoch(fractional_seconds);
84
 
 
85
 
  now_time.store(tmp, fractional_seconds);
 
81
  time_t tmp= session->query_start();
 
82
 
 
83
  (void) cached_temporal.from_time_t(tmp);
 
84
 
 
85
  now_time->year= cached_temporal.years();
 
86
  now_time->month= cached_temporal.months();
 
87
  now_time->day= cached_temporal.days();
 
88
  now_time->hour= cached_temporal.hours();
 
89
  now_time->minute= cached_temporal.minutes();
 
90
  now_time->second= cached_temporal.seconds();
86
91
}
87
92
 
88
93
bool Item_func_now::get_temporal(DateTime &to)
91
96
  return true;
92
97
}
93
98
 
94
 
bool Item_func_now::get_date(type::Time &res, uint32_t )
 
99
bool Item_func_now::get_date(DRIZZLE_TIME *res,
 
100
                             uint32_t )
95
101
{
96
 
  res= ltime;
 
102
  *res= ltime;
97
103
  return 0;
98
104
}
99
105
 
101
107
int Item_func_now::save_in_field(Field *to, bool )
102
108
{
103
109
  to->set_notnull();
104
 
  return to->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
 
110
  return to->store_time(&ltime, DRIZZLE_TIMESTAMP_DATETIME);
105
111
}
106
112
 
107
113
} /* namespace drizzled */