windows changes
[csql.git] / include / Info.h
blobc5101c3836fd6331d5ff275649dcdd41465ad19a
1 /***************************************************************************
2 * *
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
4 * *
5 ***************************************************************************/
7 #ifndef INFO_H
8 #define INFO_H
9 #include<ErrorType.h>
10 #include<DataType.h>
11 #include<Field.h>
13 #ifndef AGGTYPE
14 enum AggType
16 AGG_MIN = 1,
17 AGG_MAX,
18 AGG_SUM,
19 AGG_AVG,
20 AGG_COUNT,
21 AGG_UNKNOWN
23 #define AGGTYPE
24 #endif
26 struct IndexInfoForDriver
28 char tableName[IDENTIFIER_LENGTH];
29 char fieldName[IDENTIFIER_LENGTH];
30 char indexName[IDENTIFIER_LENGTH];
31 int type;
32 int position;
33 int pageUsed;
34 bool isUnique;
35 bool isPrimary;
38 class DataTypeInfo
40 public:
41 char name[IDENTIFIER_LENGTH];
42 int type;
43 int precision;
44 bool autoIncrement;
47 class ForeignKeyMetadata
49 public:
50 char pkTableName[IDENTIFIER_LENGTH];
51 char pkColName[IDENTIFIER_LENGTH];
52 char fkTableName[IDENTIFIER_LENGTH];
53 char fkColName[IDENTIFIER_LENGTH];
54 short keySeq;
55 short updateRule;
56 short deleteRule;
59 enum ResultSetPlan
61 Normal = 0,
62 GetTables,
63 GetColumns,
64 GetIndexes,
65 GetPriIndex,
66 GetCatalogs,
67 GetTableType,
68 GetDataType,
69 GetImportKey,
70 GetExportKey
73 class FieldNameNode;
75 /**
76 * @class FieldNameList
78 * @brief Field name list used to specify composite key while creating index. <br/>
81 class DllExport FieldNameList
83 FieldNameNode *head;
84 FieldNameNode *iter;
85 public:
86 FieldNameList() { head = iter = NULL; }
87 ~FieldNameList() { } //TODO::Remove all elements from the list
88 char *nextFieldName();
89 void resetIter(){ iter = head; }
90 int size();
92 /** appends field name to the list
93 * @param name field name
94 * @return int
96 DbRetVal append(const char *name);
98 /** removes field name from the list
99 * @param name field name
100 * @return int
102 DbRetVal remove(const char *name);
103 DbRetVal removeAll();
106 class FieldList;
107 class FieldIterator;
111 * @class TableDef
113 * @brief Represents table definition used to create the table.
114 * Encapsulates the information or schema definition of a table.For Example say if <br/>
115 * we need to create table with two fields, call addField method with necessary parameters<br/>
116 * twice. Passed as argument to createTable method of DatabaseManager to create table.<br/>
119 class DllExport TableDef
121 private:
122 FieldList fldList;
123 int fldCount;
124 public:
125 TableDef() { fldCount = 0; }
126 ~TableDef();
127 void reset();
128 /** adds a field to the schema definition.
129 * @param name field name
130 * @param type data type of the field
131 * @param length size of the field. used in case of char and binary data types.
132 * @param defaultValue default value for the field. It is currently limited to 32 bytes.
133 * @param isPrimary whether the field is primary key( not null + unique)
134 * @param notNull whether the field can be null
135 * @param unique whether the field values are unique
136 * @return int
138 int addField(const char *name, DataType type = typeUnknown, size_t
139 length = 0, const void *defaultValue = 0,
140 bool notNull = false, bool autoIn = false);
142 /** removes a field from the schema definition
143 * @param name field name
144 * @return int
146 int dropField(const char *name);
148 /** returns the total number of fields in this table definition
149 * @return int no of fields
151 int getFieldCount();
153 /** returns the total tuple size in bytes.
154 * @return size_t tuple size
156 size_t getTupleSize();
158 //Internal method used to iterate and get information stored
159 //in this table definition.
160 FieldIterator getFieldIterator(){ return fldList.getIterator(); }
161 bool isVarcharPresentInSchema(FieldIterator &iter);
164 class DllExport FieldInfo
166 public:
167 char fldName[IDENTIFIER_LENGTH];
168 DataType type;
169 size_t length;
170 size_t offset;
171 char defaultValueBuf[DEFAULT_VALUE_BUF_LENGTH];
172 AggType aType;
173 bool isNull;
174 bool isPrimary;
175 bool isDefault;
176 bool isUnique;
177 bool isAutoIncrement;
178 FieldInfo()
180 fldName[0] = '\0'; type = typeUnknown; length = 0; offset = 0;
181 defaultValueBuf[0]='\0'; aType = AGG_UNKNOWN; isNull = false;
182 isPrimary = isDefault = isUnique = isAutoIncrement = false;
188 /** A Enum value
190 enum IndexType
192 hashIndex = 0, /**<hash index*/
193 treeIndex, /**<tree index*/
194 trieIndex, /**<trie index*/
195 unknownIndex /**<no index*/
199 * @class IndexInitInfo
201 * @brief Represents index definition used to create index.
202 * Encapsulates the information or definition of an index.<br/>
205 class IndexInitInfo
207 public:
208 char tableName[IDENTIFIER_LENGTH]; /**<tablename*/
209 FieldNameList list; /**<field name list*/
210 IndexType indType; /**<index type*/
211 bool isUnique; /**<unique values*/
212 bool isPrimary; /**<primary key*/
213 IndexInitInfo() { indType = hashIndex; isUnique = false; isPrimary= false;}
214 ~IndexInitInfo() {list.removeAll();}
218 * @class HashIndexInitInfo
220 * @brief Represents hash index definition used to create index.
221 * Encapsulates the information or definition of hash index.<br/>
224 class HashIndexInitInfo : public IndexInitInfo
226 public:
227 int bucketSize; /**<bucket size*/
228 HashIndexInitInfo() { bucketSize = 1009; }
231 class ForeignKeyInfo
233 public:
234 ForeignKeyInfo(){}
235 char pkTableName[IDENTIFIER_LENGTH];
236 char fkTableName[IDENTIFIER_LENGTH];
237 FieldNameList fkFldList;
238 FieldNameList pkFldList;
240 #endif