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         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 } // end namespace mysqlpp
00154 
00155 #endif // !defined(MYSQLPP_FIELD_H)

Generated on Fri Feb 29 16:26:00 2008 for MySQL++ by  doxygen 1.4.7