Changing the error return values to +ve values
[csql.git] / include / Table.h
blob277b6e18728e9995f1a9f191f55cd42b5aff68c0
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 class Predicate;
20 class Condition;
21 class FieldNameList;
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/>
35 * @author Prabakaran Thirumalai
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 void 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
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
69 virtual void markFldNull(int colpos)=0;
71 /** checks whether the field value is null.
72 * @param name field name
74 virtual bool isFldNull(const char *name)=0;
76 /** checks whether the field value is null for the specified field position.
77 * @param colpos field position
79 virtual bool isFldNull(int colpos)=0;
81 virtual void clearFldNull(const char *name)=0;
82 virtual void clearFldNull(int colpos) =0;
85 //DML operations
86 /** executes the select statement. Based on the predicate(condition), respective index is
87 * chosen for the select. Application should call execute before they start fetching
88 * the values from the table.This starts scan on the table.
89 * @returns DbRetVal
91 virtual DbRetVal execute()=0;
93 /** insert the tuple into the table. Prior to this, the binded buffer should be updated
94 * Values present in the binded buffers of all the fields are taken and stored in
95 * the table.<br/>
96 * @returns DbRetVal
98 virtual DbRetVal insertTuple()=0;
100 /**update values in the current tuple of the table. It works only on top of select
101 * using fetch go to the tuple to be updated, then update the binded buffer value and
102 * then call this method to updates the field values in the tuple.
103 * @returns DbRetVal
105 virtual DbRetVal updateTuple()=0;
107 /**deletes the current tuple of the table. It works only on top of select.
108 * using fetch first go to the tuple to be deleted, then call this method to delete.<br/>
109 * To delete all the tuples, do not set any condition and call fetch followed by delete
110 * in a loop till fetch exhausts.
111 * @returns DbRetVal
114 virtual DbRetVal deleteTuple()=0;
116 //scan
118 /**fetches the next tuple in the table which satisfies the condition specified.
119 * execute should be called before calling this method. Application buffer should be
120 * binded to get the tuple values.
121 * @returns void* NULL if there is no tuple.
123 virtual void* fetch()=0;
125 /**fetches the next tuple in the table which satisfies the condition specified.
126 * execute should be called before calling this method. Application buffer need not be
127 * binded to call this method.
128 * @returns void* NULL if there is no tuple.
130 virtual void* fetchNoBind()=0;
133 /**closes the scan. Needs to be called before calling execute again on the same table handle. It releases the resources
134 acquired during the scan.
135 * @returns DbRetVal
138 virtual DbRetVal close()=0;
140 /**Retrieves the total space used for this table in bytes
141 * @returns DbRetVal
143 virtual long spaceUsed()=0;
145 /**Retrieves the total number of tuples present in this table
146 * @returns DbRetVal
148 virtual long numTuples()=0;
151 virtual DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info)=0;
152 virtual FieldNameList getFieldNameList()=0;
154 virtual ~Table() { }
156 #endif