summaryrefslogtreecommitdiff
path: root/sql/item_strfunc.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item_strfunc.h')
-rw-r--r--sql/item_strfunc.h129
1 files changed, 96 insertions, 33 deletions
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index be23f45c286..65c6dacbc73 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -97,23 +97,69 @@ public:
};
-class Item_func_md5 :public Item_str_ascii_func
+/**
+ Functions that return a checksum or a hash of the argument,
+ or somehow else encode or decode the argument,
+ returning an ASCII-repertoire string.
+*/
+class Item_str_ascii_checksum_func: public Item_str_ascii_func
+{
+public:
+ Item_str_ascii_checksum_func(THD *thd, Item *a)
+ :Item_str_ascii_func(thd, a) { }
+ Item_str_ascii_checksum_func(THD *thd, Item *a, Item *b)
+ :Item_str_ascii_func(thd, a, b) { }
+ bool eq(const Item *item, bool binary_cmp) const
+ {
+ // Always use binary argument comparison: MD5('x') != MD5('X')
+ return Item_func::eq(item, true);
+ }
+};
+
+
+/**
+ Functions that return a checksum or a hash of the argument,
+ or somehow else encode or decode the argument,
+ returning a binary string.
+*/
+class Item_str_binary_checksum_func: public Item_str_func
+{
+public:
+ Item_str_binary_checksum_func(THD *thd, Item *a)
+ :Item_str_func(thd, a) { }
+ Item_str_binary_checksum_func(THD *thd, Item *a, Item *b)
+ :Item_str_func(thd, a, b) { }
+ bool eq(const Item *item, bool binary_cmp) const
+ {
+ /*
+ Always use binary argument comparison:
+ FROM_BASE64('test') != FROM_BASE64('TEST')
+ */
+ return Item_func::eq(item, true);
+ }
+};
+
+
+class Item_func_md5 :public Item_str_ascii_checksum_func
{
String tmp_value;
public:
- Item_func_md5(THD *thd, Item *a): Item_str_ascii_func(thd, a) {}
+ Item_func_md5(THD *thd, Item *a): Item_str_ascii_checksum_func(thd, a) {}
String *val_str_ascii(String *);
- void fix_length_and_dec();
+ void fix_length_and_dec()
+ {
+ fix_length_and_charset(32, default_charset());
+ }
const char *func_name() const { return "md5"; }
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_func_md5>(thd, mem_root, this); }
};
-class Item_func_sha :public Item_str_ascii_func
+class Item_func_sha :public Item_str_ascii_checksum_func
{
public:
- Item_func_sha(THD *thd, Item *a): Item_str_ascii_func(thd, a) {}
+ Item_func_sha(THD *thd, Item *a): Item_str_ascii_checksum_func(thd, a) {}
String *val_str_ascii(String *);
void fix_length_and_dec();
const char *func_name() const { return "sha"; }
@@ -121,10 +167,11 @@ public:
{ return get_item_copy<Item_func_sha>(thd, mem_root, this); }
};
-class Item_func_sha2 :public Item_str_ascii_func
+class Item_func_sha2 :public Item_str_ascii_checksum_func
{
public:
- Item_func_sha2(THD *thd, Item *a, Item *b): Item_str_ascii_func(thd, a, b) {}
+ Item_func_sha2(THD *thd, Item *a, Item *b)
+ :Item_str_ascii_checksum_func(thd, a, b) {}
String *val_str_ascii(String *);
void fix_length_and_dec();
const char *func_name() const { return "sha2"; }
@@ -132,11 +179,12 @@ public:
{ return get_item_copy<Item_func_sha2>(thd, mem_root, this); }
};
-class Item_func_to_base64 :public Item_str_ascii_func
+class Item_func_to_base64 :public Item_str_ascii_checksum_func
{
String tmp_value;
public:
- Item_func_to_base64(THD *thd, Item *a): Item_str_ascii_func(thd, a) {}
+ Item_func_to_base64(THD *thd, Item *a)
+ :Item_str_ascii_checksum_func(thd, a) {}
String *val_str_ascii(String *);
void fix_length_and_dec();
const char *func_name() const { return "to_base64"; }
@@ -144,11 +192,12 @@ public:
{ return get_item_copy<Item_func_to_base64>(thd, mem_root, this); }
};
-class Item_func_from_base64 :public Item_str_func
+class Item_func_from_base64 :public Item_str_binary_checksum_func
{
String tmp_value;
public:
- Item_func_from_base64(THD *thd, Item *a): Item_str_func(thd, a) {}
+ Item_func_from_base64(THD *thd, Item *a)
+ :Item_str_binary_checksum_func(thd, a) { }
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "from_base64"; }
@@ -158,7 +207,7 @@ public:
#include <my_crypt.h>
-class Item_aes_crypt :public Item_str_func
+class Item_aes_crypt :public Item_str_binary_checksum_func
{
enum { AES_KEY_LENGTH = 128 };
void create_key(String *user_key, uchar* key);
@@ -166,7 +215,8 @@ class Item_aes_crypt :public Item_str_func
protected:
int what;
public:
- Item_aes_crypt(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b) {}
+ Item_aes_crypt(THD *thd, Item *a, Item *b)
+ :Item_str_binary_checksum_func(thd, a, b) {}
String *val_str(String *);
};
@@ -481,7 +531,7 @@ public:
authentication procedure works, see comments in password.c.
*/
-class Item_func_password :public Item_str_ascii_func
+class Item_func_password :public Item_str_ascii_checksum_func
{
public:
enum PW_Alg {OLD, NEW};
@@ -491,9 +541,9 @@ private:
bool deflt;
public:
Item_func_password(THD *thd, Item *a):
- Item_str_ascii_func(thd, a), alg(NEW), deflt(1) {}
+ Item_str_ascii_checksum_func(thd, a), alg(NEW), deflt(1) {}
Item_func_password(THD *thd, Item *a, PW_Alg al):
- Item_str_ascii_func(thd, a), alg(al), deflt(0) {}
+ Item_str_ascii_checksum_func(thd, a), alg(al), deflt(0) {}
String *val_str_ascii(String *str);
bool fix_fields(THD *thd, Item **ref);
void fix_length_and_dec()
@@ -513,12 +563,14 @@ public:
-class Item_func_des_encrypt :public Item_str_func
+class Item_func_des_encrypt :public Item_str_binary_checksum_func
{
String tmp_value,tmp_arg;
public:
- Item_func_des_encrypt(THD *thd, Item *a): Item_str_func(thd, a) {}
- Item_func_des_encrypt(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b) {}
+ Item_func_des_encrypt(THD *thd, Item *a)
+ :Item_str_binary_checksum_func(thd, a) {}
+ Item_func_des_encrypt(THD *thd, Item *a, Item *b)
+ :Item_str_binary_checksum_func(thd, a, b) {}
String *val_str(String *);
void fix_length_and_dec()
{
@@ -531,12 +583,14 @@ public:
{ return get_item_copy<Item_func_des_encrypt>(thd, mem_root, this); }
};
-class Item_func_des_decrypt :public Item_str_func
+class Item_func_des_decrypt :public Item_str_binary_checksum_func
{
String tmp_value;
public:
- Item_func_des_decrypt(THD *thd, Item *a): Item_str_func(thd, a) {}
- Item_func_des_decrypt(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b) {}
+ Item_func_des_decrypt(THD *thd, Item *a)
+ :Item_str_binary_checksum_func(thd, a) {}
+ Item_func_des_decrypt(THD *thd, Item *a, Item *b)
+ :Item_str_binary_checksum_func(thd, a, b) {}
String *val_str(String *);
void fix_length_and_dec()
{
@@ -551,7 +605,13 @@ public:
{ return get_item_copy<Item_func_des_decrypt>(thd, mem_root, this); }
};
-class Item_func_encrypt :public Item_str_func
+
+/**
+ QQ: Item_func_encrypt should derive from Item_str_ascii_checksum_func.
+ However, it should be fixed to handle UCS2, UTF16, UTF32 properly first,
+ as the underlying crypt() call expects a null-terminated input string.
+*/
+class Item_func_encrypt :public Item_str_binary_checksum_func
{
String tmp_value;
@@ -561,11 +621,12 @@ class Item_func_encrypt :public Item_str_func
collation.set(&my_charset_bin);
}
public:
- Item_func_encrypt(THD *thd, Item *a): Item_str_func(thd, a)
+ Item_func_encrypt(THD *thd, Item *a): Item_str_binary_checksum_func(thd, a)
{
constructor_helper();
}
- Item_func_encrypt(THD *thd, Item *a, Item *b): Item_str_func(thd, a, b)
+ Item_func_encrypt(THD *thd, Item *a, Item *b)
+ :Item_str_binary_checksum_func(thd, a, b)
{
constructor_helper();
}
@@ -583,7 +644,7 @@ public:
#include "sql_crypt.h"
-class Item_func_encode :public Item_str_func
+class Item_func_encode :public Item_str_binary_checksum_func
{
private:
/** Whether the PRNG has already been seeded. */
@@ -592,7 +653,7 @@ protected:
SQL_CRYPT sql_crypt;
public:
Item_func_encode(THD *thd, Item *a, Item *seed_arg):
- Item_str_func(thd, a, seed_arg) {}
+ Item_str_binary_checksum_func(thd, a, seed_arg) {}
String *val_str(String *);
void fix_length_and_dec();
const char *func_name() const { return "encode"; }
@@ -911,12 +972,12 @@ public:
};
-class Item_func_hex :public Item_str_ascii_func
+class Item_func_hex :public Item_str_ascii_checksum_func
{
String tmp_value;
public:
Item_func_hex(THD *thd, Item *a):
- Item_str_ascii_func(thd, a) {}
+ Item_str_ascii_checksum_func(thd, a) {}
const char *func_name() const { return "hex"; }
String *val_str_ascii(String *);
void fix_length_and_dec()
@@ -1291,11 +1352,12 @@ public:
#define ZLIB_DEPENDED_FUNCTION { null_value=1; return 0; }
#endif
-class Item_func_compress: public Item_str_func
+class Item_func_compress: public Item_str_binary_checksum_func
{
String buffer;
public:
- Item_func_compress(THD *thd, Item *a): Item_str_func(thd, a) {}
+ Item_func_compress(THD *thd, Item *a)
+ :Item_str_binary_checksum_func(thd, a) {}
void fix_length_and_dec(){max_length= (args[0]->max_length*120)/100+12;}
const char *func_name() const{return "compress";}
String *val_str(String *) ZLIB_DEPENDED_FUNCTION
@@ -1303,11 +1365,12 @@ public:
{ return get_item_copy<Item_func_compress>(thd, mem_root, this); }
};
-class Item_func_uncompress: public Item_str_func
+class Item_func_uncompress: public Item_str_binary_checksum_func
{
String buffer;
public:
- Item_func_uncompress(THD *thd, Item *a): Item_str_func(thd, a) {}
+ Item_func_uncompress(THD *thd, Item *a)
+ :Item_str_binary_checksum_func(thd, a) {}
void fix_length_and_dec(){ maybe_null= 1; max_length= MAX_BLOB_WIDTH; }
const char *func_name() const{return "uncompress";}
String *val_str(String *) ZLIB_DEPENDED_FUNCTION