- Main Page
- Classes
- Files

- File List
- File Members

# field.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004 /***********************************************************************
    00005  Copyright (c) 2007 by Educational Technology Resources, Inc.
    00006  Others may also hold copyrights on code in this file.  See the
    00007  CREDITS file in the top directory of the distribution for details.
    00008
    00009  This file is part of MySQL++.
    00010
    00011  MySQL++ is free software; you can redistribute it and/or modify it
    00012  under the terms of the GNU Lesser General Public License as published
    00013  by the Free Software Foundation; either version 2.1 of the License, or
    00014  (at your option) any later version.
    00015
    00016  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
    00017  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00018  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
    00019  License for more details.
    00020
    00021  You should have received a copy of the GNU Lesser General Public
    00022  License along with MySQL++; if not, write to the Free Software
    00023  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
    00024  USA
    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    // only in 4.0 +
    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 } // end namespace mysqlpp
    00156
    00157 #endif // !defined(MYSQLPP_FIELD_H)