Drizzled Public API Documentation

str.h
00001 /* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 MySQL
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; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #pragma once
00022 
00023 #include <drizzled/field.h>
00024 
00025 #include <drizzled/visibility.h>
00026 
00027 namespace drizzled
00028 {
00029 
00030 /* base class for all string related classes */
00031 
00032 class DRIZZLED_API Field_str :
00033   public Field
00034 {
00035 protected:
00036   const charset_info_st *field_charset;
00037   enum Derivation field_derivation;
00038   int  report_if_important_data(const char *ptr, const char *end);
00039 public:
00040   Field_str(unsigned char *ptr_arg,
00041             uint32_t len_arg,
00042             unsigned char *null_ptr_arg,
00043             unsigned char null_bit_arg,
00044             const char *field_name_arg,
00045             const charset_info_st * const charset);
00046   Item_result result_type () const { return STRING_RESULT; }
00047   uint32_t decimals() const { return NOT_FIXED_DEC; }
00048 
00049   using Field::store;
00050   int  store(double nr);
00051   int  store(int64_t nr, bool unsigned_val)=0;
00052   int  store_decimal(const type::Decimal *);
00053   int  store(const char *to,uint32_t length, const charset_info_st * const cs)=0;
00054 
00055   uint32_t size_of() const { return sizeof(*this); }
00056   const charset_info_st *charset(void) const { return field_charset; }
00057   void set_charset(const charset_info_st * const charset_arg)
00058   { field_charset= charset_arg; }
00059   enum Derivation derivation(void) const { return field_derivation; }
00060   virtual void set_derivation(enum Derivation derivation_arg)
00061   { field_derivation= derivation_arg; }
00062   bool binary() const { return field_charset == &my_charset_bin; }
00063   uint32_t max_display_length() { return field_length; }
00064   friend class CreateField;
00065   type::Decimal *val_decimal(type::Decimal *) const;
00066   virtual bool str_needs_quotes() { return true; }
00067   uint32_t max_data_length() const;
00068 };
00069 
00070 /*
00071   Report "not well formed" or "cannot convert" error
00072   after storing a character string info a field.
00073 
00074   SYNOPSIS
00075     check_string_copy_error()
00076     field                    - Field
00077     well_formed_error_pos    - where not well formed data was first met
00078     cannot_convert_error_pos - where a not-convertable character was first met
00079     end                      - end of the string
00080     cs                       - character set of the string
00081 
00082   NOTES
00083     As of version 5.0 both cases return the same error:
00084 
00085       "Invalid string value: 'xxx' for column 't' at row 1"
00086 
00087   Future versions will possibly introduce a new error message:
00088 
00089       "Cannot convert character string: 'xxx' for column 't' at row 1"
00090 
00091   RETURN
00092     false - If errors didn't happen
00093     true  - If an error happened
00094 */
00095 
00096 bool check_string_copy_error(Field_str *field,
00097                              const char *well_formed_error_pos,
00098                              const char *cannot_convert_error_pos,
00099                              const char *end,
00100                              const charset_info_st * const cs);
00101 
00102 
00103 } /* namespace drizzled */
00104