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