~drizzle-trunk/drizzle/development

1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
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
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 <drizzled/server_includes.h>
21
#include <drizzled/function/math/int.h>
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
22
#include <drizzled/plugin/function.h>
1086.4.3 by Devananda
fixed plugin/charlength/charlength.cc compile errors
23
24
using namespace std;
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
25
using namespace drizzled;
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
26
27
class CharLengthFunction :public Item_int_func
28
{
29
  String value;
30
public:
31
  int64_t val_int();
32
  CharLengthFunction() :Item_int_func() {}
33
  
34
  const char *func_name() const 
35
  { 
36
    return "char_length"; 
37
  }
38
39
  void fix_length_and_dec() 
40
  { 
1086.5.3 by devananda
formatting cleanup
41
    max_length= 10;
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
42
  }
43
44
  bool check_argument_count(int n)
45
  {
1086.5.3 by devananda
formatting cleanup
46
    return (n == 1);
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
47
  }
48
};
49
50
51
int64_t CharLengthFunction::val_int()
52
{
1086.5.3 by devananda
formatting cleanup
53
  assert(fixed == true);
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
54
  String *res=args[0]->val_str(&value);
55
  
1086.5.3 by devananda
formatting cleanup
56
  if (res == NULL)
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
57
  {
1086.5.3 by devananda
formatting cleanup
58
    null_value= true;
59
    return 0;
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
60
  }
61
  
1086.5.3 by devananda
formatting cleanup
62
  null_value= false;
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
63
  return (int64_t) res->numchars();
64
}
65
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
66
plugin::Create_function<CharLengthFunction> *charlengthudf= NULL;
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
67
1110.1.5 by Monty Taylor
Renamed PluginRegistry to plugin::Registry.
68
static int initialize(drizzled::plugin::Registry &registry)
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
69
{
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
70
  charlengthudf= new plugin::Create_function<CharLengthFunction>("char_length");
71
  charlengthudf->addAlias("character_length");
1130.1.8 by Monty Taylor
Added polymorphic add/remove methods around slot add/remove methods.
72
  registry.add(charlengthudf);
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
73
  return 0;
74
}
75
1110.1.5 by Monty Taylor
Renamed PluginRegistry to plugin::Registry.
76
static int finalize(drizzled::plugin::Registry &registry)
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
77
{
1130.1.8 by Monty Taylor
Added polymorphic add/remove methods around slot add/remove methods.
78
   registry.remove(charlengthudf);
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
79
   delete charlengthudf;
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
80
   return 0;
81
}
82
1228.1.5 by Monty Taylor
Merged in some naming things.
83
DRIZZLE_DECLARE_PLUGIN
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
84
{
85
  "charlength",
86
  "1.0",
87
  "Devananda van der Veen",
88
  "Return the number of characters in a string",
89
  PLUGIN_LICENSE_GPL,
90
  initialize, /* Plugin Init */
91
  finalize,   /* Plugin Deinit */
92
  NULL,   /* status variables */
93
  NULL,   /* system variables */
94
  NULL    /* config options */
95
}
1228.1.5 by Monty Taylor
Merged in some naming things.
96
DRIZZLE_DECLARE_PLUGIN_END;