From edc8b29bc52e77524a73443cd05f976e3f914284 Mon Sep 17 00:00:00 2001 From: prabatuty Date: Sat, 2 Jul 2011 17:19:21 +0000 Subject: [PATCH] varchar size not proper and join table with qualifed and unqualifed field names in projection and condition issue. --- include/AggTableImpl.h | 2 ++ include/Debug.h | 2 +- include/JoinTableImpl.h | 1 + include/OrderTableImpl.h | 3 +++ include/Table.h | 1 + include/TableImpl.h | 1 + src/sql/AlterTblStatement.cxx | 7 +++++++ src/sql/DdlStatement.cxx | 6 +++++- src/storage/DatabaseManagerImpl.cxx | 6 ++++-- src/storage/FieldList.cxx | 19 ++++++++++++++----- src/storage/JoinTableImpl.cxx | 17 +++++++++++++++++ src/storage/OrderTableImpl.cxx | 14 +++++++------- src/storage/PredicateEvalImpl.cxx | 2 +- src/storage/TableDef.cxx | 12 ++++++++++-- src/storage/TableImpl.cxx | 9 +++++++++ src/tools/csqldump.cxx | 7 ++++--- 16 files changed, 87 insertions(+), 22 deletions(-) diff --git a/include/AggTableImpl.h b/include/AggTableImpl.h index 5ab7f7de..1f5d48c6 100644 --- a/include/AggTableImpl.h +++ b/include/AggTableImpl.h @@ -91,6 +91,8 @@ class DllExport AggTableImpl:public Table virtual ~AggTableImpl(); DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info) { return tableHdl->getFieldInfo(fieldName, info); } + DbRetVal getQualifiedName(const char *fieldName, char *qualName) + { return tableHdl->getQualifiedName(fieldName, qualName); } void* insertOrGetAggNode(); void setTable(Table *impl){ tableHdl = impl;} Table* getTableHdl(){ return tableHdl; } diff --git a/include/Debug.h b/include/Debug.h index 01f29202..22819c53 100644 --- a/include/Debug.h +++ b/include/Debug.h @@ -9,7 +9,7 @@ #include #include #include -#define DEBUG 1 +//#define DEBUG 1 extern int DebugDM_Alloc; extern int DebugDM_VarAlloc; extern int DebugDM_Mutex; diff --git a/include/JoinTableImpl.h b/include/JoinTableImpl.h index 27bd61c1..9877aef2 100644 --- a/include/JoinTableImpl.h +++ b/include/JoinTableImpl.h @@ -110,6 +110,7 @@ class DllExport JoinTableImpl:public Table virtual ~JoinTableImpl(); DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info); + DbRetVal getQualifiedName(const char *fldname, char *qualName); void setTable(Table *left, Table *right) { leftTableHdl = left; rightTableHdl = right; } diff --git a/include/OrderTableImpl.h b/include/OrderTableImpl.h index 297a9e60..803d6b2b 100644 --- a/include/OrderTableImpl.h +++ b/include/OrderTableImpl.h @@ -53,6 +53,9 @@ class DllExport OrderTableImpl:public Table virtual ~OrderTableImpl(); DbRetVal getFieldInfo(const char *fieldName, FieldInfo *&info) { return tableHdl->getFieldInfo(fieldName, info); } + DbRetVal getQualifiedName(const char *fieldName, char *qualName) + { return tableHdl->getQualifiedName(fieldName, qualName); } + void setTable(Table *impl){ tableHdl = impl;} Table* getTableHdl(){ return tableHdl; } DbRetVal closeScan(); diff --git a/include/Table.h b/include/Table.h index 925ab2cd..c2074a2f 100644 --- a/include/Table.h +++ b/include/Table.h @@ -227,6 +227,7 @@ class DllExport Table virtual ~Table() { } virtual void setLoading(bool flag){}; + virtual DbRetVal getQualifiedName(const char *fldname, char *qualName)=0; //non virtual functions static void getFieldNameAlone(char *fname, char *name); diff --git a/include/TableImpl.h b/include/TableImpl.h index c6b2926c..a216ed1e 100644 --- a/include/TableImpl.h +++ b/include/TableImpl.h @@ -209,6 +209,7 @@ class DllExport TableImpl:public Table else return ErrNotExists; } + DbRetVal getQualifiedName(const char *fldname, char *qualName); List getFieldNameList(); diff --git a/src/sql/AlterTblStatement.cxx b/src/sql/AlterTblStatement.cxx index 18b3f041..063ebf75 100644 --- a/src/sql/AlterTblStatement.cxx +++ b/src/sql/AlterTblStatement.cxx @@ -111,6 +111,9 @@ DbRetVal AlterTblStatement::resolveForAddDropColumn() } else { bindFieldValues[fcount-1] = valBuf; + if (info->type == typeVarchar || info->type == typeString) + info->length++; + ret = tblDef.addField(fldName,info->type, info->length, info->defaultValueBuf, info->isNull, info->isAutoIncrement); if( 0 != ret ) { @@ -144,6 +147,10 @@ DbRetVal AlterTblStatement::resolveForAddDropColumn() name = (FieldName*)nIter.nextElement(); if (strcmp(name->fldName, fDef->fldName_) == 0) fDef->isNull_ = true; } + if (fDef->type_ == typeVarchar || fDef->type_ == typeString) { + fDef->length_++; + //varchar and char require \0 to be stored at the end + } if (!fDef->isDefault_ || fDef->isDefault_ && fDef->defaultValueBuf_[0] == '\0') { ret = tblDef.addField(fDef->fldName_, fDef->type_, fDef->length_, NULL,fDef->isNull_,fDef->isAutoIncrement_); diff --git a/src/sql/DdlStatement.cxx b/src/sql/DdlStatement.cxx index 31615bd6..29f279da 100644 --- a/src/sql/DdlStatement.cxx +++ b/src/sql/DdlStatement.cxx @@ -149,8 +149,12 @@ DbRetVal CreateTblStatement::resolve() printf("Check SQL Syntax: .\n"); return rv; } + if (fDef->type_ == typeVarchar || fDef->type_ == typeString) { + fDef->length_++; + //varchar and char require \0 to be stored at the end + } /* To check char field and restrict it for the max length 8kb(8000) */ - if( (fDef->type_ == 30) && (fDef->length_ > 8000) ){ + if( (fDef->type_ == typeString) && (fDef->length_ > 8000) ){ printError(ErrBadRange,"Char data type length should be less than 8kb(8000)."); return ErrBadRange; } diff --git a/src/storage/DatabaseManagerImpl.cxx b/src/storage/DatabaseManagerImpl.cxx index 0ec122d1..188c871f 100644 --- a/src/storage/DatabaseManagerImpl.cxx +++ b/src/storage/DatabaseManagerImpl.cxx @@ -842,9 +842,11 @@ DbRetVal DatabaseManagerImpl::writeSchemaFile() firstField = false; } else fprintf(fp, ", %s %s ", fieldName, AllDataType::getSQLString(info->type)); - if (info->type == typeString || info->type == typeVarchar || - info->type == typeBinary) + if (info->type == typeString || info->type == typeVarchar ) + fprintf(fp, "(%d)",info->length-1); + else if ( info->type == typeBinary) fprintf(fp, "(%d)",info->length); + if (info->isNull) fprintf(fp, " NOT NULL "); if (info->isDefault) fprintf(fp, " DEFAULT '%s' ", info->defaultValueBuf); if (info->isAutoIncrement) fprintf(fp, " AUTO_INCREMENT "); diff --git a/src/storage/FieldList.cxx b/src/storage/FieldList.cxx index 6fbd4672..cc87307b 100644 --- a/src/storage/FieldList.cxx +++ b/src/storage/FieldList.cxx @@ -167,7 +167,10 @@ DbRetVal FieldList::getFieldInfo(const char *fldName, FieldInfo *&info) { //the above is for count(*) strcpy(info->fldName , iter->fldDef.fldName_); - info->length = iter->fldDef.length_; + if (info->type == typeString || info->type == typeVarchar) + info->length = iter->fldDef.length_ -1; + else + info->length = iter->fldDef.length_; info->type = iter->fldDef.type_; info->offset = iter->fldDef.offset_; info->isDefault = iter->fldDef.isDefault_; @@ -185,7 +188,10 @@ DbRetVal FieldList::getFieldInfo(const char *fldName, FieldInfo *&info) if (0 == strcmp(iter->fldDef.fldName_, fldName)) { strcpy(info->fldName , iter->fldDef.fldName_); - info->length = iter->fldDef.length_; + if (info->type == typeString || info->type == typeVarchar) + info->length = iter->fldDef.length_ -1; + else + info->length = iter->fldDef.length_; info->type = iter->fldDef.type_; info->offset = iter->fldDef.offset_; info->isDefault = iter->fldDef.isDefault_; @@ -213,7 +219,8 @@ int FieldList::getFieldOffset(const char *fldName) } if (iter->fldDef.type_ != typeVarchar) offset = offset + iter->fldDef.length_; - else offset = offset + sizeof(void *); + else + offset = offset + sizeof(void *); iter = iter ->next; } return -1; @@ -266,8 +273,10 @@ int FieldList::getTupleSize() int offset = 0; while(iter != NULL) { - if (iter->fldDef.type_ == typeVarchar) offset += sizeof(void *); - else offset = offset + iter->fldDef.length_; + if (iter->fldDef.type_ == typeVarchar) + offset += sizeof(void *); + else + offset = offset + iter->fldDef.length_; iter = iter->next; } return offset; diff --git a/src/storage/JoinTableImpl.cxx b/src/storage/JoinTableImpl.cxx index 34496e93..1312472a 100644 --- a/src/storage/JoinTableImpl.cxx +++ b/src/storage/JoinTableImpl.cxx @@ -59,11 +59,20 @@ DbRetVal JoinTableImpl::bindFld(const char *fldname, void *val, bool dummy) delete info; return ErrBadCall; } + if (strcmp(elem->fieldName, fieldName)==0 && + strcmp(elem->tableName, "") ==0) + { + printError(ErrBadCall, "Field already binded %s\n", fldname); + delete info; + return ErrBadCall; + } } JoinProjFieldInfo *def = new JoinProjFieldInfo(); strcpy(def->tableName, tableName); strcpy(def->fieldName, fieldName); strcpy(def->tabFieldName, fldname); + if (strcmp (tableName, "") == 0) + getQualifiedName(fldname, def->tabFieldName); def->appBuf = val; DbRetVal rv = getFieldInfo(fldname, info); if ( OK != rv) { @@ -376,6 +385,14 @@ DbRetVal JoinTableImpl::copyValuesToBindBuffer(void *elem) } return OK; } +DbRetVal JoinTableImpl::getQualifiedName(const char *fldname, char *qualName) +{ + if (leftTableHdl != NULL) + leftTableHdl->getQualifiedName(fldname, qualName); + if (rightTableHdl != NULL) + rightTableHdl->getQualifiedName(fldname, qualName); + return OK; +} DbRetVal JoinTableImpl::getFieldInfo(const char* fldname, FieldInfo *&info) { diff --git a/src/storage/OrderTableImpl.cxx b/src/storage/OrderTableImpl.cxx index b379b445..fe184c44 100644 --- a/src/storage/OrderTableImpl.cxx +++ b/src/storage/OrderTableImpl.cxx @@ -74,7 +74,7 @@ DbRetVal OrderTableImpl::setOrderBy(const char *fldname, bool isDesc) strcpy(orderFld->fldName, fldname); orderFld->type = info->type; //orderFld->length = info->length; - orderFld->length = AllDataType::size(info->type, info->length); + orderFld->length = os::align(AllDataType::size(info->type, info->length)); orderFld->bindBuf = NULL; orderFld->isDesc = isDesc; @@ -155,7 +155,7 @@ void OrderTableImpl::checkAndSetSortAlgorithm() while (iter.hasElement()) { fValue = (FieldValue*) iter.nextElement(); - projSize = projSize + fValue->length; + projSize = projSize + os::align(fValue->length); } OrderByFldDef *ordFld=NULL; bool optGrpIntNoNull= false; @@ -203,7 +203,7 @@ int OrderTableImpl::computeOrderBySize() while (oiter.hasElement()) { oFldDef = (OrderByFldDef*) oiter.nextElement(); - nodeOffset = nodeOffset + oFldDef->length; + nodeOffset = nodeOffset + os::align(oFldDef->length); } return nodeOffset; } @@ -224,7 +224,7 @@ DbRetVal OrderTableImpl::insertDistinct() else AllDataType::copyVal(elem+nodeOffset, oFldDef->bindBuf, oFldDef->type, oFldDef->length); - nodeOffset = nodeOffset + oFldDef->length; + nodeOffset = nodeOffset + os::align(oFldDef->length); i++; } AllDataType::copyVal(elem+nodeOffset, &orderNullValues, typeInt, @@ -280,7 +280,7 @@ DbRetVal OrderTableImpl::insert() else AllDataType::copyVal(element+nodeOffset, oFldDef->bindBuf, oFldDef->type, oFldDef->length); - nodeOffset = nodeOffset + oFldDef->length; + nodeOffset = nodeOffset + os::align(oFldDef->length); i++; } AllDataType::copyVal(element+nodeOffset, &orderNullValues, typeInt, @@ -300,7 +300,7 @@ DbRetVal OrderTableImpl::insert() else AllDataType::copyVal(element+nodeOffset, fValue->value, fValue->type, fValue->length); - nodeOffset = nodeOffset + fValue->length; + nodeOffset = nodeOffset + os::align(fValue->length); i++; } AllDataType::copyVal(ptrToCopyNullValues, &nullValues, typeLongLong, @@ -365,7 +365,7 @@ DbRetVal OrderTableImpl::copyValuesToBindBuffer(void *elem) def = (FieldValue*) fIter.nextElement(); if (NULL != def->value) { AllDataType::copyVal(def->value, colPtr, def->type, def->length); - colPtr = colPtr + def->length; + colPtr = colPtr + os::align(def->length); } } return OK; diff --git a/src/storage/PredicateEvalImpl.cxx b/src/storage/PredicateEvalImpl.cxx index a5685f3d..e7bc57ec 100644 --- a/src/storage/PredicateEvalImpl.cxx +++ b/src/storage/PredicateEvalImpl.cxx @@ -391,7 +391,7 @@ DbRetVal PredicateImpl::evaluate(bool &result) return OK; } - printf("PRABA::wrong method call\n"); + printf("FATAL::wrong method call\n"); //the below code works only for single table val1= (char*)tuple + offset1; if(offset2 != -1 && operand == NULL && operandPtr == NULL) diff --git a/src/storage/TableDef.cxx b/src/storage/TableDef.cxx index 9fe48e21..e6c12fa5 100644 --- a/src/storage/TableDef.cxx +++ b/src/storage/TableDef.cxx @@ -81,6 +81,8 @@ int TableDef::addField(const char *name, DataType type, size_t length, fldDef.isNull_ = notNull; fldDef.isAutoIncrement_ = autoIn; //os::memset(fldDef.autoVal_,0, DEFAULT_VALUE_BUF_LENGTH); + + /*PRABA:COMMENTED switch(type) { case typeString : @@ -92,6 +94,8 @@ int TableDef::addField(const char *name, DataType type, size_t length, fldDef.length_ = os::align(AllDataType::size(type)); break; } + */ + if (type == typeBinary) fldDef.length_ = os::align(length); fldDef.offset_ = fldList.getTupleSize(); int ret = fldList.append(fldDef); if (0 == ret) fldCount++; @@ -117,8 +121,12 @@ size_t TableDef::getTupleSize() while (iter.hasElement()) { FieldDef *def = iter.nextElement(); - if (def->type_ == typeVarchar) length += sizeof (void *); - else length = length + def->length_; + if (def->type_ == typeVarchar) + length += sizeof (void *); + else if (def->type_ == typeString) + length += os::align(def->length_); + else + length = length + def->length_; } return length; } diff --git a/src/storage/TableImpl.cxx b/src/storage/TableImpl.cxx index e43cb127..f8256dea 100644 --- a/src/storage/TableImpl.cxx +++ b/src/storage/TableImpl.cxx @@ -49,6 +49,15 @@ void Table::getTableNameAlone(char *fname, char *name) { if (!dotFound) strcpy(start, ""); return; } +DbRetVal TableImpl::getQualifiedName(const char *fldname, char *qualName) +{ + FieldInfo *info = new FieldInfo(); + DbRetVal rv = getFieldInfo(fldname,info); + if (rv == OK) + sprintf(qualName, "%s.%s", getName(), fldname); + return rv; +} + DbRetVal TableImpl::bindFld(const char *name, void *val, bool isNullExpl) { diff --git a/src/tools/csqldump.cxx b/src/tools/csqldump.cxx index e243189b..01d7d95c 100644 --- a/src/tools/csqldump.cxx +++ b/src/tools/csqldump.cxx @@ -153,9 +153,9 @@ int main(int argc, char **argv) } else printf(", %s %s ", fieldName, AllDataType::getSQLString(info->type)); - if (info->type == typeString) printf("(%d)",info->length ); + if (info->type == typeString) printf("(%d)",info->length-1 ); if (info->type == typeBinary) printf("(%d)",info->length); - if (info->type == typeVarchar) printf("(%d)",info->length); + if (info->type == typeVarchar) printf("(%d)",info->length-1); if (info->isNull) printf(" NOT NULL "); if (info->isDefault) printf(" DEFAULT '%s' ", info->defaultValueBuf); @@ -269,7 +269,8 @@ int main(int argc, char **argv) else printf(", %s %s ", fieldName, AllDataType::getSQLString(info->type)); - if (info->type == typeString) printf("(%d)",info->length); + if (info->type == typeString) printf("(%d)",info->length-1); + if (info->type == typeVarchar) printf("(%d)",info->length-1); if (info->type == typeBinary) printf("(%d)",info->length); if (info->isNull) printf(" NOT NULL "); if (info->isDefault) printf(" DEFAULT '%s' ", -- 2.11.4.GIT