changing file creation mode from 777 to 644
[csql.git] / include / Table.h
blob0cb9af05279dc4ef0cc266121e13a3ec8b442a99
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 TABLE_H
17 #define TABLE_H
18 #include<ErrorType.h>
19 #include<Util.h>
20 #include<DataType.h>
21 class Predicate;
22 class Condition;
23 #ifndef SCANTYPE
24 enum ScanType
26 fullTableScan = 0,
27 hashIndexScan,
28 treeIndexScan,
29 unknownScan
31 #define SCANTYPE
32 #endif
33 /**
34 * @class Table
36 * @brief Handle to the database table.
37 * Table is a set of data values organized using a model of horizontal rows and columns.<br>
38 * Columns are identified by name and rows by values. It shall be visualized as a linked <br/>
39 * list of related data<br/>
40 * Functionality: <br/>
41 * 1.insert <br/>
42 * 2.update <br/>
43 * 3.delete <br/>
44 * 4.select with predicate or condition<br/>
45 * <br/>
49 class FieldInfo;
50 class Table
52 public:
53 /** sets condition for the select, update and delete operations
54 * @param c condition
56 virtual void setCondition(Condition *c)=0;
58 /** binds application buffer to the specified field of the table.
59 * Before doing any DML operations required fields are binded first.
60 * Below are the candidates for this: <br/>
61 * 1.All the fields in the projection list of select statement. <br/>
62 * 2.Field list in the insert statement.<br/>
63 * 3.Fields in the assignment list of update statement.<br/>
64 * <br/>
65 * @param name field name in the table
66 * @param val address of the application buffer. Memory should be allocated by
67 * the application before binding the buffer.
70 virtual DbRetVal bindFld(const char *name, void *val)=0;
71 /** marks the specified field to insert null when insert method is called.
72 * @param name field name in the table
74 virtual void *getBindFldAddr(const char *name)=0;
75 virtual DbRetVal markFldNull(const char *name)=0;
76 /** marks the specified field to insert null when insert method is called.
77 * @param colpos field position
79 virtual DbRetVal markFldNull(int colpos)=0;
81 /** clears the null mark which is set before.
82 * @param name field name
84 virtual void clearFldNull(const char *name)=0;
86 /** clears the null mark which is set before.
87 * @param colpos field position
89 virtual void clearFldNull(int colpos)=0;
91 /** checks whether the field value is null.
92 * @param name field name
94 virtual bool isFldNull(const char *name)=0;
96 /** checks whether the field value is null for the specified field position.
97 * @param colpos field position
99 virtual bool isFldNull(int colpos)=0;
101 virtual void clearFldNull(const char *name)=0;
102 virtual void clearFldNull(int colpos) =0;
105 //DML operations
106 /** executes the select statement. Based on the predicate(condition), respective index is
107 * chosen for the select. Application should call execute before they start fetching
108 * the values from the table.This starts scan on the table.
109 * @returns DbRetVal
111 virtual DbRetVal execute()=0;
113 /** insert the tuple into the table. Prior to this, the binded buffer should be updated
114 * Values present in the binded buffers of all the fields are taken and stored in
115 * the table.<br/>
116 * @returns DbRetVal
118 virtual DbRetVal insertTuple()=0;
120 /**update values in the current tuple of the table. It works only on top of select
121 * using fetch go to the tuple to be updated, then update the binded buffer value and
122 * then call this method to updates the field values in the tuple.
123 * @returns DbRetVal
125 virtual DbRetVal updateTuple()=0;
127 /**deletes the current tuple of the table. It works only on top of select.
128 * using fetch first go to the tuple to be deleted, then call this method to delete.<br/>
129 * To delete all the tuples, do not set any condition and call fetch followed by delete
130 * in a loop till fetch exhausts.
131 * @returns DbRetVal
134 virtual DbRetVal deleteTuple()=0;
137 /**deletes all the records which satisfies the condition set.
138 * @returns int totalTuples deleted
141 virtual int deleteWhere()=0;
145 /**deletes the all the records in the table. No transaction required to call this.
146 * It takes table level lock.
147 * @returns DbRetVal
150 virtual int truncate()=0;
152 //scan
154 /**fetches the next tuple in the table which satisfies the condition specified.
155 * execute should be called before calling this method. Application buffer should be
156 * binded to get the tuple values.
157 * @returns void* NULL if there is no tuple.
159 virtual void* fetch()=0;
160 virtual void* fetch(DbRetVal &rv)=0;
162 /**fetches the next tuple in the table which satisfies the condition specified.
163 * execute should be called before calling this method. Application buffer need not be
164 * binded to call this method.
165 * @returns void* NULL if there is no tuple.
167 virtual void* fetchNoBind()=0;
168 virtual void* fetchNoBind(DbRetVal &rv)=0;
171 /**closes the scan. Needs to be called before calling execute again on the same table handle. It releases the resources
172 acquired during the scan.
173 * @returns DbRetVal
176 virtual DbRetVal close()=0;
177 virtual DbRetVal closeScan()=0;
179 /**Retrieves the total space used for this table in bytes
180 * @returns DbRetVal
182 virtual long spaceUsed()=0;
184 /**Retrieves the total number of tuples present in this table
185 * @returns DbRetVal
187 virtual long numTuples()=0;
189 /**takes lock on the table
190 * if bool shared flag is set, it will take shared lock, or else exclusive lock
191 * @returns DbRetVal
193 virtual DbRetVal lock(bool shared)=0;
195 /**releases the lock acquired on the table
196 * @returns DbRetVal
198 virtual DbRetVal unlock()=0;
200 /**sets the undo log flag. If this flag is unset then undo logs will not be generated
201 * @returns DbRetVal
203 virtual DbRetVal setUndoLogging(bool flag)=0;
205 virtual DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)=0;
206 virtual List getFieldNameList()=0;
207 virtual char* getName()=0;
208 virtual char* getAliasName()=0;
209 virtual void printSQLIndexString(FILE *fp=NULL, int fd=-1)=0;
210 virtual void printSQLForeignString()=0;
211 virtual DbRetVal compact()=0;
212 //optimizer
213 virtual DbRetVal optimize()=0;
214 virtual ScanType getScanType()=0;
215 virtual bool hasIndex(char *name)=0;
216 virtual bool isTableInvolved(char *tblName)=0;
217 virtual bool pushPredicate(Predicate *pred)=0;
218 virtual void setPredicate(Predicate *pred)=0;
219 virtual void printPlan(int space)=0;
220 virtual void addPredicate(char *fname, ComparisionOp op, void *buf)
221 { return; }
222 virtual bool isFKTable()=0;
223 virtual void resetNullinfo()=0;
224 virtual int getFldPos(char *name)=0;
225 virtual ~Table() { }
227 virtual void setLoading(bool flag){};
229 //non virtual functions
230 static void getFieldNameAlone(char *fname, char *name);
231 static void getTableNameAlone(char *fname, char *name);
234 #endif