~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/datetime.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 04:19:44 UTC
  • mto: (2192.1.1 drizzle-staging)
  • mto: This revision was merged to the branch mainline in revision 2193.
  • Revision ID: brian@tangent.org-20110222041944-furz1h252ecz7mpd
Merge in modifications such that we check both schema and table for
replication option.

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"
 
21
#include <config.h>
22
22
#include <boost/lexical_cast.hpp>
23
 
#include "drizzled/field/datetime.h"
24
 
#include "drizzled/error.h"
25
 
#include "drizzled/table.h"
26
 
#include "drizzled/temporal.h"
27
 
#include "drizzled/session.h"
 
23
#include <drizzled/field/datetime.h>
 
24
#include <drizzled/error.h>
 
25
#include <drizzled/table.h>
 
26
#include <drizzled/temporal.h>
 
27
#include <drizzled/session.h>
28
28
 
29
29
#include <math.h>
30
30
 
61
61
  temporal.to_int64_t(&int_value);
62
62
 
63
63
#ifdef WORDS_BIGENDIAN
64
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
 
64
  if (getTable() && getTable()->isDatabaseLowByteFirst())
65
65
  {
66
66
    int8store(ptr, int_value);
67
67
  }
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 (getTable() && getTable()->isDatabaseLowByteFirst())
115
115
  {
116
116
    int8store(ptr, int_value);
117
117
  }
121
121
  return 0;
122
122
}
123
123
 
124
 
int Field_datetime::store_time(DRIZZLE_TIME *ltime, enum enum_drizzle_timestamp_type)
 
124
int Field_datetime::store_time(type::Time &ltime, type::timestamp_t)
125
125
{
126
126
  DateTime temporal;
127
127
 
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);
 
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);
134
134
 
135
135
  if (! temporal.is_valid())
136
136
  {
137
 
    char tmp_string[MAX_DATE_STRING_REP_LENGTH];
 
137
    char tmp_string[type::Time::MAX_STRING_LENGTH];
138
138
    size_t tmp_string_len;
139
139
 
140
 
    tmp_string_len= temporal.to_string(tmp_string, MAX_DATE_STRING_REP_LENGTH);
141
 
    assert(tmp_string_len < MAX_DATE_STRING_REP_LENGTH);
 
140
    tmp_string_len= temporal.to_string(tmp_string, type::Time::MAX_STRING_LENGTH);
 
141
    assert(tmp_string_len < type::Time::MAX_STRING_LENGTH);
142
142
    my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR), tmp_string);
143
143
    return 1;
144
144
  }
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 (getTable() && getTable()->isDatabaseLowByteFirst())
151
151
  {
152
152
    int8store(ptr, int_value);
153
153
  }
154
154
  else
155
155
#endif
156
156
    int64_tstore(ptr, int_value);
 
157
 
157
158
  return 0;
158
159
}
159
160
 
160
 
double Field_datetime::val_real(void)
 
161
double Field_datetime::val_real(void) const
161
162
{
162
163
  return (double) Field_datetime::val_int();
163
164
}
164
165
 
165
 
int64_t Field_datetime::val_int(void)
 
166
int64_t Field_datetime::val_int(void) const
166
167
{
167
168
  int64_t j;
168
169
 
169
170
  ASSERT_COLUMN_MARKED_FOR_READ;
170
171
 
171
172
#ifdef WORDS_BIGENDIAN
172
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
 
173
  if (getTable() && getTable()->isDatabaseLowByteFirst())
173
174
    j=sint8korr(ptr);
174
175
  else
175
176
#endif
178
179
}
179
180
 
180
181
 
181
 
String *Field_datetime::val_str(String *val_buffer,
182
 
                                String *)
 
182
String *Field_datetime::val_str(String *val_buffer, String *) const
183
183
{
184
184
  val_buffer->alloc(DateTime::MAX_STRING_LENGTH);
185
185
  val_buffer->length(DateTime::MAX_STRING_LENGTH);
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 (getTable() && getTable()->isDatabaseLowByteFirst())
192
192
    tmp=sint8korr(ptr);
193
193
  else
194
194
#endif
216
216
  return val_buffer;
217
217
}
218
218
 
219
 
bool Field_datetime::get_date(DRIZZLE_TIME *ltime, uint32_t fuzzydate)
 
219
bool Field_datetime::get_date(type::Time &ltime, uint32_t fuzzydate) const
220
220
{
221
221
  int64_t tmp=Field_datetime::val_int();
222
222
  uint32_t part1,part2;
223
223
  part1=(uint32_t) (tmp/INT64_C(1000000));
224
224
  part2=(uint32_t) (tmp - (uint64_t) part1*INT64_C(1000000));
225
225
 
226
 
  ltime->time_type=     DRIZZLE_TIMESTAMP_DATETIME;
227
 
  ltime->neg=           0;
228
 
  ltime->second_part=   0;
229
 
  ltime->second=        (int) (part2%100);
230
 
  ltime->minute=        (int) (part2/100%100);
231
 
  ltime->hour=          (int) (part2/10000);
232
 
  ltime->day=           (int) (part1%100);
233
 
  ltime->month=         (int) (part1/100%100);
234
 
  ltime->year=          (int) (part1/10000);
235
 
  return (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime->month || !ltime->day)) ? 1 : 0;
 
226
  ltime.time_type=      type::DRIZZLE_TIMESTAMP_DATETIME;
 
227
  ltime.neg=            0;
 
228
  ltime.second_part=    0;
 
229
  ltime.second= (int) (part2%100);
 
230
  ltime.minute= (int) (part2/100%100);
 
231
  ltime.hour=           (int) (part2/10000);
 
232
  ltime.day=            (int) (part1%100);
 
233
  ltime.month=  (int) (part1/100%100);
 
234
  ltime.year=           (int) (part1/10000);
 
235
 
 
236
  return (!(fuzzydate & TIME_FUZZY_DATE) && (!ltime.month || !ltime.day)) ? 1 : 0;
236
237
}
237
238
 
238
 
bool Field_datetime::get_time(DRIZZLE_TIME *ltime)
 
239
bool Field_datetime::get_time(type::Time &ltime) const
239
240
{
240
241
  return Field_datetime::get_date(ltime,0);
241
242
}
244
245
{
245
246
  int64_t a,b;
246
247
#ifdef WORDS_BIGENDIAN
247
 
  if (getTable() && getTable()->getShare()->db_low_byte_first)
 
248
  if (getTable() && getTable()->isDatabaseLowByteFirst())
248
249
  {
249
250
    a=sint8korr(a_ptr);
250
251
    b=sint8korr(b_ptr);
262
263
void Field_datetime::sort_string(unsigned char *to,uint32_t )
263
264
{
264
265
#ifdef WORDS_BIGENDIAN
265
 
  if (!getTable() || !getTable()->getShare()->db_low_byte_first)
 
266
  if (not getTable() || not getTable()->isDatabaseLowByteFirst())
266
267
  {
267
268
    to[0] = ptr[0];
268
269
    to[1] = ptr[1];