From 735b27d578f2b60c928ec2bc85d47f266c1f633a Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Fri, 22 Feb 2002 15:24:42 +0400 Subject: Added GIS extension --- sql/item_strfunc.cc | 330 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 330 insertions(+) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index c64fdc7a049..cdf909e8c4d 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1953,3 +1953,333 @@ String* Item_func_inet_ntoa::val_str(String* str) str->length(str->length()-1); // Remove last '.'; return str; } + +/******************************************************* +General functions for spatial objects +********************************************************/ + +#include "gstream.h" + +String *Item_func_geometry_from_text::val_str(String *str) +{ + Geometry geom; + String *wkt = args[0]->val_str(str); + GTextReadStream trs(wkt->ptr(), wkt->length()); + + str->length(0); + if ((null_value=(args[0]->null_value || geom.create_from_wkt(&trs, str, 0)))) + return 0; + return str; +} + + +void Item_func_geometry_from_text::fix_length_and_dec() +{ + max_length=MAX_BLOB_WIDTH; +} + + +String *Item_func_as_text::val_str(String *str) +{ + String *wkt = args[0]->val_str(str); + Geometry geom; + + str->length(0); + if ((null_value=(args[0]->null_value || + geom.create_from_wkb(wkt->ptr(),wkt->length()) || + geom.as_wkt(str)))) + return 0; + return str; +} + +void Item_func_as_text::fix_length_and_dec() +{ + max_length=MAX_BLOB_WIDTH; +} + +String *Item_func_geometry_type::val_str(String *str) +{ + String *wkt = args[0]->val_str(str); + Geometry geom; + + if ((null_value=(args[0]->null_value || + geom.create_from_wkb(wkt->ptr(),wkt->length())))) + return 0; + str->copy(geom.get_class_info()->m_name); + return str; +} + + +String *Item_func_envelope::val_str(String *str) +{ + String *wkb = args[0]->val_str(str); + Geometry geom; + + null_value = args[0]->null_value || + geom.create_from_wkb(wkb->ptr(),wkb->length()) || + geom.envelope(str); + + return null_value ? 0 : str; +} + + +String *Item_func_centroid::val_str(String *str) +{ + String *wkb = args[0]->val_str(str); + Geometry geom; + + null_value = args[0]->null_value || + geom.create_from_wkb(wkb->ptr(),wkb->length()) || + !GEOM_METHOD_PRESENT(geom,centroid) || + geom.centroid(str); + + return null_value ? 0: str; +} + + +/*********************************************** + Spatial decomposition functions +***********************************************/ + +String *Item_func_spatial_decomp::val_str(String *str) +{ + String *wkb = args[0]->val_str(str); + Geometry geom; + + if ((null_value = (args[0]->null_value || + geom.create_from_wkb(wkb->ptr(),wkb->length())))) + return 0; + + null_value=1; + switch(decomp_func) + { + case SP_STARTPOINT: + if (!GEOM_METHOD_PRESENT(geom,start_point) || geom.start_point(str)) + goto ret; + break; + + case SP_ENDPOINT: + if (!GEOM_METHOD_PRESENT(geom,end_point) || geom.end_point(str)) + goto ret; + break; + + case SP_EXTERIORRING: + if (!GEOM_METHOD_PRESENT(geom,exterior_ring) || geom.exterior_ring(str)) + goto ret; + break; + + default: + goto ret; + } + null_value=0; + +ret: + return null_value ? 0 : str; +} + + +String *Item_func_spatial_decomp_n::val_str(String *str) +{ + String *wkb = args[0]->val_str(str); + long n = (long) args[1]->val_int(); + Geometry geom; + + if ((null_value = (args[0]->null_value || + args[1]->null_value || + geom.create_from_wkb(wkb->ptr(),wkb->length()) ))) + return 0; + + null_value=1; + + switch(decomp_func_n) + { + case SP_POINTN: + if (!GEOM_METHOD_PRESENT(geom,point_n) || + geom.point_n(n,str)) + goto ret; + break; + + case SP_GEOMETRYN: + if (!GEOM_METHOD_PRESENT(geom,geometry_n) || + geom.geometry_n(n,str)) + goto ret; + break; + + case SP_INTERIORRINGN: + if (!GEOM_METHOD_PRESENT(geom,interior_ring_n) || + geom.interior_ring_n(n,str)) + goto ret; + break; + + default: + goto ret; + } + null_value=0; + +ret: + return null_value ? 0 : str; +} + + + +/*********************************************** +Functions to concatinate various spatial objects +************************************************/ + + +/* +* Concatinate doubles into Point +*/ + + +String *Item_func_point::val_str(String *str) +{ + if ( (null_value = (args[0]->null_value || + args[1]->null_value || + str->realloc(1+4+8+8)))) + return 0; + + str->length(0); + str->q_append((char)Geometry::wkbNDR); + str->q_append((uint32)Geometry::wkbPoint); + str->q_append((double)args[0]->val()); + str->q_append((double)args[1]->val()); + return str; +} + + +/* + Concatinates various items into various collections + with checkings for valid wkb type of items. + For example, MultiPoint can be a collection of Points only. + coll_type contains wkb type of target collection. + item_type contains a valid wkb type of items. + In the case when coll_type is wkbGeometryCollection, + we do not check wkb type of items, any is valid. +*/ + +String *Item_func_spatial_collection::val_str(String *str) +{ + uint i; + + null_value=1; + + str->length(0); + if(str->reserve(9,512)) + return 0; + + str->q_append((char)Geometry::wkbNDR); + str->q_append((uint32)coll_type); + str->q_append((uint32)arg_count); + + for (i = 0; i < arg_count; ++i) + { + if (args[i]->null_value) + goto ret; + + String *res = args[i]->val_str(str); + + if ( coll_type == Geometry::wkbGeometryCollection ) + { + /* + In the case of GeometryCollection we don't need + any checkings for item types, so just copy them + into target collection + */ + if ((null_value=(str->reserve(res->length(),512)))) + goto ret; + + str->q_append(res->ptr(),res->length()); + } + else + { + uint32 wkb_type, len=res->length(); + const char *data=res->ptr()+1; + + /* + In the case of named collection we must to + check that items are of specific type, let's + do this checking now + */ + + if (len<5) + goto ret; + wkb_type=uint4korr(data); + data+=4; + len-=5; + if ( wkb_type != item_type ) + goto ret; + + switch(coll_type) + { + case Geometry::wkbMultiPoint: + case Geometry::wkbMultiLineString: + case Geometry::wkbMultiPolygon: + if (lenreserve(len,512)) + goto ret; + str->q_append(data,len); + break; + + case Geometry::wkbLineString: + if (str->reserve(POINT_DATA_SIZE,512)) + goto ret; + str->q_append(data,POINT_DATA_SIZE); + break; + + case Geometry::wkbPolygon: + { + uint32 n_points; + double x1, y1, x2, y2; + + if (len < WKB_HEADER_SIZE + 4 + 8 + 8) + goto ret; + data+=WKB_HEADER_SIZE; + len-=WKB_HEADER_SIZE; + + uint32 llen=len; + const char *ldata=data; + + n_points=uint4korr(data); + data+=4; + float8get(x1,data); + data+=8; + float8get(y1,data); + data+=8; + + len-= 4 + 8 + 8; + + if (len < n_points * POINT_DATA_SIZE) + goto ret; + data+=(n_points-2) * POINT_DATA_SIZE; + + float8get(x2,data); + float8get(y2,data+8); + + if ((x1 != x2) || (y1 != y2)) + goto ret; + + if (str->reserve(llen,512)) + goto ret; + str->q_append(ldata, llen); + } + break; + + default: + goto ret; + } + } + } + + if (str->length() > max_allowed_packet) + goto ret; + + null_value = 0; + +ret: + return null_value ? 0 : str; +} -- cgit v1.2.1 From b37ce8e76944610b92087fe0e04e05f1b60903c8 Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Tue, 12 Mar 2002 21:37:58 +0400 Subject: New ctype functions/macros to support many charsets at a time --- sql/item_strfunc.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index cdf909e8c4d..de07f5b1ee7 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -42,7 +42,7 @@ uint nr_of_decimals(const char *str) if ((str=strchr(str,'.'))) { const char *start= ++str; - for ( ; isdigit(*str) ; str++) ; + for ( ; my_isdigit(system_charset_info,*str) ; str++) ; return (uint) (str-start); } return 0; @@ -1268,9 +1268,9 @@ extern "C" { extern const char *soundex_map; // In mysys/static.c } -static char get_scode(char *ptr) +static char get_scode(CHARSET_INFO *cs,char *ptr) { - uchar ch=toupper(*ptr); + uchar ch=my_toupper(cs,*ptr); if (ch < 'A' || ch > 'Z') { // Thread extended alfa (country spec) @@ -1292,21 +1292,21 @@ String *Item_func_soundex::val_str(String *str) char *to= (char *) tmp_value.ptr(); char *from= (char *) res->ptr(), *end=from+res->length(); - while (from != end && isspace(*from)) // Skip pre-space + while (from != end && my_isspace(str->charset(),*from)) // Skip pre-space from++; /* purecov: inspected */ if (from == end) return &empty_string; // No alpha characters. - *to++ = toupper(*from); // Copy first letter - last_ch = get_scode(from); // code of the first letter + *to++ = my_toupper(str->charset(),*from);// Copy first letter + last_ch = get_scode(str->charset(),from);// code of the first letter // for the first 'double-letter check. // Loop on input letters until // end of input (null) or output // letter code count = 3 for (from++ ; from < end ; from++) { - if (!isalpha(*from)) + if (!my_isalpha(str->charset(),*from)) continue; - ch=get_scode(from); + ch=get_scode(str->charset(),from); if ((ch != '0') && (ch != last_ch)) // if not skipped or double { *to++ = ch; // letter, copy to output -- cgit v1.2.1 From f8a5452877ada07efadc3e3180b619f780faec78 Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Thu, 14 Mar 2002 20:52:48 +0400 Subject: use String->charset instead of default_charset_info --- sql/item_strfunc.cc | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index de07f5b1ee7..a9ba3526e1c 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -510,7 +510,7 @@ String *Item_func_reverse::val_str(String *str) ptr = (char *) res->ptr(); end=ptr+res->length(); #ifdef USE_MB - if (use_mb(default_charset_info) && !binary) + if (use_mb(res->str_charset) && !binary) { String tmpstr; tmpstr.copy(*res); @@ -518,7 +518,7 @@ String *Item_func_reverse::val_str(String *str) register uint32 l; while (ptr < end) { - if ((l=my_ismbchar(default_charset_info, ptr,end))) + if ((l=my_ismbchar(res->str_charset, ptr,end))) tmp-=l, memcpy(tmp,ptr,l), ptr+=l; else *--tmp=*ptr++; @@ -561,8 +561,7 @@ String *Item_func_replace::val_str(String *str) #ifdef USE_MB const char *ptr,*end,*strend,*search,*search_end; register uint32 l; - bool binary_str = (args[0]->binary || args[1]->binary || - !use_mb(default_charset_info)); + bool binary_str; #endif null_value=0; @@ -573,6 +572,10 @@ String *Item_func_replace::val_str(String *str) if (args[1]->null_value) goto null; +#ifdef USE_MB + binary_str = (args[0]->binary || args[1]->binary || !use_mb(res->str_charset)); +#endif + if (res2->length() == 0) return res; #ifndef USE_MB @@ -618,7 +621,7 @@ redo: goto redo; } skipp: - if ((l=my_ismbchar(default_charset_info, ptr,strend))) ptr+=l; + if ((l=my_ismbchar(res->str_charset, ptr,strend))) ptr+=l; else ++ptr; } } @@ -676,7 +679,7 @@ String *Item_func_insert::val_str(String *str) args[3]->null_value) goto null; /* purecov: inspected */ #ifdef USE_MB - if (use_mb(default_charset_info) && !args[0]->binary) + if (use_mb(res->str_charset) && !args[0]->binary) { start=res->charpos(start); length=res->charpos(length,start); @@ -748,7 +751,7 @@ String *Item_func_left::val_str(String *str) if (length <= 0) return &empty_string; #ifdef USE_MB - if (use_mb(default_charset_info) && !binary) + if (use_mb(res->str_charset) && !binary) length = res->charpos(length); #endif if (res->length() > (ulong) length) @@ -796,7 +799,7 @@ String *Item_func_right::val_str(String *str) if (res->length() <= (uint) length) return res; /* purecov: inspected */ #ifdef USE_MB - if (use_mb(default_charset_info) && !binary) + if (use_mb(res->str_charset) && !binary) { uint start=res->numchars()-(uint) length; if (start<=0) return res; @@ -829,7 +832,7 @@ String *Item_func_substr::val_str(String *str) (arg_count == 3 && args[2]->null_value)))) return 0; /* purecov: inspected */ #ifdef USE_MB - if (use_mb(default_charset_info) && !binary) + if (use_mb(res->str_charset) && !binary) { start=res->charpos(start); length=res->charpos(length,start); @@ -889,7 +892,7 @@ String *Item_func_substr_index::val_str(String *str) return &empty_string; // Wrong parameters #ifdef USE_MB - if (use_mb(default_charset_info) && !binary) + if (use_mb(res->str_charset) && !binary) { const char *ptr=res->ptr(); const char *strend = ptr+res->length(); @@ -914,7 +917,7 @@ String *Item_func_substr_index::val_str(String *str) continue; } skipp: - if ((l=my_ismbchar(default_charset_info, ptr,strend))) ptr+=l; + if ((l=my_ismbchar(res->str_charset, ptr,strend))) ptr+=l; else ++ptr; } /* either not found or got total number when count<0 */ if (pass == 0) /* count<0 */ @@ -1043,11 +1046,11 @@ String *Item_func_rtrim::val_str(String *str) { char chr=(*remove_str)[0]; #ifdef USE_MB - if (use_mb(default_charset_info) && !binary) + if (use_mb(res->str_charset) && !binary) { while (ptr < end) { - if ((l=my_ismbchar(default_charset_info, ptr,end))) ptr+=l,p=ptr; + if ((l=my_ismbchar(res->str_charset, ptr,end))) ptr+=l,p=ptr; else ++ptr; } ptr=p; @@ -1060,12 +1063,12 @@ String *Item_func_rtrim::val_str(String *str) { const char *r_ptr=remove_str->ptr(); #ifdef USE_MB - if (use_mb(default_charset_info) && !binary) + if (use_mb(res->str_charset) && !binary) { loop: while (ptr + remove_length < end) { - if ((l=my_ismbchar(default_charset_info, ptr,end))) ptr+=l; + if ((l=my_ismbchar(res->str_charset, ptr,end))) ptr+=l; else ++ptr; } if (ptr + remove_length == end && !memcmp(ptr,r_ptr,remove_length)) @@ -1111,14 +1114,14 @@ String *Item_func_trim::val_str(String *str) while (ptr+remove_length <= end && !memcmp(ptr,r_ptr,remove_length)) ptr+=remove_length; #ifdef USE_MB - if (use_mb(default_charset_info) && !binary) + if (use_mb(res->str_charset) && !binary) { char *p=ptr; register uint32 l; loop: while (ptr + remove_length < end) { - if ((l=my_ismbchar(default_charset_info, ptr,end))) ptr+=l; + if ((l=my_ismbchar(res->str_charset, ptr,end))) ptr+=l; else ++ptr; } if (ptr + remove_length == end && !memcmp(ptr,r_ptr,remove_length)) -- cgit v1.2.1 From 1ebab2be72b48346002ad58b8066b7a448b675db Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Tue, 19 Mar 2002 20:03:10 +0400 Subject: Configure.in/Makefile.in charset related things are now earier to maintain Fixes in charset related C++ code --- sql/item_strfunc.cc | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index a9ba3526e1c..cfbfda97148 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -510,7 +510,7 @@ String *Item_func_reverse::val_str(String *str) ptr = (char *) res->ptr(); end=ptr+res->length(); #ifdef USE_MB - if (use_mb(res->str_charset) && !binary) + if (use_mb(res->charset()) && !binary) { String tmpstr; tmpstr.copy(*res); @@ -518,7 +518,7 @@ String *Item_func_reverse::val_str(String *str) register uint32 l; while (ptr < end) { - if ((l=my_ismbchar(res->str_charset, ptr,end))) + if ((l=my_ismbchar(res->charset(), ptr,end))) tmp-=l, memcpy(tmp,ptr,l), ptr+=l; else *--tmp=*ptr++; @@ -573,7 +573,7 @@ String *Item_func_replace::val_str(String *str) goto null; #ifdef USE_MB - binary_str = (args[0]->binary || args[1]->binary || !use_mb(res->str_charset)); + binary_str = (args[0]->binary || args[1]->binary || !use_mb(res->charset())); #endif if (res2->length() == 0) @@ -621,7 +621,7 @@ redo: goto redo; } skipp: - if ((l=my_ismbchar(res->str_charset, ptr,strend))) ptr+=l; + if ((l=my_ismbchar(res->charset(), ptr,strend))) ptr+=l; else ++ptr; } } @@ -679,7 +679,7 @@ String *Item_func_insert::val_str(String *str) args[3]->null_value) goto null; /* purecov: inspected */ #ifdef USE_MB - if (use_mb(res->str_charset) && !args[0]->binary) + if (use_mb(res->charset()) && !args[0]->binary) { start=res->charpos(start); length=res->charpos(length,start); @@ -751,7 +751,7 @@ String *Item_func_left::val_str(String *str) if (length <= 0) return &empty_string; #ifdef USE_MB - if (use_mb(res->str_charset) && !binary) + if (use_mb(res->charset()) && !binary) length = res->charpos(length); #endif if (res->length() > (ulong) length) @@ -799,7 +799,7 @@ String *Item_func_right::val_str(String *str) if (res->length() <= (uint) length) return res; /* purecov: inspected */ #ifdef USE_MB - if (use_mb(res->str_charset) && !binary) + if (use_mb(res->charset()) && !binary) { uint start=res->numchars()-(uint) length; if (start<=0) return res; @@ -832,7 +832,7 @@ String *Item_func_substr::val_str(String *str) (arg_count == 3 && args[2]->null_value)))) return 0; /* purecov: inspected */ #ifdef USE_MB - if (use_mb(res->str_charset) && !binary) + if (use_mb(res->charset()) && !binary) { start=res->charpos(start); length=res->charpos(length,start); @@ -892,7 +892,7 @@ String *Item_func_substr_index::val_str(String *str) return &empty_string; // Wrong parameters #ifdef USE_MB - if (use_mb(res->str_charset) && !binary) + if (use_mb(res->charset()) && !binary) { const char *ptr=res->ptr(); const char *strend = ptr+res->length(); @@ -917,7 +917,7 @@ String *Item_func_substr_index::val_str(String *str) continue; } skipp: - if ((l=my_ismbchar(res->str_charset, ptr,strend))) ptr+=l; + if ((l=my_ismbchar(res->charset(), ptr,strend))) ptr+=l; else ++ptr; } /* either not found or got total number when count<0 */ if (pass == 0) /* count<0 */ @@ -1046,11 +1046,11 @@ String *Item_func_rtrim::val_str(String *str) { char chr=(*remove_str)[0]; #ifdef USE_MB - if (use_mb(res->str_charset) && !binary) + if (use_mb(res->charset()) && !binary) { while (ptr < end) { - if ((l=my_ismbchar(res->str_charset, ptr,end))) ptr+=l,p=ptr; + if ((l=my_ismbchar(res->charset(), ptr,end))) ptr+=l,p=ptr; else ++ptr; } ptr=p; @@ -1063,12 +1063,12 @@ String *Item_func_rtrim::val_str(String *str) { const char *r_ptr=remove_str->ptr(); #ifdef USE_MB - if (use_mb(res->str_charset) && !binary) + if (use_mb(res->charset()) && !binary) { loop: while (ptr + remove_length < end) { - if ((l=my_ismbchar(res->str_charset, ptr,end))) ptr+=l; + if ((l=my_ismbchar(res->charset(), ptr,end))) ptr+=l; else ++ptr; } if (ptr + remove_length == end && !memcmp(ptr,r_ptr,remove_length)) @@ -1114,14 +1114,14 @@ String *Item_func_trim::val_str(String *str) while (ptr+remove_length <= end && !memcmp(ptr,r_ptr,remove_length)) ptr+=remove_length; #ifdef USE_MB - if (use_mb(res->str_charset) && !binary) + if (use_mb(res->charset()) && !binary) { char *p=ptr; register uint32 l; loop: while (ptr + remove_length < end) { - if ((l=my_ismbchar(res->str_charset, ptr,end))) ptr+=l; + if ((l=my_ismbchar(res->charset(), ptr,end))) ptr+=l; else ++ptr; } if (ptr + remove_length == end && !memcmp(ptr,r_ptr,remove_length)) -- cgit v1.2.1 From ae03ccc40399d01fd78a5bf393b92dbfcdf1951e Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Fri, 29 Mar 2002 18:22:21 +0400 Subject: Charset convertion operator CONVERT( string USING charset) --- sql/item_strfunc.cc | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index cfbfda97148..90f27148578 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1776,6 +1776,73 @@ String *Item_func_conv::val_str(String *str) } +String *Item_func_conv_charset::val_str(String *str) +{ + my_wc_t wc; + int cnvres; + const uchar *s, *se; + uchar *d, *d0, *de; + uint dmaxlen; + String *arg= args[0]->val_str(str); + CHARSET_INFO *from,*to; + + if (!arg) + { + null_value=1; + return 0; + } + + from=arg->charset(); + to=conv_charset; + + s=(const uchar*)arg->ptr(); + se=s+arg->length(); + + dmaxlen=arg->length()*(conv_charset->mbmaxlen?conv_charset->mbmaxlen:1)+1; + str->alloc(dmaxlen); + d0=d=(unsigned char*)str->ptr(); + de=d+dmaxlen; + + while( s < se && d < de){ + + cnvres=from->mb_wc(from,&wc,s,se); + if (cnvres>0) + { + s+=cnvres; + } + else if (cnvres==MY_CS_ILSEQ) + { + s++; + wc='?'; + } + else + break; + +outp: + cnvres=to->wc_mb(to,wc,d,de); + if (cnvres>0) + { + d+=cnvres; + } + else if (cnvres==MY_CS_ILUNI && wc!='?') + { + wc='?'; + goto outp; + } + else + break; + }; + + str->length((uint) (d-d0)); + str->set_charset(to); + return str; +} + +void Item_func_conv_charset::fix_length_and_dec() +{ + /* BAR TODO: What to do here??? */ +} + String *Item_func_hex::val_str(String *str) { if (args[0]->result_type() != STRING_RESULT) -- cgit v1.2.1 From 648bd2788aa27bed452073b8c0393c61dc58b7cc Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Fri, 29 Mar 2002 19:11:06 +0400 Subject: Now this syntax works too: CONVERT(string,charset_to,charset_from) where charset_to and charset_from are expressions. For example: CONVERT('test','latin2','cp1250') --- sql/item_strfunc.cc | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 90f27148578..df238a6c331 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1843,6 +1843,79 @@ void Item_func_conv_charset::fix_length_and_dec() /* BAR TODO: What to do here??? */ } + +String *Item_func_conv_charset3::val_str(String *str) +{ + my_wc_t wc; + int cnvres; + const uchar *s, *se; + uchar *d, *d0, *de; + uint dmaxlen; + String *arg= args[0]->val_str(str); + String *to_cs= args[1]->val_str(str); + String *from_cs= args[2]->val_str(str); + CHARSET_INFO *from_charset; + CHARSET_INFO *to_charset; + + if (!arg || args[0]->null_value || + !to_cs || args[1]->null_value || + !from_cs || args[2]->null_value || + !(from_charset=find_compiled_charset_by_name(from_cs->ptr())) || + !(to_charset=find_compiled_charset_by_name(to_cs->ptr()))) + { + null_value=1; + return 0; + } + + s=(const uchar*)arg->ptr(); + se=s+arg->length(); + + dmaxlen=arg->length()*(to_charset->mbmaxlen?to_charset->mbmaxlen:1)+1; + str->alloc(dmaxlen); + d0=d=(unsigned char*)str->ptr(); + de=d+dmaxlen; + + while( s < se && d < de){ + + cnvres=from_charset->mb_wc(from_charset,&wc,s,se); + if (cnvres>0) + { + s+=cnvres; + } + else if (cnvres==MY_CS_ILSEQ) + { + s++; + wc='?'; + } + else + break; + +outp: + cnvres=to_charset->wc_mb(to_charset,wc,d,de); + if (cnvres>0) + { + d+=cnvres; + } + else if (cnvres==MY_CS_ILUNI && wc!='?') + { + wc='?'; + goto outp; + } + else + break; + }; + + str->length((uint) (d-d0)); + str->set_charset(to_charset); + return str; +} + +void Item_func_conv_charset3::fix_length_and_dec() +{ + /* BAR TODO: What to do here??? */ +} + + String *Item_func_hex::val_str(String *str) { if (args[0]->result_type() != STRING_RESULT) -- cgit v1.2.1 From 65cf7e6201811750726a201341420318c3fe2155 Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Fri, 29 Mar 2002 20:27:53 +0400 Subject: item_strfunc.cc: Fix for possible bug when string length is more than 64K --- sql/item_strfunc.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index df238a6c331..9c1daf2edb3 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1782,7 +1782,7 @@ String *Item_func_conv_charset::val_str(String *str) int cnvres; const uchar *s, *se; uchar *d, *d0, *de; - uint dmaxlen; + uint32 dmaxlen; String *arg= args[0]->val_str(str); CHARSET_INFO *from,*to; @@ -1833,7 +1833,7 @@ outp: break; }; - str->length((uint) (d-d0)); + str->length((uint32) (d-d0)); str->set_charset(to); return str; } @@ -1850,7 +1850,7 @@ String *Item_func_conv_charset3::val_str(String *str) int cnvres; const uchar *s, *se; uchar *d, *d0, *de; - uint dmaxlen; + uint32 dmaxlen; String *arg= args[0]->val_str(str); String *to_cs= args[1]->val_str(str); String *from_cs= args[2]->val_str(str); @@ -1905,7 +1905,7 @@ outp: break; }; - str->length((uint) (d-d0)); + str->length((uint32) (d-d0)); str->set_charset(to_charset); return str; } -- cgit v1.2.1 From 79fb335f3295591ad246d67a128c1fac0ae8ef21 Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Thu, 18 Apr 2002 11:53:59 +0500 Subject: Fix for AsText() spatial function --- sql/item_strfunc.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 4a7e5dfe33f..9c791453fd8 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2128,12 +2128,16 @@ String *Item_func_as_text::val_str(String *str) { String *wkt = args[0]->val_str(str); Geometry geom; - - str->length(0); + if ((null_value=(args[0]->null_value || - geom.create_from_wkb(wkt->ptr(),wkt->length()) || - geom.as_wkt(str)))) + geom.create_from_wkb(wkt->ptr(),wkt->length())))) + return 0; + + str->length(0); + + if ((null_value=geom.as_wkt(str))) return 0; + return str; } -- cgit v1.2.1 From 196aa19cf6624c17fb3c36c876e3e1a40f18ed23 Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Fri, 17 May 2002 16:29:52 +0500 Subject: Now string values are created and filled with charset field SELECT func(charset2) FROM t ORDER BY 1 works in correct charset --- sql/item_strfunc.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 9c791453fd8..e3436ac4641 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -35,7 +35,7 @@ #endif /* HAVE_OPENSSL */ #include "md5.h" -String empty_string(""); +String empty_string("",default_charset_info); uint nr_of_decimals(const char *str) { @@ -371,7 +371,7 @@ error: String *Item_func_concat_ws::val_str(String *str) { char tmp_str_buff[10]; - String tmp_sep_str(tmp_str_buff, sizeof(tmp_str_buff)), + String tmp_sep_str(tmp_str_buff, sizeof(tmp_str_buff),default_charset_info), *sep_str, *res, *res2,*use_as_buff; uint i; @@ -989,7 +989,7 @@ String *Item_func_ltrim::val_str(String *str) if ((null_value=args[0]->null_value)) return 0; /* purecov: inspected */ char buff[MAX_FIELD_WIDTH]; - String tmp(buff,sizeof(buff)); + String tmp(buff,sizeof(buff),res->charset()); String *remove_str=args[1]->val_str(&tmp); uint remove_length; LINT_INIT(remove_length); @@ -1027,7 +1027,7 @@ String *Item_func_rtrim::val_str(String *str) if ((null_value=args[0]->null_value)) return 0; /* purecov: inspected */ char buff[MAX_FIELD_WIDTH]; - String tmp(buff,sizeof(buff)); + String tmp(buff,sizeof(buff),res->charset()); String *remove_str=args[1]->val_str(&tmp); uint remove_length; LINT_INIT(remove_length); @@ -1099,7 +1099,7 @@ String *Item_func_trim::val_str(String *str) if ((null_value=args[0]->null_value)) return 0; /* purecov: inspected */ char buff[MAX_FIELD_WIDTH]; - String tmp(buff,sizeof(buff)); + String tmp(buff,sizeof(buff),res->charset()); String *remove_str=args[1]->val_str(&tmp); uint remove_length; LINT_INIT(remove_length); @@ -1154,7 +1154,7 @@ String *Item_func_password::val_str(String *str) if (res->length() == 0) return &empty_string; make_scrambled_password(tmp_value,res->c_ptr()); - str->set(tmp_value,16); + str->set(tmp_value,16,res->charset()); return str; } @@ -1188,7 +1188,7 @@ String *Item_func_encrypt::val_str(String *str) } pthread_mutex_lock(&LOCK_crypt); char *tmp=crypt(res->c_ptr(),salt_ptr); - str->set(tmp,(uint) strlen(tmp)); + str->set(tmp,(uint) strlen(tmp),res->charset()); str->copy(); pthread_mutex_unlock(&LOCK_crypt); return str; @@ -1240,7 +1240,7 @@ String *Item_func_database::val_str(String *str) if (!current_thd->db) str->length(0); else - str->set((const char*) current_thd->db,(uint) strlen(current_thd->db)); + str->set((const char*) current_thd->db,(uint) strlen(current_thd->db), default_charset_info); return str; } @@ -2035,7 +2035,7 @@ String* Item_func_export_set::val_str(String* str) } break; case 3: - sep_buf.set(",", 1); + sep_buf.set(",", 1, default_charset_info); sep = &sep_buf; } null_value=0; @@ -2154,7 +2154,7 @@ String *Item_func_geometry_type::val_str(String *str) if ((null_value=(args[0]->null_value || geom.create_from_wkb(wkt->ptr(),wkt->length())))) return 0; - str->copy(geom.get_class_info()->m_name); + str->copy(geom.get_class_info()->m_name,strlen(geom.get_class_info()->m_name)); return str; } -- cgit v1.2.1 From 660844acd62d59d2aaed403a0189400752f11c57 Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Sun, 2 Jun 2002 21:32:02 +0500 Subject: Changed 003F -> 0000 for undefinite characters in charset.conf Charset convertion FROM dynamic charset is now working too Allow dynamic charsets in CONVERT() --- sql/item_strfunc.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index e3436ac4641..8f77f736c86 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1860,8 +1860,8 @@ String *Item_func_conv_charset3::val_str(String *str) if (!arg || args[0]->null_value || !to_cs || args[1]->null_value || !from_cs || args[2]->null_value || - !(from_charset=find_compiled_charset_by_name(from_cs->ptr())) || - !(to_charset=find_compiled_charset_by_name(to_cs->ptr()))) + !(from_charset=get_charset_by_name(from_cs->ptr(), MYF(MY_WME))) || + !(to_charset=get_charset_by_name(to_cs->ptr(), MYF(MY_WME)))) { null_value=1; return 0; -- cgit v1.2.1 From 6e54cc492c424a7697a7139600b67b9cfe36a5da Mon Sep 17 00:00:00 2001 From: "monty@hundin.mysql.fi" <> Date: Sun, 2 Jun 2002 21:22:20 +0300 Subject: Extension of .frm file (not yet ready for push) --- sql/item_strfunc.cc | 114 ++++++++++++++++++++++++++-------------------------- 1 file changed, 57 insertions(+), 57 deletions(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index e3436ac4641..b0ab03363d3 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2342,7 +2342,8 @@ String *Item_func_spatial_collection::val_str(String *str) } else { - uint32 wkb_type, len=res->length(); + enum Geometry::wkbType wkb_type; + uint32 len=res->length(); const char *data=res->ptr()+1; /* @@ -2351,75 +2352,74 @@ String *Item_func_spatial_collection::val_str(String *str) do this checking now */ - if (len<5) + if (len < 5) goto ret; - wkb_type=uint4korr(data); + wkb_type= (Geometry::wkbType) uint4korr(data); data+=4; len-=5; - if ( wkb_type != item_type ) + if (wkb_type != item_type) goto ret; - switch(coll_type) - { - case Geometry::wkbMultiPoint: - case Geometry::wkbMultiLineString: - case Geometry::wkbMultiPolygon: - if (lenreserve(len,512)) - goto ret; - str->q_append(data,len); - break; - - case Geometry::wkbLineString: - if (str->reserve(POINT_DATA_SIZE,512)) - goto ret; - str->q_append(data,POINT_DATA_SIZE); - break; - - case Geometry::wkbPolygon: - { - uint32 n_points; - double x1, y1, x2, y2; - - if (len < WKB_HEADER_SIZE + 4 + 8 + 8) - goto ret; - data+=WKB_HEADER_SIZE; - len-=WKB_HEADER_SIZE; - - uint32 llen=len; - const char *ldata=data; + data+=WKB_HEADER_SIZE; + len-=WKB_HEADER_SIZE; + if (str->reserve(len,512)) + goto ret; + str->q_append(data,len); + break; + + case Geometry::wkbLineString: + if (str->reserve(POINT_DATA_SIZE,512)) + goto ret; + str->q_append(data,POINT_DATA_SIZE); + break; + + case Geometry::wkbPolygon: + { + uint32 n_points; + double x1, y1, x2, y2; + + if (len < WKB_HEADER_SIZE + 4 + 8 + 8) + goto ret; + data+=WKB_HEADER_SIZE; + len-=WKB_HEADER_SIZE; + + uint32 llen=len; + const char *ldata=data; - n_points=uint4korr(data); - data+=4; - float8get(x1,data); - data+=8; - float8get(y1,data); - data+=8; + n_points=uint4korr(data); + data+=4; + float8get(x1,data); + data+=8; + float8get(y1,data); + data+=8; - len-= 4 + 8 + 8; + len-= 4 + 8 + 8; - if (len < n_points * POINT_DATA_SIZE) - goto ret; - data+=(n_points-2) * POINT_DATA_SIZE; + if (len < n_points * POINT_DATA_SIZE) + goto ret; + data+=(n_points-2) * POINT_DATA_SIZE; - float8get(x2,data); - float8get(y2,data+8); + float8get(x2,data); + float8get(y2,data+8); - if ((x1 != x2) || (y1 != y2)) - goto ret; + if ((x1 != x2) || (y1 != y2)) + goto ret; - if (str->reserve(llen,512)) - goto ret; - str->q_append(ldata, llen); - } - break; + if (str->reserve(llen,512)) + goto ret; + str->q_append(ldata, llen); + } + break; - default: - goto ret; + default: + goto ret; } } } -- cgit v1.2.1 From 44347c5a541c97b88b40a2a7698e33281ebcf951 Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Thu, 20 Jun 2002 22:52:56 +0500 Subject: SELECT left(non_default_charset_field,n) GROUP BY 1 now works more correctly. Still needs fixes. --- sql/item_strfunc.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 5275da95b6e..81d866bfe6d 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -759,6 +759,7 @@ String *Item_func_left::val_str(String *str) if (!res->alloced_length()) { // Don't change const str str_value= *res; // Not malloced string + str_value.set_charset(res->charset()); res= &str_value; } res->length((uint) length); -- cgit v1.2.1 From c5b8f48cf5acecb4f50155a98bf83f4eefd53484 Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Thu, 20 Jun 2002 23:26:04 +0500 Subject: New CHARSET() function --- sql/item_strfunc.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 81d866bfe6d..a4f09f9103e 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1911,12 +1911,25 @@ outp: return str; } +String *Item_func_charset::val_str(String *str) +{ + String *res = args[0]->val_str(str); + + if ((null_value=(args[0]->null_value || !res->charset()))) + return 0; + str->copy(res->charset()->name,strlen(res->charset()->name)); + return str; +} + + void Item_func_conv_charset3::fix_length_and_dec() { /* BAR TODO: What to do here??? */ } + + String *Item_func_hex::val_str(String *str) { if (args[0]->result_type() != STRING_RESULT) -- cgit v1.2.1 From 337d46966cf9fd37752a4f870b3f5161001be504 Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Wed, 26 Jun 2002 16:00:43 +0500 Subject: Several problems were fixed (mostly BLOB+charset related) Fixed that MyISAM were not working properly with non-8bit charsets in some cases CONVERT() function now works properly --- sql/item_strfunc.cc | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index a4f09f9103e..c2549ddc769 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1799,7 +1799,7 @@ String *Item_func_conv_charset::val_str(String *str) s=(const uchar*)arg->ptr(); se=s+arg->length(); - dmaxlen=arg->length()*(conv_charset->mbmaxlen?conv_charset->mbmaxlen:1)+1; + dmaxlen=arg->length()*(to->mbmaxlen?to->mbmaxlen:1)+1; str->alloc(dmaxlen); d0=d=(unsigned char*)str->ptr(); de=d+dmaxlen; @@ -1841,7 +1841,7 @@ outp: void Item_func_conv_charset::fix_length_and_dec() { - /* BAR TODO: What to do here??? */ + max_length = args[0]->max_length*(conv_charset->mbmaxlen?conv_charset->mbmaxlen:1); } @@ -1911,23 +1911,41 @@ outp: return str; } -String *Item_func_charset::val_str(String *str) -{ - String *res = args[0]->val_str(str); - if ((null_value=(args[0]->null_value || !res->charset()))) - return 0; - str->copy(res->charset()->name,strlen(res->charset()->name)); - return str; +bool Item_func_conv_charset::fix_fields(THD *thd,struct st_table_list *tables) +{ + char buff[STACK_BUFF_ALLOC]; // Max argument in function + binary=0; + used_tables_cache=0; + const_item_cache=1; + + if (thd && check_stack_overrun(thd,buff)) + return 0; // Fatal error if flag is set! + if (args[0]->fix_fields(thd,tables)) + return 1; + maybe_null=args[0]->maybe_null; + binary=args[0]->binary; + str_value.set_charset(conv_charset); + fix_length_and_dec(); + return 0; } void Item_func_conv_charset3::fix_length_and_dec() { - /* BAR TODO: What to do here??? */ + max_length = args[0]->max_length; } +String *Item_func_charset::val_str(String *str) +{ + String *res = args[0]->val_str(str); + + if ((null_value=(args[0]->null_value || !res->charset()))) + return 0; + str->copy(res->charset()->name,strlen(res->charset()->name)); + return str; +} String *Item_func_hex::val_str(String *str) -- cgit v1.2.1 From a3d8e08695ed9a4307e89c08ee6e033b464f5e94 Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Wed, 26 Jun 2002 18:08:33 +0500 Subject: SELECT DISTINCT CONVERT(field USING charset) now works properly --- sql/item_strfunc.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index c2549ddc769..8fb3b7f6897 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1925,6 +1925,7 @@ bool Item_func_conv_charset::fix_fields(THD *thd,struct st_table_list *tables) return 1; maybe_null=args[0]->maybe_null; binary=args[0]->binary; + const_item_cache=args[0]->const_item(); str_value.set_charset(conv_charset); fix_length_and_dec(); return 0; -- cgit v1.2.1 From 2e1285f296be14749bdd51464a1327171e21850a Mon Sep 17 00:00:00 2001 From: "bar@gw.udmsearch.izhnet.ru" <> Date: Thu, 27 Jun 2002 19:00:49 +0500 Subject: Fix --- sql/item_strfunc.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 8fb3b7f6897..5bb2c4015ad 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1792,6 +1792,7 @@ String *Item_func_conv_charset::val_str(String *str) null_value=1; return 0; } + null_value=0; from=arg->charset(); to=conv_charset; -- cgit v1.2.1 From 0c6cb114e2d6c922e6e15fe6ebec38b55a4a982a Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Mon, 1 Jul 2002 19:06:24 +0300 Subject: subselect clean up fix after automerge --- sql/item_strfunc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 5bb2c4015ad..1aee4e7d553 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1922,7 +1922,7 @@ bool Item_func_conv_charset::fix_fields(THD *thd,struct st_table_list *tables) if (thd && check_stack_overrun(thd,buff)) return 0; // Fatal error if flag is set! - if (args[0]->fix_fields(thd,tables)) + if (args[0]->fix_fields(thd, tables, args)) return 1; maybe_null=args[0]->maybe_null; binary=args[0]->binary; -- cgit v1.2.1 From faaddbd21495900c9599d226428bb441aeff10ab Mon Sep 17 00:00:00 2001 From: "bar@bar.mysql.r18.ru" <> Date: Thu, 22 Aug 2002 18:12:45 +0500 Subject: Stupid bug fixes in sql_yacc.cc New class Item_func_set_collation() Fixed that "SELECT CONVERT(expr USING charset) GROUP BY 1" was not working New COLLATION syntax: COLLATE latin1 --- sql/item_strfunc.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 1aee4e7d553..b5b9ed2931e 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1843,9 +1843,11 @@ outp: void Item_func_conv_charset::fix_length_and_dec() { max_length = args[0]->max_length*(conv_charset->mbmaxlen?conv_charset->mbmaxlen:1); + str_value.set_charset(conv_charset); } + String *Item_func_conv_charset3::val_str(String *str) { my_wc_t wc; @@ -1938,6 +1940,33 @@ void Item_func_conv_charset3::fix_length_and_dec() max_length = args[0]->max_length; } +String *Item_func_set_collation::val_str(String *str) +{ + str=args[0]->val_str(str); + null_value=args[0]->null_value; + str->set_charset(set_collation); + return str; +} + +bool Item_func_set_collation::fix_fields(THD *thd,struct st_table_list *tables) +{ + char buff[STACK_BUFF_ALLOC]; // Max argument in function + binary=0; + used_tables_cache=0; + const_item_cache=1; + + if (thd && check_stack_overrun(thd,buff)) + return 0; // Fatal error if flag is set! + if (args[0]->fix_fields(thd, tables, args)) + return 1; + maybe_null=args[0]->maybe_null; + binary=args[0]->binary; + const_item_cache=args[0]->const_item(); + str_value.set_charset(set_collation); + fix_length_and_dec(); + return 0; +} + String *Item_func_charset::val_str(String *str) { -- cgit v1.2.1 From 22bcce253e9f964bfec8d72f42ae55ab22e1228f Mon Sep 17 00:00:00 2001 From: "Sinisa@sinisa.nasamreza.org" <> Date: Sat, 24 Aug 2002 14:49:04 +0300 Subject: Adding a necessary functionality to ::store and ::save_in_field that will take place properly after pull from 4.0, in order to handle conversions from quoted constants to bigint's. --- sql/item_strfunc.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index b5b9ed2931e..594049b3870 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1915,7 +1915,7 @@ outp: } -bool Item_func_conv_charset::fix_fields(THD *thd,struct st_table_list *tables) +bool Item_func_conv_charset::fix_fields(THD *thd,struct st_table_list *tables, Item **ref) { char buff[STACK_BUFF_ALLOC]; // Max argument in function binary=0; @@ -1948,7 +1948,7 @@ String *Item_func_set_collation::val_str(String *str) return str; } -bool Item_func_set_collation::fix_fields(THD *thd,struct st_table_list *tables) +bool Item_func_set_collation::fix_fields(THD *thd,struct st_table_list *tables, Item **ref) { char buff[STACK_BUFF_ALLOC]; // Max argument in function binary=0; -- cgit v1.2.1 From dd5382187e68ff5337e1fe7ba5f86f0d9cdd31d5 Mon Sep 17 00:00:00 2001 From: "bar@bar.mysql.r18.ru" <> Date: Mon, 26 Aug 2002 17:33:44 +0500 Subject: Fix that this didn't work as far as sorting for ORDER BY was removed by optimizer: SELECT k FROM t1 GROUP BY k COLLATE latin1 ORDER BY k COLLATE latin1_de --- sql/item_strfunc.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 594049b3870..dc9d57b1d9d 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1967,6 +1967,26 @@ bool Item_func_set_collation::fix_fields(THD *thd,struct st_table_list *tables, return 0; } +bool Item_func_set_collation::eq(const Item *item, bool binary_cmp) const +{ + /* Assume we don't have rtti */ + if (this == item) + return 1; + if (item->type() != FUNC_ITEM) + return 0; + Item_func *item_func=(Item_func*) item; + if (arg_count != item_func->arg_count || + func_name() != item_func->func_name()) + return 0; + Item_func_set_collation *item_func_sc=(Item_func_set_collation*) item; + if (set_collation != item_func_sc->set_collation) + return 0; + for (uint i=0; i < arg_count ; i++) + if (!args[i]->eq(item_func_sc->args[i], binary_cmp)) + return 0; + return 1; +} + String *Item_func_charset::val_str(String *str) { -- cgit v1.2.1 From ad91c3b77dbbfba148288406d9733d9f3896ca7d Mon Sep 17 00:00:00 2001 From: "bar@bar.mysql.r18.ru" <> Date: Fri, 13 Sep 2002 14:11:06 +0500 Subject: Fixed that: SELECT * FROM t WHERE (c COLLATE latin1) >'a' might fail in some cases --- sql/item_strfunc.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index dc9d57b1d9d..243f11db106 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1943,7 +1943,8 @@ void Item_func_conv_charset3::fix_length_and_dec() String *Item_func_set_collation::val_str(String *str) { str=args[0]->val_str(str); - null_value=args[0]->null_value; + if ((null_value=args[0]->null_value)) + return 0; str->set_charset(set_collation); return str; } @@ -1961,8 +1962,10 @@ bool Item_func_set_collation::fix_fields(THD *thd,struct st_table_list *tables, return 1; maybe_null=args[0]->maybe_null; binary=args[0]->binary; - const_item_cache=args[0]->const_item(); str_value.set_charset(set_collation); + with_sum_func= with_sum_func || args[0]->with_sum_func; + used_tables_cache=args[0]->used_tables(); + const_item_cache=args[0]->const_item(); fix_length_and_dec(); return 0; } @@ -1987,7 +1990,6 @@ bool Item_func_set_collation::eq(const Item *item, bool binary_cmp) const return 1; } - String *Item_func_charset::val_str(String *str) { String *res = args[0]->val_str(str); -- cgit v1.2.1 From d69250a969449da43891ef5b2859df77917183a8 Mon Sep 17 00:00:00 2001 From: "monty@mashka.mysql.fi" <> Date: Wed, 2 Oct 2002 13:33:08 +0300 Subject: Fixes and code cleanups after merge with 4.0.3 Warning handling and initial prepared statement handling (last not complete yet) Changed a lot of functions that returned 0/1 to my_bool type. GRANT handling now uses read/write locks instead of mutex Change basic net functions to use THD instead of NET (needed for 4.1 protocol) Use my_sprintf instead of sprintf() + strlen() Added alloc_query() to be able to chare query initialization code with prepared statements. Cleanup handling of SHOW COUNT(*) WARNINGS and SELECT LAST_INSERT_ID() Note that the following test fails (will be fixed ASAP): sub_select, union, rpl_rotate_logs and rpl_mystery22 --- sql/item_strfunc.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'sql/item_strfunc.cc') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 2bc9b170fc1..1b091f29a6b 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2394,8 +2394,6 @@ null: General functions for spatial objects ********************************************************/ -#include "gstream.h" - String *Item_func_geometry_from_text::val_str(String *str) { Geometry geom; @@ -2715,7 +2713,7 @@ String *Item_func_spatial_collection::val_str(String *str) } } - if (str->length() > max_allowed_packet) + if (str->length() > current_thd->variables.max_allowed_packet) goto ret; null_value = 0; -- cgit v1.2.1