48
41
if (res->length() == 0)
50
43
if (!(res=args[i]->val_str(str)))
55
48
if (!(res2=args[i]->val_str(use_as_buff)))
57
50
if (res2->length() == 0)
59
52
if (res->length()+res2->length() >
60
session.variables.max_allowed_packet)
53
current_session->variables.max_allowed_packet)
62
push_warning_printf(&session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
63
ER_WARN_ALLOWED_PACKET_OVERFLOWED,
64
ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(),
65
session.variables.max_allowed_packet);
55
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
56
ER_WARN_ALLOWED_PACKET_OVERFLOWED,
57
ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(),
58
current_session->variables.max_allowed_packet);
68
61
if (!is_const && res->alloced_length() >= res->length()+res2->length())
69
62
{ // Use old buffer
72
65
else if (str->alloced_length() >= res->length()+res2->length())
75
str->replace(0,0,*res);
68
str->replace(0,0,*res);
82
75
use_as_buff= &tmp_value;
84
77
else if (res == &tmp_value)
86
if (res->append(*res2)) // Must be a blob
79
if (res->append(*res2)) // Must be a blob
89
82
else if (res2 == &tmp_value)
90
83
{ // This can happend only 1 time
91
if (tmp_value.replace(0,0,*res))
94
use_as_buff=str; // Put next arg here
84
if (tmp_value.replace(0,0,*res))
87
use_as_buff=str; // Put next arg here
96
89
else if (tmp_value.is_alloced() && res2->ptr() >= tmp_value.ptr() &&
97
res2->ptr() <= tmp_value.ptr() + tmp_value.alloced_length())
90
res2->ptr() <= tmp_value.ptr() + tmp_value.alloced_length())
100
This happens really seldom:
101
In this case res2 is sub string of tmp_value. We will
102
now work in place in tmp_value to set it to res | res2
104
/* Chop the last characters in tmp_value that isn't in res2 */
105
tmp_value.length((uint32_t) (res2->ptr() - tmp_value.ptr()) +
107
/* Place res2 at start of tmp_value, remove chars before res2 */
108
if (tmp_value.replace(0,(uint32_t) (res2->ptr() - tmp_value.ptr()),
112
use_as_buff=str; // Put next arg here
93
This happens really seldom:
94
In this case res2 is sub string of tmp_value. We will
95
now work in place in tmp_value to set it to res | res2
97
/* Chop the last characters in tmp_value that isn't in res2 */
98
tmp_value.length((uint32_t) (res2->ptr() - tmp_value.ptr()) +
100
/* Place res2 at start of tmp_value, remove chars before res2 */
101
if (tmp_value.replace(0,(uint32_t) (res2->ptr() - tmp_value.ptr()),
105
use_as_buff=str; // Put next arg here
115
108
{ // Two big const strings
117
@note We should be prudent in the initial allocation unit -- the
110
NOTE: We should be prudent in the initial allocation unit -- the
118
111
size of the arguments is a function of data distribution, which
119
112
can be any. Instead of overcommitting at the first row, we grow
120
113
the allocated amount by the factor of 2. This ensures that no
121
114
more than 25% of memory will be overcommitted on average.
124
size_t concat_len= res->length() + res2->length();
117
uint32_t concat_len= res->length() + res2->length();
126
119
if (tmp_value.alloced_length() < concat_len)
218
211
continue; // Skip NULL
220
213
if (res->length() + sep_str->length() + res2->length() >
221
session.variables.max_allowed_packet)
214
current_session->variables.max_allowed_packet)
223
push_warning_printf(&session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
224
ER_WARN_ALLOWED_PACKET_OVERFLOWED,
225
ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(),
226
session.variables.max_allowed_packet);
216
push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
217
ER_WARN_ALLOWED_PACKET_OVERFLOWED,
218
ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(),
219
current_session->variables.max_allowed_packet);
229
222
if (res->alloced_length() >=
230
res->length() + sep_str->length() + res2->length())
223
res->length() + sep_str->length() + res2->length())
231
224
{ // Use old buffer
232
225
res->append(*sep_str); // res->length() > 0 always
233
226
res->append(*res2);
235
228
else if (str->alloced_length() >=
236
res->length() + sep_str->length() + res2->length())
229
res->length() + sep_str->length() + res2->length())
238
231
/* We have room in str; We can't get any errors here */
240
233
{ // This is quote uncommon!
241
str->replace(0,0,*sep_str);
242
str->replace(0,0,*res);
234
str->replace(0,0,*sep_str);
235
str->replace(0,0,*res);
247
str->append(*sep_str);
240
str->append(*sep_str);
251
244
use_as_buff= &tmp_value;
253
246
else if (res == &tmp_value)
255
248
if (res->append(*sep_str) || res->append(*res2))
256
goto null; // Must be a blob
249
goto null; // Must be a blob
258
251
else if (res2 == &tmp_value)
259
252
{ // This can happend only 1 time
260
253
if (tmp_value.replace(0,0,*sep_str) || tmp_value.replace(0,0,*res))
263
256
use_as_buff=str; // Put next arg here
265
258
else if (tmp_value.is_alloced() && res2->ptr() >= tmp_value.ptr() &&
266
res2->ptr() < tmp_value.ptr() + tmp_value.alloced_length())
259
res2->ptr() < tmp_value.ptr() + tmp_value.alloced_length())
269
This happens really seldom:
270
In this case res2 is sub string of tmp_value. We will
271
now work in place in tmp_value to set it to res | sep_str | res2
262
This happens really seldom:
263
In this case res2 is sub string of tmp_value. We will
264
now work in place in tmp_value to set it to res | sep_str | res2
273
266
/* Chop the last characters in tmp_value that isn't in res2 */
274
267
tmp_value.length((uint32_t) (res2->ptr() - tmp_value.ptr()) +
276
269
/* Place res2 at start of tmp_value, remove chars before res2 */
277
270
if (tmp_value.replace(0,(uint32_t) (res2->ptr() - tmp_value.ptr()),
279
tmp_value.replace(res->length(),0, *sep_str))
272
tmp_value.replace(res->length(),0, *sep_str))
282
275
use_as_buff=str; // Put next arg here
285
278
{ // Two big const strings
287
@note We should be prudent in the initial allocation unit -- the
280
NOTE: We should be prudent in the initial allocation unit -- the
288
281
size of the arguments is a function of data distribution, which can
289
282
be any. Instead of overcommitting at the first row, we grow the
290
283
allocated amount by the factor of 2. This ensures that no more than
291
284
25% of memory will be overcommitted on average.
294
size_t concat_len= res->length() + sep_str->length() + res2->length();
287
uint32_t concat_len= res->length() + sep_str->length() + res2->length();
296
289
if (tmp_value.alloced_length() < concat_len)
337
arg_count cannot be less than 2,
338
it is done on parser level in sql_yacc.yy
339
so, (arg_count - 2) is safe here.
330
arg_count cannot be less than 2,
331
it is done on parser level in sql_yacc.yy
332
so, (arg_count - 2) is safe here.
341
334
max_result_length= (uint64_t) args[0]->max_length * (arg_count - 2);
342
335
for (uint32_t i=1 ; i < arg_count ; i++)