Drizzled Public API Documentation

strfunc.cc
Go to the documentation of this file.
00001 /* Copyright (C) 2000-2006 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 
00028 #include <config.h>
00029 #include <zlib.h>
00030 #include <drizzled/query_id.h>
00031 #include <drizzled/error.h>
00032 #include <drizzled/function/str/strfunc.h>
00033 
00034 // For soundex_map
00035 #include <drizzled/internal/my_static.h>
00036 
00037 using namespace std;
00038 
00039 namespace drizzled
00040 {
00041 
00042 Item_str_func::~Item_str_func() {}
00043 
00044 bool Item_str_func::fix_fields(Session *session, Item **ref)
00045 {
00046   bool res= Item_func::fix_fields(session, ref);
00047   /*
00048     In Item_str_func::check_well_formed_result() we may set null_value
00049     flag on the same condition as in test() below.
00050   */
00051   maybe_null= (maybe_null || true);
00052   return res;
00053 }
00054 
00055 
00056 type::Decimal *Item_str_func::val_decimal(type::Decimal *decimal_value)
00057 {
00058   assert(fixed == 1);
00059   char buff[64];
00060   String *res, tmp(buff,sizeof(buff), &my_charset_bin);
00061   res= val_str(&tmp);
00062   if (not res)
00063     return 0;
00064 
00065   (void)decimal_value->store(E_DEC_FATAL_ERROR, (char*) res->ptr(), res->length(), res->charset());
00066 
00067   return decimal_value;
00068 }
00069 
00070 
00071 double Item_str_func::val_real()
00072 {
00073   assert(fixed == 1);
00074   int err_not_used;
00075   char *end_not_used, buff[64];
00076   String *res, tmp(buff,sizeof(buff), &my_charset_bin);
00077   res= val_str(&tmp);
00078   return res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
00079         &end_not_used, &err_not_used) : 0.0;
00080 }
00081 
00082 
00083 int64_t Item_str_func::val_int()
00084 {
00085   assert(fixed == 1);
00086   int err;
00087   char buff[DECIMAL_LONGLONG_DIGITS];
00088   String *res, tmp(buff,sizeof(buff), &my_charset_bin);
00089   res= val_str(&tmp);
00090   return (res ?
00091     my_strntoll(res->charset(), res->ptr(), res->length(), 10, NULL,
00092           &err) :
00093     (int64_t) 0);
00094 }
00095 
00096 void Item_str_func::left_right_max_length()
00097 {
00098   max_length=args[0]->max_length;
00099   if (args[1]->const_item())
00100   {
00101     int length=(int) args[1]->val_int()*collation.collation->mbmaxlen;
00102     if (length <= 0)
00103       max_length=0;
00104     else
00105       set_if_smaller(max_length,(uint) length);
00106   }
00107 }
00108 
00109 DRIZZLED_API String my_empty_string("",default_charset_info);
00110 
00111 } /* namespace drizzled */