~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/function/str/strfunc.cc

Merge of Jay

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
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
 
 
28
#include <drizzled/server_includes.h>
 
29
#include <mysys/sha1.h>
 
30
#include <zlib.h>
 
31
#include <drizzled/query_id.h>
 
32
#include <uuid/uuid.h>
 
33
#include <drizzled/error.h>
 
34
#include <drizzled/function/str/strfunc.h>
 
35
 
 
36
// For soundex_map
 
37
#include <mysys/my_static.h>
 
38
 
 
39
using namespace std;
 
40
 
 
41
Item_str_func::~Item_str_func() {}
 
42
 
 
43
bool Item_str_func::fix_fields(Session *session, Item **ref)
 
44
{
 
45
  bool res= Item_func::fix_fields(session, ref);
 
46
  /*
 
47
    In Item_str_func::check_well_formed_result() we may set null_value
 
48
    flag on the same condition as in test() below.
 
49
  */
 
50
  maybe_null= (maybe_null || true);
 
51
  return res;
 
52
}
 
53
 
 
54
 
 
55
my_decimal *Item_str_func::val_decimal(my_decimal *decimal_value)
 
56
{
 
57
  assert(fixed == 1);
 
58
  char buff[64];
 
59
  String *res, tmp(buff,sizeof(buff), &my_charset_bin);
 
60
  res= val_str(&tmp);
 
61
  if (!res)
 
62
    return 0;
 
63
  (void)str2my_decimal(E_DEC_FATAL_ERROR, (char*) res->ptr(),
 
64
                       res->length(), res->charset(), decimal_value);
 
65
  return decimal_value;
 
66
}
 
67
 
 
68
 
 
69
double Item_str_func::val_real()
 
70
{
 
71
  assert(fixed == 1);
 
72
  int err_not_used;
 
73
  char *end_not_used, buff[64];
 
74
  String *res, tmp(buff,sizeof(buff), &my_charset_bin);
 
75
  res= val_str(&tmp);
 
76
  return res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
 
77
                          &end_not_used, &err_not_used) : 0.0;
 
78
}
 
79
 
 
80
 
 
81
int64_t Item_str_func::val_int()
 
82
{
 
83
  assert(fixed == 1);
 
84
  int err;
 
85
  char buff[22];
 
86
  String *res, tmp(buff,sizeof(buff), &my_charset_bin);
 
87
  res= val_str(&tmp);
 
88
  return (res ?
 
89
          my_strntoll(res->charset(), res->ptr(), res->length(), 10, NULL,
 
90
                      &err) :
 
91
          (int64_t) 0);
 
92
}
 
93
 
 
94
void Item_str_func::left_right_max_length()
 
95
{
 
96
  max_length=args[0]->max_length;
 
97
  if (args[1]->const_item())
 
98
  {
 
99
    int length=(int) args[1]->val_int()*collation.collation->mbmaxlen;
 
100
    if (length <= 0)
 
101
      max_length=0;
 
102
    else
 
103
      set_if_smaller(max_length,(uint) length);
 
104
  }
 
105
}
 
106
 
 
107
String my_empty_string("",default_charset_info);
 
108