~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/time.cc

  • Committer: Stewart Smith
  • Date: 2011-01-14 05:11:45 UTC
  • mto: (2086.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2087.
  • Revision ID: stewart@flamingspork.com-20110114051145-xiputq4lvmtct377
storage engine docs. add bit about some temp table only engines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
 
83
83
  if (not temporal.from_string(from, (size_t) len))
84
84
  {
85
 
    std::string tmp(boost::lexical_cast<std::string>(from));
86
 
    my_error(ER_INVALID_TIME_VALUE, MYF(0), tmp.c_str());
 
85
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
87
86
    return 1;
88
87
  }
89
88
 
95
94
int Time::store(double from)
96
95
97
96
  ASSERT_COLUMN_MARKED_FOR_WRITE;
98
 
 
99
 
  do
100
 
  {
101
 
    int64_t tmp;
102
 
 
103
 
    if (from > (double)TIME_MAX_VALUE)
104
 
    { 
105
 
      tmp= TIME_MAX_VALUE;
106
 
      break;
107
 
    }
108
 
    else if (from < (double) - TIME_MAX_VALUE)
109
 
    { 
110
 
      tmp= -TIME_MAX_VALUE;
111
 
      break;
112
 
    }
113
 
    else
114
 
    { 
115
 
      tmp=(long) floor(fabs(from));                 // Remove fractions
116
 
 
117
 
      if (from < 0)
118
 
        tmp= -tmp;
119
 
 
120
 
      if (tmp % 100 > 59 || tmp/100 % 100 > 59)
121
 
      { 
122
 
        break;
123
 
      }
124
 
    }
125
 
 
 
97
  int64_t tmp;
 
98
  int error= 0;
 
99
 
 
100
  if (from > (double)TIME_MAX_VALUE)
 
101
  { 
 
102
    tmp= TIME_MAX_VALUE;
 
103
    set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
104
                         ER_WARN_DATA_OUT_OF_RANGE, from, DRIZZLE_TIMESTAMP_TIME);
 
105
    error= 1;
 
106
  }
 
107
  else if (from < (double) - TIME_MAX_VALUE)
 
108
  { 
 
109
    tmp= -TIME_MAX_VALUE;
 
110
    set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
111
                         ER_WARN_DATA_OUT_OF_RANGE, from, DRIZZLE_TIMESTAMP_TIME);
 
112
    error= 1;
 
113
  }
 
114
  else
 
115
  { 
 
116
    tmp=(long) floor(fabs(from));                 // Remove fractions
 
117
 
 
118
    if (from < 0)
 
119
      tmp= -tmp;
 
120
 
 
121
    if (tmp % 100 > 59 || tmp/100 % 100 > 59)
 
122
    { 
 
123
      tmp=0;
 
124
      set_datetime_warning(DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
125
                           ER_WARN_DATA_OUT_OF_RANGE, from,
 
126
                           DRIZZLE_TIMESTAMP_TIME);
 
127
      error= 1;
 
128
    }
 
129
  }
 
130
 
 
131
  if (not error)
126
132
    return store(tmp, false);
127
133
 
128
 
  } while (0);
129
 
 
130
 
  std::string tmp(boost::lexical_cast<std::string>(from));
131
 
  my_error(ER_INVALID_TIME_VALUE, MYF(0), tmp.c_str());
132
 
 
133
 
  return 1;
 
134
  return error;
134
135
}
135
136
 
136
137
int Time::store(int64_t from, bool)
142
143
   * if unable to create a valid DateTime.  
143
144
   */
144
145
  drizzled::Time temporal;
145
 
  if (not temporal.from_time_t(from))
 
146
  if (! temporal.from_time_t(from))
146
147
  {
147
148
    /* Convert the integer to a string using boost::lexical_cast */
148
149
    std::string tmp(boost::lexical_cast<std::string>(from));
149
 
    my_error(ER_INVALID_TIME_VALUE, MYF(0), tmp.c_str());
 
150
 
 
151
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
150
152
    return 2;
151
153
  }
152
154
 
218
220
  return val_buffer;
219
221
}
220
222
 
221
 
bool Time::get_date(type::Time &ltime, uint32_t)
 
223
bool Time::get_date(type::Time *ltime, uint32_t)
222
224
{
223
 
  ltime.reset();
 
225
  memset(ltime, 0, sizeof(*ltime));
224
226
 
225
227
  drizzled::Time temporal;
226
228
  unpack_time(temporal);
227
229
 
228
 
  ltime.time_type= type::DRIZZLE_TIMESTAMP_DATETIME;
229
 
  ltime.year= temporal.years();
230
 
  ltime.month= temporal.months();
231
 
  ltime.day= temporal.days();
232
 
  ltime.hour= temporal.hours();
233
 
  ltime.minute= temporal.minutes();
234
 
  ltime.second= temporal.seconds();
 
230
  ltime->time_type= DRIZZLE_TIMESTAMP_DATETIME;
 
231
  ltime->year= temporal.years();
 
232
  ltime->month= temporal.months();
 
233
  ltime->day= temporal.days();
 
234
  ltime->hour= temporal.hours();
 
235
  ltime->minute= temporal.minutes();
 
236
  ltime->second= temporal.seconds();
235
237
 
236
238
  return 0;
237
239
}
238
240
 
239
 
bool Time::get_time(type::Time &ltime)
 
241
bool Time::get_time(type::Time *ltime)
240
242
{
241
243
  return Time::get_date(ltime, 0);
242
244
}