~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/epoch.cc

  • Committer: Brian Aker
  • Date: 2010-12-25 00:28:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2031.
  • Revision ID: brian@tangent.org-20101225002849-g73mg6ihulajis0o
First pass in refactoring of the name of my_decimal.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
  exception is different behavior of old/new timestamps during ALTER TABLE.
83
83
 */
84
84
  Epoch::Epoch(unsigned char *ptr_arg,
 
85
               uint32_t,
85
86
               unsigned char *null_ptr_arg,
86
87
               unsigned char null_bit_arg,
87
88
               enum utype unireg_check_arg,
88
89
               const char *field_name_arg,
89
 
               drizzled::TableShare *share) :
 
90
               drizzled::TableShare *share,
 
91
               const drizzled::CHARSET_INFO * const cs) :
90
92
  Field_str(ptr_arg,
91
 
            MicroTimestamp::MAX_STRING_LENGTH - 1, /* no \0 */
 
93
            DateTime::MAX_STRING_LENGTH - 1 /* no \0 */,
92
94
            null_ptr_arg,
93
95
            null_bit_arg,
94
96
            field_name_arg,
95
 
            &my_charset_bin)
 
97
            cs)
96
98
{
97
99
  unireg_check= unireg_check_arg;
98
100
  if (! share->getTimestampField() && unireg_check != NONE)
106
108
}
107
109
 
108
110
Epoch::Epoch(bool maybe_null_arg,
109
 
             const char *field_name_arg) :
 
111
             const char *field_name_arg,
 
112
             const CHARSET_INFO * const cs) :
110
113
  Field_str((unsigned char*) NULL,
111
 
            MicroTimestamp::MAX_STRING_LENGTH - 1, /* no \0 */
 
114
            DateTime::MAX_STRING_LENGTH - 1 /* no \0 */,
112
115
            maybe_null_arg ? (unsigned char*) "": 0,
113
116
            0,
114
117
            field_name_arg,
115
 
            &my_charset_bin)
 
118
            cs)
116
119
{
117
120
  if (unireg_check != TIMESTAMP_DN_FIELD)
118
121
    flags|= ON_UPDATE_NOW_FLAG;
162
165
 
163
166
  if (not temporal.from_string(from, (size_t) len))
164
167
  {
165
 
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
 
168
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
166
169
    return 1;
167
170
  }
168
171
 
169
172
  time_t tmp;
170
173
  temporal.to_time_t(tmp);
171
174
 
172
 
  uint64_t time_tmp= tmp;
173
 
  pack_num(time_tmp);
 
175
  pack_num(tmp);
174
176
  return 0;
175
177
}
176
178
 
178
180
{
179
181
  ASSERT_COLUMN_MARKED_FOR_WRITE;
180
182
 
181
 
  uint64_t from_tmp= (uint64_t)from;
182
 
 
183
 
  Timestamp temporal;
184
 
  if (not temporal.from_int64_t(from_tmp))
 
183
  if (from < 0 || from > 99991231235959.0)
185
184
  {
186
 
    /* Convert the integer to a string using boost::lexical_cast */
187
 
    std::string tmp(boost::lexical_cast<std::string>(from));
 
185
    /* Convert the double to a string using stringstream */
 
186
    std::stringstream ss;
 
187
    std::string tmp;
 
188
    ss.precision(18); /* 18 places should be fine for error display of double input. */
 
189
    ss << from; 
 
190
    ss >> tmp;
188
191
 
189
 
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
 
192
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
190
193
    return 2;
191
194
  }
192
 
 
193
 
  time_t tmp;
194
 
  temporal.to_time_t(tmp);
195
 
 
196
 
  uint64_t tmp_micro= tmp;
197
 
  pack_num(tmp_micro);
198
 
 
199
 
  return 0;
200
 
}
201
 
 
202
 
int Epoch::store_decimal(const type::Decimal *value)
203
 
{
204
 
  double tmp;
205
 
  value->convert(tmp);
206
 
 
207
 
  return store(tmp);
 
195
  return Epoch::store((int64_t) rint(from), false);
208
196
}
209
197
 
210
198
int Epoch::store(int64_t from, bool)
216
204
   * if unable to create a valid DateTime.  
217
205
   */
218
206
  Timestamp temporal;
219
 
  if (not temporal.from_int64_t(from))
 
207
  if (! temporal.from_int64_t(from))
220
208
  {
221
209
    /* Convert the integer to a string using boost::lexical_cast */
222
210
    std::string tmp(boost::lexical_cast<std::string>(from));
223
211
 
224
 
    my_error(ER_INVALID_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
 
212
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
225
213
    return 2;
226
214
  }
227
215
 
228
216
  time_t tmp;
229
217
  temporal.to_time_t(tmp);
230
218
 
231
 
  uint64_t tmp64= tmp;
232
 
  pack_num(tmp64);
 
219
  pack_num(tmp);
233
220
 
234
221
  return 0;
235
222
}
280
267
  return val_buffer;
281
268
}
282
269
 
283
 
bool Epoch::get_date(type::Time &ltime, uint32_t)
 
270
bool Epoch::get_date(DRIZZLE_TIME *ltime, uint32_t)
284
271
{
285
272
  uint64_t temp;
286
 
  type::Time::epoch_t time_temp;
287
273
 
288
274
  unpack_num(temp);
289
 
  time_temp= temp;
290
275
  
291
 
  ltime.reset();
292
 
 
293
 
  ltime.store(time_temp);
 
276
  memset(ltime, 0, sizeof(*ltime));
 
277
 
 
278
  Timestamp temporal;
 
279
  (void) temporal.from_time_t((time_t) temp);
 
280
 
 
281
  /* @TODO Goodbye the below code when DRIZZLE_TIME is finally gone.. */
 
282
 
 
283
  ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME;
 
284
  ltime->year= temporal.years();
 
285
  ltime->month= temporal.months();
 
286
  ltime->day= temporal.days();
 
287
  ltime->hour= temporal.hours();
 
288
  ltime->minute= temporal.minutes();
 
289
  ltime->second= temporal.seconds();
294
290
 
295
291
  return 0;
296
292
}
297
293
 
298
 
bool Epoch::get_time(type::Time &ltime)
 
294
bool Epoch::get_time(DRIZZLE_TIME *ltime)
299
295
{
300
 
  return Epoch::get_date(ltime, 0);
 
296
  return Epoch::get_date(ltime,0);
301
297
}
302
298
 
303
299
int Epoch::cmp(const unsigned char *a_ptr, const unsigned char *b_ptr)
347
343
void Epoch::set_time()
348
344
{
349
345
  Session *session= getTable() ? getTable()->in_use : current_session;
350
 
  time_t tmp= session->getCurrentTimestampEpoch();
351
 
 
 
346
  time_t tmp= session->query_start();
352
347
  set_notnull();
353
 
  pack_num(static_cast<uint32_t>(tmp));
 
348
  pack_num(tmp);
354
349
}
355
350
 
356
351
void Epoch::set_default()