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 typedef struct charset_info_st CHARSET_INFO;
00031 
00032 /* base class for all string related classes */
00033 
00034 class DRIZZLED_API Field_str :
00035   public Field
00036 {
00037 protected:
00038   const CHARSET_INFO *field_charset;
00039   enum Derivation field_derivation;
00040   int  report_if_important_data(const char *ptr, const char *end);
00041 public:
00042   Field_str(unsigned char *ptr_arg,
00043             uint32_t len_arg,
00044             unsigned char *null_ptr_arg,
00045             unsigned char null_bit_arg,
00046             const char *field_name_arg,
00047             const CHARSET_INFO * const charset);
00048   Item_result result_type () const { return STRING_RESULT; }
00049   uint32_t decimals() const { return NOT_FIXED_DEC; }
00050 
00051   using Field::store;
00052   int  store(double nr);
00053   int  store(int64_t nr, bool unsigned_val)=0;
00054   int  store_decimal(const type::Decimal *);
00055   int  store(const char *to,uint32_t length, const CHARSET_INFO * const cs)=0;
00056 
00057   uint32_t size_of() const { return sizeof(*this); }
00058   const CHARSET_INFO *charset(void) const { return field_charset; }
00059   void set_charset(const CHARSET_INFO * const charset_arg)
00060   { field_charset= charset_arg; }
00061   enum Derivation derivation(void) const { return field_derivation; }
00062   virtual void set_derivation(enum Derivation derivation_arg)
00063   { field_derivation= derivation_arg; }
00064   bool binary() const { return field_charset == &my_charset_bin; }
00065   uint32_t max_display_length() { return field_length; }
00066   friend class CreateField;
00067   type::Decimal *val_decimal(type::Decimal *) const;
00068   virtual bool str_needs_quotes() { return true; }
00069   uint32_t max_data_length() const;
00070 };
00071 
00072 /*
00073   Report "not well formed" or "cannot convert" error
00074   after storing a character string info a field.
00075 
00076   SYNOPSIS
00077     check_string_copy_error()
00078     field                    - Field
00079     well_formed_error_pos    - where not well formed data was first met
00080     cannot_convert_error_pos - where a not-convertable character was first met
00081     end                      - end of the string
00082     cs                       - character set of the string
00083 
00084   NOTES
00085     As of version 5.0 both cases return the same error:
00086 
00087       "Invalid string value: 'xxx' for column 't' at row 1"
00088 
00089   Future versions will possibly introduce a new error message:
00090 
00091       "Cannot convert character string: 'xxx' for column 't' at row 1"
00092 
00093   RETURN
00094     false - If errors didn't happen
00095     true  - If an error happened
00096 */
00097 
00098 bool check_string_copy_error(Field_str *field,
00099                              const char *well_formed_error_pos,
00100                              const char *cannot_convert_error_pos,
00101                              const char *end,
00102                              const CHARSET_INFO * const cs);
00103 
00104 
00105 } /* namespace drizzled */
00106