using tree index
[csql.git] / include / Info.h
blob7d11a66183dd8feca95aeb4ddeb7e28ff5ea84a1
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 INFO_H
17 #define INFO_H
18 #include<ErrorType.h>
19 #include<DataType.h>
20 #include<Field.h>
23 class FieldNameNode;
25 /**
26 * @class FieldNameList
28 * @brief Field name list used to specify composite key while creating index. <br/>
31 class FieldNameList
33 FieldNameNode *head;
34 FieldNameNode *iter;
35 public:
36 FieldNameList() { head = iter = NULL; }
37 ~FieldNameList() { } //TODO::Remove all elements from the list
38 char *nextFieldName();
39 void resetIter(){ iter = head; }
40 int size();
42 /** appends field name to the list
43 * @param name field name
44 * @return int
46 DbRetVal append(const char *name);
48 /** removes field name from the list
49 * @param name field name
50 * @return int
52 DbRetVal remove(const char *name);
53 DbRetVal removeAll();
56 class FieldList;
57 class FieldIterator;
60 /**
61 * @class TableDef
63 * @brief Represents table definition used to create the table.
64 * Encapsulates the information or schema definition of a table.For Example say if <br/>
65 * we need to create table with two fields, call addField method with necessary parameters<br/>
66 * twice. Passed as argument to createTable method of DatabaseManager to create table.<br/>
69 class TableDef
71 private:
72 FieldList fldList;
73 int fldCount;
75 public:
76 TableDef() { fldCount = 0; }
77 ~TableDef();
78 void reset();
79 /** adds a field to the schema definition.
80 * @param name field name
81 * @param type data type of the field
82 * @param length size of the field. used in case of char and binary data types.
83 * @param defaultValue default value for the field. It is currently limited to 32 bytes.
84 * @param isPrimary whether the field is primary key( not null + unique)
85 * @param notNull whether the field can be null
86 * @param unique whether the field values are unique
87 * @return int
89 int addField(const char *name, DataType type = typeUnknown, size_t
90 length = 0, const void *defaultValue = 0,
91 bool notNull = false);
93 /** removes a field from the schema definition
94 * @param name field name
95 * @return int
97 int dropField(const char *name);
99 /** returns the total number of fields in this table definition
100 * @return int no of fields
102 int getFieldCount();
104 /** returns the total tuple size in bytes.
105 * @return size_t tuple size
107 size_t getTupleSize();
109 //Internal method used to iterate and get information stored
110 //in this table definition.
111 FieldIterator getFieldIterator(){ return fldList.getIterator(); }
115 class FieldInfo
117 public:
118 char fldName[IDENTIFIER_LENGTH];
119 DataType type;
120 size_t length;
121 int offset;
122 char defaultValueBuf[DEFAULT_VALUE_BUF_LENGTH];
123 bool isNull;
124 bool isPrimary;
125 bool isDefault;
130 /** A Enum value
132 enum IndexType
134 hashIndex = 0, /**<hash index*/
135 treeIndex /**<tree index*/
139 * @class IndexInitInfo
141 * @brief Represents index definition used to create index.
142 * Encapsulates the information or definition of an index.<br/>
145 class IndexInitInfo
147 public:
148 char tableName[IDENTIFIER_LENGTH]; /**<tablename*/
149 FieldNameList list; /**<field name list*/
150 IndexType indType; /**<index type*/
151 bool isUnique; /**<unique values*/
152 bool isPrimary; /**<primary key*/
153 IndexInitInfo() { indType = hashIndex; isUnique = false; isPrimary= false;}
154 ~IndexInitInfo() {list.removeAll();}
158 * @class HashIndexInitInfo
160 * @brief Represents hash index definition used to create index.
161 * Encapsulates the information or definition of hash index.<br/>
164 class HashIndexInitInfo : public IndexInitInfo
166 public:
167 int bucketSize; /**<bucket size*/
168 HashIndexInitInfo() { bucketSize = 1009; }
170 #endif