reverting back the changes. causes core dump
[csql.git] / include / Field.h
blob224b1d873b6906a5c770b950f6896a1e081e1d80
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 isNullExplicit_ = false;
40 strcpy(fldName_, "");
42 char fldName_[IDENTIFIER_LENGTH];
43 DataType type_;
44 size_t length_;
45 size_t offset_;
46 //currently default value is supported for string and binary
47 //less than length 32 bytes
48 char defaultValueBuf_[DEFAULT_VALUE_BUF_LENGTH];
50 //used only in case of binding fields
51 void *bindVal_;
53 bool isNull_;
54 bool isPrimary_;
55 bool isDefault_;
56 bool isUnique_;
57 bool isAutoIncrement_;
58 bool isNullExplicit_; // if null is specified on default value field.
59 long long autoVal_;//[DEFAULT_VALUE_BUF_LENGTH];
60 //TODO::width and scale
63 class FieldNode
65 public:
66 FieldDef fldDef;
67 FieldNode *next;
71 class FieldIterator
73 public:
74 FieldNode *iter;
75 FieldIterator(FieldNode *ptr) { iter = ptr; }
76 bool hasElement()
78 if (iter == NULL) return false; else return true;
80 FieldDef* nextElement()
82 if (iter == NULL) { return NULL;}
83 FieldNode *node = iter;
84 iter = iter ->next;
85 return &(node->fldDef);
89 class FieldInfo;
91 //Internal class used to implement the field list information
92 //to create the table
93 class DllExport FieldList
95 public:
96 FieldNode *head;
97 FieldList(){ head = NULL;}
99 //TODO::pass by reference instead of value
100 DbRetVal append(FieldDef fDef);
102 DbRetVal remove(const char* fldName);
104 DbRetVal removeAll();
106 DbRetVal updateBindVal(const char *fldName, void *val, bool isNllEx=false);
107 void * getBindField(const char *fldName);
108 int getFieldOffset(const char *fldName);
109 int getFieldOffset(int fldpos);
111 //Returns position of field in the list:count starting from 1
112 int getFieldPosition(const char *fldName);
114 DataType getFieldType(const char *fldName);
116 size_t getFieldLength(const char *fldName);
118 DbRetVal getFieldInfo(const char *fldName, FieldInfo *&info);
119 void fillFieldInfo(int fldpos, void *info);
120 int size();
121 int getTupleSize();
123 FieldIterator getIterator()
125 FieldIterator iter(head);
126 return iter;
130 //The below struct should be same as Parser.h:FieldValue
131 //For performance reason and it is
132 //done such that storage does not have dependency on SQL
133 struct FieldInfoValue
135 char fldName[IDENTIFIER_LENGTH];
136 char *parsedString;
137 void *value;
138 int paramNo; // 0 ->not a param. It stores the param position
139 DataType type;
140 int aType; //assumes enum is always int
141 int length;
142 bool isNullable;
143 bool isAllocVal;
144 bool isInResSet;
146 size_t offset;
147 bool isPrimary;
148 bool isUnique;
149 bool isAutoIncrement;
152 #endif