00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <drizzled/charset_info.h>
00024 #include <drizzled/function/str/strfunc.h>
00025 #include <drizzled/item/func.h>
00026 #include <drizzled/plugin/function.h>
00027
00028 #include <uuid/uuid.h>
00029
00030 #define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
00031
00032 namespace plugin {
00033 namespace uuid {
00034
00035 class Generate: public drizzled::Item_str_func
00036 {
00037 public:
00038 Generate(): drizzled::Item_str_func() {}
00039 void fix_length_and_dec()
00040 {
00041 collation.set(drizzled::system_charset_info);
00042
00043
00044
00045
00046
00047 max_length= UUID_LENGTH * drizzled::system_charset_info->mbmaxlen;
00048 }
00049 const char *func_name() const{ return "uuid"; }
00050 drizzled::String *val_str(drizzled::String *);
00051 };
00052
00053 drizzled::String *Generate::val_str(drizzled::String *str)
00054 {
00055 uuid_t uu;
00056 char *uuid_string;
00057
00058
00059 str->realloc(UUID_LENGTH+1);
00060 str->length(UUID_LENGTH);
00061 str->set_charset(drizzled::system_charset_info);
00062 uuid_string= (char *) str->ptr();
00063 uuid_generate(uu);
00064 uuid_unparse(uu, uuid_string);
00065
00066 return str;
00067 }
00068
00069 }
00070 }
00071
00072 static int initialize(drizzled::module::Context &context)
00073 {
00074 context.add(new drizzled::plugin::Create_function<plugin::uuid::Generate>("uuid"));
00075
00076 return 0;
00077 }
00078
00079 DRIZZLE_DECLARE_PLUGIN
00080 {
00081 DRIZZLE_VERSION_ID,
00082 "uuid",
00083 "1.1",
00084 "Stewart Smith, Brian Aker",
00085 "UUID() function using libuuid",
00086 drizzled::PLUGIN_LICENSE_GPL,
00087 initialize,
00088 NULL,
00089 NULL
00090 }
00091 DRIZZLE_DECLARE_PLUGIN_END;