Commit b7403f3d authored by ram@ram.(none)'s avatar ram@ram.(none)

new QUOTE() fuction has been added

parent 77296b3f
...@@ -73,3 +73,4 @@ worm@altair.is.lan ...@@ -73,3 +73,4 @@ worm@altair.is.lan
zak@balfor.local zak@balfor.local
zak@linux.local zak@linux.local
zgreant@mysql.com zgreant@mysql.com
ram@ram.(none)
...@@ -440,3 +440,7 @@ Item *create_func_is_free_lock(Item* a) ...@@ -440,3 +440,7 @@ Item *create_func_is_free_lock(Item* a)
return new Item_func_is_free_lock(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); ...@@ -93,3 +93,4 @@ Item *create_func_weekday(Item* a);
Item *create_load_file(Item* a); Item *create_load_file(Item* a);
Item *create_wait_for_master_pos(Item* a, Item* b); Item *create_wait_for_master_pos(Item* a, Item* b);
Item *create_func_is_free_lock(Item* a); 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) ...@@ -2070,3 +2070,56 @@ String* Item_func_inet_ntoa::val_str(String* str)
str->length(str->length()-1); // Remove last '.'; str->length(str->length()-1); // Remove last '.';
return str; 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 @@ public: ...@@ -535,3 +535,12 @@ public:
const char *func_name() const { return "inet_ntoa"; } const char *func_name() const { return "inet_ntoa"; }
void fix_length_and_dec() { decimals = 0; max_length=3*8+7; } 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[] = { ...@@ -475,6 +475,7 @@ static SYMBOL sql_functions[] = {
{ "POW", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_pow)}, { "POW", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_pow)},
{ "POWER", 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)}, { "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)}, { "RADIANS", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_radians)},
{ "RAND", SYM(RAND),0,0}, { "RAND", SYM(RAND),0,0},
{ "RELEASE_LOCK", SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_release_lock)}, { "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); ...@@ -283,6 +283,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize);
%token PROCESS %token PROCESS
%token PROCESSLIST_SYM %token PROCESSLIST_SYM
%token QUERY_SYM %token QUERY_SYM
%token QUOTE
%token RAID_0_SYM %token RAID_0_SYM
%token RAID_STRIPED_SYM %token RAID_STRIPED_SYM
%token RAID_TYPE %token RAID_TYPE
...@@ -1815,6 +1816,8 @@ simple_expr: ...@@ -1815,6 +1816,8 @@ simple_expr:
} }
| POSITION_SYM '(' no_in_expr IN_SYM expr ')' | POSITION_SYM '(' no_in_expr IN_SYM expr ')'
{ $$ = new Item_func_locate($5,$3); } { $$ = new Item_func_locate($5,$3); }
| QUOTE '(' expr ')'
{ $$= new Item_func_quote($3); }
| RAND '(' expr ')' | RAND '(' expr ')'
{ $$= new Item_func_rand($3); current_thd->safe_to_cache_query=0;} { $$= new Item_func_rand($3); current_thd->safe_to_cache_query=0;}
| RAND '(' ')' | 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