~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

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 "config.h"
21
 
#include <drizzled/function/str/set_collation.h>
22
 
#include <drizzled/error.h>
23
 
#include "drizzled/charset.h"
24
 
 
25
 
static const char *binary_keyword= "BINARY";
26
 
 
27
 
String *Item_func_set_collation::val_str(String *str)
28
 
{
29
 
  assert(fixed == 1);
30
 
  str=args[0]->val_str(str);
31
 
  if ((null_value=args[0]->null_value))
32
 
    return 0;
33
 
  str->set_charset(collation.collation);
34
 
  return str;
35
 
}
36
 
 
37
 
void Item_func_set_collation::fix_length_and_dec()
38
 
{
39
 
  const CHARSET_INFO *set_collation;
40
 
  const char *colname;
41
 
  String tmp, *str= args[1]->val_str(&tmp);
42
 
  colname= str->c_ptr();
43
 
  if (colname == binary_keyword)
44
 
    set_collation= get_charset_by_csname(args[0]->collation.collation->csname, MY_CS_BINSORT);
45
 
  else
46
 
  {
47
 
    if (!(set_collation= get_charset_by_name(colname)))
48
 
    {
49
 
      my_error(ER_UNKNOWN_COLLATION, MYF(0), colname);
50
 
      return;
51
 
    }
52
 
  }
53
 
 
54
 
  if (!set_collation ||
55
 
      !my_charset_same(args[0]->collation.collation,set_collation))
56
 
  {
57
 
    my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
58
 
             colname, args[0]->collation.collation->csname);
59
 
    return;
60
 
  }
61
 
  collation.set(set_collation, DERIVATION_EXPLICIT);
62
 
  max_length= args[0]->max_length;
63
 
}
64
 
 
65
 
bool Item_func_set_collation::eq(const Item *item, bool binary_cmp) const
66
 
{
67
 
  /* Assume we don't have rtti */
68
 
  if (this == item)
69
 
    return 1;
70
 
  if (item->type() != FUNC_ITEM)
71
 
    return 0;
72
 
  Item_func *item_func=(Item_func*) item;
73
 
  if (arg_count != item_func->arg_count ||
74
 
      functype() != item_func->functype())
75
 
    return 0;
76
 
  Item_func_set_collation *item_func_sc=(Item_func_set_collation*) item;
77
 
  if (collation.collation != item_func_sc->collation.collation)
78
 
    return 0;
79
 
  for (uint32_t i=0; i < arg_count ; i++)
80
 
    if (!args[i]->eq(item_func_sc->args[i], binary_cmp))
81
 
      return 0;
82
 
  return 1;
83
 
}
84
 
 
85
 
void Item_func_set_collation::print(String *str, enum_query_type query_type)
86
 
{
87
 
  str->append('(');
88
 
  args[0]->print(str, query_type);
89
 
  str->append(STRING_WITH_LEN(" collate "));
90
 
  assert(args[1]->basic_const_item() &&
91
 
              args[1]->type() == Item::STRING_ITEM);
92
 
  args[1]->str_value.print(str);
93
 
  str->append(')');
94
 
}
95
 
 
96
 
 
97