using tree index
[csql.git] / include / Table.h
blob5b0abaf8ca4091a8663433f9f8785867bb9fcf41
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 class Predicate;
21 class Condition;
22 /**
23 * @class Table
25 * @brief Handle to the database table.
26 * Table is a set of data values organized using a model of horizontal rows and columns.<br>
27 * Columns are identified by name and rows by values. It shall be visualized as a linked <br/>
28 * list of related data<br/>
29 * Functionality: <br/>
30 * 1.insert <br/>
31 * 2.update <br/>
32 * 3.delete <br/>
33 * 4.select with predicate or condition<br/>
34 * <br/>
38 class FieldInfo;
39 class Table
41 public:
42 /** sets condition for the select, update and delete operations
43 * @param c condition
45 virtual void setCondition(Condition *c)=0;
47 /** binds application buffer to the specified field of the table.
48 * Before doing any DML operations required fields are binded first.
49 * Below are the candidates for this: <br/>
50 * 1.All the fields in the projection list of select statement. <br/>
51 * 2.Field list in the insert statement.<br/>
52 * 3.Fields in the assignment list of update statement.<br/>
53 * <br/>
54 * @param name field name in the table
55 * @param val address of the application buffer. Memory should be allocated by
56 * the application before binding the buffer.
59 virtual DbRetVal bindFld(const char *name, void *val)=0;
60 /** marks the specified field to insert null when insert method is called.
61 * @param name field name in the table
63 virtual void *getBindFldAddr(const char *name)=0;
64 virtual void markFldNull(const char *name)=0;
65 /** marks the specified field to insert null when insert method is called.
66 * @param colpos field position
68 virtual void markFldNull(int colpos)=0;
70 /** clears the null mark which is set before.
71 * @param name field name
73 virtual void clearFldNull(const char *name)=0;
75 /** clears the null mark which is set before.
76 * @param colpos field position
78 virtual void clearFldNull(int colpos)=0;
80 /** checks whether the field value is null.
81 * @param name field name
83 virtual bool isFldNull(const char *name)=0;
85 /** checks whether the field value is null for the specified field position.
86 * @param colpos field position
88 virtual bool isFldNull(int colpos)=0;
90 virtual void clearFldNull(const char *name)=0;
91 virtual void clearFldNull(int colpos) =0;
94 //DML operations
95 /** executes the select statement. Based on the predicate(condition), respective index is
96 * chosen for the select. Application should call execute before they start fetching
97 * the values from the table.This starts scan on the table.
98 * @returns DbRetVal
100 virtual DbRetVal execute()=0;
102 /** insert the tuple into the table. Prior to this, the binded buffer should be updated
103 * Values present in the binded buffers of all the fields are taken and stored in
104 * the table.<br/>
105 * @returns DbRetVal
107 virtual DbRetVal insertTuple()=0;
109 /**update values in the current tuple of the table. It works only on top of select
110 * using fetch go to the tuple to be updated, then update the binded buffer value and
111 * then call this method to updates the field values in the tuple.
112 * @returns DbRetVal
114 virtual DbRetVal updateTuple()=0;
116 /**deletes the current tuple of the table. It works only on top of select.
117 * using fetch first go to the tuple to be deleted, then call this method to delete.<br/>
118 * To delete all the tuples, do not set any condition and call fetch followed by delete
119 * in a loop till fetch exhausts.
120 * @returns DbRetVal
123 virtual DbRetVal deleteTuple()=0;
126 /**deletes all the records which satisfies the condition set.
127 * @returns int totalTuples deleted
130 virtual int deleteWhere()=0;
134 /**deletes the all the records in the table. No transaction required to call this.
135 * It takes table level lock.
136 * @returns DbRetVal
139 virtual int truncate()=0;
143 //scan
145 /**fetches the next tuple in the table which satisfies the condition specified.
146 * execute should be called before calling this method. Application buffer should be
147 * binded to get the tuple values.
148 * @returns void* NULL if there is no tuple.
150 virtual void* fetch()=0;
151 virtual void* fetch(DbRetVal &rv)=0;
153 /**fetches the next tuple in the table which satisfies the condition specified.
154 * execute should be called before calling this method. Application buffer need not be
155 * binded to call this method.
156 * @returns void* NULL if there is no tuple.
158 virtual void* fetchNoBind()=0;
159 virtual void* fetchNoBind(DbRetVal &rv)=0;
162 /**closes the scan. Needs to be called before calling execute again on the same table handle. It releases the resources
163 acquired during the scan.
164 * @returns DbRetVal
167 virtual DbRetVal close()=0;
169 /**Retrieves the total space used for this table in bytes
170 * @returns DbRetVal
172 virtual long spaceUsed()=0;
174 /**Retrieves the total number of tuples present in this table
175 * @returns DbRetVal
177 virtual long numTuples()=0;
179 /**takes lock on the table
180 * if bool shared flag is set, it will take shared lock, or else exclusive lock
181 * @returns DbRetVal
183 virtual DbRetVal lock(bool shared)=0;
185 /**releases the lock acquired on the table
186 * @returns DbRetVal
188 virtual DbRetVal unlock()=0;
190 /**sets the undo log flag. If this flag is unset then undo logs will not be generated
191 * @returns DbRetVal
193 virtual DbRetVal setUndoLogging(bool flag)=0;
195 virtual DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)=0;
196 virtual List getFieldNameList()=0;
197 virtual char* getName()=0;
198 virtual void printSQLIndexString()=0;
200 virtual ~Table() { }
202 #endif