drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
crc32udf.cc
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, Inc.
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
22
#include <drizzled/plugin.h>
23
#include <drizzled/plugin/function.h>
24
#include <drizzled/item/func.h>
25
#include <drizzled/algorithm/crc32.h>
26
27
#include <string>
28
29
using namespace
std
;
30
using namespace
drizzled
;
31
32
class
Crc32Function :
public
Item_int_func
33
{
34
public
:
35
int64_t
val_int
();
36
37
Crc32Function()
38
{
39
unsigned_flag=
true
;
40
}
41
42
const
char
*func_name()
const
43
{
44
return
"crc32"
;
45
}
46
47
void
fix_length_and_dec()
48
{
49
max_length= 10;
50
}
51
52
bool
check_argument_count
(
int
n)
53
{
54
return
(n == 1);
55
}
56
};
57
58
int64_t
Crc32Function::val_int
()
59
{
60
assert(
fixed
==
true
);
61
String
value;
62
String
*res=args[0]->val_str(&value);
63
64
if
(res == NULL)
65
{
66
null_value
=
true
;
67
return
0;
68
}
69
70
null_value
=
false
;
71
return
static_cast<
int64_t
>
(drizzled::algorithm::crc32(res->ptr(), res->length()));
72
}
73
74
static
int
initialize(
module::Context
&context)
75
{
76
context.add(
new
plugin::Create_function<Crc32Function>
(
"crc32"
));
77
return
0;
78
}
79
80
DRIZZLE_DECLARE_PLUGIN
81
{
82
DRIZZLE_VERSION_ID,
83
"crc32"
,
84
"1.0"
,
85
"Stewart Smith"
,
86
N_(
"CRC32 function"
),
87
PLUGIN_LICENSE_GPL,
88
initialize,
89
NULL,
90
NULL,
91
}
92
DRIZZLE_DECLARE_PLUGIN_END;
Crc32Function::check_argument_count
bool check_argument_count(int n)
Definition
crc32udf.cc:52
Crc32Function::val_int
int64_t val_int()
Definition
crc32udf.cc:58
drizzled::Item::fixed
bool fixed
Definition
item.h:122
drizzled::Item::null_value
bool null_value
Definition
item.h:124
drizzled::String
Definition
sql_string.h:58
drizzled::module::Context
Definition
module/context.h:45
drizzled::plugin::Create_function
Definition
drizzled/plugin/function.h:68
drizzled
TODO: Rename this file - func.h is stupid.
Definition
abort_exception.h:27
std
STL namespace.
← Back to Drizzle docs
plugin
crc32
crc32udf.cc
Generated by
1.15.0