~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/timestamp.cc

  • Committer: Stewart Smith
  • Date: 2010-03-18 12:01:34 UTC
  • mto: (1666.2.3 build)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: stewart@flamingspork.com-20100318120134-45fdnsw8g3j6c7oy
move RAND() into a plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
 
21
 
21
22
#include "config.h"
22
 
#include <boost/lexical_cast.hpp>
23
23
#include <drizzled/field/timestamp.h>
24
24
#include <drizzled/error.h>
25
25
#include <drizzled/tztime.h>
96
96
  /* For 4.0 MYD and 4.0 InnoDB compatibility */
97
97
  flags|= UNSIGNED_FLAG;
98
98
  unireg_check= unireg_check_arg;
99
 
  if (! share->getTimestampField() && unireg_check != NONE)
 
99
  if (! share->timestamp_field && unireg_check != NONE)
100
100
  {
101
101
    /* This timestamp has auto-update */
102
 
    share->setTimestampField(this);
103
 
    flags|= FUNCTION_DEFAULT_FLAG;
 
102
    share->timestamp_field= this;
 
103
    flags|= TIMESTAMP_FLAG;
104
104
    if (unireg_check != TIMESTAMP_DN_FIELD)
105
105
      flags|= ON_UPDATE_NOW_FLAG;
106
106
  }
142
142
      function should be called only for first of them (i.e. the one
143
143
      having auto-set property).
144
144
    */
145
 
    assert(getTable()->timestamp_field == this);
 
145
    assert(table->timestamp_field == this);
146
146
    /* Fall-through */
147
147
  case TIMESTAMP_DNUN_FIELD:
148
148
    return TIMESTAMP_AUTO_SET_ON_BOTH;
187
187
    std::stringstream ss;
188
188
    std::string tmp;
189
189
    ss.precision(18); /* 18 places should be fine for error display of double input. */
190
 
    ss << from; 
191
 
    ss >> tmp;
 
190
    ss << from; ss >> tmp;
192
191
 
193
192
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
194
193
    return 2;
207
206
  Timestamp temporal;
208
207
  if (! temporal.from_int64_t(from))
209
208
  {
210
 
    /* Convert the integer to a string using boost::lexical_cast */
211
 
    std::string tmp(boost::lexical_cast<std::string>(from));
 
209
    /* Convert the integer to a string using stringstream */
 
210
    std::stringstream ss;
 
211
    std::string tmp;
 
212
    ss << from; ss >> tmp;
212
213
 
213
214
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
214
215
    return 2;
228
229
 
229
230
int64_t Field_timestamp::val_int(void)
230
231
{
231
 
  uint64_t temp;
 
232
  uint32_t temp;
232
233
 
233
234
  ASSERT_COLUMN_MARKED_FOR_READ;
234
235
 
235
236
#ifdef WORDS_BIGENDIAN
236
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
237
 
    temp= uint8korr(ptr);
 
237
  if (table && table->s->db_low_byte_first)
 
238
    temp= uint4korr(ptr);
238
239
  else
239
240
#endif
240
 
    int64_tget(temp, ptr);
 
241
    longget(temp, ptr);
241
242
 
242
243
  Timestamp temporal;
243
244
  (void) temporal.from_time_t((time_t) temp);
250
251
 
251
252
String *Field_timestamp::val_str(String *val_buffer, String *)
252
253
{
253
 
  uint64_t temp;
 
254
  uint32_t temp;
254
255
  char *to;
255
256
  int to_len= field_length + 1;
256
257
 
258
259
  to= (char *) val_buffer->ptr();
259
260
 
260
261
#ifdef WORDS_BIGENDIAN
261
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
262
 
    temp= uint8korr(ptr);
 
262
  if (table && table->s->db_low_byte_first)
 
263
    temp= uint4korr(ptr);
263
264
  else
264
265
#endif
265
 
    int64_tget(temp, ptr);
 
266
    longget(temp, ptr);
266
267
 
267
268
  val_buffer->set_charset(&my_charset_bin);     /* Safety */
268
269
 
279
280
 
280
281
bool Field_timestamp::get_date(DRIZZLE_TIME *ltime, uint32_t)
281
282
{
282
 
  uint64_t temp;
 
283
  uint32_t temp;
283
284
 
284
285
#ifdef WORDS_BIGENDIAN
285
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
286
 
    temp= uint8korr(ptr);
 
286
  if (table && table->s->db_low_byte_first)
 
287
    temp= uint4korr(ptr);
287
288
  else
288
289
#endif
289
 
    int64_tget(temp, ptr);
 
290
    longget(temp, ptr);
290
291
  
291
292
  memset(ltime, 0, sizeof(*ltime));
292
293
 
313
314
 
314
315
int Field_timestamp::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
315
316
{
316
 
  int64_t a,b;
 
317
  int32_t a,b;
317
318
#ifdef WORDS_BIGENDIAN
318
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
 
319
  if (table && table->s->db_low_byte_first)
319
320
  {
320
 
    a=sint8korr(a_ptr);
321
 
    b=sint8korr(b_ptr);
 
321
    a=sint4korr(a_ptr);
 
322
    b=sint4korr(b_ptr);
322
323
  }
323
324
  else
324
325
#endif
325
326
  {
326
 
    int64_tget(a, a_ptr);
327
 
    int64_tget(b, b_ptr);
 
327
  longget(a,a_ptr);
 
328
  longget(b,b_ptr);
328
329
  }
329
 
  return ((uint64_t) a < (uint64_t) b) ? -1 : ((uint64_t) a > (uint64_t) b) ? 1 : 0;
 
330
  return ((uint32_t) a < (uint32_t) b) ? -1 : ((uint32_t) a > (uint32_t) b) ? 1 : 0;
330
331
}
331
332
 
332
333
 
333
334
void Field_timestamp::sort_string(unsigned char *to,uint32_t )
334
335
{
335
336
#ifdef WORDS_BIGENDIAN
336
 
  if (!getTable() || !getTable()->getShare()->db_low_byte_first)
 
337
  if (!table || !table->s->db_low_byte_first)
337
338
  {
338
339
    to[0] = ptr[0];
339
340
    to[1] = ptr[1];
340
341
    to[2] = ptr[2];
341
342
    to[3] = ptr[3];
342
 
    to[4] = ptr[4];
343
 
    to[5] = ptr[5];
344
 
    to[6] = ptr[6];
345
 
    to[7] = ptr[7];
346
343
  }
347
344
  else
348
345
#endif
349
346
  {
350
 
    to[0] = ptr[7];
351
 
    to[1] = ptr[6];
352
 
    to[2] = ptr[5];
353
 
    to[3] = ptr[4];
354
 
    to[4] = ptr[3];
355
 
    to[5] = ptr[2];
356
 
    to[6] = ptr[1];
357
 
    to[7] = ptr[0];
 
347
    to[0] = ptr[3];
 
348
    to[1] = ptr[2];
 
349
    to[2] = ptr[1];
 
350
    to[3] = ptr[0];
358
351
  }
359
352
}
360
353
 
365
358
 
366
359
void Field_timestamp::set_time()
367
360
{
368
 
  Session *session= getTable() ? getTable()->in_use : current_session;
369
 
  time_t tmp= session->query_start();
 
361
  Session *session= table ? table->in_use : current_session;
 
362
  long tmp= (long) session->query_start();
370
363
  set_notnull();
371
364
  store_timestamp(tmp);
372
365
}
373
366
 
374
367
void Field_timestamp::set_default()
375
368
{
376
 
  if (getTable()->timestamp_field == this &&
 
369
  if (table->timestamp_field == this &&
377
370
      unireg_check != TIMESTAMP_UN_FIELD)
378
371
    set_time();
379
372
  else
385
378
  if ((*null_value= is_null()))
386
379
    return 0;
387
380
#ifdef WORDS_BIGENDIAN
388
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
389
 
    return sint8korr(ptr);
 
381
  if (table && table->s->db_low_byte_first)
 
382
    return sint4korr(ptr);
390
383
#endif
391
 
  int64_t tmp;
392
 
  int64_tget(tmp, ptr);
 
384
  long tmp;
 
385
  longget(tmp,ptr);
393
386
  return tmp;
394
387
}
395
388
 
396
 
void Field_timestamp::store_timestamp(int64_t timestamp)
 
389
void Field_timestamp::store_timestamp(time_t timestamp)
397
390
{
398
391
#ifdef WORDS_BIGENDIAN
399
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
 
392
  if (table && table->s->db_low_byte_first)
400
393
  {
401
 
    int8store(ptr, timestamp);
 
394
    int4store(ptr,timestamp);
402
395
  }
403
396
  else
404
397
#endif
405
 
    int64_tstore(ptr, timestamp);
 
398
    longstore(ptr,(uint32_t) timestamp);
406
399
}
407
400
 
408
401
} /* namespace drizzled */