drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
set_collation.cc
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, Inc.
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
25namespace drizzled {
26
27static const char *binary_keyword= "BINARY";
28
30{
31 assert(fixed == 1);
32 str=args[0]->val_str(str);
33 if ((null_value=args[0]->null_value))
34 return 0;
35 str->set_charset(collation.collation);
36 return str;
37}
38
39void Item_func_set_collation::fix_length_and_dec()
40{
41 const charset_info_st *set_collation;
42 const char *colname;
43 String tmp, *str= args[1]->val_str(&tmp);
44 colname= str->c_ptr();
45 if (colname == binary_keyword)
46 set_collation= get_charset_by_csname(args[0]->collation.collation->csname, MY_CS_BINSORT);
47 else
48 {
49 if (!(set_collation= get_charset_by_name(colname)))
50 {
51 my_error(ER_UNKNOWN_COLLATION, MYF(0), colname);
52 return;
53 }
54 }
55
56 if (!set_collation ||
57 !my_charset_same(args[0]->collation.collation,set_collation))
58 {
59 my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
60 colname, args[0]->collation.collation->csname);
61 return;
62 }
63 collation.set(set_collation, DERIVATION_EXPLICIT);
64 max_length= args[0]->max_length;
65}
66
67bool Item_func_set_collation::eq(const Item *item, bool binary_cmp) const
68{
69 /* Assume we don't have rtti */
70 if (this == item)
71 return 1;
72 if (item->type() != FUNC_ITEM)
73 return 0;
74 Item_func *item_func=(Item_func*) item;
75 if (arg_count != item_func->arg_count ||
76 functype() != item_func->functype())
77 return 0;
78 Item_func_set_collation *item_func_sc=(Item_func_set_collation*) item;
79 if (collation.collation != item_func_sc->collation.collation)
80 return 0;
81 for (uint32_t i=0; i < arg_count ; i++)
82 if (!args[i]->eq(item_func_sc->args[i], binary_cmp))
83 return 0;
84 return 1;
85}
86
88{
89 str->append('(');
90 args[0]->print(str);
91 str->append(STRING_WITH_LEN(" collate "));
92 assert(args[1]->basic_const_item() && args[1]->type() == Item::STRING_ITEM);
93 args[1]->str_value.print(*str);
94 str->append(')');
95}
96
97} /* namespace drizzled */
98
99
bool eq(const Item *item, bool binary_cmp) const
virtual void print(String *str)
bool fixed
Definition item.h:122
bool null_value
Definition item.h:124
virtual bool basic_const_item() const
Definition item.h:476
virtual String * val_str(String *str)=0
Convert from decimal to binary representation.
Definition common_fwd.h:215
TODO: Rename this file - func.h is stupid.