#include <item_strfunc.h>
Inheritance diagram for Item_func_quote:


Public Member Functions | |
| Item_func_quote (Item *a) | |
| const char * | func_name () const |
| String * | val_str (String *) |
| void | fix_length_and_dec () |
|
|
00598 :Item_str_func(a) {}
|
|
|
Implements Item_result_field. 00602 {
00603 collation.set(args[0]->collation);
00604 max_length= args[0]->max_length * 2 + 2;
00605 }
|
|
|
Reimplemented from Item_func. 00599 { return "quote"; }
|
|
|
Implements Item. 02588 {
02589 DBUG_ASSERT(fixed == 1);
02590 /*
02591 Bit mask that has 1 for set for the position of the following characters:
02592 0, \, ' and ^Z
02593 */
02594
02595 static uchar escmask[32]=
02596 {
02597 0x01, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x00,
02598 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
02599 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
02600 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
02601 };
02602
02603 char *from, *to, *end, *start;
02604 String *arg= args[0]->val_str(str);
02605 uint arg_length, new_length;
02606 if (!arg) // Null argument
02607 {
02608 str->copy("NULL", 4, collation.collation); // Return the string 'NULL'
02609 null_value= 0;
02610 return str;
02611 }
02612
02613 arg_length= arg->length();
02614 new_length= arg_length+2; /* for beginning and ending ' signs */
02615
02616 for (from= (char*) arg->ptr(), end= from + arg_length; from < end; from++)
02617 new_length+= get_esc_bit(escmask, (uchar) *from);
02618
02619 /*
02620 We have to use realloc() instead of alloc() as we want to keep the
02621 old result in str
02622 */
02623 if (str->realloc(new_length))
02624 goto null;
02625
02626 /*
02627 As 'arg' and 'str' may be the same string, we must replace characters
02628 from the end to the beginning
02629 */
02630 to= (char*) str->ptr() + new_length - 1;
02631 *to--= '\'';
02632 for (start= (char*) arg->ptr(),end= start + arg_length; end-- != start; to--)
02633 {
02634 /*
02635 We can't use the bitmask here as we want to replace \O and ^Z with 0
02636 and Z
02637 */
02638 switch (*end) {
02639 case 0:
02640 *to--= '0';
02641 *to= '\\';
02642 break;
02643 case '\032':
02644 *to--= 'Z';
02645 *to= '\\';
02646 break;
02647 case '\'':
02648 case '\\':
02649 *to--= *end;
02650 *to= '\\';
02651 break;
02652 default:
02653 *to= *end;
02654 break;
02655 }
02656 }
02657 *to= '\'';
02658 str->length(new_length);
02659 str->set_charset(collation.collation);
02660 null_value= 0;
02661 return str;
02662
02663 null:
02664 null_value= 1;
02665 return 0;
02666 }
|
1.3.9.1