~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/datetime.cc

pandora-build v0.71. Added check for avahi.

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
 
#include "config.h"
22
 
#include <boost/lexical_cast.hpp>
 
21
#include "drizzled/server_includes.h"
23
22
#include "drizzled/field/datetime.h"
24
23
#include "drizzled/error.h"
25
24
#include "drizzled/table.h"
26
25
#include "drizzled/temporal.h"
27
26
#include "drizzled/session.h"
28
27
 
29
 
#include <math.h>
30
 
 
31
28
#include <sstream>
32
29
#include <string>
33
30
 
34
31
 
35
 
namespace drizzled
36
 
{
37
 
 
38
32
/****************************************************************************
39
33
** datetime type
40
34
** In string context: YYYY-MM-DD HH:MM:DD
41
35
** In number context: YYYYMMDDHHMMDD
 
36
** Stored as a 8 byte unsigned int. Should sometimes be change to a 6 byte int.
42
37
****************************************************************************/
43
38
 
44
39
int Field_datetime::store(const char *from,
50
45
   * Try to create a DateTime from the supplied string.  Throw an error
51
46
   * if unable to create a valid DateTime.  
52
47
   */
53
 
  DateTime temporal;
 
48
  drizzled::DateTime temporal;
54
49
  if (! temporal.from_string(from, (size_t) len))
55
50
  {
56
51
    my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), from);
61
56
  temporal.to_int64_t(&int_value);
62
57
 
63
58
#ifdef WORDS_BIGENDIAN
64
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
 
59
  if (table && table->s->db_low_byte_first)
65
60
  {
66
61
    int8store(ptr, int_value);
67
62
  }
76
71
  ASSERT_COLUMN_MARKED_FOR_WRITE;
77
72
  if (from < 0.0 || from > 99991231235959.0)
78
73
  {
79
 
    /* Convert the double to a string using boost::lexical_cast */
80
 
    std::string tmp(boost::lexical_cast<std::string>(from));
 
74
    /* Convert the double to a string using stringstream */
 
75
    std::stringstream ss;
 
76
    std::string tmp;
 
77
    ss.precision(18); /* 18 places should be fine for error display of double input. */
 
78
    ss << from; ss >> tmp;
81
79
 
82
80
    my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
83
81
    return 2;
92
90
   * Try to create a DateTime from the supplied integer.  Throw an error
93
91
   * if unable to create a valid DateTime.  
94
92
   */
95
 
  DateTime temporal;
 
93
  drizzled::DateTime temporal;
96
94
  if (! temporal.from_int64_t(from))
97
95
  {
98
 
    /* Convert the integer to a string using boost::lexical_cast */
99
 
    std::string tmp(boost::lexical_cast<std::string>(from));
 
96
    /* Convert the integer to a string using stringstream */
 
97
    std::stringstream ss;
 
98
    std::string tmp;
 
99
    ss << from; ss >> tmp;
100
100
 
101
101
    my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
102
102
    return 2;
111
111
  temporal.to_int64_t(&int_value);
112
112
 
113
113
#ifdef WORDS_BIGENDIAN
114
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
 
114
  if (table && table->s->db_low_byte_first)
115
115
  {
116
116
    int8store(ptr, int_value);
117
117
  }
123
123
 
124
124
int Field_datetime::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
125
125
{
126
 
  DateTime temporal;
 
126
  drizzled::DateTime temporal;
127
127
 
128
128
  temporal.set_years(ltime->year);
129
129
  temporal.set_months(ltime->month);
147
147
  temporal.to_int64_t(&int_value);
148
148
 
149
149
#ifdef WORDS_BIGENDIAN
150
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
 
150
  if (table && table->s->db_low_byte_first)
151
151
  {
152
152
    int8store(ptr, int_value);
153
153
  }
169
169
  ASSERT_COLUMN_MARKED_FOR_READ;
170
170
 
171
171
#ifdef WORDS_BIGENDIAN
172
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
 
172
  if (table && table->s->db_low_byte_first)
173
173
    j=sint8korr(ptr);
174
174
  else
175
175
#endif
181
181
String *Field_datetime::val_str(String *val_buffer,
182
182
                                String *)
183
183
{
184
 
  val_buffer->alloc(DateTime::MAX_STRING_LENGTH);
185
 
  val_buffer->length(DateTime::MAX_STRING_LENGTH);
 
184
  val_buffer->alloc(drizzled::DateTime::MAX_STRING_LENGTH);
 
185
  val_buffer->length(drizzled::DateTime::MAX_STRING_LENGTH);
186
186
  int64_t tmp;
187
187
 
188
188
  ASSERT_COLUMN_MARKED_FOR_READ;
189
189
 
190
190
#ifdef WORDS_BIGENDIAN
191
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
 
191
  if (table && table->s->db_low_byte_first)
192
192
    tmp=sint8korr(ptr);
193
193
  else
194
194
#endif
195
195
    int64_tget(tmp,ptr);
196
196
 
197
 
  DateTime dt;
 
197
  drizzled::DateTime dt;
198
198
 
199
199
  /* TODO: add an assert that this succeeds
200
200
   * currently fails due to bug in allowing
202
202
   * not null without a default value.
203
203
   */
204
204
  dt.from_int64_t(tmp, false); /* NOTE: this does *NOT* attempt convertion
205
 
                                 from formats such as 20090101 as
206
 
                                 the stored value has already been
207
 
                                 converted.
208
 
                               */
 
205
                                        from formats such as 20090101 as
 
206
                                        the stored value has already been
 
207
                                        converted.
 
208
                               */
209
209
 
210
210
  int rlen;
211
 
  rlen= dt.to_string((char*)val_buffer->ptr(), DateTime::MAX_STRING_LENGTH);
212
 
  assert((rlen+1) <  DateTime::MAX_STRING_LENGTH);
 
211
  rlen= dt.to_string((char*)val_buffer->ptr(), drizzled::DateTime::MAX_STRING_LENGTH);
 
212
  assert((rlen+1) <  drizzled::DateTime::MAX_STRING_LENGTH);
213
213
 
214
214
  val_buffer->length(rlen);
215
215
 
244
244
{
245
245
  int64_t a,b;
246
246
#ifdef WORDS_BIGENDIAN
247
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
 
247
  if (table && table->s->db_low_byte_first)
248
248
  {
249
249
    a=sint8korr(a_ptr);
250
250
    b=sint8korr(b_ptr);
262
262
void Field_datetime::sort_string(unsigned char *to,uint32_t )
263
263
{
264
264
#ifdef WORDS_BIGENDIAN
265
 
  if (!getTable() || !getTable()->getShare()->db_low_byte_first)
 
265
  if (!table || !table->s->db_low_byte_first)
266
266
  {
267
267
    to[0] = ptr[0];
268
268
    to[1] = ptr[1];
293
293
  res.set_ascii(STRING_WITH_LEN("datetime"));
294
294
}
295
295
 
296
 
} /* namespace drizzled */