~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/timestamp.h

  • Committer: Monty Taylor
  • Date: 2008-08-01 23:59:59 UTC
  • mto: (236.1.42 codestyle)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: monty@inaugust.com-20080801235959-n8ypy9r5aohown77
Gettext error compiles and passes test!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c++ c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
4
 *  Copyright (C) 2008 MySQL
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#ifndef DRIZZLED_FIELD_TIMESTAMP_H
22
 
#define DRIZZLED_FIELD_TIMESTAMP_H
23
 
 
24
 
#include <drizzled/field/str.h>
25
 
 
26
 
namespace drizzled
27
 
{
28
 
 
29
 
class TableShare;
30
 
typedef struct charset_info_st CHARSET_INFO;
 
21
#ifndef DRIZZLE_SERVER_FIELD_TIMESTAMP
 
22
#define DRIZZLE_SERVER_FIELD_TIMESTAMP
 
23
 
 
24
#include <drizzled/mysql_priv.h>
31
25
 
32
26
class Field_timestamp :public Field_str {
33
27
public:
34
 
 
35
 
  using Field::val_int;
36
 
  using Field::val_str;
37
 
  using Field::cmp;
38
 
  using Field::store;
39
 
  Field_timestamp(unsigned char *ptr_arg,
40
 
                  uint32_t len_arg,
41
 
                  unsigned char *null_ptr_arg,
42
 
                  unsigned char null_bit_arg,
43
 
                  enum utype unireg_check_arg,
44
 
                  const char *field_name_arg,
45
 
                  TableShare *share,
46
 
                  const CHARSET_INFO * const cs);
47
 
  Field_timestamp(bool maybe_null_arg,
48
 
                  const char *field_name_arg,
49
 
                  const CHARSET_INFO * const cs);
 
28
  Field_timestamp(uchar *ptr_arg, uint32_t len_arg,
 
29
                  uchar *null_ptr_arg, uchar null_bit_arg,
 
30
                  enum utype unireg_check_arg, const char *field_name_arg,
 
31
                  TABLE_SHARE *share, CHARSET_INFO *cs);
 
32
  Field_timestamp(bool maybe_null_arg, const char *field_name_arg,
 
33
                  CHARSET_INFO *cs);
50
34
  enum_field_types type() const { return DRIZZLE_TYPE_TIMESTAMP;}
51
 
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONGLONG; }
 
35
  enum ha_base_keytype key_type() const { return HA_KEYTYPE_ULONG_INT; }
52
36
  enum Item_result cmp_type () const { return INT_RESULT; }
53
 
  int  store(const char *to,uint32_t length,
54
 
             const CHARSET_INFO * const charset);
 
37
  int  store(const char *to,uint length,CHARSET_INFO *charset);
55
38
  int  store(double nr);
56
39
  int  store(int64_t nr, bool unsigned_val);
57
 
  int  reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=ptr[4]=ptr[5]=ptr[6]=ptr[7]=0; return 0; }
 
40
  int  reset(void) { ptr[0]=ptr[1]=ptr[2]=ptr[3]=0; return 0; }
58
41
  double val_real(void);
59
42
  int64_t val_int(void);
60
43
  String *val_str(String*,String *);
61
 
  int cmp(const unsigned char *,const unsigned char *);
62
 
  void sort_string(unsigned char *buff,uint32_t length);
63
 
  uint32_t pack_length() const { return 8; }
 
44
  bool send_binary(Protocol *protocol);
 
45
  int cmp(const uchar *,const uchar *);
 
46
  void sort_string(uchar *buff,uint length);
 
47
  uint32_t pack_length() const { return 4; }
64
48
  void sql_type(String &str) const;
65
49
  bool can_be_compared_as_int64_t() const { return true; }
66
50
  bool zero_pack() const { return 0; }
67
51
  void set_time();
68
 
  virtual void set_default();
69
 
 
 
52
  virtual void set_default()
 
53
  {
 
54
    if (table->timestamp_field == this &&
 
55
        unireg_check != TIMESTAMP_UN_FIELD)
 
56
      set_time();
 
57
    else
 
58
      Field::set_default();
 
59
  }
70
60
  /* Get TIMESTAMP field value as seconds since begging of Unix Epoch */
71
 
  long get_timestamp(bool *null_value);
72
 
private:
73
 
  void store_timestamp(int64_t timestamp);
74
 
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
61
  inline long get_timestamp(my_bool *null_value)
 
62
  {
 
63
    if ((*null_value= is_null()))
 
64
      return 0;
 
65
#ifdef WORDS_BIGENDIAN
 
66
    if (table && table->s->db_low_byte_first)
 
67
      return sint4korr(ptr);
 
68
#endif
 
69
    long tmp;
 
70
    longget(tmp,ptr);
 
71
    return tmp;
 
72
  }
 
73
  inline void store_timestamp(my_time_t timestamp)
 
74
  {
 
75
#ifdef WORDS_BIGENDIAN
 
76
    if (table && table->s->db_low_byte_first)
 
77
    {
 
78
      int4store(ptr,timestamp);
 
79
    }
 
80
    else
 
81
#endif
 
82
      longstore(ptr,(uint32_t) timestamp);
 
83
  }
 
84
  bool get_date(DRIZZLE_TIME *ltime,uint fuzzydate);
75
85
  bool get_time(DRIZZLE_TIME *ltime);
76
 
public:
77
86
  timestamp_auto_set_type get_auto_set_type() const;
78
87
};
79
88
 
80
 
} /* namespace drizzled */
81
 
 
82
 
#endif /* DRIZZLED_FIELD_TIMESTAMP_H */
 
89
#endif
83
90