~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Eric Day
  • Date: 2009-11-10 22:59:28 UTC
  • mto: This revision was merged to the branch mainline in revision 1218.
  • Revision ID: eday@oddments.org-20091110225928-hht1klldtfflwixc
Fixed header file guards and fixed test cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
21
 
 
22
 
#include <drizzled/temporal.h>
23
 
#include <drizzled/error.h>
24
 
#include <drizzled/function/time/weekday.h>
25
 
#include <drizzled/util/test.h>
26
 
 
27
 
namespace drizzled
28
 
{
 
20
#include "drizzled/server_includes.h"
 
21
#include CSTDINT_H
 
22
#include "drizzled/temporal.h"
 
23
#include "drizzled/error.h"
 
24
#include "drizzled/function/time/weekday.h"
29
25
 
30
26
int64_t Item_func_weekday::val_int()
31
27
{
39
35
  }
40
36
 
41
37
  /* Grab the first argument as a DateTime object */
42
 
  DateTime temporal;
 
38
  drizzled::DateTime temporal;
43
39
  Item_result arg0_result_type= args[0]->result_type();
44
40
  
45
41
  switch (arg0_result_type)
58
54
        char buff[DRIZZLE_MAX_LENGTH_DATETIME_AS_STRING];
59
55
        String tmp(buff,sizeof(buff), &my_charset_utf8_bin);
60
56
        String *res= args[0]->val_str(&tmp);
61
 
 
62
 
        if (res && (res != &tmp))
63
 
        {
64
 
          tmp.copy(*res);
65
 
        }
66
 
 
67
 
        if (! temporal.from_string(tmp.c_ptr(), tmp.length()))
 
57
        if (! temporal.from_string(res->c_ptr(), res->length()))
68
58
        {
69
59
          /* 
70
60
          * Could not interpret the function argument as a temporal value, 
71
61
          * so throw an error and return 0
72
62
          */
73
 
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
63
          my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
74
64
          return 0;
75
65
        }
76
66
      }
92
82
 
93
83
        res= args[0]->val_str(&tmp);
94
84
 
95
 
        if (res && (res != &tmp))
96
 
        {
97
 
          tmp.copy(*res);
98
 
        }
99
 
 
100
 
        my_error(ER_INVALID_DATETIME_VALUE, MYF(0), tmp.c_ptr());
 
85
        my_error(ER_INVALID_DATETIME_VALUE, MYF(0), res->c_ptr());
101
86
        return 0;
102
87
      }
103
88
  }
106
91
  int64_t julian_day= julian_day_number_from_gregorian_date(temporal.years(), temporal.months(), temporal.days());
107
92
  return (int64_t) day_of_week(julian_day, sunday_first) + test(odbc_type);
108
93
}
109
 
 
110
 
} /* namespace drizzled */