~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 */
2104.2.8 by Brian Aker
Merge in reference from pointer.
52
  virtual type::Time::epoch_t TIME_to_gmt_sec(const type::Time &t,
2088.8.12 by Brian Aker
Remove time_t reference.
53
                                              bool *in_dst_time_gap) const;
2104.2.8 by Brian Aker
Merge in reference from pointer.
54
  virtual void gmt_sec_to_TIME(type::Time &tmp, type::Time::epoch_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
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
61
 * Converts local time in system time zone in type::Time representation
2088.8.12 by Brian Aker
Remove time_t reference.
62
 * to its type::Time::epoch_t representation.
1436.1.3 by Tim Martin
More Doxygen commenting
63
 *
64
 * @details
65
 * This method uses system function (localtime_r()) for conversion
2088.8.12 by Brian Aker
Remove time_t reference.
66
 * local time in system time zone in type::Time structure to its type::Time::epoch_t
1436.1.3 by Tim Martin
More Doxygen commenting
67
 * representation. Unlike the same function for Time_zone_db class
68
 * it it won't handle unnormalized input properly. Still it will
2088.8.12 by Brian Aker
Remove time_t reference.
69
 * return lowest possible type::Time::epoch_t in case of ambiguity or if we
1436.1.3 by Tim Martin
More Doxygen commenting
70
 * provide time corresponding to the time-gap.
71
 *
72
 * You should call init_time() function before using this function.
73
 *
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
74
 * @param   t               pointer to type::Time structure with local time in
1436.1.3 by Tim Martin
More Doxygen commenting
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
2088.8.12 by Brian Aker
Remove time_t reference.
81
 * Corresponding type::Time::epoch_t value or 0 in case of error
1436.1.3 by Tim Martin
More Doxygen commenting
82
 */
2088.8.5 by Brian Aker
Remove duplicate code around store() for type::Time
83
type::Time::epoch_t
2104.2.8 by Brian Aker
Merge in reference from pointer.
84
Time_zone_system::TIME_to_gmt_sec(const type::Time &t, bool *in_dst_time_gap) const
1 by brian
clean slate
85
{
86
  long not_used;
2104.2.4 by Brian Aker
Additional convert.
87
  type::Time::epoch_t tmp;
2104.2.8 by Brian Aker
Merge in reference from pointer.
88
  t.convert(tmp, &not_used, in_dst_time_gap);
2104.2.4 by Brian Aker
Additional convert.
89
  return tmp;
1 by brian
clean slate
90
}
91
92
1436.1.3 by Tim Martin
More Doxygen commenting
93
/**
94
 * @brief
2088.8.12 by Brian Aker
Remove time_t reference.
95
 * Converts time from UTC seconds since Epoch (type::Time::epoch_t) representation
1436.1.3 by Tim Martin
More Doxygen commenting
96
 * to system local time zone broken-down representation.
97
 *
2030.1.5 by Brian Aker
Update for moving DRIZZLE_TIME to type::Time
98
 * @param    tmp   pointer to type::Time structure to fill-in
2088.8.12 by Brian Aker
Remove time_t reference.
99
 * @param    t     type::Time::epoch_t value to be converted
1436.1.3 by Tim Martin
More Doxygen commenting
100
 *
2088.8.12 by Brian Aker
Remove time_t reference.
101
 * Note: We assume that value passed to this function will fit into type::Time::epoch_t range
1436.1.3 by Tim Martin
More Doxygen commenting
102
 * supported by localtime_r. This conversion is putting restriction on
103
 * TIMESTAMP range in MySQL. If we can get rid of SYSTEM time zone at least
104
 * for interaction with client then we can extend TIMESTAMP range down to
105
 * the 1902 easily.
106
 */
1 by brian
clean slate
107
void
2104.2.8 by Brian Aker
Merge in reference from pointer.
108
Time_zone_system::gmt_sec_to_TIME(type::Time &tmp, type::Time::epoch_t t) const
1 by brian
clean slate
109
{
2104.2.8 by Brian Aker
Merge in reference from pointer.
110
  tmp.store(t);
1 by brian
clean slate
111
}
112
113
1436.1.3 by Tim Martin
More Doxygen commenting
114
/**
115
 * @brief
116
 * Get name of time zone
117
 *
118
 * @return
119
 * Name of time zone as String
120
 */
1 by brian
clean slate
121
const String *
122
Time_zone_system::get_name() const
123
{
124
  return &tz_SYSTEM_name;
125
}
126
127
static Time_zone_system tz_SYSTEM;
128
129
Time_zone *my_tz_SYSTEM= &tz_SYSTEM;
130
131
1436.1.3 by Tim Martin
More Doxygen commenting
132
/**
133
 * @brief
134
 * Initialize time zone support infrastructure.
135
 *
136
 * @details
137
 * This function will init memory structures needed for time zone support,
138
 * it will register mandatory SYSTEM time zone in them. It will try to open
139
 * mysql.time_zone* tables and load information about default time zone and
140
 * information which further will be shared among all time zones loaded.
141
 * If system tables with time zone descriptions don't exist it won't fail
142
 * (unless default_tzname is time zone from tables). If bootstrap parameter
143
 * is true then this routine assumes that we are in bootstrap mode and won't
144
 * load time zone descriptions unless someone specifies default time zone
145
 * which is supposedly stored in those tables.
146
 * It'll also set default time zone if it is specified.
147
 *
148
 * @param   session            current thread object
149
 * @param   default_tzname     default time zone or 0 if none.
150
 * @param   bootstrap          indicates whenever we are in bootstrap mode
151
 *
152
 * @return
153
 *  0 - ok
154
 *  1 - Error
155
 */
53.1.1 by Brian Aker
First pass through removing timezone. Left infrastructure for possible call
156
bool
520.1.22 by Brian Aker
Second pass of thd cleanup
157
my_tz_init(Session *session, const char *default_tzname)
1 by brian
clean slate
158
{
159
  if (default_tzname)
160
  {
383.1.12 by Brian Aker
Much closer toward UTF8 being around all the time...
161
    String tmp_tzname2(default_tzname, &my_charset_utf8_general_ci);
1 by brian
clean slate
162
    /*
163
      Time zone tables may be open here, and my_tz_find() may open
164
      most of them once more, but this is OK for system tables open
165
      for READ.
166
    */
520.1.22 by Brian Aker
Second pass of thd cleanup
167
    if (!(global_system_variables.time_zone= my_tz_find(session, &tmp_tzname2)))
1 by brian
clean slate
168
    {
2126.3.3 by Brian Aker
Merge in error message rework. Many error messages are fixed in this patch.
169
      errmsg_printf(error::ERROR,
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
170
                    _("Fatal error: Illegal or unknown default time zone '%s'"),
171
                    default_tzname);
53.1.1 by Brian Aker
First pass through removing timezone. Left infrastructure for possible call
172
      return true;
1 by brian
clean slate
173
    }
174
  }
175
53.1.1 by Brian Aker
First pass through removing timezone. Left infrastructure for possible call
176
  return false;
1 by brian
clean slate
177
}
178
1436.1.3 by Tim Martin
More Doxygen commenting
179
/**
180
 * @brief
181
 * Get Time_zone object for specified time zone.
182
 *
183
 * @todo
184
 * Not implemented yet. This needs to hook into some sort of OS system call.
185
 */
1 by brian
clean slate
186
Time_zone *
779.1.27 by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files.
187
my_tz_find(Session *,
188
           const String *)
1 by brian
clean slate
189
{
53.1.1 by Brian Aker
First pass through removing timezone. Left infrastructure for possible call
190
  return NULL;
191
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
192
193
} /* namespace drizzled */