Commit 4c3f3b5b authored by unknown's avatar unknown

new QUOTE() fuction has been added


BitKeeper/etc/logging_ok:
  Logging to logging@openlogging.org accepted
parent af27243c
......@@ -73,3 +73,4 @@ worm@altair.is.lan
zak@balfor.local
zak@linux.local
zgreant@mysql.com
ram@ram.(none)
......@@ -440,3 +440,7 @@ Item *create_func_is_free_lock(Item* a)
return new Item_func_is_free_lock(a);
}
Item *create_func_quote(Item* a)
{
return new Item_func_quote(a);
}
......@@ -93,3 +93,4 @@ Item *create_func_weekday(Item* a);
Item *create_load_file(Item* a);
Item *create_wait_for_master_pos(Item* a, Item* b);
Item *create_func_is_free_lock(Item* a);
Item *create_func_quote(Item* a);
......@@ -2070,3 +2070,56 @@ String* Item_func_inet_ntoa::val_str(String* str)
str->length(str->length()-1); // Remove last '.';
return str;
}
String *Item_func_quote::val_str(String *str)
{
String *arg= args[0]->val_str(str);
char *strptr, *argptr, *end, *arglast;
uint delta= 2; /* for beginning and ending ' signs */
for (argptr= (char*) arg->ptr(), end= argptr + arg->length(); argptr < end;
argptr++)
{
switch (*argptr) {
case '\'':
case '\\':
case 0:
case '\032':
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)
{
strptr-= arglast - end;
memmove(strptr, end, arglast - end);
}
*--strptr= '\'';
str->length(arg->length() + delta);
return str;
}
void Item_func_quote::fix_length_and_dec()
{
max_length= args[0]->max_length * 2 + 2;
}
......@@ -535,3 +535,12 @@ class Item_func_export_set: public Item_str_func
const char *func_name() const { return "inet_ntoa"; }
void fix_length_and_dec() { decimals = 0; max_length=3*8+7; }
};
class Item_func_quote :public Item_str_func
{
public:
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();
};
......@@ -475,6 +475,7 @@ static SYMBOL sql_functions[] = {
{ "POW", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_pow)},
{ "POWER", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_pow)},
{ "QUARTER", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_quarter)},
{ "QUOTE", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_quote)},
{ "RADIANS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_radians)},
{ "RAND", SYM(RAND),0,0},
{ "RELEASE_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_release_lock)},
......
......@@ -283,6 +283,7 @@ 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
......@@ -1815,6 +1816,8 @@ 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