~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/time.cc

  • Committer: Brian Aker
  • Date: 2011-01-26 18:29:34 UTC
  • mto: (2122.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2123.
  • Revision ID: brian@tangent.org-20110126182934-hsboi3ab5105on1g
fix test case along with the error message for TIME.

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
 
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), from);
 
85
    std::string tmp(boost::lexical_cast<std::string>(from));
 
86
    my_error(ER_INVALID_TIME_VALUE, MYF(0), tmp.c_str());
86
87
    return 1;
87
88
  }
88
89
 
94
95
int Time::store(double from)
95
96
96
97
  ASSERT_COLUMN_MARKED_FOR_WRITE;
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, type::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, type::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
 
                           type::DRIZZLE_TIMESTAMP_TIME);
127
 
      error= 1;
128
 
    }
129
 
  }
130
 
 
131
 
  if (not error)
 
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
 
132
126
    return store(tmp, false);
133
127
 
134
 
  return error;
 
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;
135
134
}
136
135
 
137
136
int Time::store(int64_t from, bool)
143
142
   * if unable to create a valid DateTime.  
144
143
   */
145
144
  drizzled::Time temporal;
146
 
  if (! temporal.from_time_t(from))
 
145
  if (not temporal.from_time_t(from))
147
146
  {
148
147
    /* Convert the integer to a string using boost::lexical_cast */
149
148
    std::string tmp(boost::lexical_cast<std::string>(from));
150
 
 
151
 
    my_error(ER_INVALID_UNIX_TIMESTAMP_VALUE, MYF(ME_FATALERROR), tmp.c_str());
 
149
    my_error(ER_INVALID_TIME_VALUE, MYF(0), tmp.c_str());
152
150
    return 2;
153
151
  }
154
152