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

new QUOTE() fuction has been added

parent 77296b3f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -73,3 +73,4 @@ worm@altair.is.lan
zak@balfor.local
zak@linux.local
zgreant@mysql.com
ram@ram.(none)
+4 −0
Original line number Diff line number Diff line
@@ -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);
}
+1 −0
Original line number Diff line number Diff line
@@ -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);
+53 −0
Original line number Diff line number Diff line
@@ -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;
}
+9 −0
Original line number Diff line number Diff line
@@ -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();
};
Loading