~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Patrick Galbraith
  • Date: 2009-10-08 22:42:05 UTC
  • mto: (1166.5.3 memcached_functions)
  • mto: This revision was merged to the branch mainline in revision 1189.
  • Revision ID: patg@patrick-galbraiths-macbook-pro.local-20091008224205-gq1pehjsivvx0qo9
Starting over with a fresh tree, moved in memcached functions.

Memcached Functions for Drizzle. 

All tests pass.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
 
20
#include "drizzled/server_includes.h"
 
21
#include CSTDINT_H
22
22
#include "drizzled/temporal.h"
23
23
#include "drizzled/error.h"
24
24
#include "drizzled/function/time/year.h"
25
25
 
26
 
namespace drizzled
27
 
{
28
 
 
29
26
int64_t Item_func_year::val_int()
30
27
{
31
28
  assert(fixed);
38
35
  }
39
36
 
40
37
  /* Grab the first argument as a DateTime object */
41
 
  DateTime temporal;
 
38
  drizzled::DateTime temporal;
42
39
  Item_result arg0_result_type= args[0]->result_type();
43
40
  
44
41
  switch (arg0_result_type)
57
54
        char buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
58
55
        String tmp(buff,sizeof(buff), &my_charset_utf8_bin);
59
56
        String *res= args[0]->val_str(&tmp);
60
 
 
61
 
        if (res && (res != &tmp))
62
 
        {
63
 
          tmp.copy(*res);
64
 
        }
65
 
 
66
 
        if (! temporal.from_string(tmp.c_ptr(), tmp.length()))
 
57
        if (! temporal.from_string(res->c_ptr(), res->length()))
67
58
        {
68
59
          /* 
69
60
          * Could not interpret the function argument as a temporal value, 
70
61
          * so throw an error and return 0
71
62
          */
72
 
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
63
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
73
64
          return 0;
74
65
        }
75
66
      }
91
82
 
92
83
        res= args[0]->val_str(&tmp);
93
84
 
94
 
        if (res && (res != &tmp))
95
 
        {
96
 
          tmp.copy(*res);
97
 
        }
98
 
 
99
 
        my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
85
        my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
100
86
        return 0;
101
87
      }
102
88
  }
114
100
  }
115
101
 
116
102
  /* Grab the first argument as a DateTime object */
117
 
  DateTime temporal;
 
103
  drizzled::DateTime temporal;
118
104
  
119
105
  if (! temporal.from_int64_t(args[0]->val_int()))
120
106
  {
141
127
  return (int64_t) temporal.years();
142
128
}
143
129
 
144
 
} /* namespace drizzled */