~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/dtcollation.cc

  • Committer: Stewart Smith
  • Date: 2009-06-16 00:45:15 UTC
  • mto: (1119.2.6 merge)
  • mto: This revision was merged to the branch mainline in revision 1124.
  • Revision ID: stewart@flamingspork.com-20090616004515-bgr8e62psvn2820l
make snowman test not leave tables behind after running

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"
 
20
#include <drizzled/server_includes.h>
21
21
#include <drizzled/dtcollation.h>
22
22
 
23
23
#include <drizzled/definitions.h>
24
 
#include "drizzled/internal/my_sys.h"
25
 
#include "drizzled/charset_info.h"
 
24
#include <mysys/my_sys.h>
 
25
#include <mystrings/m_ctype.h>
26
26
#include <drizzled/error.h>
27
27
#include <drizzled/function/str/conv_charset.h>
28
28
#include <drizzled/session.h>
29
 
#include "drizzled/charset.h"
30
29
 
31
 
namespace drizzled
32
 
{
33
30
 
34
31
DTCollation::DTCollation()
35
32
{
232
229
                       Item **args, uint32_t nargs, uint32_t flags,
233
230
                       int item_sep)
234
231
{
 
232
  Item **arg, *safe_args[2];
 
233
 
 
234
  memset(safe_args, 0, sizeof(safe_args));
 
235
 
235
236
  if (agg_item_collations(coll, fname, args, nargs, flags, item_sep))
236
237
    return true;
237
238
 
238
 
  return false;
 
239
  /*
 
240
    For better error reporting: save the first and the second argument.
 
241
    We need this only if the the number of args is 3 or 2:
 
242
    - for a longer argument list, "Illegal mix of collations"
 
243
      doesn't display each argument's characteristics.
 
244
    - if nargs is 1, then this error cannot happen.
 
245
  */
 
246
  if (nargs >=2 && nargs <= 3)
 
247
  {
 
248
    safe_args[0]= args[0];
 
249
    safe_args[1]= args[item_sep];
 
250
  }
 
251
 
 
252
  Session *session= current_session;
 
253
  bool res= false;
 
254
  uint32_t i;
 
255
 
 
256
  for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
 
257
  {
 
258
    Item* conv;
 
259
    uint32_t dummy_offset;
 
260
    if (!String::needs_conversion(0, (*arg)->collation.collation,
 
261
                                  coll.collation,
 
262
                                  &dummy_offset))
 
263
      continue;
 
264
 
 
265
    if (!(conv= (*arg)->safe_charset_converter(coll.collation)))
 
266
    {
 
267
      if (nargs >=2 && nargs <= 3)
 
268
      {
 
269
        /* restore the original arguments for better error message */
 
270
        args[0]= safe_args[0];
 
271
        args[item_sep]= safe_args[1];
 
272
      }
 
273
      my_coll_agg_error(args, nargs, fname, item_sep);
 
274
      res= true;
 
275
      break; // we cannot return here, we need to restore "arena".
 
276
    }
 
277
    if ((*arg)->type() == Item::FIELD_ITEM)
 
278
      ((Item_field *)(*arg))->no_const_subst= 1;
 
279
    /*
 
280
      If in statement prepare, then we create a converter for two
 
281
      constant items, do it once and then reuse it.
 
282
      If we're in execution of a prepared statement, arena is NULL,
 
283
      and the conv was created in runtime memory. This can be
 
284
      the case only if the argument is a parameter marker ('?'),
 
285
      because for all true constants the charset converter has already
 
286
      been created in prepare. In this case register the change for
 
287
      rollback.
 
288
    */
 
289
    session->change_item_tree(arg, conv);
 
290
    /*
 
291
      We do not check conv->fixed, because Item_func_conv_charset which can
 
292
      be return by safe_charset_converter can't be fixed at creation
 
293
    */
 
294
    conv->fix_fields(session, arg);
 
295
  }
 
296
 
 
297
  return res;
239
298
}
240
299
 
241
300
 
274
333
    my_error(ER_CANT_AGGREGATE_NCOLLATIONS,MYF(0),fname);
275
334
}
276
335
 
277
 
} /* namespace drizzled */