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 ***************************************************************************/
20 #include<Transaction.h>
23 #include<CatalogTables.h>
26 #include<DatabaseManagerImpl.h>
52 TupleIterator(Predicate
*p
, ScanType t
, IndexInfo
*i
, void *cptr
, int pslot
)
53 { bIter
= NULL
; pred_
= p
; scanType_
= t
; info
= i
; chunkPtr_
= cptr
; procSlot
=pslot
;}
57 if (bIter
) delete bIter
;
63 void* prev();//used only for tree iter during deleteTuple
67 class TableImpl
:public Table
74 //This is pointer to the pointer stored in the
75 //Transaction manager.
76 //If the transaction commits/aborts this pointer changes
77 //and this will get that newly allocated transaction
79 char tblName_
[IDENTIFIER_LENGTH
];
81 size_t length_
; //length of the tuple
84 void *curTuple_
; //holds the current tuple ptr. moved during fetch() calls
88 //ChunkIterator *iter;
98 char** indexPtr_
; // array of index ptrs to the catalog table for the indexes of this table.
100 int useIndex_
;//offet in the above array indexPtr_ for scan
106 //Either one of the below is populated based on the no of fields and
107 //is used for tuple insertions
108 bool isIntUsedForNULL
;
116 //copy Values from binded buffer to tuple pointed by arg
117 DbRetVal
copyValuesFromBindBuffer(void *tuple
, bool isInsert
=true);
118 DbRetVal
copyValuesToBindBuffer(void *tuple
);
119 void setNullBit(int fldpos
);
120 void clearNullBit(int fldpos
);
121 DbRetVal
insertIndexNode(Transaction
*trans
, void *indexPtr
, IndexInfo
*info
, void *tuple
);
122 DbRetVal
updateIndexNode(Transaction
*trans
, void *indexPtr
, IndexInfo
*info
, void *tuple
);
123 DbRetVal
deleteIndexNode(Transaction
*trans
, void *indexPtr
, IndexInfo
*info
, void *tuple
);
125 DbRetVal
createPlan();
126 Chunk
* getSystemTableChunk(CatalogTableID id
)
128 return sysDB_
->getSystemDatabaseChunk(id
);
132 TableImpl() { db_
= NULL
; chunkPtr_
= NULL
; iter
= NULL
;
133 idxInfo
= NULL
; indexPtr_
= NULL
; scanType_
= unknownScan
;
134 pred_
= NULL
; useIndex_
= -1; numFlds_
= 0;
135 iNullInfo
= 0; cNullInfo
= NULL
; isIntUsedForNULL
= true;
136 iNotNullInfo
= 0; cNotNullInfo
= NULL
;
137 isPlanCreated
= false; undoFlag
= true;}
140 void setDB(Database
*db
) { db_
= db
; }
141 Database
* getDB() { return db_
;}
142 void setSystemDB(Database
*db
) { sysDB_
= db
; }
143 void setLockManager(LockManager
*lmgr
) { lMgr_
= lmgr
; }
144 void setTrans(Transaction
**t
) { trans
= t
; }
146 DataType
getFieldType(const char *name
)
147 { return fldList_
.getFieldType(name
); }
148 int getFieldOffset(const char *name
)
149 { return fldList_
.getFieldOffset(name
); }
150 size_t getFieldLength(const char *name
)
151 { return fldList_
.getFieldLength(name
); }
153 DbRetVal
getFieldInfo(const char *fieldName
, FieldInfo
*&info
)
155 char tblName
[IDENTIFIER_LENGTH
];
156 char fldName
[IDENTIFIER_LENGTH
];
157 getTableNameAlone((char*)fieldName
, tblName
);
158 getFieldNameAlone((char*)fieldName
, fldName
);
159 if (0 == strcmp(tblName
, "") || 0 ==strcmp(tblName
, getName()))
160 return fldList_
.getFieldInfo(fldName
, info
);
165 List
getFieldNameList();
168 void setCondition(Condition
*p
)
169 { isPlanCreated
= false; if (p
) pred_
= p
->getPredicate(); else pred_
= NULL
;}
172 DbRetVal
bindFld(const char *name
, void *val
);
173 void *getBindFldAddr(const char *name
);
175 void markFldNull(const char *name
);
176 void markFldNull(int colpos
);
177 bool isFldNull(const char *name
);
178 bool isFldNull(int colpos
);
180 void clearFldNull(const char *name
);
181 void clearFldNull(int colpos
);
182 void resetNullinfo();
184 DbRetVal
insertTuple();
185 DbRetVal
updateTuple();
187 DbRetVal
deleteTuple();
194 void* fetch(DbRetVal
&rv
);
196 void* fetchNoBind(DbRetVal
&rv
);
206 DbRetVal
lock(bool shared
);
209 DbRetVal
setUndoLogging(bool flag
) { undoFlag
= flag
; }
211 void printSQLIndexString();
212 char* getName() { return tblName_
; }
213 void setTableInfo(char *name
, int tblid
, size_t length
,
214 int numFld
, int numIdx
, void *chunk
);
215 friend class DatabaseManagerImpl
;