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


Public Member Functions | |
| Item_func_replace (Item *org, Item *find, Item *replace) | |
| String * | val_str (String *) |
| void | fix_length_and_dec () |
| const char * | func_name () const |
Private Attributes | |
| String | tmp_value |
| String | tmp_value2 |
Definition at line 118 of file item_strfunc.h.
| void Item_func_replace::fix_length_and_dec | ( | ) | [virtual] |
Implements Item_result_field.
Definition at line 927 of file item_strfunc.cc.
References Item_func::agg_arg_charsets(), Item_func::args, Item::collation, int(), MAX_BLOB_WIDTH, Item::max_length, Item::maybe_null, and MY_COLL_CMP_CONV.
00928 { 00929 ulonglong max_result_length= args[0]->max_length; 00930 int diff=(int) (args[2]->max_length - args[1]->max_length); 00931 if (diff > 0 && args[1]->max_length) 00932 { // Calculate of maxreplaces 00933 ulonglong max_substrs= max_result_length/args[1]->max_length; 00934 max_result_length+= max_substrs * (uint) diff; 00935 } 00936 if (max_result_length >= MAX_BLOB_WIDTH) 00937 { 00938 max_result_length= MAX_BLOB_WIDTH; 00939 maybe_null= 1; 00940 } 00941 max_length= (ulong) max_result_length; 00942 00943 if (agg_arg_charsets(collation, args, 3, MY_COLL_CMP_CONV, 1)) 00944 return; 00945 }
Here is the call graph for this function:

| const char* Item_func_replace::func_name | ( | ) | const [inline, virtual] |
Implements Item_func.
Definition at line 126 of file item_strfunc.h.
Referenced by val_str().
Here is the caller graph for this function:

Implements Item.
Definition at line 812 of file item_strfunc.cc.
References Item_func::args, String::charset(), DTCollation::collation, Item::collation, copy_if_not_alloced(), current_thd, DBUG_ASSERT, ER, ER_WARN_ALLOWED_PACKET_OVERFLOWED, Item::fixed, func_name(), int(), String::length(), MY_CS_BINSORT, my_ismbchar, Item::null_value, offset, String::ptr(), push_warning_printf(), String::replace(), search_end(), String::set_charset(), skip(), charset_info_st::state, strend(), String::strstr(), tmp_value, tmp_value2, use_mb, Item::val_str(), and MYSQL_ERROR::WARN_LEVEL_WARN.
00813 { 00814 DBUG_ASSERT(fixed == 1); 00815 String *res,*res2,*res3; 00816 int offset; 00817 uint from_length,to_length; 00818 bool alloced=0; 00819 #ifdef USE_MB 00820 const char *ptr,*end,*strend,*search,*search_end; 00821 register uint32 l; 00822 bool binary_cmp; 00823 #endif 00824 00825 null_value=0; 00826 res=args[0]->val_str(str); 00827 if (args[0]->null_value) 00828 goto null; 00829 res2=args[1]->val_str(&tmp_value); 00830 if (args[1]->null_value) 00831 goto null; 00832 00833 res->set_charset(collation.collation); 00834 00835 #ifdef USE_MB 00836 binary_cmp = ((res->charset()->state & MY_CS_BINSORT) || !use_mb(res->charset())); 00837 #endif 00838 00839 if (res2->length() == 0) 00840 return res; 00841 #ifndef USE_MB 00842 if ((offset=res->strstr(*res2)) < 0) 00843 return res; 00844 #else 00845 offset=0; 00846 if (binary_cmp && (offset=res->strstr(*res2)) < 0) 00847 return res; 00848 #endif 00849 if (!(res3=args[2]->val_str(&tmp_value2))) 00850 goto null; 00851 from_length= res2->length(); 00852 to_length= res3->length(); 00853 00854 #ifdef USE_MB 00855 if (!binary_cmp) 00856 { 00857 search=res2->ptr(); 00858 search_end=search+from_length; 00859 redo: 00860 ptr=res->ptr()+offset; 00861 strend=res->ptr()+res->length(); 00862 end=strend-from_length+1; 00863 while (ptr < end) 00864 { 00865 if (*ptr == *search) 00866 { 00867 register char *i,*j; 00868 i=(char*) ptr+1; j=(char*) search+1; 00869 while (j != search_end) 00870 if (*i++ != *j++) goto skip; 00871 offset= (int) (ptr-res->ptr()); 00872 if (res->length()-from_length + to_length > 00873 current_thd->variables.max_allowed_packet) 00874 { 00875 push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, 00876 ER_WARN_ALLOWED_PACKET_OVERFLOWED, 00877 ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), 00878 func_name(), 00879 current_thd->variables.max_allowed_packet); 00880 00881 goto null; 00882 } 00883 if (!alloced) 00884 { 00885 alloced=1; 00886 res=copy_if_not_alloced(str,res,res->length()+to_length); 00887 } 00888 res->replace((uint) offset,from_length,*res3); 00889 offset+=(int) to_length; 00890 goto redo; 00891 } 00892 skip: 00893 if ((l=my_ismbchar(res->charset(), ptr,strend))) ptr+=l; 00894 else ++ptr; 00895 } 00896 } 00897 else 00898 #endif /* USE_MB */ 00899 do 00900 { 00901 if (res->length()-from_length + to_length > 00902 current_thd->variables.max_allowed_packet) 00903 { 00904 push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, 00905 ER_WARN_ALLOWED_PACKET_OVERFLOWED, 00906 ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(), 00907 current_thd->variables.max_allowed_packet); 00908 goto null; 00909 } 00910 if (!alloced) 00911 { 00912 alloced=1; 00913 res=copy_if_not_alloced(str,res,res->length()+to_length); 00914 } 00915 res->replace((uint) offset,from_length,*res3); 00916 offset+=(int) to_length; 00917 } 00918 while ((offset=res->strstr(*res2,(uint) offset)) >= 0); 00919 return res; 00920 00921 null: 00922 null_value=1; 00923 return 0; 00924 }
Here is the call graph for this function:

String Item_func_replace::tmp_value [private] |
String Item_func_replace::tmp_value2 [private] |
1.4.7

