~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/crc32/crc32udf.cc

  • Committer: Stewart Smith
  • Date: 2009-06-16 00:44:35 UTC
  • mto: (1119.2.6 merge)
  • mto: This revision was merged to the branch mainline in revision 1124.
  • Revision ID: stewart@flamingspork.com-20090616004435-t1vust6erhco7edc
make comment_index test not leave tables behind after running

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
22
 
#include <drizzled/plugin.h>
23
 
#include <drizzled/plugin/function.h>
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/sql_udf.h>
24
22
#include <drizzled/item/func.h>
25
 
#include <drizzled/algorithm/crc32.h>
 
23
#include <zlib.h>
26
24
 
27
25
#include <string>
28
26
 
29
27
using namespace std;
30
 
using namespace drizzled;
31
28
 
32
29
class Crc32Function :public Item_int_func
33
30
{
 
31
  String value;
34
32
public:
35
33
  int64_t val_int();
36
34
  
58
56
int64_t Crc32Function::val_int()
59
57
{
60
58
  assert(fixed == true);
61
 
  String value;
62
59
  String *res=args[0]->val_str(&value);
63
60
  
64
61
  if (res == NULL)
68
65
  }
69
66
 
70
67
  null_value= false;
71
 
  return static_cast<int64_t>(drizzled::algorithm::crc32(res->ptr(), res->length()));
72
 
}
73
 
 
74
 
plugin::Create_function<Crc32Function> *crc32udf= NULL;
75
 
 
76
 
static int initialize(module::Context &context)
77
 
{
78
 
  crc32udf= new plugin::Create_function<Crc32Function>("crc32");
79
 
  context.add(crc32udf);
80
 
  return 0;
81
 
}
82
 
 
83
 
DRIZZLE_PLUGIN(initialize, NULL, NULL);
 
68
  return (int64_t) crc32(0L, (unsigned char*)res->ptr(), res->length());
 
69
}
 
70
 
 
71
Create_function<Crc32Function> crc32udf(string("crc32"));
 
72
 
 
73
static int initialize(drizzled::plugin::Registry &registry)
 
74
{
 
75
  registry.add(&crc32udf);
 
76
  return 0;
 
77
}
 
78
 
 
79
static int finalize(drizzled::plugin::Registry &registry)  
 
80
{
 
81
  registry.remove(&crc32udf);
 
82
  return 0;
 
83
}
 
84
 
 
85
drizzle_declare_plugin(crc32)
 
86
{
 
87
  "crc32",
 
88
  "1.0",
 
89
  "Stewart Smith",
 
90
  "UDF for computing CRC32",
 
91
  PLUGIN_LICENSE_GPL,
 
92
  initialize, /* Plugin Init */
 
93
  finalize,   /* Plugin Deinit */
 
94
  NULL,   /* status variables */
 
95
  NULL,   /* system variables */
 
96
  NULL    /* config options */
 
97
}
 
98
drizzle_declare_plugin_end;