using tree index
[csql.git] / include / Field.h
blob7436fad2f0cb4ad5c9596fa90e2c494922820759
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #ifndef FIELD_H
17 #define FIELD_H
18 #include<os.h>
19 #include<DataType.h>
20 #include<ErrorType.h>
22 //used by FieldNameList
23 class FieldNameNode
25 public:
26 char fldName[IDENTIFIER_LENGTH];
27 FieldNameNode *next;
31 class FieldDef
33 public:
34 FieldDef()
36 init();
38 void init() {
39 type_ = typeUnknown;
40 length_ = 0;
41 bindVal_ = NULL;
42 isDefault_ = false;
43 isNull_ = false;
44 isPrimary_ = false;
45 isUnique_ = false;
46 strcpy(fldName_, "");
48 char fldName_[IDENTIFIER_LENGTH];
49 DataType type_;
50 size_t length_;
51 //currently default value is supported for string and binary
52 //less than length 32 bytes
53 char defaultValueBuf_[DEFAULT_VALUE_BUF_LENGTH];
55 //used only in case of binding fields
56 void *bindVal_;
58 bool isNull_;
59 bool isPrimary_;
60 bool isDefault_;
61 bool isUnique_;
62 //TODO::width and scale
65 class FieldNode
67 public:
68 FieldDef fldDef;
69 FieldNode *next;
73 class FieldIterator
75 public:
76 FieldNode *iter;
77 FieldIterator(FieldNode *ptr) { iter = ptr; }
78 bool hasElement()
80 if (iter == NULL) return false; else return true;
82 FieldDef nextElement()
84 if (iter == NULL) { FieldDef dummyDef; return dummyDef;}
85 FieldNode *node = iter;
86 iter = iter ->next;
87 return node->fldDef;
91 class FieldInfo;
93 //Internal class used to implement the field list information
94 //to create the table
95 class FieldList
97 public:
98 FieldNode *head;
99 FieldList(){ head = NULL;}
101 //TODO::pass by reference instead of value
102 DbRetVal append(FieldDef fDef);
104 DbRetVal remove(const char* fldName);
106 DbRetVal removeAll();
108 DbRetVal updateBindVal(const char *fldName, void *val);
109 void * getBindField(const char *fldName);
110 int getFieldOffset(const char *fldName);
111 int getFieldOffset(int fldpos);
113 //Returns position of field in the list:count starting from 1
114 int getFieldPosition(const char *fldName);
116 DataType getFieldType(const char *fldName);
118 size_t getFieldLength(const char *fldName);
120 DbRetVal getFieldInfo(const char *fldName, FieldInfo *&info);
122 int getTupleSize();
124 FieldIterator getIterator()
126 FieldIterator iter(head);
127 return iter;
130 #endif