windows porting first phase- ported os layer, storage module to windows
[csql.git] / include / Table.h
blob5e662041819c1cbdc16dfc290dbdbdbafb345d41
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 DllExport 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,
71 bool isNullExpl=false)=0;
72 /** marks the specified field to insert null when insert method is called.
73 * @param name field name in the table
75 virtual void *getBindFldAddr(const char *name)=0;
76 virtual DbRetVal markFldNull(const char *name)=0;
77 /** marks the specified field to insert null when insert method is called.
78 * @param colpos field position
80 virtual DbRetVal markFldNull(int colpos)=0;
82 /** clears the null mark which is set before.
83 * @param name field name
85 virtual void clearFldNull(const char *name)=0;
87 /** clears the null mark which is set before.
88 * @param colpos field position
90 virtual void clearFldNull(int colpos)=0;
92 /** checks whether the field value is null.
93 * @param name field name
95 virtual bool isFldNull(const char *name)=0;
97 /** checks whether the field value is null for the specified field position.
98 * @param colpos field position
100 virtual bool isFldNull(int colpos)=0;
102 virtual void clearFldNull(const char *name)=0;
103 virtual void clearFldNull(int colpos) =0;
106 //DML operations
107 /** executes the select statement. Based on the predicate(condition), respective index is
108 * chosen for the select. Application should call execute before they start fetching
109 * the values from the table.This starts scan on the table.
110 * @returns DbRetVal
112 virtual DbRetVal execute()=0;
114 /** insert the tuple into the table. Prior to this, the binded buffer should be updated
115 * Values present in the binded buffers of all the fields are taken and stored in
116 * the table.<br/>
117 * @returns DbRetVal
119 virtual DbRetVal insertTuple()=0;
121 /**update values in the current tuple of the table. It works only on top of select
122 * using fetch go to the tuple to be updated, then update the binded buffer value and
123 * then call this method to updates the field values in the tuple.
124 * @returns DbRetVal
126 virtual DbRetVal updateTuple()=0;
128 /**deletes the current tuple of the table. It works only on top of select.
129 * using fetch first go to the tuple to be deleted, then call this method to delete.<br/>
130 * To delete all the tuples, do not set any condition and call fetch followed by delete
131 * in a loop till fetch exhausts.
132 * @returns DbRetVal
135 virtual DbRetVal deleteTuple()=0;
138 /**deletes all the records which satisfies the condition set.
139 * @returns int totalTuples deleted
142 virtual int deleteWhere()=0;
146 /**deletes the all the records in the table. No transaction required to call this.
147 * It takes table level lock.
148 * @returns DbRetVal
151 virtual int truncate()=0;
153 //scan
155 /**fetches the next tuple in the table which satisfies the condition specified.
156 * execute should be called before calling this method. Application buffer should be
157 * binded to get the tuple values.
158 * @returns void* NULL if there is no tuple.
160 virtual void* fetch()=0;
161 virtual void* fetch(DbRetVal &rv)=0;
163 /**fetches the next tuple in the table which satisfies the condition specified.
164 * execute should be called before calling this method. Application buffer need not be
165 * binded to call this method.
166 * @returns void* NULL if there is no tuple.
168 virtual void* fetchNoBind()=0;
169 virtual void* fetchNoBind(DbRetVal &rv)=0;
172 /**closes the scan. Needs to be called before calling execute again on the same table handle. It releases the resources
173 acquired during the scan.
174 * @returns DbRetVal
177 virtual DbRetVal close()=0;
178 virtual DbRetVal closeScan()=0;
180 /**Retrieves the total space used for this table in bytes
181 * @returns DbRetVal
183 virtual long spaceUsed()=0;
185 /**Retrieves the total number of tuples present in this table
186 * @returns DbRetVal
188 virtual long numTuples()=0;
190 /**takes lock on the table
191 * if bool shared flag is set, it will take shared lock, or else exclusive lock
192 * @returns DbRetVal
194 virtual DbRetVal lock(bool shared)=0;
196 /**releases the lock acquired on the table
197 * @returns DbRetVal
199 virtual DbRetVal unlock()=0;
201 /**sets the undo log flag. If this flag is unset then undo logs will not be generated
202 * @returns DbRetVal
204 virtual DbRetVal setUndoLogging(bool flag)=0;
206 virtual DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)=0;
207 virtual List getFieldNameList()=0;
208 virtual char* getName()=0;
209 virtual char* getAliasName()=0;
210 virtual void printSQLIndexString(FILE *fp=NULL, int fd=-1)=0;
211 virtual void printSQLForeignString()=0;
212 virtual DbRetVal compact()=0;
213 //optimizer
214 virtual DbRetVal optimize()=0;
215 virtual ScanType getScanType()=0;
216 virtual bool hasIndex(char *name)=0;
217 virtual bool isTableInvolved(char *tblName)=0;
218 virtual bool pushPredicate(Predicate *pred)=0;
219 virtual void setPredicate(Predicate *pred)=0;
220 virtual void printPlan(int space)=0;
221 virtual void addPredicate(char *fname, ComparisionOp op, void *buf)
222 { return; }
223 virtual bool isFKTable()=0;
224 virtual void resetNullinfo()=0;
225 virtual int getFldPos(char *name)=0;
226 virtual ~Table() { }
228 virtual void setLoading(bool flag){};
230 //non virtual functions
231 static void getFieldNameAlone(char *fname, char *name);
232 static void getTableNameAlone(char *fname, char *name);
235 #endif