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/error.h>
00031 #include <drizzled/function/str/strfunc.h>
00032 
00033 using namespace std;
00034 
00035 namespace drizzled {
00036 
00037 bool Item_str_func::fix_fields(Session *session, Item **ref)
00038 {
00039   bool res= Item_func::fix_fields(session, ref);
00040   /*
00041     In Item_str_func::check_well_formed_result() we may set null_value
00042     flag on the same condition as in test() below.
00043   */
00044   maybe_null= true;
00045   return res;
00046 }
00047 
00048 type::Decimal *Item_str_func::val_decimal(type::Decimal *decimal_value)
00049 {
00050   assert(fixed == 1);
00051   char buff[64];
00052   String *res, tmp(buff,sizeof(buff), &my_charset_bin);
00053   res= val_str(&tmp);
00054   if (not res)
00055     return 0;
00056 
00057   (void)decimal_value->store(E_DEC_FATAL_ERROR, (char*) res->ptr(), res->length(), res->charset());
00058 
00059   return decimal_value;
00060 }
00061 
00062 
00063 double Item_str_func::val_real()
00064 {
00065   assert(fixed == 1);
00066   int err_not_used;
00067   char *end_not_used, buff[64];
00068   String *res, tmp(buff,sizeof(buff), &my_charset_bin);
00069   res= val_str(&tmp);
00070   return res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
00071         &end_not_used, &err_not_used) : 0.0;
00072 }
00073 
00074 
00075 int64_t Item_str_func::val_int()
00076 {
00077   assert(fixed == 1);
00078   int err;
00079   char buff[DECIMAL_LONGLONG_DIGITS];
00080   String *res, tmp(buff,sizeof(buff), &my_charset_bin);
00081   res= val_str(&tmp);
00082   return (res ?
00083     my_strntoll(res->charset(), res->ptr(), res->length(), 10, NULL,
00084           &err) :
00085     (int64_t) 0);
00086 }
00087 
00088 void Item_str_func::left_right_max_length()
00089 {
00090   max_length=args[0]->max_length;
00091   if (args[1]->const_item())
00092   {
00093     int length=(int) args[1]->val_int()*collation.collation->mbmaxlen;
00094     if (length <= 0)
00095       max_length=0;
00096     else
00097       set_if_smaller(max_length,(uint) length);
00098   }
00099 }
00100 
00101 DRIZZLED_API String my_empty_string("",default_charset_info);
00102 
00103 } /* namespace drizzled */