~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/time/maketime.cc

  • Committer: Brian Aker
  • Date: 2009-02-20 22:48:37 UTC
  • Revision ID: brian@tangent.org-20090220224837-fw5wrf46n4ru3e6a
First pass of stripping uint

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/current_session.h>
 
22
#include CSTDINT_H
 
23
#include <drizzled/function/time/maketime.h>
 
24
#include <drizzled/function/time/make_time_with_warn.h>
 
25
 
 
26
/**
 
27
  MAKETIME(h,m,s) is a time function that calculates a time value
 
28
  from the total number of hours, minutes, and seconds.
 
29
  Result: Time value
 
30
*/
 
31
 
 
32
String *Item_func_maketime::val_str(String *str)
 
33
{
 
34
  assert(fixed == 1);
 
35
  DRIZZLE_TIME ltime;
 
36
  bool overflow= 0;
 
37
 
 
38
  int64_t hour=   args[0]->val_int();
 
39
  int64_t minute= args[1]->val_int();
 
40
  int64_t second= args[2]->val_int();
 
41
 
 
42
  if ((null_value=(args[0]->null_value ||
 
43
                   args[1]->null_value ||
 
44
                   args[2]->null_value ||
 
45
                   minute < 0 || minute > 59 ||
 
46
                   second < 0 || second > 59 ||
 
47
                   str->alloc(MAX_DATE_STRING_REP_LENGTH))))
 
48
    return 0;
 
49
 
 
50
  memset(&ltime, 0, sizeof(ltime));
 
51
  ltime.neg= 0;
 
52
 
 
53
  /* Check for integer overflows */
 
54
  if (hour < 0)
 
55
    ltime.neg= 1;
 
56
 
 
57
  if (-hour > UINT_MAX || hour > UINT_MAX)
 
58
    overflow= 1;
 
59
 
 
60
  if (!overflow)
 
61
  {
 
62
    ltime.hour=   (uint) ((hour < 0 ? -hour : hour));
 
63
    ltime.minute= (uint) minute;
 
64
    ltime.second= (uint) second;
 
65
  }
 
66
  else
 
67
  {
 
68
    ltime.hour= TIME_MAX_HOUR;
 
69
    ltime.minute= TIME_MAX_MINUTE;
 
70
    ltime.second= TIME_MAX_SECOND;
 
71
    char buf[28];
 
72
    char *ptr= int64_t10_to_str(hour, buf, args[0]->unsigned_flag ? 10 : -10);
 
73
    int len = (int)(ptr - buf) +
 
74
      sprintf(ptr, ":%02u:%02u", (uint)minute, (uint)second);
 
75
    make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
76
                                 buf, len, DRIZZLE_TIMESTAMP_TIME,
 
77
                                 NULL);
 
78
  }
 
79
 
 
80
  if (make_time_with_warn((DATE_TIME_FORMAT *) 0, &ltime, str))
 
81
  {
 
82
    null_value= 1;
 
83
    return 0;
 
84
  }
 
85
  return str;
 
86
}
 
87