~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Monty Taylor
  • Date: 2008-12-18 07:24:54 UTC
  • mto: This revision was merged to the branch mainline in revision 714.
  • Revision ID: monty@bitters-20081218072454-8pnep622damjgqli
Fixed one more my_time thing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
22
22
#include <drizzled/function/str/replace.h>
23
23
#include <drizzled/error.h>
24
24
#include <drizzled/session.h>
25
25
 
26
 
namespace drizzled
27
 
{
28
 
 
29
26
/**
30
27
  Replace all occurences of string2 in string1 with string3.
31
28
 
32
29
  Don't reallocate val_str() if not needed.
33
30
 
34
31
  @todo
35
 
    Fix that this works with binary strings
 
32
    Fix that this works with binary strings when using USE_MB
36
33
*/
37
34
 
38
35
String *Item_func_replace::val_str(String *str)
42
39
  int offset;
43
40
  uint32_t from_length,to_length;
44
41
  bool alloced=0;
 
42
#ifdef USE_MB
45
43
  const char *ptr,*end,*strend,*search,*search_end;
46
44
  register uint32_t l;
47
45
  bool binary_cmp;
 
46
#endif
48
47
 
49
48
  null_value=0;
50
49
  res=args[0]->val_str(str);
56
55
 
57
56
  res->set_charset(collation.collation);
58
57
 
 
58
#ifdef USE_MB
59
59
  binary_cmp = ((res->charset()->state & MY_CS_BINSORT) || !use_mb(res->charset()));
 
60
#endif
60
61
 
61
62
  if (res2->length() == 0)
62
63
    return res;
 
64
#ifndef USE_MB
 
65
  if ((offset=res->strstr(*res2)) < 0)
 
66
    return res;
 
67
#else
63
68
  offset=0;
64
69
  if (binary_cmp && (offset=res->strstr(*res2)) < 0)
65
70
    return res;
 
71
#endif
66
72
  if (!(res3=args[2]->val_str(&tmp_value2)))
67
73
    goto null;
68
74
  from_length= res2->length();
69
75
  to_length=   res3->length();
70
76
 
 
77
#ifdef USE_MB
71
78
  if (!binary_cmp)
72
79
  {
73
80
    search=res2->ptr();
86
93
            if (*i++ != *j++) goto skip;
87
94
          offset= (int) (ptr-res->ptr());
88
95
          if (res->length()-from_length + to_length >
89
 
              session.variables.max_allowed_packet)
 
96
              current_session->variables.max_allowed_packet)
90
97
          {
91
 
            push_warning_printf(&session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
98
            push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
92
99
                                ER_WARN_ALLOWED_PACKET_OVERFLOWED,
93
100
                                ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED),
94
101
                                func_name(),
95
 
                                session.variables.max_allowed_packet);
 
102
                                current_session->variables.max_allowed_packet);
96
103
 
97
104
            goto null;
98
105
          }
111
118
    }
112
119
  }
113
120
  else
 
121
#endif /* USE_MB */
114
122
    do
115
123
    {
116
124
      if (res->length()-from_length + to_length >
117
 
          session.variables.max_allowed_packet)
 
125
          current_session->variables.max_allowed_packet)
118
126
      {
119
 
        push_warning_printf(&session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
127
        push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
120
128
                            ER_WARN_ALLOWED_PACKET_OVERFLOWED,
121
129
                            ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(),
122
 
                            session.variables.max_allowed_packet);
 
130
                            current_session->variables.max_allowed_packet);
123
131
        goto null;
124
132
      }
125
133
      if (!alloced)
160
168
}
161
169
 
162
170
 
163
 
} /* namespace drizzled */