~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/timestamp.cc

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

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
 
                                 TableShare *share,
 
80
                                 TABLE_SHARE *share,
88
81
                                 const CHARSET_INFO * const cs)
89
 
  :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)
 
82
  :Field_str(ptr_arg, MAX_DATETIME_WIDTH, null_ptr_arg, null_bit_arg,
 
83
             unireg_check_arg, field_name_arg, cs)
95
84
{
96
85
  /* For 4.0 MYD and 4.0 InnoDB compatibility */
97
86
  flags|= UNSIGNED_FLAG;
98
 
  unireg_check= unireg_check_arg;
99
 
  if (! share->timestamp_field && unireg_check != NONE)
 
87
  if (!share->timestamp_field && unireg_check != NONE)
100
88
  {
101
89
    /* This timestamp has auto-update */
102
90
    share->timestamp_field= this;
109
97
Field_timestamp::Field_timestamp(bool maybe_null_arg,
110
98
                                 const char *field_name_arg,
111
99
                                 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)
 
100
  :Field_str((unsigned char*) 0, MAX_DATETIME_WIDTH,
 
101
             maybe_null_arg ? (unsigned char*) "": 0, 0,
 
102
             NONE, field_name_arg, cs)
118
103
{
119
104
  /* For 4.0 MYD and 4.0 InnoDB compatibility */
120
105
  flags|= UNSIGNED_FLAG;
121
 
  if (unireg_check != TIMESTAMP_DN_FIELD)
122
 
    flags|= ON_UPDATE_NOW_FLAG;
 
106
    if (unireg_check != TIMESTAMP_DN_FIELD)
 
107
      flags|= ON_UPDATE_NOW_FLAG;
123
108
}
124
109
 
125
110
/**
160
145
                           uint32_t len,
161
146
                           const CHARSET_INFO * const )
162
147
{
163
 
  Timestamp temporal;
164
 
 
165
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
 
148
  drizzled::Timestamp temporal;
166
149
 
167
150
  if (! temporal.from_string(from, (size_t) len))
168
151
  {
179
162
 
180
163
int Field_timestamp::store(double from)
181
164
{
182
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
183
 
 
184
165
  if (from < 0 || from > 99991231235959.0)
185
166
  {
186
167
    /* Convert the double to a string using stringstream */
197
178
 
198
179
int Field_timestamp::store(int64_t from, bool)
199
180
{
200
 
  ASSERT_COLUMN_MARKED_FOR_WRITE;
201
 
 
202
181
  /* 
203
182
   * Try to create a DateTime from the supplied integer.  Throw an error
204
183
   * if unable to create a valid DateTime.  
205
184
   */
206
 
  Timestamp temporal;
 
185
  drizzled::Timestamp temporal;
207
186
  if (! temporal.from_int64_t(from))
208
187
  {
209
188
    /* Convert the integer to a string using stringstream */
231
210
{
232
211
  uint32_t temp;
233
212
 
234
 
  ASSERT_COLUMN_MARKED_FOR_READ;
235
 
 
236
213
#ifdef WORDS_BIGENDIAN
237
214
  if (table && table->s->db_low_byte_first)
238
215
    temp= uint4korr(ptr);
240
217
#endif
241
218
    longget(temp, ptr);
242
219
 
243
 
  Timestamp temporal;
 
220
  drizzled::Timestamp temporal;
244
221
  (void) temporal.from_time_t((time_t) temp);
245
222
 
246
223
  /* We must convert into a "timestamp-formatted integer" ... */
253
230
{
254
231
  uint32_t temp;
255
232
  char *to;
256
 
  int to_len= field_length + 1;
257
233
 
258
 
  val_buffer->alloc(to_len);
 
234
  val_buffer->alloc(field_length + 1);
259
235
  to= (char *) val_buffer->ptr();
260
236
 
261
237
#ifdef WORDS_BIGENDIAN
267
243
 
268
244
  val_buffer->set_charset(&my_charset_bin);     /* Safety */
269
245
 
270
 
  Timestamp temporal;
 
246
  drizzled::Timestamp temporal;
271
247
  (void) temporal.from_time_t((time_t) temp);
272
 
 
273
 
  int rlen;
274
 
  rlen= temporal.to_string(to, to_len);
275
 
  assert(rlen < to_len);
276
 
 
277
 
  val_buffer->length(rlen);
 
248
  size_t to_len;
 
249
 
 
250
  temporal.to_string(to, &to_len);
 
251
  val_buffer->length((uint32_t) to_len);
278
252
  return val_buffer;
279
253
}
280
254
 
291
265
  
292
266
  memset(ltime, 0, sizeof(*ltime));
293
267
 
294
 
  Timestamp temporal;
 
268
  drizzled::Timestamp temporal;
295
269
  (void) temporal.from_time_t((time_t) temp);
296
270
 
297
271
  /* @TODO Goodbye the below code when DRIZZLE_TIME is finally gone.. */
397
371
#endif
398
372
    longstore(ptr,(uint32_t) timestamp);
399
373
}
400
 
 
401
 
} /* namespace drizzled */