*** empty log message ***
[csql.git] / include / Field.h
blob2e7c477a69edfc6fcffd3a1e050ff87faff1c172
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 offset_ = 0;
42 bindVal_ = NULL;
43 isDefault_ = false;
44 isNull_ = false;
45 isPrimary_ = false;
46 isUnique_ = false;
47 strcpy(fldName_, "");
49 char fldName_[IDENTIFIER_LENGTH];
50 DataType type_;
51 size_t length_;
52 size_t offset_;
53 //currently default value is supported for string and binary
54 //less than length 32 bytes
55 char defaultValueBuf_[DEFAULT_VALUE_BUF_LENGTH];
57 //used only in case of binding fields
58 void *bindVal_;
60 bool isNull_;
61 bool isPrimary_;
62 bool isDefault_;
63 bool isUnique_;
64 //TODO::width and scale
67 class FieldNode
69 public:
70 FieldDef fldDef;
71 FieldNode *next;
75 class FieldIterator
77 public:
78 FieldNode *iter;
79 FieldIterator(FieldNode *ptr) { iter = ptr; }
80 bool hasElement()
82 if (iter == NULL) return false; else return true;
84 FieldDef* nextElement()
86 if (iter == NULL) { return NULL;}
87 FieldNode *node = iter;
88 iter = iter ->next;
89 return &(node->fldDef);
93 class FieldInfo;
95 //Internal class used to implement the field list information
96 //to create the table
97 class FieldList
99 public:
100 FieldNode *head;
101 FieldList(){ head = NULL;}
103 //TODO::pass by reference instead of value
104 DbRetVal append(FieldDef fDef);
106 DbRetVal remove(const char* fldName);
108 DbRetVal removeAll();
110 DbRetVal updateBindVal(const char *fldName, void *val);
111 void * getBindField(const char *fldName);
112 int getFieldOffset(const char *fldName);
113 int getFieldOffset(int fldpos);
115 //Returns position of field in the list:count starting from 1
116 int getFieldPosition(const char *fldName);
118 DataType getFieldType(const char *fldName);
120 size_t getFieldLength(const char *fldName);
122 DbRetVal getFieldInfo(const char *fldName, FieldInfo *&info);
124 int getTupleSize();
126 FieldIterator getIterator()
128 FieldIterator iter(head);
129 return iter;
132 #endif