1086.9.1
by Devananda
refactored function/length into plugin/length |
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 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
20 |
#include "config.h" |
1086.9.1
by Devananda
refactored function/length into plugin/length |
21 |
#include <drizzled/function/math/int.h> |
1130.1.9
by Monty Taylor
Changed some plugins from including slots to include plugins. Oops. |
22 |
#include <drizzled/plugin/function.h> |
1086.9.1
by Devananda
refactored function/length into plugin/length |
23 |
|
24 |
using namespace std; |
|
1093.1.62
by Monty Taylor
Moved UDFs to slot organization. |
25 |
using namespace drizzled; |
1086.9.1
by Devananda
refactored function/length into plugin/length |
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 |
{
|
|
1086.10.3
by devananda
formatting cleanup |
46 |
return (n == 1); |
1086.9.1
by Devananda
refactored function/length into plugin/length |
47 |
}
|
48 |
};
|
|
49 |
||
50 |
int64_t LengthFunction::val_int() |
|
51 |
{
|
|
1086.10.3
by devananda
formatting cleanup |
52 |
assert(fixed == true); |
1086.9.1
by Devananda
refactored function/length into plugin/length |
53 |
String *res=args[0]->val_str(&value); |
54 |
||
1086.10.3
by devananda
formatting cleanup |
55 |
if (res == NULL) |
1086.9.1
by Devananda
refactored function/length into plugin/length |
56 |
{
|
1086.10.3
by devananda
formatting cleanup |
57 |
null_value= true; |
58 |
return 0; |
|
1086.9.1
by Devananda
refactored function/length into plugin/length |
59 |
}
|
60 |
||
1086.10.3
by devananda
formatting cleanup |
61 |
null_value= false; |
1086.9.1
by Devananda
refactored function/length into plugin/length |
62 |
return (int64_t) res->length(); |
63 |
}
|
|
64 |
||
1093.1.62
by Monty Taylor
Moved UDFs to slot organization. |
65 |
plugin::Create_function<LengthFunction> *lengthudf= NULL; |
1228.3.1
by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just |
66 |
plugin::Create_function<LengthFunction> *octet_lengthudf= NULL; |
1086.9.1
by Devananda
refactored function/length into plugin/length |
67 |
|
1530.2.6
by Monty Taylor
Moved plugin::Context to module::Context. |
68 |
static int initialize(drizzled::module::Context &context) |
1086.9.1
by Devananda
refactored function/length into plugin/length |
69 |
{
|
1093.1.62
by Monty Taylor
Moved UDFs to slot organization. |
70 |
lengthudf= new plugin::Create_function<LengthFunction>("length"); |
1228.3.1
by Monty Taylor
Removed NameMap. Also remove the aliases from the plugin, since we can just |
71 |
octet_lengthudf= new plugin::Create_function<LengthFunction>("octet_length"); |
1324.2.2
by Monty Taylor
Use the plugin::Context everywhere. |
72 |
context.add(lengthudf); |
73 |
context.add(octet_lengthudf); |
|
1086.9.1
by Devananda
refactored function/length into plugin/length |
74 |
return 0; |
75 |
}
|
|
76 |
||
1228.1.5
by Monty Taylor
Merged in some naming things. |
77 |
DRIZZLE_DECLARE_PLUGIN
|
1086.9.1
by Devananda
refactored function/length into plugin/length |
78 |
{
|
1241.10.2
by Monty Taylor
Added support for embedding the drizzle version number in the plugin file. |
79 |
DRIZZLE_VERSION_ID, |
1086.9.1
by Devananda
refactored function/length into plugin/length |
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 |
}
|
|
1228.1.5
by Monty Taylor
Merged in some naming things. |
89 |
DRIZZLE_DECLARE_PLUGIN_END; |