00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #if !defined(MYSQLPP_FIELD_H)
00028 #define MYSQLPP_FIELD_H
00029
00030 #include "common.h"
00031 #include "type_info.h"
00032
00033 #include <vector>
00034
00035 namespace mysqlpp {
00036
00045
00046 class Field
00047 {
00048 public:
00050 Field() :
00051 length_(0),
00052 max_length_(0),
00053 flags_(0)
00054 {
00055 }
00056
00058 Field(const MYSQL_FIELD* pf) :
00059 name_(pf->name),
00060 table_(pf->table),
00061 #if MYSQL_VERSION_ID > 40000
00062 db_(pf->db),
00063 #endif
00064 type_(pf->type, (pf->flags & UNSIGNED_FLAG) != 0,
00065 (pf->flags & NOT_NULL_FLAG) == 0),
00066 length_(pf->length),
00067 max_length_(pf->max_length),
00068 flags_(pf->flags)
00069 {
00070 }
00071
00073 Field(const Field& other) :
00074 name_(other.name_),
00075 table_(other.table_),
00076 db_(other.db_),
00077 type_(other.type_),
00078 length_(other.length_),
00079 max_length_(other.max_length_),
00080 flags_(other.flags_)
00081 {
00082 }
00083
00085 bool auto_increment() const { return flags_ & AUTO_INCREMENT_FLAG; }
00086
00088 bool binary_type() const { return flags_ & BINARY_FLAG; }
00089
00091 bool blob_type() const { return flags_ & BLOB_FLAG; }
00092
00094 const char* db() const { return db_.c_str(); }
00095
00097 bool enumeration() const { return flags_ & ENUM_FLAG; }
00098
00103 size_t length() const { return length_; }
00104
00107 size_t max_length() const { return max_length_; }
00108
00110 bool multiple_key() const { return flags_ & MULTIPLE_KEY_FLAG; }
00111
00113 const char* name() const { return name_.c_str(); }
00114
00115 #if defined(NO_DEFAULT_VALUE_FLAG)
00117 bool no_default() const { return flags_ & NO_DEFAULT_VALUE_FLAG; }
00118 #endif
00119
00121 bool primary_key() const { return flags_ & PRI_KEY_FLAG; }
00122
00124 bool set_type() const { return flags_ & SET_FLAG; }
00125
00127 const char* table() const { return table_.c_str(); }
00128
00130 bool timestamp() const { return flags_ & TIMESTAMP_FLAG; }
00131
00133 const mysql_type_info& type() const { return type_; }
00134
00136 bool unique_key() const { return flags_ & UNIQUE_KEY_FLAG; }
00137
00139 bool zerofill() const { return flags_ & ZEROFILL_FLAG; }
00140
00141 private:
00142 std::string name_;
00143 std::string table_;
00144 std::string db_;
00145 mysql_type_info type_;
00146 size_t length_;
00147 size_t max_length_;
00148 unsigned int flags_;
00149 };
00150
00151
00153 typedef std::vector<Field> Fields;
00154
00155 }
00156
00157 #endif // !defined(MYSQLPP_FIELD_H)