~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/length/length.cc

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 "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
 
 
27
 
class LengthFunction :public Item_int_func
28
 
{
29
 
  String value;
30
 
public:
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
 
 
44
 
  bool check_argument_count(int n)
45
 
  {
46
 
    return (n == 1);
47
 
  }
48
 
};
49
 
 
50
 
int64_t LengthFunction::val_int()
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::plugin::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
 
  "Return the byte length of a string",
84
 
  PLUGIN_LICENSE_GPL,
85
 
  initialize, /* Plugin Init */
86
 
  NULL,   /* system variables */
87
 
  NULL    /* config options */
88
 
}
89
 
DRIZZLE_DECLARE_PLUGIN_END;