00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include<Table.h>
00017 #include<Index.h>
00018 #include<CatalogTables.h>
00019 #include<Lock.h>
00020 #include<Debug.h>
00021
00022
00023 DbRetVal FieldList::append(FieldDef fDef)
00024 {
00025 FieldNode *newNode = new FieldNode();
00026 newNode->fldDef = fDef;
00027 newNode->next = NULL;
00028
00029 if (NULL == head) { head = newNode; return OK; }
00030
00031 FieldNode *iter = head;
00032 while (NULL != iter->next) iter = iter->next;
00033 iter->next = newNode;
00034 return OK;
00035 }
00036
00037
00038 DbRetVal FieldList::remove(const char* fldName)
00039 {
00040 if (NULL == head)
00041 {
00042 printError(ErrNotExists, "There are no elements in the list. Empty list");
00043 return ErrNotExists;
00044 }
00045 FieldNode *iter = head, *prev = head;
00046 while (iter->next != NULL)
00047 {
00048 if (0 == strcmp(iter->fldDef.fldName_, fldName))
00049 {
00050 prev->next = iter->next;
00051 delete iter;
00052 }
00053 prev = iter;
00054 iter = iter->next;
00055 }
00056 if( iter == head)
00057 {
00058 if (0 == strcmp(iter->fldDef.fldName_, fldName))
00059 {
00060 delete head;
00061 head = NULL;
00062 return OK;
00063 }
00064
00065 }
00066 if( prev == head)
00067 {
00068 if (0 == strcmp(iter->fldDef.fldName_, fldName))
00069 {
00070 head->next = NULL;
00071 delete iter;
00072 return OK;
00073 }
00074 }
00075 printError(ErrNotFound, "There are no elements in the list");
00076 return ErrNotFound;
00077 }
00078
00079 DbRetVal FieldList::removeAll()
00080 {
00081 if (NULL == head) return OK;
00082 FieldNode *iter = head, *next = head;
00083 while (iter->next != NULL)
00084 {
00085 next = iter->next;
00086 delete iter;
00087 iter = next;
00088 }
00089 delete iter;
00090 head = NULL;
00091 return OK;
00092 }
00093
00094
00095
00096 DbRetVal FieldList::updateBindVal(const char *fldName, void *val )
00097 {
00098 if (NULL == val)
00099 {
00100 printError(ErrBadArg, "Value passed is NULL");
00101 return ErrBadArg;
00102 }
00103 FieldNode *iter = head;
00104 while(NULL != iter)
00105 {
00106 if (strcmp(iter->fldDef.fldName_, fldName) == 0)
00107 {
00108 iter->fldDef.bindVal_ = val;
00109 return OK;
00110 }
00111 iter = iter ->next;
00112 }
00113 printError(ErrNotFound, "Field not present in the list");
00114 return ErrNotFound;
00115 }
00116
00117 DbRetVal FieldList::getFieldInfo(const char *fldName, FieldInfo *&info)
00118 {
00119 FieldNode *iter = head;
00120 while(iter != NULL)
00121 {
00122 if (0 == strcmp(iter->fldDef.fldName_, fldName))
00123 {
00124 strcpy(info->fldName , iter->fldDef.fldName_);
00125 info->length = iter->fldDef.length_;
00126 info->type = iter->fldDef.type_;
00127 info->offset = getFieldOffset(fldName);
00128 info->isDefault = iter->fldDef.isDefault_;
00129 strcpy(info->defaultValueBuf, iter->fldDef.defaultValueBuf_);
00130 info->isNull = iter->fldDef.isNull_;
00131 info->isPrimary = iter->fldDef.isPrimary_;
00132 return OK;
00133
00134 }
00135 iter = iter ->next;
00136 }
00137 return ErrNotFound;
00138 }
00139
00140 int FieldList::getFieldOffset(const char *fldName)
00141 {
00142 FieldNode *iter = head;
00143 int offset = 0;
00144 while(iter != NULL)
00145 {
00146 if (0 == strcmp(iter->fldDef.fldName_, fldName))
00147 {
00148 return offset;
00149 }
00150 offset = offset + os::align(iter->fldDef.length_);
00151 iter = iter ->next;
00152 }
00153 return -1;
00154 }
00155 int FieldList::getFieldOffset(int fldpos)
00156 {
00157 if (fldpos < 1) return -1;
00158 FieldNode *iter = head;
00159 int offset = 0;
00160 int counter =0;
00161 while(iter != NULL)
00162 {
00163 if (counter == fldpos -1)
00164 {
00165 return offset;
00166 }
00167 offset = offset + os::align(iter->fldDef.length_);
00168 iter = iter ->next;
00169 counter++;
00170 }
00171 return -1;
00172 }
00173
00174
00175
00176
00177 int FieldList::getFieldPosition(const char *fldName)
00178 {
00179 int position = 1;
00180 FieldNode *iter = head;
00181 while(iter != NULL)
00182 {
00183 if (0 == strcmp(iter->fldDef.fldName_, fldName))
00184 return position;
00185 position++;
00186 iter = iter->next;
00187 }
00188
00189 return -1;
00190 }
00191
00192 int FieldList::getTupleSize()
00193 {
00194 FieldNode *iter = head;
00195 int offset = 0;
00196 while(iter != NULL)
00197 {
00198 offset = offset + os::align(iter->fldDef.length_);
00199 iter = iter ->next;
00200 }
00201 return offset;
00202 }
00203
00204
00205
00206 DataType FieldList::getFieldType(const char *fldName)
00207 {
00208 FieldNode *iter = head;
00209 int offset = 0;
00210 while(iter != NULL)
00211 {
00212 if (0 == strcmp(iter->fldDef.fldName_, fldName))
00213 {
00214 return iter->fldDef.type_;
00215 }
00216 iter = iter ->next;
00217 }
00218 return typeUnknown;
00219 }
00220
00221
00222 size_t FieldList::getFieldLength(const char *fldName)
00223 {
00224 FieldNode *iter = head;
00225 int offset = 0;
00226 while(iter != NULL)
00227 {
00228 if (0 == strcmp(iter->fldDef.fldName_, fldName))
00229 {
00230 return iter->fldDef.length_;
00231 }
00232 iter = iter ->next;
00233 }
00234 return -1;
00235 }
00236
00237
00238
00239
00240 DbRetVal FieldNameList::append(const char *name)
00241 {
00242 FieldNameNode *newNode = new FieldNameNode();
00243 strcpy(newNode->fldName, name);
00244 newNode->next = NULL;
00245
00246 if (NULL == head) { head = newNode; return OK; }
00247
00248 FieldNameNode *it = head;
00249 while (NULL != it->next) it = it->next;
00250 it->next = newNode;
00251 return OK;
00252 }
00253
00254
00255 DbRetVal FieldNameList::remove(const char* name)
00256 {
00257 if (NULL == head)
00258 {
00259 printError(ErrNotExists, "List is empty");
00260 return ErrNotExists;
00261 }
00262 FieldNameNode *ite = head, *prev = head;
00263 while (ite->next != NULL)
00264 {
00265 if (0 == strcmp(ite->fldName, name))
00266 {
00267 prev->next = ite->next;
00268 delete ite;
00269 }
00270 prev = ite;
00271 ite = ite->next;
00272 }
00273 if( ite == head)
00274 {
00275 if (0 == strcmp(ite->fldName, name))
00276 {
00277 delete head;
00278 head = NULL;
00279 return OK;
00280 }
00281
00282 }
00283 if( prev == head)
00284 {
00285 if (0 == strcmp(ite->fldName, name))
00286 {
00287 head->next = NULL;
00288 delete ite;
00289 return OK;
00290 }
00291 }
00292 printError(ErrNotFound, "Field name %s not present in the list", name);
00293 return ErrNotFound;
00294 }
00295
00296 DbRetVal FieldNameList::removeAll()
00297 {
00298 if (NULL == head) return OK;
00299 FieldNameNode *iter = head, *next = head;
00300 while (iter->next != NULL)
00301 {
00302 next = iter->next;
00303 delete iter;
00304 iter = next;
00305 }
00306 delete iter;
00307 head = NULL;
00308 return OK;
00309 }
00310
00311 char* FieldNameList::nextFieldName()
00312 {
00313 if (iter == NULL) return NULL;
00314 FieldNameNode *node = iter;
00315 iter = iter ->next;
00316 return node->fldName;
00317 }
00318
00319 int FieldNameList::size()
00320 {
00321 FieldNameNode *it = head;
00322 if (NULL == it) return 0;
00323 int count = 1;
00324 while (NULL != it->next) {it = it->next; count++;}
00325 return count;
00326 }