Drizzled Public API Documentation

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 
24 using namespace std;
25 using namespace drizzled;
26 
28 {
29  String value;
30 public:
31  int64_t val_int();
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 
65 plugin::Create_function<LengthFunction> *lengthudf= NULL;
66 plugin::Create_function<LengthFunction> *octet_lengthudf= NULL;
67 
68 static 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 
77 DRIZZLE_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 }
89 DRIZZLE_DECLARE_PLUGIN_END;