~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
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <config.h>
2148.7.12 by Brian Aker
Merge in header fixes.
21
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
22
#include <drizzled/function/math/int.h>
2148.7.12 by Brian Aker
Merge in header fixes.
23
#include <drizzled/plugin.h>
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
24
#include <drizzled/plugin/function.h>
1086.4.3 by Devananda
fixed plugin/charlength/charlength.cc compile errors
25
26
using namespace std;
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
27
using namespace drizzled;
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
28
29
class CharLengthFunction :public Item_int_func
30
{
31
  String value;
32
public:
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
  { 
1086.5.3 by devananda
formatting cleanup
43
    max_length= 10;
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
44
  }
45
46
  bool check_argument_count(int n)
47
  {
1086.5.3 by devananda
formatting cleanup
48
    return (n == 1);
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
49
  }
50
};
51
52
53
int64_t CharLengthFunction::val_int()
54
{
1086.5.3 by devananda
formatting cleanup
55
  assert(fixed == true);
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
56
  String *res=args[0]->val_str(&value);
57
  
1086.5.3 by devananda
formatting cleanup
58
  if (res == NULL)
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
59
  {
1086.5.3 by devananda
formatting cleanup
60
    null_value= true;
61
    return 0;
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
62
  }
63
  
1086.5.3 by devananda
formatting cleanup
64
  null_value= false;
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
65
  return (int64_t) res->numchars();
66
}
67
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
68
plugin::Create_function<CharLengthFunction> *charlengthudf= NULL;
1228.3.1 by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just
69
plugin::Create_function<CharLengthFunction> *characterlengthudf= NULL;
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
70
1530.2.6 by Monty Taylor
Moved plugin::Context to module::Context.
71
static int initialize(drizzled::module::Context &context)
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
72
{
1093.1.62 by Monty Taylor
Moved UDFs to slot organization.
73
  charlengthudf= new plugin::Create_function<CharLengthFunction>("char_length");
1228.3.1 by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just
74
  characterlengthudf= new plugin::Create_function<CharLengthFunction>("character_length");
1324.2.2 by Monty Taylor
Use the plugin::Context everywhere.
75
  context.add(charlengthudf);
76
  context.add(characterlengthudf);
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
77
  return 0;
78
}
79
1228.1.5 by Monty Taylor
Merged in some naming things.
80
DRIZZLE_DECLARE_PLUGIN
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
81
{
1241.10.2 by Monty Taylor
Added support for embedding the drizzle version number in the plugin file.
82
  DRIZZLE_VERSION_ID,
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
83
  "charlength",
84
  "1.0",
85
  "Devananda van der Veen",
86
  "Return the number of characters in a string",
87
  PLUGIN_LICENSE_GPL,
88
  initialize, /* Plugin Init */
2095.3.1 by Monty Taylor
Re-purpose the old plugin sysvar slot in the struct to be a depends list.
89
  NULL,   /* depends */
1086.4.1 by Devananda
refactored functin/charlength into plugin/charlength
90
  NULL    /* config options */
91
}
1228.1.5 by Monty Taylor
Merged in some naming things.
92
DRIZZLE_DECLARE_PLUGIN_END;