~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/str.h

Merge/fix in FAQ.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* - mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 MySQL
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; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
#ifndef DRIZZLED_FIELD_STR_H
22
 
#define DRIZZLED_FIELD_STR_H
23
 
 
24
 
#include <drizzled/field.h>
25
 
 
26
 
#include <drizzled/visibility.h>
27
 
 
28
 
namespace drizzled
29
 
{
30
 
 
31
 
typedef struct charset_info_st CHARSET_INFO;
32
 
 
33
 
/* base class for all string related classes */
34
 
 
35
 
class DRIZZLED_API Field_str :
36
 
  public Field
37
 
{
38
 
protected:
39
 
  const CHARSET_INFO *field_charset;
40
 
  enum Derivation field_derivation;
41
 
  int  report_if_important_data(const char *ptr, const char *end);
42
 
public:
43
 
  Field_str(unsigned char *ptr_arg,
44
 
            uint32_t len_arg,
45
 
            unsigned char *null_ptr_arg,
46
 
            unsigned char null_bit_arg,
47
 
            const char *field_name_arg,
48
 
            const CHARSET_INFO * const charset);
49
 
  Item_result result_type () const { return STRING_RESULT; }
50
 
  uint32_t decimals() const { return NOT_FIXED_DEC; }
51
 
 
52
 
  using Field::store;
53
 
  int  store(double nr);
54
 
  int  store(int64_t nr, bool unsigned_val)=0;
55
 
  int  store_decimal(const type::Decimal *);
56
 
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const cs)=0;
57
 
 
58
 
  uint32_t size_of() const { return sizeof(*this); }
59
 
  const CHARSET_INFO *charset(void) const { return field_charset; }
60
 
  void set_charset(const CHARSET_INFO * const charset_arg)
61
 
  { field_charset= charset_arg; }
62
 
  enum Derivation derivation(void) const { return field_derivation; }
63
 
  virtual void set_derivation(enum Derivation derivation_arg)
64
 
  { field_derivation= derivation_arg; }
65
 
  bool binary() const { return field_charset == &my_charset_bin; }
66
 
  uint32_t max_display_length() { return field_length; }
67
 
  friend class CreateField;
68
 
  type::Decimal *val_decimal(type::Decimal *) const;
69
 
  virtual bool str_needs_quotes() { return true; }
70
 
  uint32_t max_data_length() const;
71
 
};
72
 
 
73
 
/*
74
 
  Report "not well formed" or "cannot convert" error
75
 
  after storing a character string info a field.
76
 
 
77
 
  SYNOPSIS
78
 
    check_string_copy_error()
79
 
    field                    - Field
80
 
    well_formed_error_pos    - where not well formed data was first met
81
 
    cannot_convert_error_pos - where a not-convertable character was first met
82
 
    end                      - end of the string
83
 
    cs                       - character set of the string
84
 
 
85
 
  NOTES
86
 
    As of version 5.0 both cases return the same error:
87
 
 
88
 
      "Invalid string value: 'xxx' for column 't' at row 1"
89
 
 
90
 
  Future versions will possibly introduce a new error message:
91
 
 
92
 
      "Cannot convert character string: 'xxx' for column 't' at row 1"
93
 
 
94
 
  RETURN
95
 
    false - If errors didn't happen
96
 
    true  - If an error happened
97
 
*/
98
 
 
99
 
bool check_string_copy_error(Field_str *field,
100
 
                             const char *well_formed_error_pos,
101
 
                             const char *cannot_convert_error_pos,
102
 
                             const char *end,
103
 
                             const CHARSET_INFO * const cs);
104
 
 
105
 
 
106
 
} /* namespace drizzled */
107
 
 
108
 
#endif /* DRIZZLED_FIELD_STR_H */