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

Merge rkalimullin@work.mysql.com:/home/bk/mysql-4.0

into ram.(none):/home/ram/work/mysql-4.0
parents 214ed2f3 b43eb82b
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);
+38 −0
Original line number Diff line number Diff line
@@ -2070,3 +2070,41 @@ String* Item_func_inet_ntoa::val_str(String* str)
  str->length(str->length()-1);			// Remove last '.';
  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 *from, *to, *end;
  uint delta= 2; /* for beginning and ending ' signs */

  for (from= (char*) arg->ptr(), end= from + arg->length(); from < end; from++)
  {
    if (*(escmask + (*from >> 3)) and (1 << (*from & 7)))
      delta++;
  }
  if (str->alloc(arg->length() + delta))
  {
    null_value= 1;
    return 0;
  }
  to= (char*) str->ptr() + arg->length() + delta - 1;
  *to--= '\'';
  for (end= (char*) arg->ptr(), from= end + arg->length() - 1; from >= end; 
       from--, to--)
  {
    *to= *from;
    if (*(escmask + (*from >> 3)) and (1 << (*from & 7)))
      *--to= '\\';
  }
  *to= '\'';
  str->length(arg->length() + delta);
  return str;
}
+9 −0
Original line number Diff line number Diff line
@@ -526,3 +526,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() { max_length= args[0]->max_length * 2 + 2; }
};
Loading