#include <Info.h>
Collaboration diagram for TableDef:
Public Member Functions | |
TableDef () | |
~TableDef () | |
void | reset () |
int | addField (const char *name, DataType type=typeUnknown, size_t length=0, const void *defaultValue=0, bool notNull=false) |
adds a field to the schema definition. | |
int | dropField (const char *name) |
removes a field from the schema definition | |
int | getFieldCount () |
returns the total number of fields in this table definition | |
size_t | getTupleSize () |
returns the total tuple size in bytes. | |
FieldIterator | getFieldIterator () |
Encapsulates the information or schema definition of a table.For Example say if
we need to create table with two fields, call addField method with necessary parameters
twice. Passed as argument to createTable method of DatabaseManager to create table.
Definition at line 69 of file Info.h.
TableDef::~TableDef | ( | ) |
Definition at line 21 of file TableDef.cxx.
References reset().
00022 { 00023 reset(); 00024 }
Here is the call graph for this function:
int TableDef::addField | ( | const char * | name, | |
DataType | type = typeUnknown , |
|||
size_t | length = 0 , |
|||
const void * | defaultValue = 0 , |
|||
bool | notNull = false | |||
) |
adds a field to the schema definition.
name | field name | |
type | data type of the field | |
length | size of the field. used in case of char and binary data types. | |
defaultValue | default value for the field. It is currently limited to 32 bytes. | |
isPrimary | whether the field is primary key( not null + unique) | |
notNull | whether the field can be null | |
unique | whether the field values are unique |
Definition at line 30 of file TableDef.cxx.
References FieldList::append(), DEFAULT_VALUE_BUF_LENGTH, FieldDef::defaultValueBuf_, ErrAlready, ErrBadArg, FieldDef::fldName_, getFieldIterator(), FieldIterator::hasElement(), IDENTIFIER_LENGTH, FieldDef::isDefault_, FieldDef::isNull_, FieldDef::length_, os::memcpy(), os::memset(), FieldIterator::nextElement(), printError, AllDataType::size(), FieldDef::type_, typeBinary, and typeString.
Referenced by CacheTableLoader::load(), and CreateTblStatement::resolve().
00032 { 00033 if (name == NULL) return (int)ErrBadArg; 00034 // The following code checks for duplicates 00035 FieldIterator iter = getFieldIterator(); 00036 while (iter.hasElement()) 00037 { 00038 FieldDef def = iter.nextElement(); 00039 if (! strcmp(def.fldName_, name)) { 00040 printError(ErrAlready, "Field %s already Exists", name); 00041 return (int) ErrAlready; 00042 } 00043 } 00044 FieldDef fldDef; 00045 strcpy(fldDef.fldName_, name); 00046 fldDef.fldName_[IDENTIFIER_LENGTH] = '\0'; 00047 fldDef.type_ = type; 00048 fldDef.length_ = length; 00049 if (defaultValue != NULL) 00050 { 00051 fldDef.isDefault_ = true; 00052 os::memcpy(fldDef.defaultValueBuf_, defaultValue, 00053 DEFAULT_VALUE_BUF_LENGTH); 00054 } 00055 else 00056 { 00057 fldDef.isDefault_ = false; 00058 os::memset(fldDef.defaultValueBuf_,0, DEFAULT_VALUE_BUF_LENGTH); 00059 } 00060 fldDef.isNull_ = notNull; 00061 switch(type) 00062 { 00063 case typeString : 00064 case typeBinary: 00065 fldDef.length_ = length; 00066 break; 00067 default: 00068 fldDef.length_ = AllDataType::size(type); 00069 break; 00070 } 00071 int ret = fldList.append(fldDef); 00072 if (0 == ret) fldCount++; 00073 return ret; 00074 }
Here is the call graph for this function:
Here is the caller graph for this function:
int TableDef::dropField | ( | const char * | name | ) |
removes a field from the schema definition
name | field name |
Definition at line 76 of file TableDef.cxx.
References FieldList::remove().
00077 { 00078 int ret = fldList.remove(name); 00079 if (0 == ret) fldCount--; 00080 return ret; 00081 }
Here is the call graph for this function:
int TableDef::getFieldCount | ( | ) |
returns the total number of fields in this table definition
Definition at line 83 of file TableDef.cxx.
Referenced by DatabaseManagerImpl::createTable().
Here is the caller graph for this function:
FieldIterator TableDef::getFieldIterator | ( | ) | [inline] |
Definition at line 111 of file Info.h.
References FieldList::getIterator().
Referenced by addField(), DatabaseManagerImpl::createTable(), and getTupleSize().
00111 { return fldList.getIterator(); }
Here is the call graph for this function:
Here is the caller graph for this function:
size_t TableDef::getTupleSize | ( | ) |
returns the total tuple size in bytes.
Definition at line 88 of file TableDef.cxx.
References os::align(), getFieldIterator(), FieldIterator::hasElement(), and FieldIterator::nextElement().
Referenced by DatabaseManagerImpl::createTable().
00089 { 00090 size_t length = 0; 00091 FieldIterator iter = getFieldIterator(); 00092 while (iter.hasElement()) 00093 { 00094 FieldDef def = iter.nextElement(); 00095 length = length + os::align(def.length_); 00096 } 00097 return length; 00098 }
Here is the call graph for this function:
Here is the caller graph for this function:
void TableDef::reset | ( | ) |
Definition at line 25 of file TableDef.cxx.
References FieldList::removeAll().
Referenced by CreateTblStatement::~CreateTblStatement(), and ~TableDef().
00026 { 00027 fldList.removeAll(); 00028 fldCount = 0; 00029 }
Here is the call graph for this function:
Here is the caller graph for this function: