Commit 8c1d8eb4 authored by unknown's avatar unknown

QUOTE() func changes according to monty's suggestions


sql/item_strfunc.cc:
  added bitmap for QUOTE() func
sql/item_strfunc.h:
  moved fix_length_and_dec code to .h file
sql/sql_yacc.yy:
  removed QUOTE stuff
parent 744a4f95
......@@ -2071,55 +2071,40 @@ String* Item_func_inet_ntoa::val_str(String* str)
return str;
}
/*
QUOTE() function returns argument string in single quotes,
also adds a \ before \, ' CHAR(0) and CHAR(24)
*/
String *Item_func_quote::val_str(String *str)
{
static char escmask[64] = {0x01, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
String *arg= args[0]->val_str(str);
char *strptr, *argptr, *end, *arglast;
char *from, *to, *end;
uint delta= 2; /* for beginning and ending ' signs */
for (argptr= (char*) arg->ptr(), end= argptr + arg->length(); argptr < end;
argptr++)
for (from= (char*) arg->ptr(), end= from + arg->length(); from < end; from++)
{
switch (*argptr) {
case '\'':
case '\\':
case 0:
case '\032':
if (*(escmask + (*from >> 3)) and (1 << (*from & 7)))
delta++;
}
}
if (str->alloc(arg->length() + delta))
{
null_value= 1;
return 0;
}
strptr= (char*) str->ptr() + arg->length() + delta - 1;
*strptr= '\'';
for (end= (char*) arg->ptr(), arglast= end + arg->length(),
argptr= arglast - 1; argptr >= end; argptr--)
{
switch (*argptr) {
case '\'':
case '\\':
case 0:
case '\032':
strptr-= arglast - argptr;
memmove(strptr, argptr, arglast - argptr);
arglast= argptr;
*--strptr= '\\';
}
}
if (arglast != end)
to= (char*) str->ptr() + arg->length() + delta - 1;
*to--= '\'';
for (end= (char*) arg->ptr(), from= end + arg->length() - 1; from >= end;
from--, to--)
{
strptr-= arglast - end;
memmove(strptr, end, arglast - end);
*to= *from;
if (*(escmask + (*from >> 3)) and (1 << (*from & 7)))
*--to= '\\';
}
*--strptr= '\'';
*to= '\'';
str->length(arg->length() + delta);
return str;
}
void Item_func_quote::fix_length_and_dec()
{
max_length= args[0]->max_length * 2 + 2;
}
......@@ -542,5 +542,5 @@ class Item_func_quote :public Item_str_func
Item_func_quote(Item *a) :Item_str_func(a) {}
const char *func_name() const { return "quote"; }
String *val_str(String *);
void fix_length_and_dec();
void fix_length_and_dec() { max_length= args[0]->max_length * 2 + 2; }
};
......@@ -283,7 +283,6 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token PROCESS
%token PROCESSLIST_SYM
%token QUERY_SYM
%token QUOTE
%token RAID_0_SYM
%token RAID_STRIPED_SYM
%token RAID_TYPE
......@@ -1816,8 +1815,6 @@ simple_expr:
}
| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
{ $$ = new Item_func_locate($5,$3); }
| QUOTE '(' expr ')'
{ $$= new Item_func_quote($3); }
| RAND '(' expr ')'
{ $$= new Item_func_rand($3); current_thd->safe_to_cache_query=0;}
| RAND '(' ')'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment