1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
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. *
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. *
15 ***************************************************************************/
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/>
44 * 4.select with predicate or condition<br/>
53 /** sets condition for the select, update and delete operations
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/>
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;
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.
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
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.
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.
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.
150 virtual int truncate()=0;
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.
176 virtual DbRetVal
close()=0;
177 virtual DbRetVal
closeScan()=0;
179 /**Retrieves the total space used for this table in bytes
182 virtual long spaceUsed()=0;
184 /**Retrieves the total number of tuples present in this table
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
193 virtual DbRetVal
lock(bool shared
)=0;
195 /**releases the lock acquired on the table
198 virtual DbRetVal
unlock()=0;
200 /**sets the undo log flag. If this flag is unset then undo logs will not be generated
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 void printSQLIndexString()=0;
211 virtual DbRetVal
optimize()=0;
212 virtual ScanType
getScanType()=0;
213 virtual bool hasIndex(char *name
)=0;
214 virtual bool isTableInvolved(char *tblName
)=0;
215 virtual bool pushPredicate(Predicate
*pred
)=0;
216 virtual void setPredicate(Predicate
*pred
)=0;
217 virtual void printPlan(int space
)=0;
218 virtual void addPredicate(char *fname
, ComparisionOp op
, void *buf
)
221 virtual void resetNullinfo()=0;
222 virtual int getFldPos(char *name
)=0;
226 //non virtual functions
227 static void getFieldNameAlone(char *fname
, char *name
);
228 static void getTableNameAlone(char *fname
, char *name
);