[Libreoffice-commits] core.git: 7 commits - connectivity/source dbaccess/source include/connectivity
Lionel Elie Mamane
lionel at mamane.lu
Thu Jul 11 08:53:40 PDT 2013
connectivity/source/parse/sqliterator.cxx | 47 ++++++++++++---
dbaccess/source/core/api/SingleSelectQueryComposer.cxx | 51 ++++++++++++++---
dbaccess/source/core/inc/SingleSelectQueryComposer.hxx | 20 ++++++
dbaccess/source/ui/dlg/directsql.cxx | 1
dbaccess/source/ui/dlg/queryorder.cxx | 25 --------
include/connectivity/sqliterator.hxx | 8 ++
6 files changed, 106 insertions(+), 46 deletions(-)
New commits:
commit 33fe41cf45efb89f9a7629c5df5a6b4d5b7c0b76
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date: Thu Jul 11 17:42:31 2013 +0200
sort is ascending by default
Change-Id: I38354405acbbdb27b9e7ce1d19e862b7b352c850
diff --git a/connectivity/source/parse/sqliterator.cxx b/connectivity/source/parse/sqliterator.cxx
index 95c6314..4dc4058 100644
--- a/connectivity/source/parse/sqliterator.cxx
+++ b/connectivity/source/parse/sqliterator.cxx
@@ -1115,7 +1115,7 @@ void OSQLParseTreeIterator::traverseByColumnNames(const OSQLParseNode* pSelectNo
OSQLParseNode * pOptAscDesc = pColumnRef->getParent()->getChild(1);
OSL_ENSURE(pOptAscDesc != NULL,"OSQLParseTreeIterator: error in parse tree!");
- sal_Bool bAscending = pOptAscDesc && SQL_ISTOKEN(pOptAscDesc,ASC);
+ sal_Bool bAscending = ! (pOptAscDesc && SQL_ISTOKEN(pOptAscDesc,DESC));
setOrderByColumnName(sColumnName, aTableRange,bAscending);
}
else
commit b93b9e6d424faa7f6664a15b0507885f87745b01
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date: Thu Jul 11 17:04:42 2013 +0200
microoptimisation
Change-Id: I977fbd8387b069574d9818923ada54392d39347a
diff --git a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
index 24c2076..58a5564 100644
--- a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
+++ b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
@@ -695,7 +695,7 @@ void OSingleSelectQueryComposer::setSingleAdditiveClause( SQLPart _ePart, const
clearColumns( ParameterColumns );
if ( _ePart == Order )
clearColumns( OrderColumns );
- if ( _ePart == Group )
+ else if ( _ePart == Group )
clearColumns( GroupByColumns );
// also, since the "additive filter" change, we need to rebuild our "additive" statement
commit 417925840e8697aaee8eb2f566d7e706bc8c379d
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date: Thu Jul 11 16:53:45 2013 +0200
give right function name in debug messages
Change-Id: I7d82e34545a5aab657f3156b8c5b23c8a8531a11
diff --git a/connectivity/source/parse/sqliterator.cxx b/connectivity/source/parse/sqliterator.cxx
index af90f99..95c6314 100644
--- a/connectivity/source/parse/sqliterator.cxx
+++ b/connectivity/source/parse/sqliterator.cxx
@@ -1903,7 +1903,7 @@ void OSQLParseTreeIterator::setGroupByColumnName(const OUString & rColumnName, O
}
#ifdef SQL_TEST_PARSETREEITERATOR
- cout << "OSQLParseTreeIterator::setOrderByColumnName: "
+ cout << "OSQLParseTreeIterator::setGroupByColumnName: "
<< (const char *) rColumnName << ", "
<< (const char *) rTableRange << ", "
<< (bAscending ? "true" : "false")
commit 40370f759c403c5f07fb4d77680bd8f954e55231
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date: Thu Jul 11 16:53:23 2013 +0200
ORDER BY columns are prioritarily *SELECT* columns
as opposed to *table* columns,
and notwithstanding HSQLDB 1.8 (our embedded database) bugs.
Actually, supporting ORDER BY on non-select (but table) columns is OPTIONAL for DBMSs
(but quite common)
Change-Id: I6725dfda36b09429a78262bff6f3d3e3dd9032b6
diff --git a/connectivity/source/parse/sqliterator.cxx b/connectivity/source/parse/sqliterator.cxx
index 927dfa9..af90f99 100644
--- a/connectivity/source/parse/sqliterator.cxx
+++ b/connectivity/source/parse/sqliterator.cxx
@@ -1868,7 +1868,9 @@ OUString OSQLParseTreeIterator::getUniqueColumnName(const OUString & rColumnName
void OSQLParseTreeIterator::setOrderByColumnName(const OUString & rColumnName, OUString & rTableRange, sal_Bool bAscending)
{
SAL_INFO( "connectivity.parse", "parse Ocke.Janssen at sun.com OSQLParseTreeIterator::setOrderByColumnName" );
- Reference<XPropertySet> xColumn = findColumn( rColumnName, rTableRange, false );
+ Reference<XPropertySet> xColumn = findSelectColumn( rColumnName );
+ if ( !xColumn.is() )
+ xColumn = findColumn ( rColumnName, rTableRange, false );
if ( xColumn.is() )
m_aOrderColumns->get().push_back(new OOrderColumn( xColumn, rTableRange, isCaseSensitive(), bAscending ) );
else
@@ -2046,6 +2048,30 @@ const OSQLParseNode* OSQLParseTreeIterator::getSimpleHavingTree() const
}
// -----------------------------------------------------------------------------
+Reference< XPropertySet > OSQLParseTreeIterator::findSelectColumn( const OUString & rColumnName )
+{
+ SAL_INFO( "connectivity.parse", "parse lionel at mamane.lu OSQLParseTreeIterator::findSelectColumn" );
+ for ( OSQLColumns::Vector::const_iterator lookupColumn = m_aSelectColumns->get().begin();
+ lookupColumn != m_aSelectColumns->get().end();
+ ++lookupColumn )
+ {
+ Reference< XPropertySet > xColumn( *lookupColumn );
+ try
+ {
+ OUString sName, sTableName;
+ xColumn->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_NAME ) ) >>= sName;
+ if ( sName == rColumnName )
+ return xColumn;
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+ return NULL;
+}
+
+// -----------------------------------------------------------------------------
Reference< XPropertySet > OSQLParseTreeIterator::findColumn( const OUString & rColumnName, OUString & rTableRange, bool _bLookInSubTables )
{
SAL_INFO( "connectivity.parse", "parse Ocke.Janssen at sun.com OSQLParseTreeIterator::findColumn" );
diff --git a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
index 1cbb0d1..24c2076 100644
--- a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
+++ b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
@@ -456,7 +456,7 @@ void SAL_CALL OSingleSelectQueryComposer::appendFilterByColumn( const Reference<
setConditionByColumn(column,andCriteria,F_tmp,filterOperator);
}
-OUString OSingleSelectQueryComposer::impl_getColumnName_throw(const Reference< XPropertySet >& column)
+OUString OSingleSelectQueryComposer::impl_getColumnRealName_throw(const Reference< XPropertySet >& column, bool bGroupBy)
{
::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
@@ -471,17 +471,18 @@ OUString OSingleSelectQueryComposer::impl_getColumnName_throw(const Reference< X
throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_NOT_VALID),*this,SQLSTATE_GENERAL,1000,makeAny(aErr) );
}
- OUString aName,aNewName;
+ OUString aName, aNewName;
column->getPropertyValue(PROPERTY_NAME) >>= aName;
- if ( !m_xMetaData->supportsOrderByUnrelated() && m_aCurrentColumns[SelectColumns] && !m_aCurrentColumns[SelectColumns]->hasByName(aName))
+ if ( bGroupBy &&
+ !m_xMetaData->supportsGroupByUnrelated() &&
+ m_aCurrentColumns[SelectColumns] &&
+ !m_aCurrentColumns[SelectColumns]->hasByName(aName) )
{
OUString sError(DBACORE_RESSTRING(RID_STR_COLUMN_MUST_VISIBLE));
throw SQLException(sError.replaceAll("%name", aName),*this,SQLSTATE_GENERAL,1000,Any() );
}
- // Attach filter
- // Construct SELECT without WHERE and ORDER BY
OUString aQuote = m_xMetaData->getIdentifierQuoteString();
if ( m_aCurrentColumns[SelectColumns]->hasByName(aName) )
{
@@ -491,7 +492,7 @@ OUString OSingleSelectQueryComposer::impl_getColumnName_throw(const Reference< X
OSL_ENSURE(xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_TABLENAME),"Property TABLENAME not available!");
OSL_ENSURE(xColumn->getPropertySetInfo()->hasPropertyByName("Function"),"Property FUNCTION not available!");
- OUString sRealName,sTableName;
+ OUString sRealName, sTableName;
xColumn->getPropertyValue(PROPERTY_REALNAME) >>= sRealName;
xColumn->getPropertyValue(PROPERTY_TABLENAME) >>= sTableName;
sal_Bool bFunction = sal_False;
@@ -525,11 +526,43 @@ OUString OSingleSelectQueryComposer::impl_getColumnName_throw(const Reference< X
return aNewName;
}
+OUString OSingleSelectQueryComposer::impl_getColumnName_throw(const Reference< XPropertySet >& column, bool bOrderBy)
+{
+ ::connectivity::checkDisposed(OSubComponent::rBHelper.bDisposed);
+
+ getColumns();
+ if ( !column.is()
+ || !m_aCurrentColumns[SelectColumns]
+ || !column->getPropertySetInfo()->hasPropertyByName(PROPERTY_NAME)
+ )
+ {
+ OUString sError(DBACORE_RESSTRING(RID_STR_COLUMN_UNKNOWN_PROP));
+ SQLException aErr(sError.replaceAll("%value", OUString(PROPERTY_NAME)),*this,SQLSTATE_GENERAL,1000,Any() );
+ throw SQLException(DBACORE_RESSTRING(RID_STR_COLUMN_NOT_VALID),*this,SQLSTATE_GENERAL,1000,makeAny(aErr) );
+ }
+
+ OUString aName, aNewName;
+ column->getPropertyValue(PROPERTY_NAME) >>= aName;
+
+ if ( bOrderBy &&
+ !m_xMetaData->supportsOrderByUnrelated() &&
+ m_aCurrentColumns[SelectColumns] &&
+ !m_aCurrentColumns[SelectColumns]->hasByName(aName) )
+ {
+ OUString sError(DBACORE_RESSTRING(RID_STR_COLUMN_MUST_VISIBLE));
+ throw SQLException(sError.replaceAll("%name", aName),*this,SQLSTATE_GENERAL,1000,Any() );
+ }
+
+ const OUString aQuote = m_xMetaData->getIdentifierQuoteString();
+ aNewName = ::dbtools::quoteName(aQuote,aName);
+ return aNewName;
+}
+
void SAL_CALL OSingleSelectQueryComposer::appendOrderByColumn( const Reference< XPropertySet >& column, sal_Bool ascending ) throw(SQLException, RuntimeException)
{
SAL_INFO("dbaccess", "OSingleSelectQueryComposer::appendOrderByColumn" );
::osl::MutexGuard aGuard( m_aMutex );
- OUString sColumnName( impl_getColumnName_throw(column) );
+ OUString sColumnName( impl_getColumnName_throw(column, true) );
OUString sOrder = getOrder();
if ( !(sOrder.isEmpty() || sColumnName.isEmpty()) )
sOrder += COMMA;
@@ -544,7 +577,7 @@ void SAL_CALL OSingleSelectQueryComposer::appendGroupByColumn( const Reference<
{
SAL_INFO("dbaccess", "OSingleSelectQueryComposer::appendGroupByColumn" );
::osl::MutexGuard aGuard( m_aMutex );
- OUString sColumnName( impl_getColumnName_throw(column) );
+ OUString sColumnName( impl_getColumnRealName_throw(column, true) );
OrderCreator aComposer;
aComposer.append( getGroup() );
aComposer.append( sColumnName );
diff --git a/dbaccess/source/core/inc/SingleSelectQueryComposer.hxx b/dbaccess/source/core/inc/SingleSelectQueryComposer.hxx
index 1f9c720..7031b4d 100644
--- a/dbaccess/source/core/inc/SingleSelectQueryComposer.hxx
+++ b/dbaccess/source/core/inc/SingleSelectQueryComposer.hxx
@@ -180,9 +180,25 @@ namespace dbaccess
*/
OUString composeStatementFromParts( const ::std::vector< OUString >& _rParts );
- /** return the name of the column.
+ /** return the name of the column in the *source* *table*.
+
+ That is, for (SELECT a AS b FROM t), it returns A or "t"."A", as appropriate.
+
+ Use e.g. for WHERE, GROUP BY and HAVING clauses.
+
+ @param bGroupBy: for GROUP BY clause? In that case, throw exception if trying to use an unrelated column and the database does not support that.
+ */
+ OUString impl_getColumnRealName_throw(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column, bool bGroupBy);
+
+ /** return the name of the column in the *query*
+
+ That is, for (SELECT a AS b FROM t), it returns "b"
+
+ Use e.g. for ORDER BY clause.
+
+ @param bOrderBy: for ORDER BY clause? In that case, throw exception if trying to use an unrelated column and the database does not support that.
*/
- OUString impl_getColumnName_throw(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column);
+ OUString impl_getColumnName_throw(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& column, bool bOrderBy);
protected:
virtual ~OSingleSelectQueryComposer();
diff --git a/dbaccess/source/ui/dlg/queryorder.cxx b/dbaccess/source/ui/dlg/queryorder.cxx
index 60860c3..c241c77 100644
--- a/dbaccess/source/ui/dlg/queryorder.cxx
+++ b/dbaccess/source/ui/dlg/queryorder.cxx
@@ -234,30 +234,7 @@ OUString DlgOrderCrit::GetOrderList( ) const
sOrder += OUString(",");
String sName = m_aColumnList[i]->GetSelectEntry();
- try
- {
- sal_Bool bFunction = sal_False;
- Reference< XPropertySet > xColumn;
- if ( xColumns.is() && xColumns->hasByName( sName ) && (xColumns->getByName( sName ) >>= xColumn) && xColumn.is() )
- {
- if ( xColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_REALNAME) )
- {
- OUString sRealName;
- xColumn->getPropertyValue(PROPERTY_REALNAME) >>= sRealName;
- sName = sRealName;
- static OUString sFunction("Function");
- if ( xColumn->getPropertySetInfo()->hasPropertyByName(sFunction) )
- xColumn->getPropertyValue(sFunction) >>= bFunction;
- }
- }
- if ( bFunction )
- sOrder += sName;
- else
- sOrder += ::dbtools::quoteName(sQuote,sName);
- }
- catch(const Exception&)
- {
- }
+ sOrder += ::dbtools::quoteName(sQuote,sName);
if(m_aValueList[i]->GetSelectEntryPos())
sOrder += sDESC;
else
diff --git a/include/connectivity/sqliterator.hxx b/include/connectivity/sqliterator.hxx
index ee967dd..b9a1b6c 100644
--- a/include/connectivity/sqliterator.hxx
+++ b/include/connectivity/sqliterator.hxx
@@ -111,6 +111,14 @@ namespace connectivity
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > findColumn(
const OUString & rColumnName, OUString & rTableRange, bool _bLookInSubTables );
+ /** finds a column with a given name among the select columns
+ @param rColumnName
+ the column name to look for
+ @return
+ */
+ ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > findSelectColumn(
+ const OUString & rColumnName );
+
protected:
void setSelectColumnName(::rtl::Reference<OSQLColumns>& _rColumns,const OUString & rColumnName,const OUString & rColumnAlias, const OUString & rTableRange,sal_Bool bFkt=sal_False,sal_Int32 _nType = com::sun::star::sdbc::DataType::VARCHAR,sal_Bool bAggFkt=sal_False);
void appendColumns(::rtl::Reference<OSQLColumns>& _rColumns,const OUString& _rTableAlias,const OSQLTable& _rTable);
commit ad1049716a6e62066a196c78b163c30af3a2d264
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date: Thu Jul 11 16:41:48 2013 +0200
remove unreachable code, reorganise OSL_ENSUREs
Change-Id: I5a5df020dd6900e28a9db94bfa179baa3f59dc4a
diff --git a/connectivity/source/parse/sqliterator.cxx b/connectivity/source/parse/sqliterator.cxx
index fa605a4..927dfa9 100644
--- a/connectivity/source/parse/sqliterator.cxx
+++ b/connectivity/source/parse/sqliterator.cxx
@@ -1096,23 +1096,19 @@ void OSQLParseTreeIterator::traverseByColumnNames(const OSQLParseNode* pSelectNo
pColumnRef = pColumnRef->getChild(0);
}
+ OSL_ENSURE(pColumnRef != NULL,"OSQLParseTreeIterator: error in parse tree!");
aTableRange = OUString();
sColumnName = OUString();
if ( SQL_ISRULE(pColumnRef,column_ref) )
{
// Column name (and TableRange):
- if(SQL_ISRULE(pColumnRef,column_ref))
- getColumnRange(pColumnRef,sColumnName,aTableRange);
- else // an expression
- pColumnRef->parseNodeToStr( sColumnName, m_pImpl->m_xConnection, NULL, sal_False, sal_False );
-
- OSL_ENSURE(!sColumnName.isEmpty(),"sColumnName must not be empty!");
+ getColumnRange(pColumnRef,sColumnName,aTableRange);
}
else
{ // here I found a predicate
pColumnRef->parseNodeToStr( sColumnName, m_pImpl->m_xConnection, NULL, sal_False, sal_False );
}
- OSL_ENSURE(pColumnRef != NULL,"OSQLParseTreeIterator: error in parse tree!");
+ OSL_ENSURE(!sColumnName.isEmpty(),"sColumnName must not be empty!");
if ( _bOrder )
{
// Ascending/Descending
commit 48e5349a6e7f155e8709c4e9d0839eea51d57557
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date: Thu Jul 11 16:40:10 2013 +0200
lcl_getColumnRange: no table range -> match 1st name-matching select column
as opposed to no match
Change-Id: I811abd9df5b6cc617c28ab330cecb406cd11e709
diff --git a/connectivity/source/parse/sqliterator.cxx b/connectivity/source/parse/sqliterator.cxx
index 0ae7b83..fa605a4 100644
--- a/connectivity/source/parse/sqliterator.cxx
+++ b/connectivity/source/parse/sqliterator.cxx
@@ -751,8 +751,11 @@ namespace
OUString sName, sTableName;
xColumn->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_REALNAME ) ) >>= sName;
xColumn->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_TABLENAME ) ) >>= sTableName;
- if ( sName == _out_rColumnName && sTableName == _out_rTableRange )
+ if ( sName == _out_rColumnName && ( _out_rTableRange.isEmpty() || sTableName == _out_rTableRange ) )
+ {
xColumn->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_NAME ) ) >>= _out_rColumnAliasIfPresent;
+ break;
+ }
}
catch( const Exception& )
{
commit 72e71b829d43144c2991b589b0db96097d7f4fb7
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date: Thu Jul 11 11:44:03 2013 +0200
delete in destructor checkbox created in constructor
Change-Id: Ifceae4c7ffe15bfc62ce34f4463fd4e071403359
fixes: debug build aborts when closing that window
diff --git a/dbaccess/source/ui/dlg/directsql.cxx b/dbaccess/source/ui/dlg/directsql.cxx
index cccafea..bb73d8a 100644
--- a/dbaccess/source/ui/dlg/directsql.cxx
+++ b/dbaccess/source/ui/dlg/directsql.cxx
@@ -121,6 +121,7 @@ DBG_NAME(DirectSQLDialog)
stopAllComponentListening();
}
delete m_pSQLHistory;
+ delete m_pShowOutput;
DBG_DTOR(DirectSQLDialog,NULL);
}
More information about the Libreoffice-commits
mailing list