~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/item_strfunc.cc

  • Committer: Stewart Smith
  • Date: 2008-07-13 06:56:15 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713065615-vzok75kgnnviokl9
Move MD5() into a UDF

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
#include "mysql_priv.h"
34
34
#include <m_ctype.h>
35
 
#include "my_md5.h"
36
35
#include "sha1.h"
37
36
#include "sha2.h"
38
37
#include <zlib.h>
98
97
          (longlong) 0);
99
98
}
100
99
 
101
 
 
102
 
String *Item_func_md5::val_str(String *str)
103
 
{
104
 
  assert(fixed == 1);
105
 
  String * sptr= args[0]->val_str(str);
106
 
  str->set_charset(&my_charset_bin);
107
 
  if (sptr)
108
 
  {
109
 
    my_MD5_CTX context;
110
 
    uchar digest[16];
111
 
 
112
 
    null_value=0;
113
 
    my_MD5Init (&context);
114
 
    my_MD5Update (&context,(uchar *) sptr->ptr(), sptr->length());
115
 
    my_MD5Final (digest, &context);
116
 
    if (str->alloc(32))                         // Ensure that memory is free
117
 
    {
118
 
      null_value=1;
119
 
      return 0;
120
 
    }
121
 
    sprintf((char *) str->ptr(),
122
 
            "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
123
 
            digest[0], digest[1], digest[2], digest[3],
124
 
            digest[4], digest[5], digest[6], digest[7],
125
 
            digest[8], digest[9], digest[10], digest[11],
126
 
            digest[12], digest[13], digest[14], digest[15]);
127
 
    str->length((uint) 32);
128
 
    return str;
129
 
  }
130
 
  null_value=1;
131
 
  return 0;
132
 
}
133
 
 
134
 
 
135
 
void Item_func_md5::fix_length_and_dec()
136
 
{
137
 
  max_length=32;
138
 
  /*
139
 
    The MD5() function treats its parameter as being a case sensitive. Thus
140
 
    we set binary collation on it so different instances of MD5() will be
141
 
    compared properly.
142
 
  */
143
 
  args[0]->collation.set(
144
 
      get_charset_by_csname(args[0]->collation.collation->csname,
145
 
                            MY_CS_BINSORT,MYF(0)), DERIVATION_COERCIBLE);
146
 
}
147
 
 
148
100
/**
149
101
  Concatenate args with the following premises:
150
102
  If only one arg (which is ok), return value of arg;