include/Field.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by www.databasecache.com                           *
00003  *   Contact: praba_tuty@databasecache.com                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015   ***************************************************************************/
00016 #ifndef FIELD_H
00017 #define FIELD_H
00018 #include<os.h>
00019 #include<DataType.h>
00020 #include<ErrorType.h>
00021 
00022 //used by FieldNameList
00023 class FieldNameNode
00024 {
00025     public:
00026     char  fldName[IDENTIFIER_LENGTH];
00027     FieldNameNode *next;
00028 };
00029 
00030 
00031 class FieldDef
00032 {
00033     public:
00034     FieldDef()
00035     {
00036         init();
00037     }
00038     void init() {
00039         type_ = typeUnknown;
00040         length_ = 0;
00041         bindVal_ = NULL;
00042         isDefault_ = false;
00043         isNull_ = false;
00044         isPrimary_ = false;
00045         isUnique_ = false;
00046         strcpy(fldName_, "");
00047     }
00048     char fldName_[IDENTIFIER_LENGTH];
00049     DataType type_;
00050     size_t length_;
00051     //currently default value is supported for string and binary
00052     //less than length 32 bytes
00053     char defaultValueBuf_[DEFAULT_VALUE_BUF_LENGTH];
00054 
00055     //used only in case of binding fields
00056     void *bindVal_;
00057 
00058     bool isNull_;
00059     bool isPrimary_;
00060     bool isDefault_;
00061     bool isUnique_;
00062     //TODO::width and scale
00063 };
00064 
00065 class FieldNode
00066 {
00067     public:
00068     FieldDef fldDef;
00069     FieldNode *next;
00070 };
00071 
00072 
00073 class FieldIterator
00074 {
00075     public:
00076     FieldNode *iter;
00077     FieldIterator(FieldNode *ptr) { iter = ptr; }
00078     bool hasElement()
00079     {
00080         if (iter == NULL) return false; else return true;
00081     }
00082     FieldDef nextElement()
00083     {
00084         if (iter == NULL) { FieldDef dummyDef; return dummyDef;}
00085         FieldNode *node = iter;
00086         iter = iter ->next;
00087         return node->fldDef;
00088     }
00089 };
00090 
00091 class FieldInfo;
00092 
00093 //Internal class used to implement the field list information
00094 //to create the table
00095 class FieldList
00096 {
00097     public:
00098     FieldNode *head;
00099     FieldList(){ head = NULL;}
00100 
00101     //TODO::pass by reference instead of value
00102     DbRetVal append(FieldDef fDef);
00103 
00104     DbRetVal remove(const char* fldName);
00105 
00106     DbRetVal removeAll();
00107 
00108     DbRetVal updateBindVal(const char *fldName, void *val);
00109 
00110     int getFieldOffset(const char *fldName);
00111     int getFieldOffset(int fldpos);
00112 
00113     //Returns position of field in the list:count starting from 1
00114     int getFieldPosition(const char *fldName);
00115 
00116     DataType getFieldType(const char *fldName);
00117 
00118     size_t getFieldLength(const char *fldName);
00119 
00120     DbRetVal getFieldInfo(const char *fldName, FieldInfo *&info);
00121 
00122     int getTupleSize();
00123 
00124     FieldIterator getIterator()
00125     {
00126         FieldIterator iter(head);
00127         return iter;
00128     }
00129 };
00130 #endif

Generated on Mon Jun 9 22:37:14 2008 for csql by  doxygen 1.4.7