MySQL++  3.3.0
field.h
Go to the documentation of this file.
1 
4 /***********************************************************************
5  Copyright (c) 2007 by Educational Technology Resources, Inc.
6  Others may also hold copyrights on code in this file. See the
7  CREDITS.txt file in the top directory of the distribution for details.
8 
9  This file is part of MySQL++.
10 
11  MySQL++ is free software; you can redistribute it and/or modify it
12  under the terms of the GNU Lesser General Public License as published
13  by the Free Software Foundation; either version 2.1 of the License, or
14  (at your option) any later version.
15 
16  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19  License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with MySQL++; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
24  USA
25 ***********************************************************************/
26 
27 #if !defined(MYSQLPP_FIELD_H)
28 #define MYSQLPP_FIELD_H
29 
30 #include "common.h"
31 #include "type_info.h"
32 
33 #include <vector>
34 
35 namespace mysqlpp {
36 
45 
46 class Field
47 {
48 public:
50  Field() :
51  length_(0),
52  max_length_(0),
53  flags_(0)
54  {
55  }
56 
58  Field(const MYSQL_FIELD* pf) :
59  name_(pf->name),
60  table_(pf->table),
61 #if MYSQL_VERSION_ID > 40000 // only in 4.0 +
62  db_(pf->db),
63 #endif
64  type_(pf->type, (pf->flags & UNSIGNED_FLAG) != 0,
65  (pf->flags & NOT_NULL_FLAG) == 0),
66  length_(pf->length),
67  max_length_(pf->max_length),
68  flags_(pf->flags)
69  {
70  }
71 
73  Field(const Field& other) :
74  name_(other.name_),
75  table_(other.table_),
76  db_(other.db_),
77  type_(other.type_),
78  length_(other.length_),
79  max_length_(other.max_length_),
80  flags_(other.flags_)
81  {
82  }
83 
85  bool auto_increment() const { return flags_ & AUTO_INCREMENT_FLAG; }
86 
88  bool binary_type() const { return flags_ & BINARY_FLAG; }
89 
91  bool blob_type() const { return flags_ & BLOB_FLAG; }
92 
94  const char* db() const { return db_.c_str(); }
95 
97  bool enumeration() const { return flags_ & ENUM_FLAG; }
98 
103  size_t length() const { return length_; }
104 
107  size_t max_length() const { return max_length_; }
108 
110  bool multiple_key() const { return flags_ & MULTIPLE_KEY_FLAG; }
111 
113  const char* name() const { return name_.c_str(); }
114 
115 #if defined(NO_DEFAULT_VALUE_FLAG)
117  bool no_default() const { return flags_ & NO_DEFAULT_VALUE_FLAG; }
118 #endif
119 
121  bool primary_key() const { return flags_ & PRI_KEY_FLAG; }
122 
124  bool set_type() const { return flags_ & SET_FLAG; }
125 
127  const char* table() const { return table_.c_str(); }
128 
130  bool timestamp() const { return flags_ & TIMESTAMP_FLAG; }
131 
133  const mysql_type_info& type() const { return type_; }
134 
136  bool unique_key() const { return flags_ & UNIQUE_KEY_FLAG; }
137 
139  bool zerofill() const { return flags_ & ZEROFILL_FLAG; }
140 
141 private:
142  std::string name_;
143  std::string table_;
144  std::string db_;
145  mysql_type_info type_;
146  size_t length_;
147  size_t max_length_;
148  unsigned int flags_;
149 };
150 
151 
153 typedef std::vector<Field> Fields;
154 
155 } // end namespace mysqlpp
156 
157 #endif // !defined(MYSQLPP_FIELD_H)
Class to hold information about a SQL field.
Definition: field.h:47
bool primary_key() const
Returns true if field is part of a primary key.
Definition: field.h:121
size_t length() const
Return the creation size of the field.
Definition: field.h:103
bool binary_type() const
Returns true if field is of some binary type.
Definition: field.h:88
bool timestamp() const
Returns true if field's type is timestamp.
Definition: field.h:130
Field(const Field &other)
Create object as a copy of another Field.
Definition: field.h:73
bool auto_increment() const
Returns true if field auto-increments.
Definition: field.h:85
bool set_type() const
Returns true if field is of some 'set' type.
Definition: field.h:124
bool enumeration() const
Returns true if field is of an enumerated value type.
Definition: field.h:97
Field(const MYSQL_FIELD *pf)
Create object from C API field structure.
Definition: field.h:58
const char * table() const
Return the name of the table the field comes from.
Definition: field.h:127
bool multiple_key() const
Returns true if field is part of a key.
Definition: field.h:110
bool blob_type() const
Returns true if field is of some BLOB type.
Definition: field.h:91
const char * name() const
Return the field's name.
Definition: field.h:113
bool unique_key() const
Returns true if field is part of a unique key.
Definition: field.h:136
const char * db() const
Return the name of the database the field comes from.
Definition: field.h:94
const mysql_type_info & type() const
Return information about the field's type.
Definition: field.h:133
bool zerofill() const
Returns true if field has the zerofill attribute.
Definition: field.h:139
Field()
Create empty object.
Definition: field.h:50
size_t max_length() const
Return the maximum number of bytes stored in this field in any of the rows in the result set we were ...
Definition: field.h:107
SQL field type information.
Definition: type_info.h:159
This file includes top-level definitions for use both internal to the library, and outside it....
std::vector< Field > Fields
The list-of-Fields type.
Definition: field.h:153
Declares classes that provide an interface between the SQL and C++ type systems.