~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/timestamp.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-07-08 04:26:02 UTC
  • mto: (1089.3.4 merge)
  • mto: This revision was merged to the branch mainline in revision 1092.
  • Revision ID: osullivan.padraig@gmail.com-20090708042602-x4hmf9ny8dcpvb22
Replaced an instance where a uint8_t type was being used to hold a
collection of flags. Converted it to a std::bitset<2> instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
 
22
 
#include "config.h"
 
22
#include <drizzled/server_includes.h>
23
23
#include <drizzled/field/timestamp.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/tztime.h>
26
26
#include <drizzled/table.h>
27
27
#include <drizzled/session.h>
28
28
 
29
 
#include <math.h>
30
 
 
31
 
#include <sstream>
32
 
 
33
29
#include "drizzled/temporal.h"
34
30
 
35
 
namespace drizzled
36
 
{
37
31
 
38
32
/**
39
33
  TIMESTAMP type holds datetime values in range from 1970-01-01 00:00:01 UTC to
79
73
  exception is different behavior of old/new timestamps during ALTER TABLE.
80
74
 */
81
75
Field_timestamp::Field_timestamp(unsigned char *ptr_arg,
82
 
                                 uint32_t,
83
 
                                 unsigned char *null_ptr_arg,
84
 
                                 unsigned char null_bit_arg,
 
76
                                 uint32_t ,
 
77
                                 unsigned char *null_ptr_arg, unsigned char null_bit_arg,
85
78
                                 enum utype unireg_check_arg,
86
79
                                 const char *field_name_arg,
87
80
                                 TableShare *share,
88
81
                                 const CHARSET_INFO * const cs)
89
82
  :Field_str(ptr_arg,
90
 
             DateTime::MAX_STRING_LENGTH - 1 /* no \0 */,
91
 
             null_ptr_arg,
92
 
             null_bit_arg,
93
 
             field_name_arg,
94
 
             cs)
 
83
             drizzled::DateTime::MAX_STRING_LENGTH - 1 /* no \0 */,
 
84
             null_ptr_arg, null_bit_arg,
 
85
             unireg_check_arg, field_name_arg, cs)
95
86
{
96
87
  /* For 4.0 MYD and 4.0 InnoDB compatibility */
97
88
  flags|= UNSIGNED_FLAG;
98
 
  unireg_check= unireg_check_arg;
99
 
  if (! share->timestamp_field && unireg_check != NONE)
 
89
  if (!share->timestamp_field && unireg_check != NONE)
100
90
  {
101
91
    /* This timestamp has auto-update */
102
92
    share->timestamp_field= this;
109
99
Field_timestamp::Field_timestamp(bool maybe_null_arg,
110
100
                                 const char *field_name_arg,
111
101
                                 const CHARSET_INFO * const cs)
112
 
  :Field_str((unsigned char*) NULL,
113
 
             DateTime::MAX_STRING_LENGTH - 1 /* no \0 */,
114
 
             maybe_null_arg ? (unsigned char*) "": 0,
115
 
             0,
116
 
             field_name_arg,
117
 
             cs)
 
102
  :Field_str((unsigned char*) 0,
 
103
             drizzled::DateTime::MAX_STRING_LENGTH - 1 /* no \0 */,
 
104
             maybe_null_arg ? (unsigned char*) "": 0, 0,
 
105
             NONE, field_name_arg, cs)
118
106
{
119
107
  /* For 4.0 MYD and 4.0 InnoDB compatibility */
120
108
  flags|= UNSIGNED_FLAG;
121
 
  if (unireg_check != TIMESTAMP_DN_FIELD)
122
 
    flags|= ON_UPDATE_NOW_FLAG;
 
109
    if (unireg_check != TIMESTAMP_DN_FIELD)
 
110
      flags|= ON_UPDATE_NOW_FLAG;
123
111
}
124
112
 
125
113
/**
160
148
                           uint32_t len,
161
149
                           const CHARSET_INFO * const )
162
150
{
163
 
  Timestamp temporal;
164
 
 
165
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
 
151
  drizzled::Timestamp temporal;
166
152
 
167
153
  if (! temporal.from_string(from, (size_t) len))
168
154
  {
179
165
 
180
166
int Field_timestamp::store(double from)
181
167
{
182
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
183
 
 
184
168
  if (from < 0 || from > 99991231235959.0)
185
169
  {
186
170
    /* Convert the double to a string using stringstream */
197
181
 
198
182
int Field_timestamp::store(int64_t from, bool)
199
183
{
200
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
201
 
 
202
184
  /* 
203
185
   * Try to create a DateTime from the supplied integer.  Throw an error
204
186
   * if unable to create a valid DateTime.  
205
187
   */
206
 
  Timestamp temporal;
 
188
  drizzled::Timestamp temporal;
207
189
  if (! temporal.from_int64_t(from))
208
190
  {
209
191
    /* Convert the integer to a string using stringstream */
231
213
{
232
214
  uint32_t temp;
233
215
 
234
 
  ASSERT_COLUMN_MARKED_FOR_READ;
235
 
 
236
216
#ifdef WORDS_BIGENDIAN
237
217
  if (table && table->s->db_low_byte_first)
238
218
    temp= uint4korr(ptr);
240
220
#endif
241
221
    longget(temp, ptr);
242
222
 
243
 
  Timestamp temporal;
 
223
  drizzled::Timestamp temporal;
244
224
  (void) temporal.from_time_t((time_t) temp);
245
225
 
246
226
  /* We must convert into a "timestamp-formatted integer" ... */
267
247
 
268
248
  val_buffer->set_charset(&my_charset_bin);     /* Safety */
269
249
 
270
 
  Timestamp temporal;
 
250
  drizzled::Timestamp temporal;
271
251
  (void) temporal.from_time_t((time_t) temp);
272
252
 
273
253
  int rlen;
291
271
  
292
272
  memset(ltime, 0, sizeof(*ltime));
293
273
 
294
 
  Timestamp temporal;
 
274
  drizzled::Timestamp temporal;
295
275
  (void) temporal.from_time_t((time_t) temp);
296
276
 
297
277
  /* @TODO Goodbye the below code when DRIZZLE_TIME is finally gone.. */
397
377
#endif
398
378
    longstore(ptr,(uint32_t) timestamp);
399
379
}
400
 
 
401
 
} /* namespace drizzled */