1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
5 |
* Copyright (C) 2010 Stewart Smith
|
6 |
*
|
|
7 |
* This program is free software; you can redistribute it and/or modify
|
|
8 |
* it under the terms of the GNU General Public License as published by
|
|
9 |
* the Free Software Foundation; version 2 of the License.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
21 |
#include "config.h" |
|
22 |
#include <drizzled/plugin/function.h> |
|
23 |
#include <drizzled/item/func.h> |
|
24 |
#include <drizzled/function/str/strfunc.h> |
|
25 |
#include <uuid/uuid.h> |
|
26 |
||
27 |
#define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
|
|
28 |
||
1996.2.1
by Brian Aker
uuid type code. |
29 |
namespace plugin { |
30 |
namespace uuid { |
|
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
31 |
|
1996.2.1
by Brian Aker
uuid type code. |
32 |
class Generate: public drizzled::Item_str_func |
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
33 |
{
|
34 |
public: |
|
1996.2.1
by Brian Aker
uuid type code. |
35 |
Generate(): drizzled::Item_str_func() {} |
36 |
void fix_length_and_dec() |
|
37 |
{
|
|
38 |
collation.set(drizzled::system_charset_info); |
|
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
39 |
/*
|
40 |
NOTE! uuid() should be changed to use 'ascii'
|
|
41 |
charset when hex(), format(), md5(), etc, and implicit
|
|
42 |
number-to-string conversion will use 'ascii'
|
|
43 |
*/
|
|
1996.2.1
by Brian Aker
uuid type code. |
44 |
max_length= UUID_LENGTH * drizzled::system_charset_info->mbmaxlen; |
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
45 |
}
|
46 |
const char *func_name() const{ return "uuid"; } |
|
1996.2.1
by Brian Aker
uuid type code. |
47 |
drizzled::String *val_str(drizzled::String *); |
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
48 |
};
|
49 |
||
1996.2.1
by Brian Aker
uuid type code. |
50 |
drizzled::String *Generate::val_str(drizzled::String *str) |
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
51 |
{
|
52 |
uuid_t uu; |
|
53 |
char *uuid_string; |
|
54 |
||
55 |
/* 36 characters for uuid string +1 for NULL */
|
|
56 |
str->realloc(UUID_LENGTH+1); |
|
57 |
str->length(UUID_LENGTH); |
|
1996.2.1
by Brian Aker
uuid type code. |
58 |
str->set_charset(drizzled::system_charset_info); |
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
59 |
uuid_string= (char *) str->ptr(); |
1996.2.1
by Brian Aker
uuid type code. |
60 |
uuid_generate(uu); |
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
61 |
uuid_unparse(uu, uuid_string); |
62 |
||
63 |
return str; |
|
64 |
}
|
|
65 |
||
1996.2.1
by Brian Aker
uuid type code. |
66 |
} // uuid |
67 |
} // plugin |
|
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
68 |
|
1530.2.6
by Monty Taylor
Moved plugin::Context to module::Context. |
69 |
static int initialize(drizzled::module::Context &context) |
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
70 |
{
|
1996.2.1
by Brian Aker
uuid type code. |
71 |
context.add(new drizzled::plugin::Create_function<plugin::uuid::Generate>("uuid")); |
72 |
||
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
73 |
return 0; |
74 |
}
|
|
75 |
||
76 |
DRIZZLE_DECLARE_PLUGIN
|
|
77 |
{
|
|
78 |
DRIZZLE_VERSION_ID, |
|
79 |
"uuid", |
|
1996.2.1
by Brian Aker
uuid type code. |
80 |
"1.1", |
81 |
"Stewart Smith, Brian Aker", |
|
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
82 |
"UUID() function using libuuid", |
1996.2.1
by Brian Aker
uuid type code. |
83 |
drizzled::PLUGIN_LICENSE_GPL, |
1300.4.5
by Stewart Smith
convert UUID() to plugin. We move the libuuid requirement to the UUID() function plugin as it's not neeeded anywhere else |
84 |
initialize, /* Plugin Init */ |
85 |
NULL, /* system variables */ |
|
86 |
NULL /* config options */ |
|
87 |
}
|
|
88 |
DRIZZLE_DECLARE_PLUGIN_END; |