~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: Brian Aker
  • Date: 2009-07-11 19:23:04 UTC
  • mfrom: (1089.1.14 merge)
  • Revision ID: brian@gaz-20090711192304-ootijyl5yf9jq9kd
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include <drizzled/server_includes.h>
 
21
#include CSTDINT_H
 
22
#include <drizzled/function/str/set_collation.h>
 
23
#include <drizzled/error.h>
 
24
 
 
25
String *Item_func_set_collation::val_str(String *str)
 
26
{
 
27
  assert(fixed == 1);
 
28
  str=args[0]->val_str(str);
 
29
  if ((null_value=args[0]->null_value))
 
30
    return 0;
 
31
  str->set_charset(collation.collation);
 
32
  return str;
 
33
}
 
34
 
 
35
void Item_func_set_collation::fix_length_and_dec()
 
36
{
 
37
  const CHARSET_INFO *set_collation;
 
38
  const char *colname;
 
39
  String tmp, *str= args[1]->val_str(&tmp);
 
40
  colname= str->c_ptr();
 
41
  if (colname == binary_keyword)
 
42
    set_collation= get_charset_by_csname(args[0]->collation.collation->csname, MY_CS_BINSORT);
 
43
  else
 
44
  {
 
45
    if (!(set_collation= get_charset_by_name(colname)))
 
46
    {
 
47
      my_error(ER_UNKNOWN_COLLATION, MYF(0), colname);
 
48
      return;
 
49
    }
 
50
  }
 
51
 
 
52
  if (!set_collation ||
 
53
      !my_charset_same(args[0]->collation.collation,set_collation))
 
54
  {
 
55
    my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
 
56
             colname, args[0]->collation.collation->csname);
 
57
    return;
 
58
  }
 
59
  collation.set(set_collation, DERIVATION_EXPLICIT);
 
60
  max_length= args[0]->max_length;
 
61
}
 
62
 
 
63
bool Item_func_set_collation::eq(const Item *item, bool binary_cmp) const
 
64
{
 
65
  /* Assume we don't have rtti */
 
66
  if (this == item)
 
67
    return 1;
 
68
  if (item->type() != FUNC_ITEM)
 
69
    return 0;
 
70
  Item_func *item_func=(Item_func*) item;
 
71
  if (arg_count != item_func->arg_count ||
 
72
      functype() != item_func->functype())
 
73
    return 0;
 
74
  Item_func_set_collation *item_func_sc=(Item_func_set_collation*) item;
 
75
  if (collation.collation != item_func_sc->collation.collation)
 
76
    return 0;
 
77
  for (uint32_t i=0; i < arg_count ; i++)
 
78
    if (!args[i]->eq(item_func_sc->args[i], binary_cmp))
 
79
      return 0;
 
80
  return 1;
 
81
}
 
82
 
 
83
void Item_func_set_collation::print(String *str, enum_query_type query_type)
 
84
{
 
85
  str->append('(');
 
86
  args[0]->print(str, query_type);
 
87
  str->append(STRING_WITH_LEN(" collate "));
 
88
  assert(args[1]->basic_const_item() &&
 
89
              args[1]->type() == Item::STRING_ITEM);
 
90
  args[1]->str_value.print(str);
 
91
  str->append(')');
 
92
}
 
93
 
 
94
 
 
95