~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/uuid_function/uuid_function.cc

  • Committer: Brian Aker
  • Date: 2010-12-16 04:01:22 UTC
  • mfrom: (1996.2.1 compare)
  • Revision ID: brian@tangent.org-20101216040122-eodh5shwsij35ybe
Merge in uuid tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
#define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
28
28
 
29
 
using namespace drizzled;
 
29
namespace plugin {
 
30
namespace uuid {
30
31
 
31
 
class UuidFunction: public Item_str_func
 
32
class Generate: public drizzled::Item_str_func
32
33
{
33
34
public:
34
 
  UuidFunction(): Item_str_func() {}
35
 
  void fix_length_and_dec() {
36
 
    collation.set(system_charset_info);
 
35
  Generate(): drizzled::Item_str_func() {}
 
36
  void fix_length_and_dec()
 
37
  {
 
38
    collation.set(drizzled::system_charset_info);
37
39
    /*
38
40
       NOTE! uuid() should be changed to use 'ascii'
39
41
       charset when hex(), format(), md5(), etc, and implicit
40
42
       number-to-string conversion will use 'ascii'
41
43
    */
42
 
    max_length= UUID_LENGTH * system_charset_info->mbmaxlen;
 
44
    max_length= UUID_LENGTH * drizzled::system_charset_info->mbmaxlen;
43
45
  }
44
46
  const char *func_name() const{ return "uuid"; }
45
 
  String *val_str(String *);
 
47
  drizzled::String *val_str(drizzled::String *);
46
48
};
47
49
 
48
 
String *UuidFunction::val_str(String *str)
 
50
drizzled::String *Generate::val_str(drizzled::String *str)
49
51
{
50
52
  uuid_t uu;
51
53
  char *uuid_string;
53
55
  /* 36 characters for uuid string +1 for NULL */
54
56
  str->realloc(UUID_LENGTH+1);
55
57
  str->length(UUID_LENGTH);
56
 
  str->set_charset(system_charset_info);
 
58
  str->set_charset(drizzled::system_charset_info);
57
59
  uuid_string= (char *) str->ptr();
58
 
  uuid_generate_random(uu);
 
60
  uuid_generate(uu);
59
61
  uuid_unparse(uu, uuid_string);
60
62
 
61
63
  return str;
62
64
}
63
65
 
64
 
plugin::Create_function<UuidFunction> *uuid_function= NULL;
 
66
} // uuid
 
67
} // plugin
65
68
 
66
69
static int initialize(drizzled::module::Context &context)
67
70
{
68
 
  uuid_function= new plugin::Create_function<UuidFunction>("uuid");
69
 
  context.add(uuid_function);
 
71
  context.add(new drizzled::plugin::Create_function<plugin::uuid::Generate>("uuid"));
 
72
 
70
73
  return 0;
71
74
}
72
75
 
74
77
{
75
78
  DRIZZLE_VERSION_ID,
76
79
  "uuid",
77
 
  "1.0",
78
 
  "Stewart Smith",
 
80
  "1.1",
 
81
  "Stewart Smith, Brian Aker",
79
82
  "UUID() function using libuuid",
80
 
  PLUGIN_LICENSE_GPL,
 
83
  drizzled::PLUGIN_LICENSE_GPL,
81
84
  initialize, /* Plugin Init */
82
85
  NULL,   /* system variables */
83
86
  NULL    /* config options */