drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
function/str/strfunc.cc
Go to the documentation of this file.
1/* Copyright (C) 2000-2006 MySQL AB
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16
27
28#include <config.h>
29#include <zlib.h>
30#include <drizzled/error.h>
31#include <drizzled/function/str/strfunc.h>
32
33using namespace std;
34
35namespace drizzled {
36
37bool Item_str_func::fix_fields(Session *session, Item **ref)
38{
39 bool res= Item_func::fix_fields(session, ref);
40 /*
41 In Item_str_func::check_well_formed_result() we may set null_value
42 flag on the same condition as in test() below.
43 */
44 maybe_null= true;
45 return res;
46}
47
49{
50 assert(fixed == 1);
51 char buff[64];
52 String *res, tmp(buff,sizeof(buff), &my_charset_bin);
53 res= val_str(&tmp);
54 if (not res)
55 return 0;
56
57 (void)decimal_value->store(E_DEC_FATAL_ERROR, (char*) res->ptr(), res->length(), res->charset());
58
59 return decimal_value;
60}
61
62
64{
65 assert(fixed == 1);
66 int err_not_used;
67 char *end_not_used, buff[64];
68 String *res, tmp(buff,sizeof(buff), &my_charset_bin);
69 res= val_str(&tmp);
70 return res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
71 &end_not_used, &err_not_used) : 0.0;
72}
73
74
76{
77 assert(fixed == 1);
78 int err;
79 char buff[DECIMAL_LONGLONG_DIGITS];
80 String *res, tmp(buff,sizeof(buff), &my_charset_bin);
81 res= val_str(&tmp);
82 return (res ?
83 my_strntoll(res->charset(), res->ptr(), res->length(), 10, NULL,
84 &err) :
85 (int64_t) 0);
86}
87
88void Item_str_func::left_right_max_length()
89{
90 max_length=args[0]->max_length;
91 if (args[1]->const_item())
92 {
93 int length=(int) args[1]->val_int()*collation.collation->mbmaxlen;
94 if (length <= 0)
95 max_length=0;
96 else
97 set_if_smaller(max_length,(uint) length);
98 }
99}
100
101DRIZZLED_API String my_empty_string("",default_charset_info);
102
103} /* namespace drizzled */
virtual bool const_item() const
type::Decimal * val_decimal(type::Decimal *)
bool fixed
Definition item.h:122
bool maybe_null
Definition item.h:123
virtual String * val_str(String *str)=0
int store(uint32_t mask, const char *from, uint32_t length, const charset_info_st *charset)
Convert string for decimal when string can be in some multibyte charset.
TODO: Rename this file - func.h is stupid.
STL namespace.
#define DRIZZLED_API
Definition visibility.h:38