~drizzle-trunk/drizzle/development

574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <config.h>
670.1.20 by Monty Taylor
Renamed functions to function... everything else is singular.
21
#include <drizzled/function/str/set_collation.h>
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
22
#include <drizzled/error.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
23
#include <drizzled/charset.h>
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
24
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
25
namespace drizzled
26
{
27
1241.9.33 by Monty Taylor
Moved most of the global vars to set_var where they belong.
28
static const char *binary_keyword= "BINARY";
29
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
30
String *Item_func_set_collation::val_str(String *str)
31
{
32
  assert(fixed == 1);
33
  str=args[0]->val_str(str);
34
  if ((null_value=args[0]->null_value))
35
    return 0;
36
  str->set_charset(collation.collation);
37
  return str;
38
}
39
40
void Item_func_set_collation::fix_length_and_dec()
41
{
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
42
  const charset_info_st *set_collation;
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
43
  const char *colname;
44
  String tmp, *str= args[1]->val_str(&tmp);
45
  colname= str->c_ptr();
46
  if (colname == binary_keyword)
862 by Brian Aker
Remove charset directory code.
47
    set_collation= get_charset_by_csname(args[0]->collation.collation->csname, MY_CS_BINSORT);
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
48
  else
49
  {
862 by Brian Aker
Remove charset directory code.
50
    if (!(set_collation= get_charset_by_name(colname)))
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
51
    {
52
      my_error(ER_UNKNOWN_COLLATION, MYF(0), colname);
53
      return;
54
    }
55
  }
56
57
  if (!set_collation ||
58
      !my_charset_same(args[0]->collation.collation,set_collation))
59
  {
60
    my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
61
             colname, args[0]->collation.collation->csname);
62
    return;
63
  }
1022.1.3 by Brian Aker
Force UTF8 (remove the bits for looking for ascii).
64
  collation.set(set_collation, DERIVATION_EXPLICIT);
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
65
  max_length= args[0]->max_length;
66
}
67
68
bool Item_func_set_collation::eq(const Item *item, bool binary_cmp) const
69
{
70
  /* Assume we don't have rtti */
71
  if (this == item)
72
    return 1;
73
  if (item->type() != FUNC_ITEM)
74
    return 0;
75
  Item_func *item_func=(Item_func*) item;
76
  if (arg_count != item_func->arg_count ||
77
      functype() != item_func->functype())
78
    return 0;
79
  Item_func_set_collation *item_func_sc=(Item_func_set_collation*) item;
80
  if (collation.collation != item_func_sc->collation.collation)
81
    return 0;
82
  for (uint32_t i=0; i < arg_count ; i++)
83
    if (!args[i]->eq(item_func_sc->args[i], binary_cmp))
84
      return 0;
85
  return 1;
86
}
87
2215.2.1 by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing.
88
void Item_func_set_collation::print(String *str)
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
89
{
90
  str->append('(');
2215.2.1 by Stewart Smith
remove enum_query_type which was effectively unused. It was set to one value once, compared to it once (i.e. always true) and passed around everywhere doing nothing.
91
  args[0]->print(str);
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
92
  str->append(STRING_WITH_LEN(" collate "));
93
  assert(args[1]->basic_const_item() &&
94
              args[1]->type() == Item::STRING_ITEM);
95
  args[1]->str_value.print(str);
96
  str->append(')');
97
}
98
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
99
} /* namespace drizzled */
574.3.10 by Lee
moving functions from item_strfunc to functions/str directory
100
101