00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*- 00002 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: 00003 * 00004 * Copyright (C) 2008 Sun Microsystems, Inc. 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; version 2 of the License. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #pragma once 00021 00022 #include <drizzled/definitions.h> 00023 #include <drizzled/visibility.h> 00024 #include <drizzled/common_fwd.h> 00025 00026 namespace drizzled { 00027 00028 class DRIZZLED_API DTCollation 00029 { 00030 public: 00031 const charset_info_st* collation; 00032 Derivation derivation; 00033 00034 DRIZZLED_LOCAL DTCollation(); 00035 DRIZZLED_LOCAL DTCollation(const charset_info_st*, Derivation); 00036 void set(DTCollation &dt); 00037 void set(const charset_info_st*, Derivation); 00038 void set(const charset_info_st*); 00039 void set(Derivation derivation_arg); 00040 bool set(DTCollation &dt1, DTCollation &dt2, uint32_t flags= 0); 00041 00078 DRIZZLED_LOCAL bool aggregate(DTCollation &dt, uint32_t flags= 0); 00079 00080 DRIZZLED_LOCAL const char *derivation_name() const; 00081 00082 }; 00083 00084 00085 bool agg_item_collations(DTCollation &c, const char *name, 00086 Item **items, uint32_t nitems, 00087 uint32_t flags, int item_sep); 00088 bool agg_item_collations_for_comparison(DTCollation &c, const char *name, 00089 Item **items, uint32_t nitems, 00090 uint32_t flags); 00091 00092 /* 00093 00094 @note In Drizzle we have just one charset, so no conversion is required (though collation may). 00095 00096 Collect arguments' character sets together. 00097 00098 We allow to apply automatic character set conversion in some cases. 00099 The conditions when conversion is possible are: 00100 - arguments A and B have different charsets 00101 - A wins according to coercibility rules 00102 (i.e. a column is stronger than a string constant, 00103 an explicit COLLATE clause is stronger than a column) 00104 - character set of A is either superset for character set of B, 00105 or B is a string constant which can be converted into the 00106 character set of A without data loss. 00107 00108 If all of the above is true, then it's possible to convert 00109 B into the character set of A, and then compare according 00110 to the collation of A. 00111 00112 For functions with more than two arguments: 00113 @code 00114 collect(A,B,C) ::= collect(collect(A,B),C) 00115 @endcode 00116 Since this function calls Session::change_item_tree() on the passed Item ** 00117 pointers, it is necessary to pass the original Item **'s, not copies. 00118 Otherwise their values will not be properly restored (see BUG#20769). 00119 If the items are not consecutive (eg. args[2] and args[5]), use the 00120 item_sep argument, ie. 00121 @code 00122 agg_item_charsets(coll, fname, &args[2], 2, flags, 3) 00123 @endcode 00124 */ 00125 bool agg_item_charsets(DTCollation &c, const char *name, 00126 Item **items, uint32_t nitems, uint32_t flags, 00127 int item_sep); 00128 00129 00130 void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname); 00131 void my_coll_agg_error(DTCollation &c1, DTCollation &c2, DTCollation &c3, 00132 const char *fname); 00133 void my_coll_agg_error(Item** args, uint32_t count, const char *fname, 00134 int item_sep); 00135 00136 } /* namespace drizzled */ 00137