From 75c03192cf91d7fe1f1c90413636f623e6ad70bd Mon Sep 17 00:00:00 2001 From: prabatuty Date: Thu, 31 Jul 2008 06:12:35 +0000 Subject: [PATCH] 2031095 select count(*) from t1 is not working --- src/sql/SelStatement.cxx | 16 ++++++++++++++-- src/sql/dmlyacc.yxx | 5 +++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/sql/SelStatement.cxx b/src/sql/SelStatement.cxx index e952159e..6f91783a 100644 --- a/src/sql/SelStatement.cxx +++ b/src/sql/SelStatement.cxx @@ -258,6 +258,17 @@ DbRetVal SelStatement::resolve() printError(ErrNotExists, "Unable to open the table:Table not exists"); return ErrNotExists; } + List fNameList = table->getFieldNameList(); + ListIterator fNameIter = fNameList.getIterator(); + Identifier *elem = NULL; + if (fNameIter.hasElement()) + elem = (Identifier*) fNameIter.nextElement(); + if (elem == NULL) + { + printError(ErrNotExists, "No fields present in the table %s", parsedData->getTableName()); + return ErrNotExists; + } + //get the fieldname list and validate field names ListIterator iter = parsedData->getFieldNameList().getIterator(); FieldName *name = NULL; @@ -285,7 +296,7 @@ DbRetVal SelStatement::resolve() printError(ErrSysFatal, "Should never happen. Field Name list has NULL"); return ErrSysFatal; } - if ('*' == name->fldName[0]) + if ('*' == name->fldName[0] && name->aType != AGG_COUNT) { iter.reset(); while (iter.hasElement()) @@ -302,6 +313,7 @@ DbRetVal SelStatement::resolve() //as they all are deleted during resolveStar method. break; } else { + if ('*' == name->fldName[0]) strcpy(name->fldName, elem->name); rv = table->getFieldInfo(name->fldName, fInfo); if (ErrNotFound == rv) { @@ -318,7 +330,7 @@ DbRetVal SelStatement::resolve() newVal->type = fInfo->type; newVal->length = fInfo->length; // for binary datatype input buffer size should be 2 times the length - if(newVal->type == typeBinary) + if(newVal->type == typeBinary) newVal->value = AllDataType::alloc(fInfo->type, 2 * fInfo->length); else newVal->value = AllDataType::alloc(fInfo->type, fInfo->length); parsedData->insertFieldValue(newVal); diff --git a/src/sql/dmlyacc.yxx b/src/sql/dmlyacc.yxx index f859d93d..2f65c457 100644 --- a/src/sql/dmlyacc.yxx +++ b/src/sql/dmlyacc.yxx @@ -275,6 +275,11 @@ field: ident parsedData->insertField((char*)$3, AGG_COUNT); free( $1 ); } + | COUNT '(' STAR ')' + { + parsedData->insertField("*", AGG_COUNT); + free( $1 ); + } | STAR { parsedData->insertField((char*)$1); -- 2.11.4.GIT