~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/datetime.cc

  • Committer: patrick crews
  • Date: 2010-09-29 15:15:19 UTC
  • mfrom: (1099.4.188 drizzle)
  • Revision ID: gleebix@gmail.com-20100929151519-6mrmzd1ciw2p9nws
Tags: 2010.09.1802
Update translations

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include "config.h"
22
 
#include <boost/lexical_cast.hpp>
23
22
#include "drizzled/field/datetime.h"
24
23
#include "drizzled/error.h"
25
24
#include "drizzled/table.h"
61
60
  temporal.to_int64_t(&int_value);
62
61
 
63
62
#ifdef WORDS_BIGENDIAN
64
 
  if (getTable() && getTable()->isDatabaseLowByteFirst())
 
63
  if (getTable() && getTable()->s->db_low_byte_first)
65
64
  {
66
65
    int8store(ptr, int_value);
67
66
  }
76
75
  ASSERT_COLUMN_MARKED_FOR_WRITE;
77
76
  if (from < 0.0 || from > 99991231235959.0)
78
77
  {
79
 
    /* Convert the double to a string using boost::lexical_cast */
80
 
    std::string tmp(boost::lexical_cast<std::string>(from));
 
78
    /* Convert the double to a string using stringstream */
 
79
    std::stringstream ss;
 
80
    std::string tmp;
 
81
    ss.precision(18); /* 18 places should be fine for error display of double input. */
 
82
    ss << from; ss >> tmp;
81
83
 
82
84
    my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
83
85
    return 2;
95
97
  DateTime temporal;
96
98
  if (! temporal.from_int64_t(from))
97
99
  {
98
 
    /* Convert the integer to a string using boost::lexical_cast */
99
 
    std::string tmp(boost::lexical_cast<std::string>(from));
 
100
    /* Convert the integer to a string using stringstream */
 
101
    std::stringstream ss;
 
102
    std::string tmp;
 
103
    ss << from; ss >> tmp;
100
104
 
101
105
    my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp.c_str());
102
106
    return 2;
111
115
  temporal.to_int64_t(&int_value);
112
116
 
113
117
#ifdef WORDS_BIGENDIAN
114
 
  if (getTable() && getTable()->isDatabaseLowByteFirst())
 
118
  if (getTable() && getTable()->s->db_low_byte_first)
115
119
  {
116
120
    int8store(ptr, int_value);
117
121
  }
121
125
  return 0;
122
126
}
123
127
 
124
 
int Field_datetime::store_time(type::Time &ltime, type::timestamp_t)
 
128
int Field_datetime::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
125
129
{
126
130
  DateTime temporal;
127
131
 
128
 
  temporal.set_years(ltime.year);
129
 
  temporal.set_months(ltime.month);
130
 
  temporal.set_days(ltime.day);
131
 
  temporal.set_hours(ltime.hour);
132
 
  temporal.set_minutes(ltime.minute);
133
 
  temporal.set_seconds(ltime.second);
 
132
  temporal.set_years(ltime->year);
 
133
  temporal.set_months(ltime->month);
 
134
  temporal.set_days(ltime->day);
 
135
  temporal.set_hours(ltime->hour);
 
136
  temporal.set_minutes(ltime->minute);
 
137
  temporal.set_seconds(ltime->second);
134
138
 
135
139
  if (! temporal.is_valid())
136
140
  {
137
 
    char tmp_string[type::Time::MAX_STRING_LENGTH];
 
141
    char tmp_string[MAX_DATE_STRING_REP_LENGTH];
138
142
    size_t tmp_string_len;
139
143
 
140
 
    tmp_string_len= temporal.to_string(tmp_string, type::Time::MAX_STRING_LENGTH);
141
 
    assert(tmp_string_len < type::Time::MAX_STRING_LENGTH);
 
144
    tmp_string_len= temporal.to_string(tmp_string, MAX_DATE_STRING_REP_LENGTH);
 
145
    assert(tmp_string_len < MAX_DATE_STRING_REP_LENGTH);
142
146
    my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp_string);
143
147
    return 1;
144
148
  }
147
151
  temporal.to_int64_t(&int_value);
148
152
 
149
153
#ifdef WORDS_BIGENDIAN
150
 
  if (getTable() && getTable()->isDatabaseLowByteFirst())
 
154
  if (getTable() && getTable()->s->db_low_byte_first)
151
155
  {
152
156
    int8store(ptr, int_value);
153
157
  }
154
158
  else
155
159
#endif
156
160
    int64_tstore(ptr, int_value);
157
 
 
158
161
  return 0;
159
162
}
160
163
 
170
173
  ASSERT_COLUMN_MARKED_FOR_READ;
171
174
 
172
175
#ifdef WORDS_BIGENDIAN
173
 
  if (getTable() && getTable()->isDatabaseLowByteFirst())
 
176
  if (getTable() && getTable()->s->db_low_byte_first)
174
177
    j=sint8korr(ptr);
175
178
  else
176
179
#endif
189
192
  ASSERT_COLUMN_MARKED_FOR_READ;
190
193
 
191
194
#ifdef WORDS_BIGENDIAN
192
 
  if (getTable() && getTable()->isDatabaseLowByteFirst())
 
195
  if (getTable() && getTable()->s->db_low_byte_first)
193
196
    tmp=sint8korr(ptr);
194
197
  else
195
198
#endif
217
220
  return val_buffer;
218
221
}
219
222
 
220
 
bool Field_datetime::get_date(type::Time &ltime, uint32_t fuzzydate)
 
223
bool Field_datetime::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
221
224
{
222
225
  int64_t tmp=Field_datetime::val_int();
223
226
  uint32_t part1,part2;
224
227
  part1=(uint32_t) (tmp/INT64_C(1000000));
225
228
  part2=(uint32_t) (tmp - (uint64_t) part1*INT64_C(1000000));
226
229
 
227
 
  ltime.time_type=      type::DRIZZLE_TIMESTAMP_DATETIME;
228
 
  ltime.neg=            0;
229
 
  ltime.second_part=    0;
230
 
  ltime.second= (int) (part2%100);
231
 
  ltime.minute= (int) (part2/100%100);
232
 
  ltime.hour=           (int) (part2/10000);
233
 
  ltime.day=            (int) (part1%100);
234
 
  ltime.month=  (int) (part1/100%100);
235
 
  ltime.year=           (int) (part1/10000);
236
 
 
237
 
  return (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime.month || !ltime.day)) ? 1 : 0;
 
230
  ltime->time_type=     DRIZZLE_TIMESTAMP_DATETIME;
 
231
  ltime->neg=           0;
 
232
  ltime->second_part=   0;
 
233
  ltime->second=        (int) (part2%100);
 
234
  ltime->minute=        (int) (part2/100%100);
 
235
  ltime->hour=          (int) (part2/10000);
 
236
  ltime->day=           (int) (part1%100);
 
237
  ltime->month=         (int) (part1/100%100);
 
238
  ltime->year=          (int) (part1/10000);
 
239
  return (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ? 1 : 0;
238
240
}
239
241
 
240
 
bool Field_datetime::get_time(type::Time &ltime)
 
242
bool Field_datetime::get_time(DRIZZLE_TIME *ltime)
241
243
{
242
244
  return Field_datetime::get_date(ltime,0);
243
245
}
246
248
{
247
249
  int64_t a,b;
248
250
#ifdef WORDS_BIGENDIAN
249
 
  if (getTable() && getTable()->isDatabaseLowByteFirst())
 
251
  if (getTable() && getTable()->s->db_low_byte_first)
250
252
  {
251
253
    a=sint8korr(a_ptr);
252
254
    b=sint8korr(b_ptr);
264
266
void Field_datetime::sort_string(unsigned char *to,uint32_t )
265
267
{
266
268
#ifdef WORDS_BIGENDIAN
267
 
  if (not getTable() || not getTable()->isDatabaseLowByteFirst())
 
269
  if (!getTable() || !getTable()->s->db_low_byte_first)
268
270
  {
269
271
    to[0] = ptr[0];
270
272
    to[1] = ptr[1];