Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00042
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 }