kexi
KexiDB::Field Class Reference#include <field.h>
Inheritance diagram for KexiDB::Field:
List of all members.
Detailed Description
Meta-data for a field.
KexiDB::Field provides information about single database field.
Field class has defined following members:
- name
- type
- database constraints
- additional options
- length (make sense mostly for string types)
- precision (for floating-point type)
- defaultValue
- caption (user readable name that can be e.g. translated)
- description (user readable name additional text, can be useful for developers)
- width (a hint for displaying in tabular mode or as text box)
Field can also have assigned expression (see KexiDB::BaseExpr class, and expression() method). If an expression is defined, then field's name is
Note that aliases for fields are defined within query, not in Field object, because the same field can be used in different queries with different alias.
Notes for advanced use: Field obeject is designed to be owned by a parent object. Such a parent object can be KexiDB::TableSchema, if the field defines single table column, or KexiDB::QuerySchema, if the field defines an expression (KexiDB::BaseExpr class).
Using expression class for fields allos to define expressions within queries like "SELECT AVG(price) FROM products"
You can choose whether your field is owned by query or table, using appropriate constructor, or using parameterless constructor and calling setTable() or setQuery() later.
Definition at line 72 of file field.h.
|
Public Types |
typedef QPtrList< Field > | List |
typedef QPtrVector< Field > | Vector |
typedef QPtrListIterator<
Field > | ListIterator |
typedef QPair< Field *, Field * > | Pair |
typedef QPtrList< Pair > | PairList |
| InvalidType = 0 |
| Byte = 1 |
| ShortInteger = 2 |
| Integer = 3 |
| BigInteger = 4 |
| Boolean = 5 |
| Date = 6 |
| DateTime = 7 |
| Time = 8 |
| Float = 9 |
| Double = 10 |
| Text = 11 |
| LongText = 12 |
| BLOB = 13 |
| LastType = 13 |
| Null = 64 |
| Asterisk = 128 |
| Enum = 129 |
| Map = 130 |
| InvalidGroup = 0 |
| TextGroup = 1 |
| IntegerGroup = 2 |
| FloatGroup = 3 |
| BooleanGroup = 4 |
| DateTimeGroup = 5 |
| BLOBGroup = 6 |
| LastTypeGroup = 6 |
| NoConstraints = 0 |
| AutoInc = 1 |
| Unique = 2 |
| PrimaryKey = 4 |
| ForeignKey = 8 |
| NotNull = 16 |
| NotEmpty = 32 |
| Indexed = 64 |
| NoOptions = 0 |
| Unsigned = 1 |
enum | Type {
InvalidType = 0,
Byte = 1,
ShortInteger = 2,
Integer = 3,
BigInteger = 4,
Boolean = 5,
Date = 6,
DateTime = 7,
Time = 8,
Float = 9,
Double = 10,
Text = 11,
LongText = 12,
BLOB = 13,
LastType = 13,
Null = 64,
Asterisk = 128,
Enum = 129,
Map = 130
} |
enum | TypeGroup {
InvalidGroup = 0,
TextGroup = 1,
IntegerGroup = 2,
FloatGroup = 3,
BooleanGroup = 4,
DateTimeGroup = 5,
BLOBGroup = 6,
LastTypeGroup = 6
} |
enum | Constraints {
NoConstraints = 0,
AutoInc = 1,
Unique = 2,
PrimaryKey = 4,
ForeignKey = 8,
NotNull = 16,
NotEmpty = 32,
Indexed = 64
} |
enum | Options { NoOptions = 0,
Unsigned = 1
} |
Public Member Functions |
| Field (TableSchema *tableSchema) |
| Field (QuerySchema *querySchema, BaseExpr *expr=0) |
| Field () |
| Field (const QString &name, Type ctype, uint cconst=NoConstraints, uint options=NoOptions, uint length=0, uint precision=0, QVariant defaultValue=QVariant(), const QString &caption=QString::null, const QString &description=QString::null, uint width=0) |
| Field (const Field &f) |
virtual | ~Field () |
QString | name () const |
virtual TableSchema * | table () const |
virtual void | setTable (TableSchema *table) |
QuerySchema * | query () const |
void | setQuery (QuerySchema *query) |
bool | isAutoIncrement () const |
bool | isPrimaryKey () const |
bool | isUniqueKey () const |
bool | isForeignKey () const |
bool | isNotNull () const |
bool | isNotEmpty () const |
bool | isIndexed () const |
bool | isNumericType () const |
bool | isIntegerType () const |
bool | isFPNumericType () const |
bool | isDateTimeType () const |
bool | isTextType () const |
uint | options () const |
void | setOptions (uint options) |
QVariant::Type | variantType () const |
Type | type () const |
QString | typeName () const |
TypeGroup | typeGroup () const |
QString | typeGroupName () const |
QString | typeString () const |
QString | typeGroupString () const |
QString | subType () const |
void | setSubType (const QString &subType) |
QVariant | defaultValue () const |
uint | length () const |
uint | precision () const |
uint | scale () const |
uint | constraints () const |
int | order () const |
QString | caption () const |
QString | captionOrName () const |
QString | description () const |
uint | width () const |
bool | isUnsigned () const |
bool | hasEmptyProperty () const |
bool | isAutoIncrementAllowed () const |
void | setType (Type t) |
void | setName (const QString &name) |
void | setConstraints (uint c) |
void | setLength (uint l) |
void | setScale (uint s) |
void | setPrecision (uint p) |
void | setUnsigned (bool u) |
void | setDefaultValue (const QVariant &def) |
bool | setDefaultValue (const QCString &def) |
void | setAutoIncrement (bool a) |
void | setPrimaryKey (bool p) |
void | setUniqueKey (bool u) |
void | setForeignKey (bool f) |
void | setNotNull (bool n) |
void | setNotEmpty (bool n) |
void | setIndexed (bool s) |
void | setCaption (const QString &caption) |
void | setDescription (const QString &description) |
void | setWidth (uint w) |
bool | isQueryAsterisk () const |
virtual QString | debugString () |
void | debug () |
KexiDB::BaseExpr * | expression () |
void | setExpression (KexiDB::BaseExpr *expr) |
bool | isExpression () const |
QValueVector< QString > | enumHints () const |
QString | enumHint (uint num) |
void | setEnumHints (const QValueVector< QString > &l) |
Static Public Member Functions |
static uint | defaultTextLength () |
static QVariant::Type | variantType (uint type) |
static QString | typeName (uint type) |
static QString | typeString (uint type) |
static Type | typeForString (const QString typeString) |
static TypeGroup | typeGroupForString (const QString typeGroupString) |
static TypeGroup | typeGroup (uint type) |
static QString | typeGroupName (uint typeGroup) |
static QString | typeGroupString (uint typeGroup) |
static bool | isNumericType (uint type) |
static bool | isIntegerType (uint type) |
static bool | isFPNumericType (uint type) |
static bool | isDateTimeType (uint type) |
static bool | isTextType (uint type) |
static bool | hasEmptyProperty (uint type) |
static bool | isAutoIncrementAllowed (uint type) |
Protected Member Functions |
void | init () |
Protected Attributes |
FieldList * | m_parent |
QString | m_name |
QString | m_subType |
uint | m_constraints |
uint | m_length |
uint | m_precision |
uint | m_options |
QVariant | m_defaultValue |
int | m_order |
QString | m_caption |
QString | m_desc |
uint | m_width |
QValueVector< QString > | m_hints |
KexiDB::BaseExpr * | m_expr |
Static Protected Attributes |
static FieldTypeNames | m_typeNames |
static FieldTypeGroupNames | m_typeGroupNames |
Friends |
class | Connection |
class | FieldList |
class | TableSchema |
class | QuerySchema |
Classes |
class | FieldTypeGroupNames |
class | FieldTypeNames |
Member Typedef Documentation
list of fields
Definition at line 75 of file field.h.
iterator for list of fields
Definition at line 77 of file field.h.
fields pair
Definition at line 78 of file field.h.
list of fields pair
Definition at line 79 of file field.h.
vector of fields
Definition at line 76 of file field.h.
Member Enumeration Documentation
- Enumerator:
-
NotEmpty |
only legal for string-like and blob fields |
Definition at line 129 of file field.h.
Unified (most common used) types of fields. - Enumerator:
-
InvalidType |
Unsupported/Unimplemented type |
Byte |
1 byte, signed or unsigned |
ShortInteger |
2 bytes, signed or unsigned |
Integer |
4 bytes, signed or unsigned |
BigInteger |
8 bytes, signed or unsigned |
Boolean |
0 or 1 |
Float |
4 bytes |
Double |
8 bytes |
Text |
Other name: Varchar; no more than 200 bytes, for efficiency |
LongText |
Other name: Memo. More than 200 bytes |
BLOB |
Large binary object |
LastType |
This line should be at the end of the list of types! |
Null |
Used for fields that are "NULL" expressions. |
Asterisk |
Special, internal types:.
Used in QueryAsterisk subclass objects only, not used in table definitions, but only in query definitions |
Enum |
An integer internal with a string list of hints |
Map |
Mapping from string to string list (more generic than Enum |
Definition at line 82 of file field.h.
Type groups for fields.
Definition at line 116 of file field.h.
Constructor & Destructor Documentation
Field::Field |
( |
const Field & |
f |
) |
|
Copy constructor.
Definition at line 90 of file field.cpp.
Member Function Documentation
QString KexiDB::Field::caption |
( |
|
) |
const [inline] |
- Returns:
- caption of this field.
Definition at line 337 of file field.h.
QString KexiDB::Field::captionOrName |
( |
|
) |
const [inline] |
- Returns:
- caption of this field or - if empty - return its name.
Definition at line 340 of file field.h.
uint KexiDB::Field::constraints |
( |
|
) |
const [inline] |
- Returns:
- the constraints defined for this field.
Definition at line 330 of file field.h.
Shows debug information about this field.
Definition at line 592 of file field.cpp.
QString Field::debugString |
( |
|
) |
[virtual] |
QString KexiDB::Field::description |
( |
|
) |
const [inline] |
- Returns:
- description text for this field.
Definition at line 343 of file field.h.
QValueVector<QString> KexiDB::Field::enumHints |
( |
|
) |
const [inline] |
- Returns:
- the hints for enum fields.
Definition at line 499 of file field.h.
- Returns:
- KexiDB::BaseExpr object if the field value is an expression. Unless the expression is set with setExpresion(), it is null.
Definition at line 479 of file field.h.
bool Field::hasEmptyProperty |
( |
uint |
type |
) |
[static] |
static version of hasEmptyProperty() method - Returns:
- true if this field type has EMPTY property (i.e. it is string or BLOB type)
Definition at line 256 of file field.cpp.
bool KexiDB::Field::hasEmptyProperty |
( |
|
) |
const [inline] |
- Returns:
- true if this field has EMPTY property (i.e. it is of type string or is a BLOB).
Definition at line 356 of file field.h.
bool KexiDB::Field::isAutoIncrement |
( |
|
) |
const [inline] |
- Returns:
- true if the field is autoincrement (e.g. integer/numeric)
Definition at line 225 of file field.h.
bool Field::isAutoIncrementAllowed |
( |
uint |
type |
) |
[static] |
bool KexiDB::Field::isAutoIncrementAllowed |
( |
|
) |
const [inline] |
- Returns:
- true if this field can be auto-incremented. Actually, returns true for integer field type.
- See also:
- IntegerType, isAutoIncrement()
Definition at line 364 of file field.h.
bool Field::isDateTimeType |
( |
uint |
type |
) |
[static] |
static version of isDateTimeType() method ! - Returns:
- true if the field is of any date or time related type
Definition at line 233 of file field.cpp.
bool KexiDB::Field::isDateTimeType |
( |
|
) |
const [inline] |
- Returns:
- true if the field is of any date or time related type
Definition at line 267 of file field.h.
bool KexiDB::Field::isExpression |
( |
|
) |
const [inline] |
- Returns:
- true if there is expression defined for this field. This method is provided for better readibility
Definition at line 495 of file field.h.
bool KexiDB::Field::isForeignKey |
( |
|
) |
const [inline] |
- Returns:
- true if the field is member of single-field foreign key
Definition at line 234 of file field.h.
bool Field::isFPNumericType |
( |
uint |
type |
) |
[static] |
static version of isFPNumericType() method ! - Returns:
- true if the field is of any floating point numeric type
Definition at line 228 of file field.cpp.
bool KexiDB::Field::isFPNumericType |
( |
|
) |
const [inline] |
- Returns:
- true if the field is of any floating point numeric type
Definition at line 260 of file field.h.
bool KexiDB::Field::isIndexed |
( |
|
) |
const [inline] |
- Returns:
- true if the field is indexed using single-field database index.
Definition at line 243 of file field.h.
bool Field::isIntegerType |
( |
uint |
type |
) |
[static] |
bool KexiDB::Field::isIntegerType |
( |
|
) |
const [inline] |
- Returns:
- true if the field is of any integer type
Definition at line 253 of file field.h.
bool KexiDB::Field::isNotEmpty |
( |
|
) |
const [inline] |
- Returns:
- true if the field is not allowed to be null
Definition at line 240 of file field.h.
bool KexiDB::Field::isNotNull |
( |
|
) |
const [inline] |
- Returns:
- true if the field is not allowed to be null
Definition at line 237 of file field.h.
bool Field::isNumericType |
( |
uint |
type |
) |
[static] |
static version of isNumericType() method ! - Returns:
- true if the field is of any numeric type (integer or floating point)
Definition at line 213 of file field.cpp.
bool KexiDB::Field::isNumericType |
( |
|
) |
const [inline] |
- Returns:
- true if the field is of any numeric type (integer or floating point)
Definition at line 246 of file field.h.
bool KexiDB::Field::isPrimaryKey |
( |
|
) |
const [inline] |
- Returns:
- true if the field is member of single-field primary key
Definition at line 228 of file field.h.
bool KexiDB::Field::isQueryAsterisk |
( |
|
) |
const [inline] |
There can be added asterisks (QueryAsterisk objects) to query schemas' field list. QueryAsterisk subclasses Field class, and to check if the given object (pointed by Field*) is asterisk or just ordinary field definition, you can call this method. This is just effective version of QObject::isA(). Every QueryAsterisk object returns true here, and every Field object returns false.
Definition at line 468 of file field.h.
bool Field::isTextType |
( |
uint |
type |
) |
[static] |
static version of isTextType() method ! - Returns:
- true if the field is of any text type
Definition at line 245 of file field.cpp.
bool KexiDB::Field::isTextType |
( |
|
) |
const [inline] |
- Returns:
- true if the field is of any text type
Definition at line 274 of file field.h.
bool KexiDB::Field::isUniqueKey |
( |
|
) |
const [inline] |
- Returns:
- true if the field is member of single-field unique key
Definition at line 231 of file field.h.
bool KexiDB::Field::isUnsigned |
( |
|
) |
const [inline] |
if the type has the unsigned attribute
Definition at line 350 of file field.h.
uint KexiDB::Field::length |
( |
|
) |
const [inline] |
- Returns:
- length of text, only meaningful if the field type is text.
Definition at line 314 of file field.h.
int KexiDB::Field::order |
( |
|
) |
const [inline] |
- Returns:
- order of this field in containing table (counting starts from 0) (-1 if unspecified).
Definition at line 334 of file field.h.
uint KexiDB::Field::precision |
( |
|
) |
const [inline] |
- Returns:
- precision for numeric and other fields that have both length (scale) and precision (floating point types).
Definition at line 318 of file field.h.
For special use when the field defines expression. - Returns:
- query schema of query that owns this field or null if it has no query assigned.
- See also:
- table()
Reimplemented in KexiDB::QueryAsterisk.
Definition at line 297 of file field.cpp.
uint KexiDB::Field::scale |
( |
|
) |
const [inline] |
- Returns:
- scale for numeric and other fields that have both length (scale) and precision (floating point types). The scale of a numeric is the count of decimal digits in the fractional part, to the right of the decimal point. The precision of a numeric is the total count of significant digits in the whole number, that is, the number of digits to both sides of the decimal point. So the number 23.5141 has a precision of 6 and a scale of 4. Integers can be considered to have a scale of zero.
Definition at line 327 of file field.h.
void Field::setAutoIncrement |
( |
bool |
a |
) |
|
void Field::setConstraints |
( |
uint |
c |
) |
|
Sets constraints to c. If PrimaryKey is set in c, also constraits implied by being primary key are enforced (see setPrimaryKey()). If Indexed is not set in c, constraits implied by not being are enforced as well (see setIndexed()).
Definition at line 326 of file field.cpp.
bool Field::setDefaultValue |
( |
const QCString & |
def |
) |
|
Sets default value decoded from QCString. Decoding errors are detected (value is strictly checked against field type)
- if one is encountered, default value is cleared (defaultValue()==QVariant()).
- Returns:
- true if given value was valid for field type.
- Todo:
- BigInteger support
Definition at line 379 of file field.cpp.
void KexiDB::Field::setEnumHints |
( |
const QValueVector< QString > & |
l |
) |
[inline] |
sets the hint for enum fields
Definition at line 502 of file field.h.
Sets expression data expr. If there was already expression set, it is destroyed before new assignment. This Field object becames owner of expr object, so you do not have to worry about deleting it later. If the expr is null, current field's expression is deleted, if exists.
Because the field defines an expression, it should be assigned to a query, not to a table.
Definition at line 597 of file field.cpp.
void Field::setForeignKey |
( |
bool |
f |
) |
|
Sets whether the field has to be declared with single-field foreign key. Used in IndexSchema::setForeigKey().
Definition at line 528 of file field.cpp.
void Field::setIndexed |
( |
bool |
s |
) |
|
Specifies whether the field is indexed (KexiDB::Indexed item) (by single-field implicit index) or not. Use this with caution. Since index is used to control unique, not null/empty constratins, setting this to false implies setting:
- setPrimaryKey(false)
- setUniqueKey(false)
- setNotNull(false)
- setNotEmpty(false) because above flags need index to be present. Similarly, setting one of the above flags to true, will automatically do setIndexed(true) for the same reason.
Definition at line 547 of file field.cpp.
void Field::setLength |
( |
uint |
l |
) |
|
Sets length for this field. Only works for Text Type (even not LongText!).
Definition at line 342 of file field.cpp.
void Field::setName |
( |
const QString & |
name |
) |
|
Sets name name for this field.
Definition at line 309 of file field.cpp.
void Field::setNotEmpty |
( |
bool |
n |
) |
|
Specifies whether the field has single-field unique constraint or not (KexiDB::NotEmpty item). Setting this to true implies setting Indexed flag to true (setIndexed(true)), because index is required it control not empty constraint.
Definition at line 541 of file field.cpp.
void Field::setNotNull |
( |
bool |
n |
) |
|
Specifies whether the field has single-field unique constraint or not (KexiDB::NotNull item). Setting this to true implies setting Indexed flag to true (setIndexed(true)), because index is required it control not null constraint.
Definition at line 535 of file field.cpp.
void Field::setPrecision |
( |
uint |
p |
) |
|
Sets scale for this field. Only works for floating-point types.
Definition at line 350 of file field.cpp.
void Field::setPrimaryKey |
( |
bool |
p |
) |
|
Specifies whether the field is single-field primary key or not (KexiDB::PrimeryKey item).
Use this with caution. Setting this to true implies setting:
- setUniqueKey(true)
- setNotNull(true)
- setNotEmpty(true)
- setIndexed(true)
Setting this to false implies setting setAutoIncrement(false).
- Todo:
- is this ok for all engines?
Definition at line 501 of file field.cpp.
For special use when field defines expression. Sets query schema of query that owns this field. This does not adds the field to query object. You do not need to call this method by hand. Call QuerySchema::addField() instead. - See also:
- setQuery()
Definition at line 303 of file field.cpp.
void Field::setScale |
( |
uint |
s |
) |
|
Sets scale for this field. Only works for floating-point types.
Definition at line 358 of file field.cpp.
void KexiDB::Field::setSubType |
( |
const QString & |
subType |
) |
[inline] |
Sets (optional) subtype for this field. - See also:
- subType()
Definition at line 309 of file field.h.
void Field::setType |
( |
Type |
t |
) |
|
Sets type t for this field. This does nothing if there's already expression assigned, see expression().
Definition at line 315 of file field.cpp.
void Field::setUniqueKey |
( |
bool |
u |
) |
|
Specifies whether the field has single-field unique constraint or not (KexiDB::Unique item). Setting this to true implies setting Indexed flag to true (setIndexed(true)), because index is required it control unique constraint.
Definition at line 518 of file field.cpp.
QString KexiDB::Field::subType |
( |
|
) |
const [inline] |
- Returns:
- (optional) subtype for this field. Subtype is a string providing additional hint for field's type. E.g. for BLOB type, it can be a MIME type or certain QVariant type name, for example: "QPixmap", "QColor" or "QFont"
Definition at line 305 of file field.h.
Return a type for this field. If there's expression assigned, type of the expression is returned instead.
Definition at line 120 of file field.cpp.
Field::Type Field::typeForString |
( |
const QString |
typeString |
) |
[static] |
- Returns:
- type for a given typeString
Definition at line 184 of file field.cpp.
- Returns:
- group for type
Definition at line 266 of file field.cpp.
Field::TypeGroup Field::typeGroupForString |
( |
const QString |
typeGroupString |
) |
[static] |
- Returns:
- type group for a given typeGroupString
Definition at line 192 of file field.cpp.
QString Field::typeGroupName |
( |
uint |
typeGroup |
) |
[static] |
QString Field::typeGroupString |
( |
uint |
typeGroup |
) |
[static] |
- Returns:
- type group string for typeGroup, e.g. "IntegerGroup" for IntegerGroup type (not-i18n'd, type has to be an element from Field::Type, not greater than Field::LastType)
Definition at line 178 of file field.cpp.
QString Field::typeName |
( |
uint |
type |
) |
[static] |
QString Field::typeString |
( |
uint |
type |
) |
[static] |
- Returns:
- type string for type, e.g. "Integer" for Integer type (not-i18n'd, type has to be an element from Field::Type, not greater than Field::LastType)
Definition at line 166 of file field.cpp.
QVariant::Type Field::variantType |
( |
uint |
type |
) |
[static] |
Converts field type to QVariant equivalent as accurate as possible.
Definition at line 127 of file field.cpp.
uint KexiDB::Field::width |
( |
|
) |
const [inline] |
- Returns:
- width of this field (usually in pixels or points) 0 (the default) means there is no hint for the width.
Definition at line 347 of file field.h.
Member Data Documentation
also used for storing scale for floating point types
Definition at line 514 of file field.h.
In most cases this points to a TableSchema object that field is assigned.
Definition at line 509 of file field.h.
real i18n'd type group names (and not-i18n'd group name strings)
Definition at line 547 of file field.h.
real i18n'd type names (and not-i18n'd type name strings)
Definition at line 544 of file field.h.
The documentation for this class was generated from the following files:
|