field.h
Go to the documentation of this file.
/***********************************************************************
Copyright (c) 2007 by Educational Technology Resources, Inc.
Others may also hold copyrights on code in this file. See the
CREDITS.txt file in the top directory of the distribution for details.
This file is part of MySQL++.
MySQL++ is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
MySQL++ is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with MySQL++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
***********************************************************************/
#if !defined(MYSQLPP_FIELD_H)
#define MYSQLPP_FIELD_H
#include "common.h"
#include "type_info.h"
#include <vector>
namespace mysqlpp {
class Field
{
public:
Field() :
length_(0),
max_length_(0),
flags_(0)
{
}
Field(const MYSQL_FIELD* pf) :
name_(pf->name),
table_(pf->table),
#if MYSQL_VERSION_ID > 40000 // only in 4.0 +
db_(pf->db),
#endif
type_(pf->type, (pf->flags & UNSIGNED_FLAG) != 0,
(pf->flags & NOT_NULL_FLAG) == 0),
length_(pf->length),
max_length_(pf->max_length),
flags_(pf->flags)
{
}
Field(const Field& other) :
name_(other.name_),
table_(other.table_),
db_(other.db_),
type_(other.type_),
length_(other.length_),
max_length_(other.max_length_),
flags_(other.flags_)
{
}
bool auto_increment() const { return flags_ & AUTO_INCREMENT_FLAG; }
bool binary_type() const { return flags_ & BINARY_FLAG; }
bool blob_type() const { return flags_ & BLOB_FLAG; }
const char* db() const { return db_.c_str(); }
bool enumeration() const { return flags_ & ENUM_FLAG; }
size_t length() const { return length_; }
size_t max_length() const { return max_length_; }
bool multiple_key() const { return flags_ & MULTIPLE_KEY_FLAG; }
const char* name() const { return name_.c_str(); }
#if defined(NO_DEFAULT_VALUE_FLAG)
bool no_default() const { return flags_ & NO_DEFAULT_VALUE_FLAG; }
#endif
bool primary_key() const { return flags_ & PRI_KEY_FLAG; }
bool set_type() const { return flags_ & SET_FLAG; }
const char* table() const { return table_.c_str(); }
bool timestamp() const { return flags_ & TIMESTAMP_FLAG; }
const mysql_type_info& type() const { return type_; }
bool unique_key() const { return flags_ & UNIQUE_KEY_FLAG; }
bool zerofill() const { return flags_ & ZEROFILL_FLAG; }
private:
std::string name_;
std::string table_;
std::string db_;
mysql_type_info type_;
size_t length_;
size_t max_length_;
unsigned int flags_;
};
typedef std::vector<Field> Fields;
} // end namespace mysqlpp
#endif // !defined(MYSQLPP_FIELD_H)
mysqlpp::Field::table
const char * table() const
Return the name of the table the field comes from.
Definition: field.h:127
mysqlpp::Field::zerofill
bool zerofill() const
Returns true if field has the zerofill attribute.
Definition: field.h:139
mysqlpp::Field::binary_type
bool binary_type() const
Returns true if field is of some binary type.
Definition: field.h:88
mysqlpp::Field::Field
Field()
Create empty object.
Definition: field.h:50
mysqlpp::Field::blob_type
bool blob_type() const
Returns true if field is of some BLOB type.
Definition: field.h:91
mysqlpp::Field
Class to hold information about a SQL field.
Definition: field.h:46
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::type
const mysql_type_info & type() const
Return information about the field&#39;s type.
Definition: field.h:133
mysqlpp::mysql_type_info
SQL field type information.
Definition: type_info.h:148
mysqlpp::Field::unique_key
bool unique_key() const
Returns true if field is part of a unique key.
Definition: field.h:136
mysqlpp::Field::timestamp
bool timestamp() const
Returns true if field&#39;s type is timestamp.
Definition: field.h:130
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::db
const char * db() const
Return the name of the database the field comes from.
Definition: field.h:94
type_info.h
Declares classes that provide an interface between the SQL and C++ type systems.
mysqlpp::Field::Field
Field(const Field &other)
Create object as a copy of another Field.
Definition: field.h:73
mysqlpp::Field::name
const char * name() const
Return the field&#39;s name.
Definition: field.h:113
mysqlpp::Field::primary_key
bool primary_key() const
Returns true if field is part of a primary key.
Definition: field.h:121
common.h
This file includes top-level definitions for use both internal to the library, and outside it...
mysqlpp::Field::multiple_key
bool multiple_key() const
Returns true if field is part of a key.
Definition: field.h:110
mysqlpp::Field::enumeration
bool enumeration() const
Returns true if field is of an enumerated value type.
Definition: field.h:97
mysqlpp::Field::Field
Field(const MYSQL_FIELD *pf)
Create object from C API field structure.
Definition: field.h:58
mysqlpp::Field::length
size_t length() const
Return the creation size of the field.
Definition: field.h:103
mysqlpp::Field::auto_increment
bool auto_increment() const
Returns true if field auto-increments.
Definition: field.h:85