~drizzle-trunk/drizzle/development

520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
520.4.14 by Monty Taylor
Removed korr.h and tztime.h from common_includes. Also removed the HAVE_DTRACE block and stuck it in autoconf.
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
1 by brian
clean slate
19
20
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
21
#include "config.h"
1502.3.1 by iwamatsu at nigauri
Add cstdio include to files needing it. Fixes the build on some debian
22
#include <cstdio>
1237.9.4 by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file.
23
#include "drizzled/tzfile.h"
24
#include "drizzled/tztime.h"
25
#include "drizzled/gettext.h"
26
#include "drizzled/session.h"
1237.9.8 by Monty Taylor
Fixed solaris build.
27
#include "drizzled/time_functions.h"
1 by brian
clean slate
28
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
29
namespace drizzled
30
{
31
1436.1.3 by Tim Martin
More Doxygen commenting
32
/**
33
 * String with names of SYSTEM time zone.
34
 */
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
35
static const String tz_SYSTEM_name("SYSTEM", 6, &my_charset_utf8_general_ci);
1 by brian
clean slate
36
37
1436.1.3 by Tim Martin
More Doxygen commenting
38
/**
39
 * Instance of this class represents local time zone used on this system
40
 * (specified by TZ environment variable or via any other system mechanism).
41
 * It uses system functions (localtime_r, my_system_gmt_sec) for conversion
42
 * and is always available. Because of this it is used by default - if there
43
 * were no explicit time zone specified. On the other hand because of this
44
 * conversion methods provided by this class is significantly slower and
45
 * possibly less multi-threaded-friendly than corresponding Time_zone_db
46
 * methods so the latter should be preffered there it is possible.
47
 */
1 by brian
clean slate
48
class Time_zone_system : public Time_zone
49
{
50
public:
51
  Time_zone_system() {}                       /* Remove gcc warning */
726.1.1 by Toru Maesaka
Use time_t instead of my_time_t which should be safe (as in wide enough) on POSIX compliant systems.
52
  virtual time_t TIME_to_gmt_sec(const DRIZZLE_TIME *t,
93 by Brian Aker
Convert tztime.cc to bool from my_bool.
53
                                    bool *in_dst_time_gap) const;
726.1.1 by Toru Maesaka
Use time_t instead of my_time_t which should be safe (as in wide enough) on POSIX compliant systems.
54
  virtual void gmt_sec_to_TIME(DRIZZLE_TIME *tmp, time_t t) const;
1 by brian
clean slate
55
  virtual const String * get_name() const;
56
};
57
58
1436.1.3 by Tim Martin
More Doxygen commenting
59
/**
60
 * @brief
61
 * Converts local time in system time zone in DRIZZLE_TIME representation
62
 * to its time_t representation.
63
 *
64
 * @details
65
 * This method uses system function (localtime_r()) for conversion
66
 * local time in system time zone in DRIZZLE_TIME structure to its time_t
67
 * representation. Unlike the same function for Time_zone_db class
68
 * it it won't handle unnormalized input properly. Still it will
69
 * return lowest possible time_t in case of ambiguity or if we
70
 * provide time corresponding to the time-gap.
71
 *
72
 * You should call init_time() function before using this function.
73
 *
74
 * @param   t               pointer to DRIZZLE_TIME structure with local time in
75
 *                          broken-down representation.
76
 * @param   in_dst_time_gap pointer to bool which is set to true if datetime
77
 *                          value passed doesn't really exist (i.e. falls into
78
 *                          spring time-gap) and is not touched otherwise.
79
 *
80
 * @return
81
 * Corresponding time_t value or 0 in case of error
82
 */
726.1.1 by Toru Maesaka
Use time_t instead of my_time_t which should be safe (as in wide enough) on POSIX compliant systems.
83
time_t
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
84
Time_zone_system::TIME_to_gmt_sec(const DRIZZLE_TIME *t, bool *in_dst_time_gap) const
1 by brian
clean slate
85
{
86
  long not_used;
87
  return my_system_gmt_sec(t, &not_used, in_dst_time_gap);
88
}
89
90
1436.1.3 by Tim Martin
More Doxygen commenting
91
/**
92
 * @brief
93
 * Converts time from UTC seconds since Epoch (time_t) representation
94
 * to system local time zone broken-down representation.
95
 *
96
 * @param    tmp   pointer to DRIZZLE_TIME structure to fill-in
97
 * @param    t     time_t value to be converted
98
 *
99
 * Note: We assume that value passed to this function will fit into time_t range
100
 * supported by localtime_r. This conversion is putting restriction on
101
 * TIMESTAMP range in MySQL. If we can get rid of SYSTEM time zone at least
102
 * for interaction with client then we can extend TIMESTAMP range down to
103
 * the 1902 easily.
104
 */
1 by brian
clean slate
105
void
726.1.1 by Toru Maesaka
Use time_t instead of my_time_t which should be safe (as in wide enough) on POSIX compliant systems.
106
Time_zone_system::gmt_sec_to_TIME(DRIZZLE_TIME *tmp, time_t t) const
1 by brian
clean slate
107
{
108
  struct tm tmp_tm;
109
  time_t tmp_t= (time_t)t;
110
111
  localtime_r(&tmp_t, &tmp_tm);
112
  localtime_to_TIME(tmp, &tmp_tm);
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
113
  tmp->time_type= DRIZZLE_TIMESTAMP_DATETIME;
1 by brian
clean slate
114
}
115
116
1436.1.3 by Tim Martin
More Doxygen commenting
117
/**
118
 * @brief
119
 * Get name of time zone
120
 *
121
 * @return
122
 * Name of time zone as String
123
 */
1 by brian
clean slate
124
const String *
125
Time_zone_system::get_name() const
126
{
127
  return &tz_SYSTEM_name;
128
}
129
130
static Time_zone_system tz_SYSTEM;
131
132
Time_zone *my_tz_SYSTEM= &tz_SYSTEM;
133
134
1436.1.3 by Tim Martin
More Doxygen commenting
135
/**
136
 * @brief
137
 * Initialize time zone support infrastructure.
138
 *
139
 * @details
140
 * This function will init memory structures needed for time zone support,
141
 * it will register mandatory SYSTEM time zone in them. It will try to open
142
 * mysql.time_zone* tables and load information about default time zone and
143
 * information which further will be shared among all time zones loaded.
144
 * If system tables with time zone descriptions don't exist it won't fail
145
 * (unless default_tzname is time zone from tables). If bootstrap parameter
146
 * is true then this routine assumes that we are in bootstrap mode and won't
147
 * load time zone descriptions unless someone specifies default time zone
148
 * which is supposedly stored in those tables.
149
 * It'll also set default time zone if it is specified.
150
 *
151
 * @param   session            current thread object
152
 * @param   default_tzname     default time zone or 0 if none.
153
 * @param   bootstrap          indicates whenever we are in bootstrap mode
154
 *
155
 * @return
156
 *  0 - ok
157
 *  1 - Error
158
 */
53.1.1 by Brian Aker
First pass through removing timezone. Left infrastructure for possible call
159
bool
520.1.22 by Brian Aker
Second pass of thd cleanup
160
my_tz_init(Session *session, const char *default_tzname)
1 by brian
clean slate
161
{
162
  if (default_tzname)
163
  {
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
164
    String tmp_tzname2(default_tzname, &my_charset_utf8_general_ci);
1 by brian
clean slate
165
    /*
166
      Time zone tables may be open here, and my_tz_find() may open
167
      most of them once more, but this is OK for system tables open
168
      for READ.
169
    */
520.1.22 by Brian Aker
Second pass of thd cleanup
170
    if (!(global_system_variables.time_zone= my_tz_find(session, &tmp_tzname2)))
1 by brian
clean slate
171
    {
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
172
      errmsg_printf(ERRMSG_LVL_ERROR,
173
                    _("Fatal error: Illegal or unknown default time zone '%s'"),
174
                    default_tzname);
53.1.1 by Brian Aker
First pass through removing timezone. Left infrastructure for possible call
175
      return true;
1 by brian
clean slate
176
    }
177
  }
178
53.1.1 by Brian Aker
First pass through removing timezone. Left infrastructure for possible call
179
  return false;
1 by brian
clean slate
180
}
181
1436.1.3 by Tim Martin
More Doxygen commenting
182
/**
183
 * @brief
184
 * Get Time_zone object for specified time zone.
185
 *
186
 * @todo
187
 * Not implemented yet. This needs to hook into some sort of OS system call.
188
 */
1 by brian
clean slate
189
Time_zone *
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
190
my_tz_find(Session *,
191
           const String *)
1 by brian
clean slate
192
{
53.1.1 by Brian Aker
First pass through removing timezone. Left infrastructure for possible call
193
  return NULL;
194
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
195
196
} /* namespace drizzled */