*** empty log message ***
[csql.git] / include / Table.h
blob925ab2cd64ee1d46c8775ea396757f7069e4677e
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 trieIndexScan,
30 unknownScan
32 #define SCANTYPE
33 #endif
34 /**
35 * @class Table
37 * @brief Handle to the database table.
38 * Table is a set of data values organized using a model of horizontal rows and columns.<br>
39 * Columns are identified by name and rows by values. It shall be visualized as a linked <br/>
40 * list of related data<br/>
41 * Functionality: <br/>
42 * 1.insert <br/>
43 * 2.update <br/>
44 * 3.delete <br/>
45 * 4.select with predicate or condition<br/>
46 * <br/>
50 class FieldInfo;
51 class DllExport Table
53 public:
54 /** sets condition for the select, update and delete operations
55 * @param c condition
57 virtual void setCondition(Condition *c)=0;
59 /** binds application buffer to the specified field of the table.
60 * Before doing any DML operations required fields are binded first.
61 * Below are the candidates for this: <br/>
62 * 1.All the fields in the projection list of select statement. <br/>
63 * 2.Field list in the insert statement.<br/>
64 * 3.Fields in the assignment list of update statement.<br/>
65 * <br/>
66 * @param name field name in the table
67 * @param val address of the application buffer. Memory should be allocated by
68 * the application before binding the buffer.
71 virtual DbRetVal bindFld(const char *name, void *val,
72 bool isNullExpl=false)=0;
73 /** marks the specified field to insert null when insert method is called.
74 * @param name field name in the table
76 virtual void *getBindFldAddr(const char *name)=0;
77 virtual DbRetVal markFldNull(const char *name)=0;
78 /** marks the specified field to insert null when insert method is called.
79 * @param colpos field position
81 virtual DbRetVal markFldNull(int colpos)=0;
83 /** clears the null mark which is set before.
84 * @param name field name
86 virtual void clearFldNull(const char *name)=0;
88 /** clears the null mark which is set before.
89 * @param colpos field position
91 virtual void clearFldNull(int colpos)=0;
93 /** checks whether the field value is null.
94 * @param name field name
96 virtual bool isFldNull(const char *name)=0;
98 /** checks whether the field value is null for the specified field position.
99 * @param colpos field position
101 virtual bool isFldNull(int colpos)=0;
103 virtual void clearFldNull(const char *name)=0;
104 virtual void clearFldNull(int colpos) =0;
107 //DML operations
108 /** executes the select statement. Based on the predicate(condition), respective index is
109 * chosen for the select. Application should call execute before they start fetching
110 * the values from the table.This starts scan on the table.
111 * @returns DbRetVal
113 virtual DbRetVal execute()=0;
115 /** insert the tuple into the table. Prior to this, the binded buffer should be updated
116 * Values present in the binded buffers of all the fields are taken and stored in
117 * the table.<br/>
118 * @returns DbRetVal
120 virtual DbRetVal insertTuple()=0;
122 /**update values in the current tuple of the table. It works only on top of select
123 * using fetch go to the tuple to be updated, then update the binded buffer value and
124 * then call this method to updates the field values in the tuple.
125 * @returns DbRetVal
127 virtual DbRetVal updateTuple()=0;
129 /**deletes the current tuple of the table. It works only on top of select.
130 * using fetch first go to the tuple to be deleted, then call this method to delete.<br/>
131 * To delete all the tuples, do not set any condition and call fetch followed by delete
132 * in a loop till fetch exhausts.
133 * @returns DbRetVal
136 virtual DbRetVal deleteTuple()=0;
139 /**deletes all the records which satisfies the condition set.
140 * @returns int totalTuples deleted
143 virtual int deleteWhere()=0;
147 /**deletes the all the records in the table. No transaction required to call this.
148 * It takes table level lock.
149 * @returns DbRetVal
152 virtual int truncate()=0;
154 //scan
156 /**fetches the next tuple in the table which satisfies the condition specified.
157 * execute should be called before calling this method. Application buffer should be
158 * binded to get the tuple values.
159 * @returns void* NULL if there is no tuple.
161 virtual void* fetch()=0;
162 virtual void* fetch(DbRetVal &rv)=0;
164 /**fetches the next tuple in the table which satisfies the condition specified.
165 * execute should be called before calling this method. Application buffer need not be
166 * binded to call this method.
167 * @returns void* NULL if there is no tuple.
169 virtual void* fetchNoBind()=0;
170 virtual void* fetchNoBind(DbRetVal &rv)=0;
173 /**closes the scan. Needs to be called before calling execute again on the same table handle. It releases the resources
174 acquired during the scan.
175 * @returns DbRetVal
178 virtual DbRetVal close()=0;
179 virtual DbRetVal closeScan()=0;
181 /**Retrieves the total space used for this table in bytes
182 * @returns DbRetVal
184 virtual long spaceUsed()=0;
186 /**Retrieves the total number of tuples present in this table
187 * @returns DbRetVal
189 virtual long numTuples()=0;
191 /**takes lock on the table
192 * if bool shared flag is set, it will take shared lock, or else exclusive lock
193 * @returns DbRetVal
195 virtual DbRetVal lock(bool shared)=0;
197 /**releases the lock acquired on the table
198 * @returns DbRetVal
200 virtual DbRetVal unlock()=0;
202 /**sets the undo log flag. If this flag is unset then undo logs will not be generated
203 * @returns DbRetVal
205 virtual DbRetVal setUndoLogging(bool flag)=0;
207 virtual DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)=0;
208 virtual List getFieldNameList()=0;
209 virtual char* getName()=0;
210 virtual char* getAliasName()=0;
211 virtual void printSQLIndexString(FILE *fp=NULL, int fd=-1)=0;
212 virtual void printSQLForeignString()=0;
213 virtual DbRetVal compact()=0;
214 //optimizer
215 virtual DbRetVal optimize()=0;
216 virtual ScanType getScanType()=0;
217 virtual bool hasIndex(char *name)=0;
218 virtual bool isTableInvolved(char *tblName)=0;
219 virtual bool pushPredicate(Predicate *pred)=0;
220 virtual void setPredicate(Predicate *pred)=0;
221 virtual void printPlan(int space)=0;
222 virtual void addPredicate(char *fname, ComparisionOp op, void *buf)
223 { return; }
224 virtual bool isFKTable()=0;
225 virtual void resetNullinfo()=0;
226 virtual int getFldPos(char *name)=0;
227 virtual ~Table() { }
229 virtual void setLoading(bool flag){};
231 //non virtual functions
232 static void getFieldNameAlone(char *fname, char *name);
233 static void getTableNameAlone(char *fname, char *name);
236 #endif