1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
5
5
* Copyright (C) 2010 Stewart Smith
7
7
* This program is free software; you can redistribute it and/or modify
21
21
#include "config.h"
23
#include <drizzled/charset_info.h>
22
#include <drizzled/plugin/function.h>
23
#include <drizzled/item/func.h>
24
24
#include <drizzled/function/str/strfunc.h>
25
#include <drizzled/item/func.h>
26
#include <drizzled/plugin/function.h>
28
25
#include <uuid/uuid.h>
30
27
#define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
29
using namespace drizzled;
35
class Generate: public drizzled::Item_str_func
31
class UuidFunction: public Item_str_func
38
Generate(): drizzled::Item_str_func() {}
39
void fix_length_and_dec()
41
collation.set(drizzled::system_charset_info);
34
UuidFunction(): Item_str_func() {}
35
void fix_length_and_dec() {
36
collation.set(system_charset_info);
43
38
NOTE! uuid() should be changed to use 'ascii'
44
39
charset when hex(), format(), md5(), etc, and implicit
45
40
number-to-string conversion will use 'ascii'
47
max_length= UUID_LENGTH * drizzled::system_charset_info->mbmaxlen;
42
max_length= UUID_LENGTH * system_charset_info->mbmaxlen;
49
44
const char *func_name() const{ return "uuid"; }
50
drizzled::String *val_str(drizzled::String *);
45
String *val_str(String *);
53
drizzled::String *Generate::val_str(drizzled::String *str)
48
String *UuidFunction::val_str(String *str)
58
53
/* 36 characters for uuid string +1 for NULL */
59
54
str->realloc(UUID_LENGTH+1);
60
55
str->length(UUID_LENGTH);
61
str->set_charset(drizzled::system_charset_info);
56
str->set_charset(system_charset_info);
62
57
uuid_string= (char *) str->ptr();
58
uuid_generate_random(uu);
64
59
uuid_unparse(uu, uuid_string);
64
plugin::Create_function<UuidFunction> *uuid_function= NULL;
72
66
static int initialize(drizzled::module::Context &context)
74
context.add(new drizzled::plugin::Create_function<plugin::uuid::Generate>("uuid"));
68
uuid_function= new plugin::Create_function<UuidFunction>("uuid");
69
context.add(uuid_function);
81
75
DRIZZLE_VERSION_ID,
84
"Stewart Smith, Brian Aker",
85
79
"UUID() function using libuuid",
86
drizzled::PLUGIN_LICENSE_GPL,
87
81
initialize, /* Plugin Init */
82
NULL, /* system variables */
89
83
NULL /* config options */
91
85
DRIZZLE_DECLARE_PLUGIN_END;