~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/uuid_function/uuid_function.cc

  • Committer: Stewart Smith
  • Author(s): Marko Mäkelä, Stewart Smith
  • Date: 2010-11-17 05:52:09 UTC
  • mto: (2021.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1971.
  • Revision ID: stewart@flamingspork.com-20101117055209-69m035q6h7e1txrc
Merge Revision revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg from MySQL InnoDB

Original revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg

Original Authors: Marko Mkel <marko.makela@oracle.com>
Original commit message:
Bug#52199 utf32: mbminlen=4, mbmaxlen=4, type->mbminlen=0, type->mbmaxlen=4

Merge and adjust a forgotten change to fix this bug.
rb://393 approved by Jimmy Yang
  ------------------------------------------------------------------------
  r3794 | marko | 2009-01-07 14:14:53 +0000 (Wed, 07 Jan 2009) | 18 lines

  branches/6.0: Allow the minimum length of a multi-byte character to be
  up to 4 bytes. (Bug #35391)

  dtype_t, dict_col_t: Replace mbminlen:2, mbmaxlen:3 with mbminmaxlen:5.
  In this way, the 5 bits can hold two values of 0..4, and the storage size
  of the fields will not cross the 64-bit boundary.  Encode the values as
  DATA_MBMAX * mbmaxlen + mbminlen.  Define the auxiliary macros
  DB_MBMINLEN(mbminmaxlen), DB_MBMAXLEN(mbminmaxlen), and
  DB_MINMAXLEN(mbminlen, mbmaxlen).

  Try to trim and pad UTF-16 and UTF-32 with spaces as appropriate.

  Alexander Barkov suggested the use of cs->cset->fill(cs, buff, len, 0x20).
  ha_innobase::store_key_val_for_row() now does that, but the added function
  row_mysql_pad_col() does not, because it doesn't have the MySQL TABLE object.

  rb://49 approved by Heikki Tuuri
  ------------------------------------------------------------------------

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *  Copyright (C) 2010 Stewart Smith
6
6
 *
7
7
 *  This program is free software; you can redistribute it and/or modify
19
19
 */
20
20
 
21
21
#include "config.h"
22
 
 
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>
27
 
 
28
25
#include <uuid/uuid.h>
29
26
 
30
27
#define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
31
28
 
32
 
namespace plugin {
33
 
namespace uuid {
 
29
using namespace drizzled;
34
30
 
35
 
class Generate: public drizzled::Item_str_func
 
31
class UuidFunction: public Item_str_func
36
32
{
37
33
public:
38
 
  Generate(): drizzled::Item_str_func() {}
39
 
  void fix_length_and_dec()
40
 
  {
41
 
    collation.set(drizzled::system_charset_info);
 
34
  UuidFunction(): Item_str_func() {}
 
35
  void fix_length_and_dec() {
 
36
    collation.set(system_charset_info);
42
37
    /*
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'
46
41
    */
47
 
    max_length= UUID_LENGTH * drizzled::system_charset_info->mbmaxlen;
 
42
    max_length= UUID_LENGTH * system_charset_info->mbmaxlen;
48
43
  }
49
44
  const char *func_name() const{ return "uuid"; }
50
 
  drizzled::String *val_str(drizzled::String *);
 
45
  String *val_str(String *);
51
46
};
52
47
 
53
 
drizzled::String *Generate::val_str(drizzled::String *str)
 
48
String *UuidFunction::val_str(String *str)
54
49
{
55
50
  uuid_t uu;
56
51
  char *uuid_string;
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();
63
 
  uuid_generate(uu);
 
58
  uuid_generate_random(uu);
64
59
  uuid_unparse(uu, uuid_string);
65
60
 
66
61
  return str;
67
62
}
68
63
 
69
 
} // uuid
70
 
} // plugin
 
64
plugin::Create_function<UuidFunction> *uuid_function= NULL;
71
65
 
72
66
static int initialize(drizzled::module::Context &context)
73
67
{
74
 
  context.add(new drizzled::plugin::Create_function<plugin::uuid::Generate>("uuid"));
75
 
 
 
68
  uuid_function= new plugin::Create_function<UuidFunction>("uuid");
 
69
  context.add(uuid_function);
76
70
  return 0;
77
71
}
78
72
 
80
74
{
81
75
  DRIZZLE_VERSION_ID,
82
76
  "uuid",
83
 
  "1.1",
84
 
  "Stewart Smith, Brian Aker",
 
77
  "1.0",
 
78
  "Stewart Smith",
85
79
  "UUID() function using libuuid",
86
 
  drizzled::PLUGIN_LICENSE_GPL,
 
80
  PLUGIN_LICENSE_GPL,
87
81
  initialize, /* Plugin Init */
88
 
  NULL,   /* depends */
 
82
  NULL,   /* system variables */
89
83
  NULL    /* config options */
90
84
}
91
85
DRIZZLE_DECLARE_PLUGIN_END;