~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to plugin/crc32/crc32udf.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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/plugin/function.h>
 
22
#include <drizzled/item/func.h>
 
23
#include <drizzled/algorithm/crc32.h>
 
24
 
 
25
#include <string>
 
26
 
 
27
using namespace std;
 
28
using namespace drizzled;
 
29
 
 
30
class Crc32Function :public Item_int_func
 
31
{
 
32
public:
 
33
  int64_t val_int();
 
34
  
 
35
  Crc32Function() :Item_int_func() 
 
36
  { 
 
37
    unsigned_flag= true; 
 
38
  }
 
39
  
 
40
  const char *func_name() const 
 
41
  { 
 
42
    return "crc32"; 
 
43
  }
 
44
  
 
45
  void fix_length_and_dec() 
 
46
  { 
 
47
    max_length= 10; 
 
48
  }
 
49
  
 
50
  bool check_argument_count(int n) 
 
51
  { 
 
52
    return (n == 1); 
 
53
  }
 
54
};
 
55
 
 
56
int64_t Crc32Function::val_int()
 
57
{
 
58
  assert(fixed == true);
 
59
  String value;
 
60
  String *res=args[0]->val_str(&value);
 
61
  
 
62
  if (res == NULL)
 
63
  {
 
64
    null_value= true;
 
65
    return 0;
 
66
  }
 
67
 
 
68
  null_value= false;
 
69
  return static_cast<int64_t>(drizzled::algorithm::crc32(res->ptr(), res->length()));
 
70
}
 
71
 
 
72
plugin::Create_function<Crc32Function> *crc32udf= NULL;
 
73
 
 
74
static int initialize(plugin::Registry &registry)
 
75
{
 
76
  crc32udf= new plugin::Create_function<Crc32Function>("crc32");
 
77
  registry.add(crc32udf);
 
78
  return 0;
 
79
}
 
80
 
 
81
static int finalize(plugin::Registry &registry)  
 
82
{
 
83
  registry.remove(crc32udf);
 
84
  delete crc32udf;
 
85
  return 0;
 
86
}
 
87
 
 
88
DRIZZLE_PLUGIN(initialize, finalize, NULL);