From a963c25ec59e453bde9e1e6d9d29f2c23c6acf81 Mon Sep 17 00:00:00 2001 From: kishoramballi Date: Sat, 31 Oct 2009 11:01:44 +0000 Subject: [PATCH] Varchar Implementation part 1 --- include/CatalogTables.h | 6 ++-- include/DataType.h | 1 + include/Info.h | 2 +- include/TableImpl.h | 5 +-- src/sql/MetadataStatement.cxx | 10 +++--- src/sql/SelStatement.cxx | 2 ++ src/sql/dmllex.lxx | 1 + src/sql/dmlyacc.yxx | 8 ++++- src/storage/CatalogTables.cxx | 6 ++-- src/storage/DataType.cxx | 6 +++- src/storage/DatabaseManagerImpl.cxx | 62 ++++++++++++++++++++++++++++++------- src/storage/FieldList.cxx | 5 +-- src/storage/TableDef.cxx | 14 ++++++++- src/storage/TableImpl.cxx | 61 +++++++++++++++++++++++++++++++----- src/tools/csqldump.cxx | 1 + 15 files changed, 153 insertions(+), 37 deletions(-) diff --git a/include/CatalogTables.h b/include/CatalogTables.h index 8886be43..ff7e8e44 100644 --- a/include/CatalogTables.h +++ b/include/CatalogTables.h @@ -87,7 +87,7 @@ class CTABLE int numFlds_; int numIndexes_; void* chunkPtr_; - + void* varcharChunkPtr_; }; class CatalogTableTABLE @@ -99,7 +99,7 @@ class CatalogTableTABLE //Last argument is OUT parameter which will contain the //pointer to the inserted tuple DbRetVal insert(const char *name, int id, size_t size, - int numFlds, void* chunk, void *&tptr); + int numFlds, void* chunk, void *&tptr, void *vcchunk); //Second argument is OUT parameter which will contain the //chunk pointer of this table @@ -107,7 +107,7 @@ class CatalogTableTABLE //pointer to the removed tuple DbRetVal remove(const char *name, void *&chunk, void *&tptr); - DbRetVal getChunkAndTblPtr(const char *name, void *&chunk, void *&tptr); + DbRetVal getChunkAndTblPtr(const char *name, void *&chunk, void *&tptr, void*& vcchunk); DbRetVal setChunkPtr(const char *name, void *firstPage, void *curPage); List getTableList(); }; diff --git a/include/DataType.h b/include/DataType.h index dbc4de56..74bed503 100644 --- a/include/DataType.h +++ b/include/DataType.h @@ -37,6 +37,7 @@ enum DataType { typeString = 30, typeBinary = 31, + typeVarchar = 32, typeComposite = 98, typeULong = 99, diff --git a/include/Info.h b/include/Info.h index 052c75c1..4f76626a 100644 --- a/include/Info.h +++ b/include/Info.h @@ -158,7 +158,7 @@ class TableDef //Internal method used to iterate and get information stored //in this table definition. FieldIterator getFieldIterator(){ return fldList.getIterator(); } - + bool isVarcharPresentInSchema(FieldIterator &iter); }; class FieldInfo diff --git a/include/TableImpl.h b/include/TableImpl.h index 7a758fcc..a2b95ee1 100644 --- a/include/TableImpl.h +++ b/include/TableImpl.h @@ -106,6 +106,7 @@ class TableImpl:public Table size_t length_; //length of the tuple int numFlds_; void* chunkPtr_; + void* vcChunkPtr_; void *curTuple_; //holds the current tuple ptr. moved during fetch() calls Predicate *pred_; @@ -169,7 +170,7 @@ class TableImpl:public Table public: - TableImpl() { db_ = NULL; chunkPtr_ = NULL; iter = NULL; + TableImpl() { db_ = NULL; chunkPtr_ = NULL; vcChunkPtr_=NULL; iter = NULL; idxInfo = NULL; indexPtr_ = NULL; scanType_ = unknownScan; pred_ = NULL; useIndex_ = -1; numFlds_ = 0; bindListArray_ = NULL; iNullInfo = 0; cNullInfo = NULL; isIntUsedForNULL = true; @@ -271,7 +272,7 @@ class TableImpl:public Table char* getAliasName() { return aliasName; } void setAliasName(char *name); void setTableInfo(char *name, int tblid, size_t length, - int numFld, int numIdx, void *chunk); + int numFld, int numIdx, void *chunk, void *vcchunk); void setLoading(bool flag) { loadFlag = flag; } friend class DatabaseManagerImpl; }; diff --git a/src/sql/MetadataStatement.cxx b/src/sql/MetadataStatement.cxx index b4c53870..87eca0eb 100644 --- a/src/sql/MetadataStatement.cxx +++ b/src/sql/MetadataStatement.cxx @@ -34,6 +34,7 @@ ListIterator MetadataStatement::getExportKeyIterator() void *tPkptr =NULL; void *tFkptr = NULL; void *chunkPk = NULL; + void *vcchunkPk = NULL; char *pkFldName = NULL; char *fkFldName = NULL; ForeignKeyMetadata *fkMeta= NULL; @@ -41,8 +42,8 @@ ListIterator MetadataStatement::getExportKeyIterator() fkTbl = (TableImpl *) tblIter.nextElement(); FieldNameList pkFieldList,fkFieldList; CatalogTableTABLE cTable(tbl->sysDB_); - cTable.getChunkAndTblPtr(tbl->getName(), chunkPk, tPkptr); - cTable.getChunkAndTblPtr(fkTbl->getName(), chunkPk, tFkptr); + cTable.getChunkAndTblPtr(tbl->getName(), chunkPk, tPkptr, vcchunkPk); + cTable.getChunkAndTblPtr(fkTbl->getName(), chunkPk, tFkptr, vcchunkPk); CatalogTableFK cFk(tbl->sysDB_); cFk.getPkFkFieldInfo(tPkptr,tFkptr,pkFieldList,fkFieldList); pkFieldList.resetIter(); @@ -83,6 +84,7 @@ ListIterator MetadataStatement::getImportKeyIterator() void *tPkptr =NULL; void *tFkptr = NULL; void *chunkPk = NULL; + void *vcchunkPk = NULL; char *pkFldName = NULL; char *fkFldName = NULL; ForeignKeyMetadata *fkMeta= NULL; @@ -90,8 +92,8 @@ ListIterator MetadataStatement::getImportKeyIterator() fkTbl = (TableImpl *) tblIter.nextElement(); FieldNameList pkFieldList,fkFieldList; CatalogTableTABLE cTable(tbl->sysDB_); - cTable.getChunkAndTblPtr(tbl->getName(), chunkPk, tPkptr); - cTable.getChunkAndTblPtr(fkTbl->getName(), chunkPk, tFkptr); + cTable.getChunkAndTblPtr(tbl->getName(), chunkPk, tPkptr, vcchunkPk); + cTable.getChunkAndTblPtr(fkTbl->getName(), chunkPk, tFkptr, vcchunkPk); CatalogTableFK cFk(tbl->sysDB_); cFk.getPkFkFieldInfo(tFkptr,tPkptr,fkFieldList,pkFieldList); pkFieldList.resetIter(); diff --git a/src/sql/SelStatement.cxx b/src/sql/SelStatement.cxx index 56a09a2b..e5af01e5 100644 --- a/src/sql/SelStatement.cxx +++ b/src/sql/SelStatement.cxx @@ -1101,6 +1101,7 @@ void* SelStatement::fetchAndPrint(bool SQL) switch(value->type) { case typeString: + case typeVarchar: case typeBinary: case typeDate: case typeTime: @@ -1124,6 +1125,7 @@ void* SelStatement::fetchAndPrint(bool SQL) switch(value->type) { case typeString: + case typeVarchar: case typeBinary: case typeDate: case typeTime: diff --git a/src/sql/dmllex.lxx b/src/sql/dmllex.lxx index d22cfd8b..54208db9 100644 --- a/src/sql/dmllex.lxx +++ b/src/sql/dmllex.lxx @@ -128,6 +128,7 @@ operator "<"|">"|">="|"<="|"="|"\!="|"<>"|"LIKE"|"like" if(strcasecmp(yytext,"TIMESTAMP") ==0) token = TIMESTAMP_TYPE; if(strcasecmp(yytext,"BINARY") ==0) token = BINARY_TYPE; if(strcasecmp(yytext,"CHAR") ==0) token = CHAR_TYPE; + if(strcasecmp(yytext,"VARCHAR") ==0) token = VARCHAR_TYPE; if(strcasecmp(yytext,"BIGINT") ==0) token = BIGINT_TYPE; if(strcasecmp(yytext,"TINYINT") ==0) token = TINYINT_TYPE; if(strcasecmp(yytext,"FLOAT") ==0) token = FLOAT_TYPE; diff --git a/src/sql/dmlyacc.yxx b/src/sql/dmlyacc.yxx index 12312873..6af7e4a7 100644 --- a/src/sql/dmlyacc.yxx +++ b/src/sql/dmlyacc.yxx @@ -29,7 +29,7 @@ void yyerror(const char* Msg); %token DELETE UPDATE SET NULL_VALUE %token CREATE TABLE PRIMARY KEY DEFAULT INDEX ON HASH TREE UNIQUE DROP SIZE FOREIGN REFERENCES COMPACT %token CACHE CONDITION FIELDLIST PK DIRECT DSN UNCACHE NOSCHEMA -%token INT_TYPE LONG_TYPE SHORT_TYPE DOUBLE_TYPE TIMESTAMP_TYPE DATE_TYPE CHAR_TYPE TIME_TYPE BIGINT_TYPE FLOAT_TYPE TINYINT_TYPE BINARY_TYPE +%token INT_TYPE LONG_TYPE SHORT_TYPE DOUBLE_TYPE TIMESTAMP_TYPE DATE_TYPE CHAR_TYPE VARCHAR_TYPE TIME_TYPE BIGINT_TYPE FLOAT_TYPE TINYINT_TYPE BINARY_TYPE %token USER PASSWORD ALTER FLUSH %token MIN MAX AVG SUM COUNT GROUP BY HAVING ORDER ASC DESC DISTINCT %token ';' ',' '(' ')' @@ -1035,6 +1035,12 @@ field_type: INT_TYPE parsedData->setFldLength(2); } ; + | VARCHAR_TYPE + { + parsedData->setFldType(typeVarchar); + parsedData->setFldLength(2); + } + ; | BINARY_TYPE { parsedData->setFldType(typeBinary); diff --git a/src/storage/CatalogTables.cxx b/src/storage/CatalogTables.cxx index 9b39c54a..5456f623 100644 --- a/src/storage/CatalogTables.cxx +++ b/src/storage/CatalogTables.cxx @@ -22,7 +22,7 @@ char ChunkName[MAX_CHUNKS][CHUNK_NAME_LEN]={"UserChunkTableId","LockTableHashBuc DbRetVal CatalogTableTABLE::insert(const char *name, int id, size_t size, - int numFlds, void* chunk, void *&tptr) + int numFlds, void* chunk, void *&tptr, void *vcchunk) { Chunk *tChunk = systemDatabase_->getSystemDatabaseChunk(TableTableId); DbRetVal rv = OK; @@ -40,6 +40,7 @@ DbRetVal CatalogTableTABLE::insert(const char *name, int id, size_t size, tableInfo->numFlds_ = numFlds; tableInfo->numIndexes_ = 0; tableInfo->chunkPtr_ = chunk; + tableInfo->varcharChunkPtr_ = vcchunk; printDebug(DM_SystemDatabase,"One Row inserted into TABLE %x %s",tptr, name); return OK; } @@ -75,7 +76,7 @@ DbRetVal CatalogTableTABLE::remove(const char *name, void *&chunk, void *&tptr) } DbRetVal CatalogTableTABLE::getChunkAndTblPtr(const char *name, - void *&chunk, void *&tptr) + void *&chunk, void *&tptr, void *&vcchunk) { Chunk *chk = systemDatabase_->getSystemDatabaseChunk(TableTableId); ChunkIterator iter = chk->getIterator();; @@ -85,6 +86,7 @@ DbRetVal CatalogTableTABLE::getChunkAndTblPtr(const char *name, { //there will be only one row for this table(Primary key) chunk = (Chunk*) ((CTABLE*)tptr)->chunkPtr_; + vcchunk = (Chunk*) ((CTABLE*)tptr)->varcharChunkPtr_; return OK; } } diff --git a/src/storage/DataType.cxx b/src/storage/DataType.cxx index f86d62a4..fb98642f 100644 --- a/src/storage/DataType.cxx +++ b/src/storage/DataType.cxx @@ -466,6 +466,7 @@ char* AllDataType::getSQLString(DataType type) case typeTime: return "TIME"; case typeTimeStamp: return "TIMESTAMP"; case typeString: return "CHAR"; + case typeVarchar: return "VARCHAR"; case typeBinary: return "BINARY"; default: return "UNKNOWN"; } @@ -1297,6 +1298,7 @@ void* AllDataType::alloc(DataType type, int length) //TODO::for porting //fldDef.length_ = sizeof(long double); break; + case typeVarchar: case typeString: if (length == 0 ) return NULL; dest = malloc(length); @@ -1412,7 +1414,8 @@ DbRetVal AllDataType::strToValue(void* dest, char *src, DataType type, int lengt break; } case typeDecimal: //TODO::for porting - case typeString: { + case typeString: + case typeVarchar: { strncpy((char*)dest, (char*)src, length); char *d =(char*)dest; d[length-1] = '\0'; @@ -1953,6 +1956,7 @@ int AllDataType::printVal(void* src, DataType srcType, int length,int dbFlag ) } case typeString: + case typeVarchar: { count = printf("%s", (char*)src); break; diff --git a/src/storage/DatabaseManagerImpl.cxx b/src/storage/DatabaseManagerImpl.cxx index fd733b61..4977aefe 100644 --- a/src/storage/DatabaseManagerImpl.cxx +++ b/src/storage/DatabaseManagerImpl.cxx @@ -509,7 +509,6 @@ DbRetVal DatabaseManagerImpl::createTable(const char *name, TableDef &def) int addSize = 0; if (fldCount < 31) addSize = 4; else addSize = os::align(fldCount); size_t sizeofTuple = os::alignLong(def.getTupleSize()+addSize); - rv = systemDatabase_->getDatabaseMutex(); if (OK != rv ) { printError(rv, "Unable to get Database mutex"); @@ -518,10 +517,11 @@ DbRetVal DatabaseManagerImpl::createTable(const char *name, TableDef &def) void *tptr =NULL; void *chunk = NULL; + void *vcchunk = NULL; //check whether table already exists CatalogTableTABLE cTable(systemDatabase_); - cTable.getChunkAndTblPtr(name, chunk, tptr); + cTable.getChunkAndTblPtr(name, chunk, tptr, vcchunk); if (NULL != tptr) { systemDatabase_->releaseDatabaseMutex(); @@ -541,11 +541,30 @@ DbRetVal DatabaseManagerImpl::createTable(const char *name, TableDef &def) ptr->setChunkName(name); //add row to TABLE int tblID = ((Chunk*)ptr)->getChunkID(); + + //check whether varchar is present in table + FieldIterator fiter = def.getFieldIterator(); + bool isVarcharPresent = def.isVarcharPresentInSchema(fiter); + Chunk *vcptr = NULL; + if (isVarcharPresent) { + //creat chunk to store varchar values + vcptr = createUserChunk(); + if (NULL == vcptr) + { + deleteUserChunk(ptr); + systemDatabase_->releaseDatabaseMutex(); + printError(ErrNoResource, "Unable to create user chunk for varchar"); + return ErrNoResource; + } + printDebug(DM_Database,"Created UserChunk for Varchar:%x", vcptr); + vcptr->setChunkName(name); + } rv = cTable.insert(name, tblID, sizeofTuple, - def.getFieldCount(), ptr, tptr); + def.getFieldCount(), ptr, tptr, vcptr); if (OK != rv) { deleteUserChunk(ptr); + if (vcptr) deleteUserChunk(vcptr); systemDatabase_->releaseDatabaseMutex(); printError(ErrSysInternal, "Unable to update catalog table TABLE"); return ErrSysInternal; @@ -558,6 +577,7 @@ DbRetVal DatabaseManagerImpl::createTable(const char *name, TableDef &def) if (OK != rv) { deleteUserChunk(ptr); + if (vcptr) deleteUserChunk(vcptr); void *cptr, *ttptr;//Dummy as remove below needs both these OUT params cTable.remove(name, cptr, ttptr); systemDatabase_->releaseDatabaseMutex(); @@ -580,6 +600,7 @@ DbRetVal DatabaseManagerImpl::dropTable(const char *name) { void *chunk = NULL; void *tptr =NULL; + void *vcchunk = NULL; DbRetVal rv = systemDatabase_->getDatabaseMutex(); if (OK != rv) { printError(ErrSysInternal, "Unable to get database mutex"); @@ -587,7 +608,7 @@ DbRetVal DatabaseManagerImpl::dropTable(const char *name) } //remove the entry in TABLE CatalogTableTABLE cTable(systemDatabase_); - rv = cTable.getChunkAndTblPtr(name, chunk, tptr); + rv = cTable.getChunkAndTblPtr(name, chunk, tptr, vcchunk); if (OK != rv) { systemDatabase_->releaseDatabaseMutex(); printError(ErrSysInternal, "Table %s does not exist", name); @@ -634,6 +655,17 @@ DbRetVal DatabaseManagerImpl::dropTable(const char *name) return rv; } printDebug(DM_Database,"Deleted UserChunk:%x", chunk); + + if (vcchunk != NULL) { + rv = deleteUserChunk((Chunk*)vcchunk); + if (OK != rv) { + systemDatabase_->releaseDatabaseMutex(); + printError(rv, "Unable to delete the chunk"); + return rv; + } + printDebug(DM_Database,"Deleted UserChunk for Varchar:%x", chunk); + } + //TODO::check whether indexes are available and drop that also. CatalogTableINDEX cIndex(systemDatabase_); int noIndexes = cIndex.getNumIndexes(tptr); @@ -672,6 +704,7 @@ Table* DatabaseManagerImpl::openTable(const char *name,bool checkpkfk) //to store the chunk pointer of table void *chunk = NULL; + void *vcchunk = NULL; //to store the tuple pointer of the table void *tptr =NULL; @@ -687,7 +720,7 @@ Table* DatabaseManagerImpl::openTable(const char *name,bool checkpkfk) return NULL; } CatalogTableTABLE cTable(systemDatabase_); - ret = cTable.getChunkAndTblPtr(name, chunk, tptr); + ret = cTable.getChunkAndTblPtr(name, chunk, tptr, vcchunk); if ( OK != ret) { systemDatabase_->releaseDatabaseMutex(); @@ -697,7 +730,8 @@ Table* DatabaseManagerImpl::openTable(const char *name,bool checkpkfk) } CTABLE *tTuple = (CTABLE*)tptr; table->setTableInfo(tTuple->tblName_, tTuple->tblID_, tTuple->length_, - tTuple->numFlds_, tTuple->numIndexes_, tTuple->chunkPtr_); + tTuple->numFlds_, tTuple->numIndexes_, + tTuple->chunkPtr_, tTuple->varcharChunkPtr_); /*rv = table->lock(true); //take shared lock if (rv !=OK) { @@ -936,6 +970,7 @@ DbRetVal DatabaseManagerImpl::createHashIndex(const char *indName, const char *t } void *tptr =NULL; void *chunk = NULL; + void *vcchunk = NULL; DbRetVal rv = systemDatabase_->getDatabaseMutex(); if (OK != rv) { @@ -945,7 +980,7 @@ DbRetVal DatabaseManagerImpl::createHashIndex(const char *indName, const char *t //check whether table exists CatalogTableTABLE cTable(systemDatabase_); - cTable.getChunkAndTblPtr(tblName, chunk, tptr); + cTable.getChunkAndTblPtr(tblName, chunk, tptr,chunk); if (NULL == tptr) { systemDatabase_->releaseDatabaseMutex(); @@ -1117,6 +1152,7 @@ DbRetVal DatabaseManagerImpl::createTreeIndex(const char *indName, const char *t } void *tptr =NULL; void *chunk = NULL; + void *vcchunk = NULL; DbRetVal rv = systemDatabase_->getDatabaseMutex(); if (OK != rv) { @@ -1126,7 +1162,7 @@ DbRetVal DatabaseManagerImpl::createTreeIndex(const char *indName, const char *t //check whether table exists CatalogTableTABLE cTable(systemDatabase_); - cTable.getChunkAndTblPtr(tblName, chunk, tptr); + cTable.getChunkAndTblPtr(tblName, chunk, tptr, vcchunk); if (NULL == tptr) { systemDatabase_->releaseDatabaseMutex(); @@ -1328,6 +1364,7 @@ DbRetVal DatabaseManagerImpl::createForeignKey(char *fKName,ForeignKeyInfo *info } void *tptr =NULL; void *chunk = NULL; + void *vcchunk = NULL; rv = systemDatabase_->getDatabaseMutex(); if (OK != rv) { @@ -1335,7 +1372,7 @@ DbRetVal DatabaseManagerImpl::createForeignKey(char *fKName,ForeignKeyInfo *info return ErrSysInternal; } CatalogTableTABLE cTable(systemDatabase_); - cTable.getChunkAndTblPtr(info->fkTableName, chunk, tptr); + cTable.getChunkAndTblPtr(info->fkTableName, chunk, tptr, vcchunk); if (NULL == tptr) { systemDatabase_->releaseDatabaseMutex(); @@ -1356,8 +1393,9 @@ DbRetVal DatabaseManagerImpl::createForeignKey(char *fKName,ForeignKeyInfo *info } void *tPkptr =NULL; void *chunkPk = NULL; + void *vcchunkPk = NULL; CatalogTableTABLE c2Table(systemDatabase_); - c2Table.getChunkAndTblPtr(info->pkTableName, chunkPk, tPkptr); + c2Table.getChunkAndTblPtr(info->pkTableName, chunkPk, tPkptr, vcchunkPk); if (NULL == tPkptr) { systemDatabase_->releaseDatabaseMutex(); @@ -1705,9 +1743,9 @@ DbRetVal DatabaseManagerImpl::writeSchemaFile() fprintf(fp, "CREATE TABLE %s (", elem->name); Table *table = openTable(elem->name); - void *chunk = NULL; void *tptr =NULL; + void *chunk = NULL; void *tptr =NULL; void *vcchunk = NULL; CatalogTableTABLE cTable(systemDatabase_); - rv = cTable.getChunkAndTblPtr(elem->name, chunk, tptr); + rv = cTable.getChunkAndTblPtr(elem->name, chunk, tptr, vcchunk); struct Object obj; strcpy(obj.name, elem->name); obj.type = Tbl; diff --git a/src/storage/FieldList.cxx b/src/storage/FieldList.cxx index d0196f16..3fd96e35 100644 --- a/src/storage/FieldList.cxx +++ b/src/storage/FieldList.cxx @@ -245,8 +245,9 @@ int FieldList::getTupleSize() int offset = 0; while(iter != NULL) { - offset = offset + iter->fldDef.length_; - iter = iter ->next; + if (iter->fldDef.type_ == typeVarchar) offset += sizeof(void *); + else offset = offset + iter->fldDef.length_; + iter = iter->next; } return offset; } diff --git a/src/storage/TableDef.cxx b/src/storage/TableDef.cxx index 75621e40..99f35179 100644 --- a/src/storage/TableDef.cxx +++ b/src/storage/TableDef.cxx @@ -82,6 +82,7 @@ int TableDef::addField(const char *name, DataType type, size_t length, switch(type) { case typeString : + case typeVarchar: case typeBinary : fldDef.length_ = os::align(length); break; @@ -114,7 +115,18 @@ size_t TableDef::getTupleSize() while (iter.hasElement()) { FieldDef *def = iter.nextElement(); - length = length + def->length_; + if (def->type_ == typeVarchar) length += sizeof (void *); + else length = length + def->length_; } return length; } + +bool TableDef::isVarcharPresentInSchema(FieldIterator &iter) +{ + while (iter.hasElement()) + { + FieldDef *fDef = iter.nextElement(); + if (fDef->type_ == typeVarchar) return true; + } + return false; +} diff --git a/src/storage/TableImpl.cxx b/src/storage/TableImpl.cxx index 0d365d31..cde18d1d 100644 --- a/src/storage/TableImpl.cxx +++ b/src/storage/TableImpl.cxx @@ -940,6 +940,18 @@ DbRetVal TableImpl::deleteTuple() lMgr_->releaseLock(curTuple_); } } + + FieldIterator fIter = fldList_.getIterator(); + char *colPtr = (char*) curTuple_; + while (fIter.hasElement()) { + FieldDef *def = fIter.nextElement(); + colPtr = (char *) curTuple_ + def->offset_; + if (def->type_ == typeVarchar) { + char *ptr = (char *) *(int *) colPtr; + ((Chunk *) vcChunkPtr_)->free(db_, ptr); + } + } + ((Chunk*)chunkPtr_)->free(db_, curTuple_); iter->prev(); @@ -1039,6 +1051,18 @@ DbRetVal TableImpl::updateTuple() } } } + + FieldIterator fIter = fldList_.getIterator(); + char *colPtr = (char*) curTuple_; + while (fIter.hasElement()) { + FieldDef *def = fIter.nextElement(); + colPtr = (char *) curTuple_ + def->offset_; + if (def->type_ == typeVarchar) { + char *ptr = (char *) *(int *) colPtr; + ((Chunk *) vcChunkPtr_)->free(db_, ptr); + } + } + if (!loadFlag) ret = (*trans)->appendUndoLog(sysDB_, UpdateOperation, curTuple_, length_); if (ret != OK) { @@ -1173,6 +1197,17 @@ DbRetVal TableImpl::copyValuesFromBindBuffer(void *tuplePtr, bool isInsert) else if (!def->isNull_ && isInsert && !def->bindVal_) setNullBit(fldpos); colPtr = colPtr + def->length_; break; + case typeVarchar: + { + DbRetVal rv = OK; + void *ptr = + ((Chunk *) vcChunkPtr_)->allocate(db_, def->length_+1 , &rv); + memset(ptr, 0, def->length_+1); + memcpy(colPtr, &ptr, sizeof(void *)); + strcpy((char *)ptr, (char *)def->bindVal_); + colPtr = colPtr + sizeof(void *); + break; + } default: if (NULL != def->bindVal_){ if(!isInsert && isFldNull(fldpos)){clearNullBit(fldpos);} @@ -1207,7 +1242,13 @@ DbRetVal TableImpl::copyValuesToBindBuffer(void *tuplePtr) for (int i = 0; i < numBindFlds_; i++) { def = (FieldDef *) bindListArray_[i]; colPtr = (char *) tuplePtr + def->offset_; - AllDataType::copyVal(def->bindVal_, colPtr, def->type_, def->length_); + if (def->type_ != typeVarchar) + AllDataType::copyVal(def->bindVal_, colPtr, def->type_, + def->length_); + else { + char *ptr = (char *) *(int *) colPtr; + strcpy((char *)def->bindVal_, ptr); + } } return OK; } @@ -1302,7 +1343,7 @@ DbRetVal TableImpl::updateIndexNode(Transaction *tr, void *indexPtr, IndexInfo * void TableImpl::setTableInfo(char *name, int tblid, size_t length, - int numFld, int numIdx, void *chunk) + int numFld, int numIdx, void *chunk, void *vcchunk) { strcpy(tblName_, name); tblID_ = tblid; @@ -1310,6 +1351,7 @@ void TableImpl::setTableInfo(char *name, int tblid, size_t length, numFlds_ = numFld; numIndexes_ = numIdx; chunkPtr_ = chunk; + vcChunkPtr_ = vcchunk; } long TableImpl::spaceUsed() @@ -1515,6 +1557,7 @@ void TableImpl::printSQLForeignString() void *tPkptr =NULL; void *tFkptr = NULL; void *chunkPk = NULL; + void *vcchunkPk = NULL; CatalogTableTABLE cTable(sysDB_); TableImpl *fkTbl =NULL; ListIterator tblIter = tblList.getIterator(); @@ -1522,9 +1565,9 @@ void TableImpl::printSQLForeignString() int firstFK=true; while (tblIter.hasElement()){ fkTbl = (TableImpl *) tblIter.nextElement(); - rv = cTable.getChunkAndTblPtr(fkTbl->getName(), chunkPk, tPkptr); + rv = cTable.getChunkAndTblPtr(fkTbl->getName(), chunkPk, tPkptr, vcchunkPk ); if ( OK != rv){return ;} - rv = cTable.getChunkAndTblPtr(getName(), chunkPk, tFkptr); + rv = cTable.getChunkAndTblPtr(getName(), chunkPk, tFkptr, vcchunkPk); if ( OK != rv){return ;} CatalogTableFK cFk(sysDB_); rv = cFk.getPkFkFieldInfo(tPkptr,tFkptr,pkFieldList,fkFieldList); @@ -1570,10 +1613,11 @@ bool TableImpl::isPkTableHasRecord(char *pkTableName, TableImpl *fkTbl,bool isIn void *tPkptr =NULL; void *tFkptr = NULL; void *chunkPk = NULL; + void *vcchunkPk = NULL; CatalogTableTABLE cTable(sysDB_); - rv = cTable.getChunkAndTblPtr(pkTableName, chunkPk, tPkptr); + rv = cTable.getChunkAndTblPtr(pkTableName, chunkPk, tPkptr, vcchunkPk); if ( OK != rv){return false;} - rv = cTable.getChunkAndTblPtr(getName(), chunkPk, tFkptr); + rv = cTable.getChunkAndTblPtr(getName(), chunkPk, tFkptr, vcchunkPk); if ( OK != rv){return false;} CatalogTableFK cFk(sysDB_); rv = cFk.getPkFkFieldInfo(tPkptr,tFkptr,pkFieldList,fkFieldList); @@ -1651,10 +1695,11 @@ bool TableImpl::isFkTableHasRecord(char *pkTableName, TableImpl *fkTbl) void *tPkptr =NULL; void *tFkptr = NULL; void *chunkPk = NULL; + void *vcchunkPk = NULL; CatalogTableTABLE cTable(sysDB_); - rv = cTable.getChunkAndTblPtr(getName(), chunkPk, tPkptr); + rv = cTable.getChunkAndTblPtr(getName(), chunkPk, tPkptr, vcchunkPk); if ( OK != rv){return false;} - rv = cTable.getChunkAndTblPtr(pkTableName, chunkPk, tFkptr); + rv = cTable.getChunkAndTblPtr(pkTableName, chunkPk, tFkptr, vcchunkPk); if ( OK != rv){return false;} CatalogTableFK cFk(sysDB_); rv = cFk.getPkFkFieldInfo(tPkptr,tFkptr,pkFieldList,fkFieldList); diff --git a/src/tools/csqldump.cxx b/src/tools/csqldump.cxx index 7be46810..50812270 100644 --- a/src/tools/csqldump.cxx +++ b/src/tools/csqldump.cxx @@ -147,6 +147,7 @@ int main(int argc, char **argv) printf(", %s %s ", fieldName, AllDataType::getSQLString(info->type)); if (info->type == typeString) printf("(%d)",info->length ); if (info->type == typeBinary) printf("(%d)",info->length); + if (info->type == typeVarchar) printf("(%d)",info->length); if (info->isNull) printf(" NOT NULL "); if (info->isDefault) printf(" DEFAULT '%s' ", info->defaultValueBuf); if (info->isAutoIncrement) printf(" AUTO_INCREMENT "); -- 2.11.4.GIT