MySQL++ Reference Manual

MySQL++: field.h Source File

MySQL++ 3.2.4

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)
116 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)
mysqlpp::Field::enumeration
bool enumeration() const
Returns true if field is of an enumerated value type.
Definition: field.h:97
mysqlpp::Field::primary_key
bool primary_key() const
Returns true if field is part of a primary key.
Definition: field.h:121
mysqlpp
Definition: autoflag.h:31
mysqlpp::Field::blob_type
bool blob_type() const
Returns true if field is of some BLOB type.
Definition: field.h:91
mysqlpp::Field::Field
Field()
Create empty object.
Definition: field.h:50
mysqlpp::Field
Class to hold information about a SQL field.
Definition: field.h:46
mysqlpp::Field::timestamp
bool timestamp() const
Returns true if field&#39;s type is timestamp.
Definition: field.h:130
mysqlpp::mysql_type_info
SQL field type information.
Definition: type_info.h:148
mysqlpp::Field::type
const mysql_type_info & type() const
Return information about the field&#39;s type.
Definition: field.h:133
mysqlpp::Field::db
const char * db() const
Return the name of the database the field comes from.
Definition: field.h:94
mysqlpp::Field::multiple_key
bool multiple_key() const
Returns true if field is part of a key.
Definition: field.h:110
type_info.h
Declares classes that provide an interface between the SQL and C++ type systems.
mysqlpp::Field::binary_type
bool binary_type() const
Returns true if field is of some binary type.
Definition: field.h:88
mysqlpp::Fields
std::vector< Field > Fields
The list-of-Fields type.
Definition: field.h:153
mysqlpp::Field::max_length
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
mysqlpp::Field::table
const char * table() const
Return the name of the table the field comes from.
Definition: field.h:127
mysqlpp::Field::Field
Field(const Field &other)
Create object as a copy of another Field.
Definition: field.h:73
common.h
This file includes top-level definitions for use both internal to the library, and outside it...
mysqlpp::Field::auto_increment
bool auto_increment() const
Returns true if field auto-increments.
Definition: field.h:85
mysqlpp::Field::set_type
bool set_type() const
Returns true if field is of some &#39;set&#39; type.
Definition: field.h:124
mysqlpp::Field::length
size_t length() const
Return the creation size of the field.
Definition: field.h:103
mysqlpp::Field::Field
Field(const MYSQL_FIELD *pf)
Create object from C API field structure.
Definition: field.h:58
mysqlpp::Field::unique_key
bool unique_key() const
Returns true if field is part of a unique key.
Definition: field.h:136
mysqlpp::Field::zerofill
bool zerofill() const
Returns true if field has the zerofill attribute.
Definition: field.h:139
mysqlpp::Field::name
const char * name() const
Return the field&#39;s name.
Definition: field.h:113