~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field/str.h

  • Committer: Brian Aker
  • Date: 2009-04-17 01:45:33 UTC
  • Revision ID: brian@gaz-20090417014533-exdrtriab9zecqs2
Refactor get_variable to session

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 DRIZZLE_SERVER_FIELD_STR
 
22
#define DRIZZLE_SERVER_FIELD_STR
 
23
 
 
24
#include <drizzled/field.h>
 
25
 
 
26
typedef struct charset_info_st CHARSET_INFO;
 
27
 
 
28
/* base class for all string related classes */
 
29
 
 
30
class Field_str :public Field {
 
31
protected:
 
32
  const CHARSET_INFO *field_charset;
 
33
  enum Derivation field_derivation;
 
34
public:
 
35
  Field_str(unsigned char *ptr_arg,uint32_t len_arg,
 
36
            unsigned char *null_ptr_arg,
 
37
            unsigned char null_bit_arg, utype unireg_check_arg,
 
38
            const char *field_name_arg, const CHARSET_INFO * const charset);
 
39
  Item_result result_type () const { return STRING_RESULT; }
 
40
  uint32_t decimals() const { return NOT_FIXED_DEC; }
 
41
 
 
42
  using Field::store;
 
43
  int  store(double nr);
 
44
  int  store(int64_t nr, bool unsigned_val)=0;
 
45
  int  store_decimal(const my_decimal *);
 
46
  int  store(const char *to,uint32_t length, const CHARSET_INFO * const cs)=0;
 
47
 
 
48
  uint32_t size_of() const { return sizeof(*this); }
 
49
  const CHARSET_INFO *charset(void) const { return field_charset; }
 
50
  void set_charset(const CHARSET_INFO * const charset_arg)
 
51
  { field_charset= charset_arg; }
 
52
  enum Derivation derivation(void) const { return field_derivation; }
 
53
  virtual void set_derivation(enum Derivation derivation_arg)
 
54
  { field_derivation= derivation_arg; }
 
55
  bool binary() const { return field_charset == &my_charset_bin; }
 
56
  uint32_t max_display_length() { return field_length; }
 
57
  friend class Create_field;
 
58
  my_decimal *val_decimal(my_decimal *);
 
59
  virtual bool str_needs_quotes() { return true; }
 
60
  bool compare_str_field_flags(Create_field *new_field, uint32_t flags);
 
61
  uint32_t is_equal(Create_field *new_field);
 
62
};
 
63
 
 
64
/*
 
65
  Report "not well formed" or "cannot convert" error
 
66
  after storing a character string info a field.
 
67
 
 
68
  SYNOPSIS
 
69
    check_string_copy_error()
 
70
    field                    - Field
 
71
    well_formed_error_pos    - where not well formed data was first met
 
72
    cannot_convert_error_pos - where a not-convertable character was first met
 
73
    end                      - end of the string
 
74
    cs                       - character set of the string
 
75
 
 
76
  NOTES
 
77
    As of version 5.0 both cases return the same error:
 
78
 
 
79
      "Invalid string value: 'xxx' for column 't' at row 1"
 
80
 
 
81
  Future versions will possibly introduce a new error message:
 
82
 
 
83
      "Cannot convert character string: 'xxx' for column 't' at row 1"
 
84
 
 
85
  RETURN
 
86
    false - If errors didn't happen
 
87
    true  - If an error happened
 
88
*/
 
89
 
 
90
bool check_string_copy_error(Field_str *field,
 
91
                             const char *well_formed_error_pos,
 
92
                             const char *cannot_convert_error_pos,
 
93
                             const char *end,
 
94
                             const CHARSET_INFO * const cs);
 
95
 
 
96
 
 
97
#endif