~drizzle-trunk/drizzle/development

574.3.2 by Lee
initial changes to break out item_strfunc into functions/str
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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
574.3.2 by Lee
initial changes to break out item_strfunc into functions/str
15
16
17
/**
18
  @file
19
20
  @brief
21
  This file defines all string functions
22
23
  @warning
24
    Some string functions don't always put and end-null on a String.
25
    (This shouldn't be needed)
26
*/
27
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
28
#include <config.h>
574.3.2 by Lee
initial changes to break out item_strfunc into functions/str
29
#include <zlib.h>
30
#include <drizzled/query_id.h>
31
#include <drizzled/error.h>
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
32
#include <drizzled/function/str/strfunc.h>
574.3.2 by Lee
initial changes to break out item_strfunc into functions/str
33
34
using namespace std;
35
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
36
namespace drizzled
37
{
38
1022.2.29 by Monty Taylor
Fixed some no-inline warnings.
39
Item_str_func::~Item_str_func() {}
40
574.3.2 by Lee
initial changes to break out item_strfunc into functions/str
41
bool Item_str_func::fix_fields(Session *session, Item **ref)
42
{
43
  bool res= Item_func::fix_fields(session, ref);
44
  /*
45
    In Item_str_func::check_well_formed_result() we may set null_value
46
    flag on the same condition as in test() below.
47
  */
48
  maybe_null= (maybe_null || true);
49
  return res;
50
}
51
52
2030.1.4 by Brian Aker
Change my_decimal to Decimal
53
type::Decimal *Item_str_func::val_decimal(type::Decimal *decimal_value)
574.3.2 by Lee
initial changes to break out item_strfunc into functions/str
54
{
55
  assert(fixed == 1);
56
  char buff[64];
57
  String *res, tmp(buff,sizeof(buff), &my_charset_bin);
58
  res= val_str(&tmp);
2034.2.5 by Brian Aker
Improvement for decimal in encapsulation.
59
  if (not res)
574.3.2 by Lee
initial changes to break out item_strfunc into functions/str
60
    return 0;
2034.2.5 by Brian Aker
Improvement for decimal in encapsulation.
61
62
  (void)decimal_value->store(E_DEC_FATAL_ERROR, (char*) res->ptr(), res->length(), res->charset());
63
574.3.2 by Lee
initial changes to break out item_strfunc into functions/str
64
  return decimal_value;
65
}
66
67
68
double Item_str_func::val_real()
69
{
70
  assert(fixed == 1);
71
  int err_not_used;
72
  char *end_not_used, buff[64];
73
  String *res, tmp(buff,sizeof(buff), &my_charset_bin);
74
  res= val_str(&tmp);
75
  return res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
76
			  &end_not_used, &err_not_used) : 0.0;
77
}
78
79
80
int64_t Item_str_func::val_int()
81
{
82
  assert(fixed == 1);
83
  int err;
2148.5.3 by Brian Aker
Remove hard coded array for numbers (this also fixes a couple of spots where
84
  char buff[DECIMAL_LONGLONG_DIGITS];
574.3.2 by Lee
initial changes to break out item_strfunc into functions/str
85
  String *res, tmp(buff,sizeof(buff), &my_charset_bin);
86
  res= val_str(&tmp);
87
  return (res ?
88
	  my_strntoll(res->charset(), res->ptr(), res->length(), 10, NULL,
89
		      &err) :
90
	  (int64_t) 0);
91
}
92
93
void Item_str_func::left_right_max_length()
94
{
95
  max_length=args[0]->max_length;
96
  if (args[1]->const_item())
97
  {
98
    int length=(int) args[1]->val_int()*collation.collation->mbmaxlen;
99
    if (length <= 0)
100
      max_length=0;
101
    else
102
      set_if_smaller(max_length,(uint) length);
103
  }
104
}
105
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
106
DRIZZLED_API String my_empty_string("",default_charset_info);
629.6.5 by Lee
clean up remaining functions in strfunc, move to functions/str directory
107
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
108
} /* namespace drizzled */