dba33d: #i69262# allow functions to be grouped

This commit is contained in:
Ocke Janssen [oj]
2009-11-26 12:56:23 +01:00
parent 9bc02eaf9c
commit 8a3694e8aa
5 changed files with 106 additions and 122 deletions

View File

@@ -171,6 +171,10 @@ namespace dbaui
const String& _sCriteria,
::rtl::OUString& _rsErrorMessage,
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxColumn) const;
void fillFunctionInfo( const ::connectivity::OSQLParseNode* pNode
,const ::rtl::OUString& sFunctionTerm
,OTableFieldDescRef& aInfo);
protected:
// return the Rectangle where I can paint myself
virtual void resizeDocumentView(Rectangle& rRect);

View File

@@ -83,6 +83,7 @@ namespace dbaui
inline sal_Bool IsEmpty() const;
OTableFieldDesc& operator=( const OTableFieldDesc& _aField );
sal_Bool operator==( const OTableFieldDesc& rDesc );
sal_Bool IsVisible() const { return m_bVisible;}

View File

@@ -186,11 +186,6 @@ namespace
sal_Bool bHaving,
bool _bAddOrOnOneLine);
void fillFunctionInfo( OQueryDesignView* _pView
,const ::connectivity::OSQLParseNode* pNode
,const ::rtl::OUString& sFunctionTerm
,OTableFieldDescRef& aInfo);
//------------------------------------------------------------------------------
::rtl::OUString quoteTableAlias(sal_Bool _bQuote, const ::rtl::OUString& _sAliasName, const ::rtl::OUString& _sQuote)
{
@@ -2262,35 +2257,6 @@ namespace
return eErrorCode;
}
//------------------------------------------------------------------------------
void fillFunctionInfo( OQueryDesignView* _pView
,const ::connectivity::OSQLParseNode* pNode
,const ::rtl::OUString& sFunctionTerm
,OTableFieldDescRef& aInfo)
{
// get the type out of the funtion name
OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
sal_Int32 nDataType = DataType::DOUBLE;
::rtl::OUString sFieldName = sFunctionTerm;
OSQLParseNode* pFunctionName = pNode->getChild(0);
if ( !SQL_ISPUNCTUATION(pFunctionName,"{") )
{
if ( SQL_ISRULEOR2(pNode,length_exp,char_value_fct) )
pFunctionName = pFunctionName->getChild(0);
::rtl::OUString sFunctionName = pFunctionName->getTokenValue();
if ( !sFunctionName.getLength() )
sFunctionName = ::rtl::OStringToOUString(OSQLParser::TokenIDToStr(pFunctionName->getTokenID()),RTL_TEXTENCODING_UTF8);
nDataType = OSQLParser::getFunctionReturnType(
sFunctionName
,&rController.getParser().getContext());
}
aInfo->SetDataType(nDataType);
aInfo->SetFieldType(TAB_NORMAL_FIELD);
aInfo->SetField(sFieldName);
aInfo->SetTabWindow(NULL);
}
//------------------------------------------------------------------------------
SqlParseError InstallFields(OQueryDesignView* _pView,
const ::connectivity::OSQLParseNode* pNode,
OJoinTableView::OTableWindowMap* pTabList )
@@ -2298,7 +2264,7 @@ namespace
if( pNode==0 || !SQL_ISRULE(pNode,select_statement))
return eNoSelectStatement;
::connectivity::OSQLParseNode* pParseTree = pNode->getChild(2);
::connectivity::OSQLParseNode* pParseTree = pNode->getChild(2); // selection
sal_Bool bFirstField = sal_True; // bei der Initialisierung mu<6D> auf alle Faelle das erste Feld neu aktiviert werden
SqlParseError eErrorCode = eOk;
@@ -2329,9 +2295,6 @@ namespace
if ( SQL_ISRULE(pColumnRef,derived_column) )
{
if ( !xConnection.is() )
break;
::rtl::OUString aColumnAlias(rController.getParseIterator().getColumnAlias(pColumnRef)); // kann leer sein
pColumnRef = pColumnRef->getChild(0);
OTableFieldDescRef aInfo = new OTableFieldDesc();
@@ -2412,7 +2375,7 @@ namespace
}
else
{
fillFunctionInfo(_pView,pColumnRef,aColumns,aInfo);
_pView->fillFunctionInfo(pColumnRef,aColumns,aInfo);
aInfo->SetFieldAlias(aColumnAlias);
}
@@ -2533,7 +2496,7 @@ namespace
_pView->getLocale(),
static_cast<sal_Char>(_pView->getDecimalSeparator().toChar()),
&rController.getParser().getContext());
fillFunctionInfo(_pView,pArgument,sCondition,aDragLeft);
_pView->fillFunctionInfo(pArgument,sCondition,aDragLeft);
aDragLeft->SetFunctionType(FKT_OTHER);
aDragLeft->SetOrderDir(eOrderDir);
aDragLeft->SetVisible(sal_False);
@@ -2565,7 +2528,7 @@ namespace
const ::connectivity::OSQLParseNode* pSelectRoot )
{
SqlParseError eErrorCode = eOk;
if (!pSelectRoot->getChild(3)->getChild(2)->isLeaf())
if (!pSelectRoot->getChild(3)->getChild(2)->isLeaf()) // opt_group_by_clause
{
OQueryController& rController = static_cast<OQueryController&>(_pView->getController());
::connectivity::OSQLParseNode* pGroupBy = pSelectRoot->getChild(3)->getChild(2)->getChild(2);
@@ -2600,7 +2563,7 @@ namespace
&rController.getParser().getContext(),
sal_True,
sal_True); // quote is to true because we need quoted elements inside the function
fillFunctionInfo(_pView,pArgument,sGroupByExpression,aDragInfo);
_pView->fillFunctionInfo(pArgument,sGroupByExpression,aDragInfo);
aDragInfo->SetFunctionType(FKT_OTHER);
aDragInfo->SetGroupBy(sal_True);
aDragInfo->SetVisible(sal_False);
@@ -3324,4 +3287,32 @@ bool OQueryDesignView::initByParseIterator( ::dbtools::SQLExceptionInfo* _pError
}
return eErrorCode == eOk;
}
//------------------------------------------------------------------------------
void OQueryDesignView::fillFunctionInfo( const ::connectivity::OSQLParseNode* pNode
,const ::rtl::OUString& sFunctionTerm
,OTableFieldDescRef& aInfo)
{
// get the type out of the funtion name
OQueryController& rController = static_cast<OQueryController&>(getController());
sal_Int32 nDataType = DataType::DOUBLE;
::rtl::OUString sFieldName = sFunctionTerm;
OSQLParseNode* pFunctionName = pNode->getChild(0);
if ( !SQL_ISPUNCTUATION(pFunctionName,"{") )
{
if ( SQL_ISRULEOR2(pNode,length_exp,char_value_fct) )
pFunctionName = pFunctionName->getChild(0);
::rtl::OUString sFunctionName = pFunctionName->getTokenValue();
if ( !sFunctionName.getLength() )
sFunctionName = ::rtl::OStringToOUString(OSQLParser::TokenIDToStr(pFunctionName->getTokenID()),RTL_TEXTENCODING_UTF8);
nDataType = OSQLParser::getFunctionReturnType(
sFunctionName
,&rController.getParser().getContext());
}
aInfo->SetDataType(nDataType);
aInfo->SetFieldType(TAB_NORMAL_FIELD);
aInfo->SetField(sFieldName);
aInfo->SetTabWindow(NULL);
}
// -----------------------------------------------------------------------------

View File

@@ -890,78 +890,56 @@ sal_Bool OSelectionBrowseBox::saveField(const String& _sFieldName,OTableFieldDes
OSL_ENSURE(0,"Unsupported function inserted!");
}
else if( SQL_ISRULEOR2(pColumnRef,position_exp,extract_exp) ||
SQL_ISRULEOR2(pColumnRef,fold,char_substring_fct) ||
SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct) )
// a calculation has been found ( can be calc and function )
{
// append the whole text as field name
// so we first clear the function field
clearEntryFunctionField(_sFieldName,aSelEntry,_bListAction,nColumnId);
sal_Bool bQuote = sal_True;
sal_Int32 nDataType = DataType::DOUBLE;
OSQLParseNode* pFunctionName = pColumnRef->getChild(0);
if ( !SQL_ISPUNCTUATION(pFunctionName,"{") )
{
if ( SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct) )
pFunctionName = pFunctionName->getChild(0);
if ( pFunctionName )
{
::rtl::OUString sFunctionName = pFunctionName->getTokenValue();
if ( !sFunctionName.getLength() )
sFunctionName = ::rtl::OStringToOUString(OSQLParser::TokenIDToStr(pFunctionName->getTokenID()),RTL_TEXTENCODING_MS_1252);
nDataType = OSQLParser::getFunctionReturnType(
sFunctionName
,&rController.getParser().getContext());
aSelEntry->SetDataType(nDataType);
}
}
// now parse the whole statement
sal_uInt32 nFunCount = pColumnRef->count();
::rtl::OUString sParameters;
for(sal_uInt32 function = 0; function < nFunCount; ++function)
pColumnRef->getChild(function)->parseNodeToStr( sParameters, xConnection, &rParser.getContext(), sal_True, bQuote );
::rtl::OUString aSelectionAlias = aSelEntry->GetAlias();
aSelEntry->SetAlias(::rtl::OUString());
sal_Int32 nNewFunctionType = aSelEntry->GetFunctionType() | FKT_NUMERIC | FKT_OTHER;
aSelEntry->SetFunctionType(nNewFunctionType);
aSelEntry->SetFieldType(TAB_NORMAL_FIELD);
aSelEntry->SetTabWindow(NULL);
aSelEntry->SetField(sParameters);
notifyTableFieldChanged(aSelectionAlias,aSelEntry->GetAlias(),_bListAction, nColumnId);
}
else
{
// so we first clear the function field
clearEntryFunctionField(_sFieldName,aSelEntry,_bListAction,nColumnId);
::rtl::OUString aColumns;
pColumnRef->parseNodeToStr( aColumns,
::rtl::OUString sFunction;
pColumnRef->parseNodeToStr( sFunction,
xConnection,
&rController.getParser().getContext(),
sal_True,
sal_True);
// get the type out of the funtion name
sal_Int32 nDataType = DataType::DOUBLE;
aSelEntry->SetDataType(nDataType);
aSelEntry->SetField(aColumns);
aSelEntry->SetFieldType(TAB_NORMAL_FIELD);
aSelEntry->SetTabWindow(NULL);
aSelEntry->SetAlias(::rtl::OUString());
aSelEntry->SetFieldAlias(sColumnAlias);
aSelEntry->SetFunctionType(FKT_NUMERIC | FKT_OTHER);
sal_True); // quote is to true because we need quoted elements inside the function
getDesignView()->fillFunctionInfo(pColumnRef,sFunction,aSelEntry);
if( SQL_ISRULEOR2(pColumnRef,position_exp,extract_exp) ||
SQL_ISRULEOR2(pColumnRef,fold,char_substring_fct) ||
SQL_ISRULEOR2(pColumnRef,length_exp,char_value_fct) )
// a calculation has been found ( can be calc and function )
{
// now parse the whole statement
sal_uInt32 nFunCount = pColumnRef->count();
::rtl::OUString sParameters;
for(sal_uInt32 function = 0; function < nFunCount; ++function)
pColumnRef->getChild(function)->parseNodeToStr( sParameters, xConnection, &rParser.getContext(), sal_True, sal_True );
sOldAlias = aSelEntry->GetAlias();
sal_Int32 nNewFunctionType = aSelEntry->GetFunctionType() | FKT_NUMERIC | FKT_OTHER;
aSelEntry->SetFunctionType(nNewFunctionType);
aSelEntry->SetField(sParameters);
}
else
{
aSelEntry->SetFieldAlias(sColumnAlias);
if ( SQL_ISRULE(pColumnRef,set_fct_spec) )
aSelEntry->SetFunctionType(/*FKT_NUMERIC | */FKT_OTHER);
else
{
if ( SQL_ISRULEOR2(pColumnRef,num_value_exp,term) || SQL_ISRULE(pColumnRef,factor) )
aSelEntry->SetDataType(DataType::DOUBLE);
else if ( SQL_ISRULE(pColumnRef,value_exp) )
aSelEntry->SetDataType(DataType::TIMESTAMP);
else
aSelEntry->SetDataType(DataType::VARCHAR);
aSelEntry->SetFunctionType(FKT_NUMERIC | FKT_OTHER);
}
}
aSelEntry->SetAlias(::rtl::OUString());
notifyTableFieldChanged(sOldAlias,aSelEntry->GetAlias(),_bListAction, nColumnId);
}
}
if ( i > 0 && InsertField(aSelEntry,BROWSER_INVALIDID,sal_True,sal_False).isEmpty() ) // may we have to append more than one field
{ // the field could not be isnerted
@@ -2889,7 +2867,7 @@ bool OSelectionBrowseBox::HasFieldByAliasName(const ::rtl::OUString& rFieldName,
{
if ( (*aIter)->GetFieldAlias() == rFieldName )
{
rInfo = *aIter;
rInfo.getBody() = (*aIter).getBody();
break;
}
}

View File

@@ -69,24 +69,10 @@ OTableFieldDesc::OTableFieldDesc()
//------------------------------------------------------------------------------
OTableFieldDesc::OTableFieldDesc(const OTableFieldDesc& rRS)
: ::vos::OReference()
,m_vecCriteria( rRS.m_vecCriteria)
,m_aTableName(rRS.GetTable())
,m_aAliasName(rRS.GetAlias()) // table range
,m_aFieldName(rRS.GetField()) // column
,m_aFieldAlias(rRS.GetFieldAlias()) // column alias
,m_aFunctionName(rRS.GetFunction()) // Funktionsname
,m_pTabWindow(rRS.GetTabWindow())
,m_eDataType(rRS.GetDataType())
,m_eFunctionType( rRS.GetFunctionType() )
,m_eFieldType(rRS.GetFieldType())
,m_eOrderDir(rRS.GetOrderDir())
,m_nIndex(rRS.GetFieldIndex())
,m_nColWidth(rRS.GetColWidth())
,m_nColumnId( rRS.m_nColumnId)
,m_bGroupBy(rRS.IsGroupBy())
,m_bVisible(rRS.IsVisible())
{
DBG_CTOR(OTableFieldDesc,NULL);
*this = rRS;
}
//------------------------------------------------------------------------------
@@ -107,7 +93,31 @@ OTableFieldDesc::~OTableFieldDesc()
{
DBG_DTOR(OTableFieldDesc,NULL);
}
//------------------------------------------------------------------------------
OTableFieldDesc& OTableFieldDesc::operator=( const OTableFieldDesc& rRS )
{
if (&rRS == this)
return *this;
m_vecCriteria = rRS.m_vecCriteria;
m_aTableName = rRS.GetTable();
m_aAliasName = rRS.GetAlias(); // table range
m_aFieldName = rRS.GetField(); // column
m_aFieldAlias = rRS.GetFieldAlias(); // column alias
m_aFunctionName = rRS.GetFunction(); // Funktionsname
m_pTabWindow = rRS.GetTabWindow();
m_eDataType = rRS.GetDataType();
m_eFunctionType = rRS.GetFunctionType();
m_eFieldType = rRS.GetFieldType();
m_eOrderDir = rRS.GetOrderDir();
m_nIndex = rRS.GetFieldIndex();
m_nColWidth = rRS.GetColWidth();
m_nColumnId = rRS.m_nColumnId;
m_bGroupBy = rRS.IsGroupBy();
m_bVisible = rRS.IsVisible();
return *this;
}
//------------------------------------------------------------------------------
sal_Bool OTableFieldDesc::operator==( const OTableFieldDesc& rDesc )
{