drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
charlength.cc
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, Inc.
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 <config.h>
21
22#include <drizzled/function/math/int.h>
23#include <drizzled/plugin.h>
24#include <drizzled/plugin/function.h>
25
26using namespace std;
27using namespace drizzled;
28
29class CharLengthFunction :public Item_int_func
30{
31 String value;
32public:
33 int64_t val_int();
34 CharLengthFunction() :Item_int_func() {}
35
36 const char *func_name() const
37 {
38 return "char_length";
39 }
40
41 void fix_length_and_dec()
42 {
43 max_length= 10;
44 }
45
47 {
48 return (n == 1);
49 }
50};
51
52
54{
55 assert(fixed == true);
56 String *res=args[0]->val_str(&value);
57
58 if (res == NULL)
59 {
60 null_value= true;
61 return 0;
62 }
63
64 null_value= false;
65 return (int64_t) res->numchars();
66}
67
69plugin::Create_function<CharLengthFunction> *characterlengthudf= NULL;
70
71static int initialize(drizzled::module::Context &context)
72{
73 charlengthudf= new plugin::Create_function<CharLengthFunction>("char_length");
74 characterlengthudf= new plugin::Create_function<CharLengthFunction>("character_length");
75 context.add(charlengthudf);
76 context.add(characterlengthudf);
77 return 0;
78}
79
80DRIZZLE_DECLARE_PLUGIN
81{
82 DRIZZLE_VERSION_ID,
83 "charlength",
84 "1.0",
85 "Devananda van der Veen",
86 N_("CHAR_LENGTH and CHARACTER_LENGTH functions"),
87 PLUGIN_LICENSE_GPL,
88 initialize,
89 NULL,
90 NULL
91}
92DRIZZLE_DECLARE_PLUGIN_END;
bool check_argument_count(int n)
Definition charlength.cc:46
bool fixed
Definition item.h:122
bool null_value
Definition item.h:124
TODO: Rename this file - func.h is stupid.
STL namespace.