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>
36 static char ScanTypeNames
[][10] =
38 "TableScan", "HashScan", "TreeScan", "Invalid"
57 TupleIterator(Predicate
*p
, ScanType t
, IndexInfo
*i
, void *cptr
, int pslot
)
58 { bIter
= NULL
; pred_
= p
; scanType_
= t
; info
= i
; chunkPtr_
= cptr
; procSlot
=pslot
;}
62 if (bIter
) delete bIter
;
68 void* prev();//used only for tree iter during deleteTuple
72 class TableImpl
:public Table
79 //This is pointer to the pointer stored in the
80 //Transaction manager.
81 //If the transaction commits/aborts this pointer changes
82 //and this will get that newly allocated transaction
84 char tblName_
[IDENTIFIER_LENGTH
];
86 size_t length_
; //length of the tuple
89 void *curTuple_
; //holds the current tuple ptr. moved during fetch() calls
93 //ChunkIterator *iter;
103 char** indexPtr_
; // array of index ptrs to the catalog table for the indexes of this table.
105 int useIndex_
;//offet in the above array indexPtr_ for scan
111 //Either one of the below is populated based on the no of fields and
112 //is used for tuple insertions
113 bool isIntUsedForNULL
;
121 //copy Values from binded buffer to tuple pointed by arg
122 DbRetVal
copyValuesFromBindBuffer(void *tuple
, bool isInsert
=true);
123 DbRetVal
copyValuesToBindBuffer(void *tuple
);
124 void setNullBit(int fldpos
);
125 void clearNullBit(int fldpos
);
126 DbRetVal
insertIndexNode(Transaction
*trans
, void *indexPtr
, IndexInfo
*info
, void *tuple
);
127 DbRetVal
updateIndexNode(Transaction
*trans
, void *indexPtr
, IndexInfo
*info
, void *tuple
);
128 DbRetVal
deleteIndexNode(Transaction
*trans
, void *indexPtr
, IndexInfo
*info
, void *tuple
);
130 DbRetVal
createPlan();
131 Chunk
* getSystemTableChunk(CatalogTableID id
)
133 return sysDB_
->getSystemDatabaseChunk(id
);
137 TableImpl() { db_
= NULL
; chunkPtr_
= NULL
; iter
= NULL
;
138 idxInfo
= NULL
; indexPtr_
= NULL
; scanType_
= unknownScan
;
139 pred_
= NULL
; useIndex_
= -1; numFlds_
= 0;
140 iNullInfo
= 0; cNullInfo
= NULL
; isIntUsedForNULL
= true;
141 iNotNullInfo
= 0; cNotNullInfo
= NULL
; curTuple_
= NULL
;
142 isPlanCreated
= false; undoFlag
= true;}
145 void setDB(Database
*db
) { db_
= db
; }
146 Database
* getDB() { return db_
;}
147 void setSystemDB(Database
*db
) { sysDB_
= db
; }
148 void setLockManager(LockManager
*lmgr
) { lMgr_
= lmgr
; }
149 void setTrans(Transaction
**t
) { trans
= t
; }
151 DataType
getFieldType(const char *name
)
152 { return fldList_
.getFieldType(name
); }
153 int getFieldOffset(const char *name
)
154 { return fldList_
.getFieldOffset(name
); }
155 size_t getFieldLength(const char *name
)
156 { return fldList_
.getFieldLength(name
); }
158 DbRetVal
getFieldInfo(const char *fieldName
, FieldInfo
*&info
)
160 char tblName
[IDENTIFIER_LENGTH
];
161 char fldName
[IDENTIFIER_LENGTH
];
162 getTableNameAlone((char*)fieldName
, tblName
);
163 getFieldNameAlone((char*)fieldName
, fldName
);
164 if (0 == strcmp(tblName
, "") || 0 ==strcmp(tblName
, getName()))
165 return fldList_
.getFieldInfo(fldName
, info
);
170 List
getFieldNameList();
173 void setCondition(Condition
*p
)
174 { isPlanCreated
= false; if (p
) pred_
= p
->getPredicate(); else pred_
= NULL
;}
177 DbRetVal
bindFld(const char *name
, void *val
);
178 void *getBindFldAddr(const char *name
);
179 int getFldPos(char *name
);
180 void markFldNull(const char *name
);
181 void markFldNull(int colpos
);
182 bool isFldNull(const char *name
);
183 bool isFldNull(int colpos
);
185 void clearFldNull(const char *name
);
186 void clearFldNull(int colpos
);
187 void resetNullinfo();
188 DbRetVal
insertTuple();
189 DbRetVal
updateTuple();
191 DbRetVal
deleteTuple();
198 void* fetch(DbRetVal
&rv
);
200 void* fetchNoBind(DbRetVal
&rv
);
203 DbRetVal
closeScan();
210 void printPlan(int space
);
212 DbRetVal
lock(bool shared
);
215 DbRetVal
setUndoLogging(bool flag
) { undoFlag
= flag
; }
217 void printSQLIndexString();
218 bool isTableInvolved(char *tblName
);
219 bool pushPredicate(Predicate
*pred
);
220 void setPredicate(Predicate
*pred
);
221 char* getName() { return tblName_
; }
222 void setTableInfo(char *name
, int tblid
, size_t length
,
223 int numFld
, int numIdx
, void *chunk
);
224 friend class DatabaseManagerImpl
;