~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

Remove dead memset call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    if (res->length() == 0)
49
49
    {
50
50
      if (!(res=args[i]->val_str(str)))
51
 
        goto null;
 
51
        goto null;
52
52
    }
53
53
    else
54
54
    {
55
55
      if (!(res2=args[i]->val_str(use_as_buff)))
56
 
        goto null;
 
56
        goto null;
57
57
      if (res2->length() == 0)
58
 
        continue;
 
58
        continue;
59
59
      if (res->length()+res2->length() >
60
 
          current_session->variables.max_allowed_packet)
 
60
          session.variables.max_allowed_packet)
61
61
      {
62
 
        push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
63
 
                            ER_WARN_ALLOWED_PACKET_OVERFLOWED,
64
 
                            ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(),
65
 
                            current_session->variables.max_allowed_packet);
66
 
        goto null;
 
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);
 
66
        goto null;
67
67
      }
68
68
      if (!is_const && res->alloced_length() >= res->length()+res2->length())
69
69
      {                                         // Use old buffer
70
 
        res->append(*res2);
 
70
        res->append(*res2);
71
71
      }
72
72
      else if (str->alloced_length() >= res->length()+res2->length())
73
73
      {
74
 
        if (str == res2)
75
 
          str->replace(0,0,*res);
76
 
        else
77
 
        {
78
 
          str->copy(*res);
79
 
          str->append(*res2);
80
 
        }
 
74
        if (str == res2)
 
75
          str->replace(0,0,*res);
 
76
        else
 
77
        {
 
78
          str->copy(*res);
 
79
          str->append(*res2);
 
80
        }
81
81
        res= str;
82
82
        use_as_buff= &tmp_value;
83
83
      }
84
84
      else if (res == &tmp_value)
85
85
      {
86
 
        if (res->append(*res2))                 // Must be a blob
87
 
          goto null;
 
86
        if (res->append(*res2))                 // Must be a blob
 
87
          goto null;
88
88
      }
89
89
      else if (res2 == &tmp_value)
90
90
      {                                         // This can happend only 1 time
91
 
        if (tmp_value.replace(0,0,*res))
92
 
          goto null;
93
 
        res= &tmp_value;
94
 
        use_as_buff=str;                        // Put next arg here
 
91
        if (tmp_value.replace(0,0,*res))
 
92
          goto null;
 
93
        res= &tmp_value;
 
94
        use_as_buff=str;                        // Put next arg here
95
95
      }
96
96
      else if (tmp_value.is_alloced() && res2->ptr() >= tmp_value.ptr() &&
97
 
               res2->ptr() <= tmp_value.ptr() + tmp_value.alloced_length())
 
97
               res2->ptr() <= tmp_value.ptr() + tmp_value.alloced_length())
98
98
      {
99
 
        /*
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
103
 
        */
104
 
        /* Chop the last characters in tmp_value that isn't in res2 */
105
 
        tmp_value.length((uint32_t) (res2->ptr() - tmp_value.ptr()) +
106
 
                         res2->length());
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()),
109
 
                              *res))
110
 
          goto null;
111
 
        res= &tmp_value;
112
 
        use_as_buff=str;                        // Put next arg here
 
99
        /*
 
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
 
103
        */
 
104
        /* Chop the last characters in tmp_value that isn't in res2 */
 
105
        tmp_value.length((uint32_t) (res2->ptr() - tmp_value.ptr()) +
 
106
                         res2->length());
 
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()),
 
109
                              *res))
 
110
          goto null;
 
111
        res= &tmp_value;
 
112
        use_as_buff=str;                        // Put next arg here
113
113
      }
114
114
      else
115
115
      {                                         // Two big const strings
116
116
        /*
117
 
          NOTE: We should be prudent in the initial allocation unit -- the
 
117
          @note We should be prudent in the initial allocation unit -- the
118
118
          size of the arguments is a function of data distribution, which
119
119
          can be any. Instead of overcommitting at the first row, we grow
120
120
          the allocated amount by the factor of 2. This ensures that no
139
139
          }
140
140
        }
141
141
 
142
 
        if (tmp_value.copy(*res) || tmp_value.append(*res2))
143
 
          goto null;
 
142
        if (tmp_value.copy(*res) || tmp_value.append(*res2))
 
143
          goto null;
144
144
 
145
 
        res= &tmp_value;
146
 
        use_as_buff=str;
 
145
        res= &tmp_value;
 
146
        use_as_buff=str;
147
147
      }
148
148
      is_const= 0;
149
149
    }
169
169
    if (args[i]->collation.collation->mbmaxlen != collation.collation->mbmaxlen)
170
170
      max_result_length+= (args[i]->max_length /
171
171
                           args[i]->collation.collation->mbmaxlen) *
172
 
                           collation.collation->mbmaxlen;
 
172
        collation.collation->mbmaxlen;
173
173
    else
174
174
      max_result_length+= args[i]->max_length;
175
175
  }
218
218
      continue;                                 // Skip NULL
219
219
 
220
220
    if (res->length() + sep_str->length() + res2->length() >
221
 
        current_session->variables.max_allowed_packet)
 
221
        session.variables.max_allowed_packet)
222
222
    {
223
 
      push_warning_printf(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
224
 
                          ER_WARN_ALLOWED_PACKET_OVERFLOWED,
225
 
                          ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED), func_name(),
226
 
                          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);
227
227
      goto null;
228
228
    }
229
229
    if (res->alloced_length() >=
230
 
        res->length() + sep_str->length() + res2->length())
 
230
        res->length() + sep_str->length() + res2->length())
231
231
    {                                           // Use old buffer
232
232
      res->append(*sep_str);                    // res->length() > 0 always
233
233
      res->append(*res2);
234
234
    }
235
235
    else if (str->alloced_length() >=
236
 
             res->length() + sep_str->length() + res2->length())
 
236
             res->length() + sep_str->length() + res2->length())
237
237
    {
238
238
      /* We have room in str;  We can't get any errors here */
239
239
      if (str == res2)
240
240
      {                                         // This is quote uncommon!
241
 
        str->replace(0,0,*sep_str);
242
 
        str->replace(0,0,*res);
 
241
        str->replace(0,0,*sep_str);
 
242
        str->replace(0,0,*res);
243
243
      }
244
244
      else
245
245
      {
246
 
        str->copy(*res);
247
 
        str->append(*sep_str);
248
 
        str->append(*res2);
 
246
        str->copy(*res);
 
247
        str->append(*sep_str);
 
248
        str->append(*res2);
249
249
      }
250
250
      res=str;
251
251
      use_as_buff= &tmp_value;
253
253
    else if (res == &tmp_value)
254
254
    {
255
255
      if (res->append(*sep_str) || res->append(*res2))
256
 
        goto null; // Must be a blob
 
256
        goto null; // Must be a blob
257
257
    }
258
258
    else if (res2 == &tmp_value)
259
259
    {                                           // This can happend only 1 time
260
260
      if (tmp_value.replace(0,0,*sep_str) || tmp_value.replace(0,0,*res))
261
 
        goto null;
 
261
        goto null;
262
262
      res= &tmp_value;
263
263
      use_as_buff=str;                          // Put next arg here
264
264
    }
265
265
    else if (tmp_value.is_alloced() && res2->ptr() >= tmp_value.ptr() &&
266
 
             res2->ptr() < tmp_value.ptr() + tmp_value.alloced_length())
 
266
             res2->ptr() < tmp_value.ptr() + tmp_value.alloced_length())
267
267
    {
268
268
      /*
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
 
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
272
272
      */
273
273
      /* Chop the last characters in tmp_value that isn't in res2 */
274
274
      tmp_value.length((uint32_t) (res2->ptr() - tmp_value.ptr()) +
275
 
                       res2->length());
 
275
                       res2->length());
276
276
      /* Place res2 at start of tmp_value, remove chars before res2 */
277
277
      if (tmp_value.replace(0,(uint32_t) (res2->ptr() - tmp_value.ptr()),
278
 
                            *res) ||
279
 
          tmp_value.replace(res->length(),0, *sep_str))
280
 
        goto null;
 
278
                            *res) ||
 
279
          tmp_value.replace(res->length(),0, *sep_str))
 
280
        goto null;
281
281
      res= &tmp_value;
282
282
      use_as_buff=str;                  // Put next arg here
283
283
    }
284
284
    else
285
285
    {                                           // Two big const strings
286
286
      /*
287
 
        NOTE: We should be prudent in the initial allocation unit -- the
 
287
        @note We should be prudent in the initial allocation unit -- the
288
288
        size of the arguments is a function of data distribution, which can
289
289
        be any. Instead of overcommitting at the first row, we grow the
290
290
        allocated amount by the factor of 2. This ensures that no more than
310
310
      }
311
311
 
312
312
      if (tmp_value.copy(*res) ||
313
 
          tmp_value.append(*sep_str) ||
314
 
          tmp_value.append(*res2))
315
 
        goto null;
 
313
          tmp_value.append(*sep_str) ||
 
314
          tmp_value.append(*res2))
 
315
        goto null;
316
316
      res= &tmp_value;
317
317
      use_as_buff=str;
318
318
    }
334
334
    return;
335
335
 
336
336
  /*
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.
 
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.
340
340
  */
341
341
  max_result_length= (uint64_t) args[0]->max_length * (arg_count - 2);
342
342
  for (uint32_t i=1 ; i < arg_count ; i++)