changing file creation mode from 777 to 644
[csql.git] / include / Field.h
blobcac5bec40c37840844a741209ce26d443d8cab43
1 /***************************************************************************
2 * *
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
4 * *
5 ***************************************************************************/
7 #ifndef FIELD_H
8 #define FIELD_H
9 #include<os.h>
10 #include<DataType.h>
11 #include<ErrorType.h>
13 //used by FieldNameList
14 class FieldNameNode
16 public:
17 char fldName[IDENTIFIER_LENGTH];
18 FieldNameNode *next;
22 class FieldDef
24 public:
25 FieldDef()
27 init();
29 void init() {
30 type_ = typeUnknown;
31 length_ = 0;
32 offset_ = 0;
33 bindVal_ = NULL;
34 isDefault_ = false;
35 isNull_ = false;
36 isPrimary_ = false;
37 isUnique_ = false;
38 isAutoIncrement_=false;
39 strcpy(fldName_, "");
41 char fldName_[IDENTIFIER_LENGTH];
42 DataType type_;
43 size_t length_;
44 size_t offset_;
45 //currently default value is supported for string and binary
46 //less than length 32 bytes
47 char defaultValueBuf_[DEFAULT_VALUE_BUF_LENGTH];
49 //used only in case of binding fields
50 void *bindVal_;
52 bool isNull_;
53 bool isPrimary_;
54 bool isDefault_;
55 bool isUnique_;
56 bool isAutoIncrement_;
57 long long autoVal_;//[DEFAULT_VALUE_BUF_LENGTH];
58 //TODO::width and scale
61 class FieldNode
63 public:
64 FieldDef fldDef;
65 FieldNode *next;
69 class FieldIterator
71 public:
72 FieldNode *iter;
73 FieldIterator(FieldNode *ptr) { iter = ptr; }
74 bool hasElement()
76 if (iter == NULL) return false; else return true;
78 FieldDef* nextElement()
80 if (iter == NULL) { return NULL;}
81 FieldNode *node = iter;
82 iter = iter ->next;
83 return &(node->fldDef);
87 class FieldInfo;
89 //Internal class used to implement the field list information
90 //to create the table
91 class FieldList
93 public:
94 FieldNode *head;
95 FieldList(){ head = NULL;}
97 //TODO::pass by reference instead of value
98 DbRetVal append(FieldDef fDef);
100 DbRetVal remove(const char* fldName);
102 DbRetVal removeAll();
104 DbRetVal updateBindVal(const char *fldName, void *val);
105 void * getBindField(const char *fldName);
106 int getFieldOffset(const char *fldName);
107 int getFieldOffset(int fldpos);
109 //Returns position of field in the list:count starting from 1
110 int getFieldPosition(const char *fldName);
112 DataType getFieldType(const char *fldName);
114 size_t getFieldLength(const char *fldName);
116 DbRetVal getFieldInfo(const char *fldName, FieldInfo *&info);
117 void fillFieldInfo(int fldpos, void *info);
118 int size();
119 int getTupleSize();
121 FieldIterator getIterator()
123 FieldIterator iter(head);
124 return iter;
128 //The below struct should be same as Parser.h:FieldValue
129 //For performance reason and it is
130 //done such that storage does not have dependency on SQL
131 struct FieldInfoValue
133 char fldName[IDENTIFIER_LENGTH];
134 char *parsedString;
135 void *value;
136 int paramNo; // 0 ->not a param. It stores the param position
137 DataType type;
138 int aType; //assumes enum is always int
139 int length;
140 bool isNullable;
141 bool isAllocVal;
142 bool isInResSet;
144 size_t offset;
145 bool isPrimary;
146 bool isUnique;
147 bool isAutoIncrement;
150 #endif