#include <item_strfunc.h>
Inheritance diagram for Item_func_format:


Public Member Functions | |
| Item_func_format (Item *org, int dec) | |
| String * | val_str (String *) |
| void | fix_length_and_dec () |
| const char * | func_name () const |
| void | print (String *) |
Private Attributes | |
| String | tmp_str |
Definition at line 499 of file item_strfunc.h.
| Item_func_format::Item_func_format | ( | Item * | org, | |
| int | dec | |||
| ) |
Definition at line 1822 of file item_strfunc.cc.
References Item::decimals, and set_zone().
01822 :Item_str_func(org) 01823 { 01824 decimals=(uint) set_zone(dec,0,30); 01825 }
Here is the call graph for this function:

| void Item_func_format::fix_length_and_dec | ( | ) | [inline, virtual] |
Implements Item_result_field.
Definition at line 505 of file item_strfunc.h.
References Item_func::args, DTCollation::collation, Item::collation, Item::decimals, Item::default_charset(), Item::max_length, charset_info_st::mbmaxlen, and DTCollation::set().
00506 { 00507 collation.set(default_charset()); 00508 uint char_length= args[0]->max_length/args[0]->collation.collation->mbmaxlen; 00509 max_length= ((char_length + (char_length-args[0]->decimals)/3) * 00510 collation.collation->mbmaxlen); 00511 }
Here is the call graph for this function:

| const char* Item_func_format::func_name | ( | ) | const [inline, virtual] |
| void Item_func_format::print | ( | String * | ) | [virtual] |
Reimplemented from Item_func.
Definition at line 1894 of file item_strfunc.cc.
References String::append(), Item_func::args, buffer, Item::decimals, my_charset_bin, Item::print(), String::set(), and STRING_WITH_LEN.
01895 { 01896 str->append(STRING_WITH_LEN("format(")); 01897 args[0]->print(str); 01898 str->append(','); 01899 // my_charset_bin is good enough for numbers 01900 char buffer[20]; 01901 String st(buffer, sizeof(buffer), &my_charset_bin); 01902 st.set((ulonglong)decimals, &my_charset_bin); 01903 str->append(st); 01904 str->append(')'); 01905 }
Here is the call graph for this function:

Implements Item.
Definition at line 1833 of file item_strfunc.cc.
References Item_func::args, copy_if_not_alloced(), DBUG_ASSERT, DECIMAL_RESULT, Item::decimals, Item::default_charset(), E_DEC_FATAL_ERROR, FALSE, Item::fixed, int(), INT_RESULT, isnan, String::length(), my_decimal2string(), my_decimal_round(), my_double_round(), Item::null_value, pos(), String::ptr(), Item_str_func::result_type(), String::set_real(), my_decimal::sign(), tmp_str, Item::val_decimal(), and Item::val_real().
01834 { 01835 uint32 length, str_length ,dec; 01836 int diff; 01837 DBUG_ASSERT(fixed == 1); 01838 dec= decimals ? decimals+1 : 0; 01839 01840 if (args[0]->result_type() == DECIMAL_RESULT || 01841 args[0]->result_type() == INT_RESULT) 01842 { 01843 my_decimal dec_val, rnd_dec, *res; 01844 res= args[0]->val_decimal(&dec_val); 01845 if ((null_value=args[0]->null_value)) 01846 return 0; /* purecov: inspected */ 01847 my_decimal_round(E_DEC_FATAL_ERROR, res, decimals, false, &rnd_dec); 01848 my_decimal2string(E_DEC_FATAL_ERROR, &rnd_dec, 0, 0, 0, str); 01849 str_length= str->length(); 01850 if (rnd_dec.sign()) 01851 str_length--; 01852 } 01853 else 01854 { 01855 double nr= args[0]->val_real(); 01856 if ((null_value=args[0]->null_value)) 01857 return 0; /* purecov: inspected */ 01858 nr= my_double_round(nr, decimals, FALSE); 01859 /* Here default_charset() is right as this is not an automatic conversion */ 01860 str->set_real(nr,decimals, default_charset()); 01861 if (isnan(nr)) 01862 return str; 01863 str_length=str->length(); 01864 if (nr < 0) 01865 str_length--; // Don't count sign 01866 } 01867 /* We need this test to handle 'nan' values */ 01868 if (str_length >= dec+4) 01869 { 01870 char *tmp,*pos; 01871 length= str->length()+(diff=((int)(str_length- dec-1))/3); 01872 str= copy_if_not_alloced(&tmp_str,str,length); 01873 str->length(length); 01874 tmp= (char*) str->ptr()+length - dec-1; 01875 for (pos= (char*) str->ptr()+length-1; pos != tmp; pos--) 01876 pos[0]= pos[-diff]; 01877 while (diff) 01878 { 01879 *pos= *(pos - diff); 01880 pos--; 01881 *pos= *(pos - diff); 01882 pos--; 01883 *pos= *(pos - diff); 01884 pos--; 01885 pos[0]=','; 01886 pos--; 01887 diff--; 01888 } 01889 } 01890 return str; 01891 }
Here is the call graph for this function:

String Item_func_format::tmp_str [private] |
1.4.7

