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 db_(pf->db),
00062 type_(pf->type, (pf->flags & UNSIGNED_FLAG) != 0,
00063 (pf->flags & NOT_NULL_FLAG) == 0),
00064 length_(pf->length),
00065 max_length_(pf->max_length),
00066 flags_(pf->flags)
00067 {
00068 }
00069
00071 Field(const Field& other) :
00072 name_(other.name_),
00073 table_(other.table_),
00074 db_(other.db_),
00075 type_(other.type_),
00076 length_(other.length_),
00077 max_length_(other.max_length_),
00078 flags_(other.flags_)
00079 {
00080 }
00081
00083 bool auto_increment() const { return flags_ & AUTO_INCREMENT_FLAG; }
00084
00086 bool binary_type() const { return flags_ & BINARY_FLAG; }
00087
00089 bool blob_type() const { return flags_ & BLOB_FLAG; }
00090
00092 const char* db() const { return db_.c_str(); }
00093
00095 bool enumeration() const { return flags_ & ENUM_FLAG; }
00096
00101 size_t length() const { return length_; }
00102
00105 size_t max_length() const { return max_length_; }
00106
00108 bool multiple_key() const { return flags_ & MULTIPLE_KEY_FLAG; }
00109
00111 const char* name() const { return name_.c_str(); }
00112
00113 #if defined(NO_DEFAULT_VALUE_FLAG)
00115 bool no_default() const { return flags_ & NO_DEFAULT_VALUE_FLAG; }
00116 #endif
00117
00119 bool primary_key() const { return flags_ & PRI_KEY_FLAG; }
00120
00122 bool set_type() const { return flags_ & SET_FLAG; }
00123
00125 const char* table() const { return table_.c_str(); }
00126
00128 bool timestamp() const { return flags_ & TIMESTAMP_FLAG; }
00129
00131 const mysql_type_info& type() const { return type_; }
00132
00134 bool unique_key() const { return flags_ & UNIQUE_KEY_FLAG; }
00135
00137 bool zerofill() const { return flags_ & ZEROFILL_FLAG; }
00138
00139 private:
00140 std::string name_;
00141 std::string table_;
00142 std::string db_;
00143 mysql_type_info type_;
00144 size_t length_;
00145 size_t max_length_;
00146 unsigned int flags_;
00147 };
00148
00149
00151 typedef std::vector<Field> Fields;
00152
00153 }
00154
00155 #endif // !defined(MYSQLPP_FIELD_H)