dba33f: #i108548# extend SingleSelectQueryComposer appendFilterByColumn with additonal parameter

This commit is contained in:
Ocke Janssen [oj] 2010-01-22 08:14:22 +01:00
parent cb2da11da5
commit 02f6eae3aa
7 changed files with 90 additions and 85 deletions

View File

@ -52,6 +52,7 @@ namespace connectivity
{ {
::rtl::OUString m_aRealName; ::rtl::OUString m_aRealName;
::rtl::OUString m_aTableName; ::rtl::OUString m_aTableName;
::rtl::OUString m_sLabel;
sal_Bool m_bFunction; sal_Bool m_bFunction;
sal_Bool m_bDbasePrecisionChanged; sal_Bool m_bDbasePrecisionChanged;
sal_Bool m_bAggregateFunction; sal_Bool m_bAggregateFunction;
@ -79,6 +80,7 @@ namespace connectivity
virtual void construct(); virtual void construct();
void setRealName(const ::rtl::OUString& _rName) { m_aRealName = _rName; } void setRealName(const ::rtl::OUString& _rName) { m_aRealName = _rName; }
void setLabel(const ::rtl::OUString& i_sLabel) { m_sLabel = i_sLabel; }
void setTableName(const ::rtl::OUString& _rName) { m_aTableName = _rName; } void setTableName(const ::rtl::OUString& _rName) { m_aTableName = _rName; }
void setFunction(sal_Bool _bFunction) { m_bFunction = _bFunction; } void setFunction(sal_Bool _bFunction) { m_bFunction = _bFunction; }
void setAggregateFunction(sal_Bool _bFunction) { m_bAggregateFunction = _bFunction; } void setAggregateFunction(sal_Bool _bFunction) { m_bAggregateFunction = _bFunction; }
@ -86,6 +88,7 @@ namespace connectivity
void setDbasePrecisionChanged(sal_Bool _bDbasePrecisionChanged) { m_bDbasePrecisionChanged = _bDbasePrecisionChanged; } void setDbasePrecisionChanged(sal_Bool _bDbasePrecisionChanged) { m_bDbasePrecisionChanged = _bDbasePrecisionChanged; }
::rtl::OUString getRealName() const { return m_aRealName; } ::rtl::OUString getRealName() const { return m_aRealName; }
::rtl::OUString getLabel() const { return m_sLabel; }
::rtl::OUString getTableName() const { return m_aTableName; } ::rtl::OUString getTableName() const { return m_aTableName; }
sal_Bool getFunction() const { return m_bFunction; } sal_Bool getFunction() const { return m_bFunction; }
sal_Bool getDbasePrecisionChanged() const { return m_bDbasePrecisionChanged; } sal_Bool getDbasePrecisionChanged() const { return m_bDbasePrecisionChanged; }

View File

@ -129,9 +129,27 @@ using namespace ::com::sun::star::beans;
case DataType::TIMESTAMP: case DataType::TIMESTAMP:
{ {
DateTime aDateTime; DateTime aDateTime;
bool bOk = false;
if (_rVal.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_DOUBLE)
{
double nValue = 0.0;
_rVal >>= nValue;
aDateTime = DBTypeConversion::toDateTime(nValue);
bOk = true;
}
else if (_rVal.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_STRING)
{
::rtl::OUString sValue;
_rVal >>= sValue;
aDateTime = DBTypeConversion::toDateTime(sValue);
bOk = true;
}
else
bOk = _rVal >>= aDateTime;
OSL_VERIFY_RES( bOk, "DBTypeConversion::toSQLString: _rVal is not datetime!");
// check if this is really a timestamp or only a date // check if this is really a timestamp or only a date
if ( _rVal >>= aDateTime ) if ( bOk )
{ {
if (bQuote) if (bQuote)
aRet.appendAscii("{TS '"); aRet.appendAscii("{TS '");
@ -145,7 +163,24 @@ using namespace ::com::sun::star::beans;
case DataType::DATE: case DataType::DATE:
{ {
Date aDate; Date aDate;
OSL_VERIFY_RES( _rVal >>= aDate, "DBTypeConversion::toSQLString: _rVal is not date!"); bool bOk = false;
if (_rVal.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_DOUBLE)
{
double nValue = 0.0;
_rVal >>= nValue;
aDate = DBTypeConversion::toDate(nValue);
bOk = true;
}
else if (_rVal.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_STRING)
{
::rtl::OUString sValue;
_rVal >>= sValue;
aDate = DBTypeConversion::toDate(sValue);
bOk = true;
}
else
bOk = _rVal >>= aDate;
OSL_VERIFY_RES( bOk, "DBTypeConversion::toSQLString: _rVal is not date!");
if (bQuote) if (bQuote)
aRet.appendAscii("{D '"); aRet.appendAscii("{D '");
aRet.append(DBTypeConversion::toDateString(aDate)); aRet.append(DBTypeConversion::toDateString(aDate));
@ -155,7 +190,24 @@ using namespace ::com::sun::star::beans;
case DataType::TIME: case DataType::TIME:
{ {
Time aTime; Time aTime;
OSL_VERIFY_RES( _rVal >>= aTime,"DBTypeConversion::toSQLString: _rVal is not time!"); bool bOk = false;
if (_rVal.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_DOUBLE)
{
double nValue = 0.0;
_rVal >>= nValue;
aTime = DBTypeConversion::toTime(nValue);
bOk = true;
}
else if (_rVal.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_STRING)
{
::rtl::OUString sValue;
_rVal >>= sValue;
aTime = DBTypeConversion::toTime(sValue);
bOk = true;
}
else
bOk = _rVal >>= aTime;
OSL_VERIFY_RES( bOk,"DBTypeConversion::toSQLString: _rVal is not time!");
if (bQuote) if (bQuote)
aRet.appendAscii("{T '"); aRet.appendAscii("{T '");
aRet.append(DBTypeConversion::toTimeString(aTime)); aRet.append(DBTypeConversion::toTimeString(aTime));

View File

@ -96,6 +96,7 @@ namespace dbtools
const sal_Char* getPROPERTY_ID_FIELDTYPE() { return "FieldType"; } const sal_Char* getPROPERTY_ID_FIELDTYPE() { return "FieldType"; }
const sal_Char* getPROPERTY_ID_VALUE() { return "Value"; } const sal_Char* getPROPERTY_ID_VALUE() { return "Value"; }
const sal_Char* getPROPERTY_ID_ACTIVE_CONNECTION() { return "ActiveConnection"; } const sal_Char* getPROPERTY_ID_ACTIVE_CONNECTION() { return "ActiveConnection"; }
const sal_Char* getPROPERTY_ID_LABEL() { return "Label"; }
//============================================================ //============================================================
//= error messages //= error messages
@ -183,6 +184,7 @@ namespace dbtools
case PROPERTY_ID_HAVINGCLAUSE: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_HAVINGCLAUSE() ); break; } case PROPERTY_ID_HAVINGCLAUSE: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_HAVINGCLAUSE() ); break; }
case PROPERTY_ID_ISSIGNED: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_ISSIGNED() ); break; } case PROPERTY_ID_ISSIGNED: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_ISSIGNED() ); break; }
case PROPERTY_ID_ISSEARCHABLE: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_ISSEARCHABLE() ); break; } case PROPERTY_ID_ISSEARCHABLE: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_ISSEARCHABLE() ); break; }
case PROPERTY_ID_LABEL: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_LABEL() ); break; }
case PROPERTY_ID_APPLYFILTER: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_APPLYFILTER() ); break; } case PROPERTY_ID_APPLYFILTER: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_APPLYFILTER() ); break; }
case PROPERTY_ID_FILTER: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_FILTER() ); break; } case PROPERTY_ID_FILTER: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_FILTER() ); break; }
case PROPERTY_ID_MASTERFIELDS: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_MASTERFIELDS() ); break; } case PROPERTY_ID_MASTERFIELDS: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_MASTERFIELDS() ); break; }

View File

@ -136,7 +136,7 @@ pProperties[nPos++] = ::com::sun::star::beans::Property(::connectivity::OMetaCon
#define PROPERTY_ID_INVALID_INDEX 41 #define PROPERTY_ID_INVALID_INDEX 41
#define PROPERTY_ID_HY010 43 #define PROPERTY_ID_HY010 43
// FREE #define PROPERTY_ID_LABEL 44
#define PROPERTY_ID_DELIMITER 45 #define PROPERTY_ID_DELIMITER 45
#define PROPERTY_ID_FORMATKEY 46 #define PROPERTY_ID_FORMATKEY 46
#define PROPERTY_ID_LOCALE 47 #define PROPERTY_ID_LOCALE 47

View File

@ -155,6 +155,7 @@ OParseColumn* OParseColumn::createColumnForResultSet( const Reference< XResultSe
) ); ) );
pColumn->setIsSearchable( _rxResMetaData->isSearchable( _nColumnPos ) ); pColumn->setIsSearchable( _rxResMetaData->isSearchable( _nColumnPos ) );
pColumn->setRealName(_rxResMetaData->getColumnName( _nColumnPos )); pColumn->setRealName(_rxResMetaData->getColumnName( _nColumnPos ));
pColumn->setLabel(sLabel);
return pColumn; return pColumn;
} }
@ -171,7 +172,7 @@ void OParseColumn::construct()
registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME), PROPERTY_ID_REALNAME, 0, &m_aRealName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL))); registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME), PROPERTY_ID_REALNAME, 0, &m_aRealName, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DBASEPRECISIONCHANGED), PROPERTY_ID_DBASEPRECISIONCHANGED, 0, &m_bDbasePrecisionChanged, ::getCppuType(reinterpret_cast<sal_Bool*>(NULL))); registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DBASEPRECISIONCHANGED), PROPERTY_ID_DBASEPRECISIONCHANGED, 0, &m_bDbasePrecisionChanged, ::getCppuType(reinterpret_cast<sal_Bool*>(NULL)));
registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISSEARCHABLE), PROPERTY_ID_ISSEARCHABLE, 0, &m_bIsSearchable, ::getCppuType(reinterpret_cast< sal_Bool*>(NULL))); registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISSEARCHABLE), PROPERTY_ID_ISSEARCHABLE, 0, &m_bIsSearchable, ::getCppuType(reinterpret_cast< sal_Bool*>(NULL)));
registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL), PROPERTY_ID_LABEL, 0, &m_sLabel, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
::cppu::IPropertyArrayHelper* OParseColumn::createArrayHelper() const ::cppu::IPropertyArrayHelper* OParseColumn::createArrayHelper() const

View File

@ -138,19 +138,9 @@ namespace svx
{ {
try try
{ {
// need a query composer for this Reference< XTablesSupplier > xSupTab;
Reference< XSQLQueryComposerFactory > xComposerFac; _rxForm->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SingleSelectQueryComposer"))) >>= xSupTab;
_rxForm->getPropertyValue(FM_PROP_ACTIVE_CONNECTION) >>= xComposerFac;
Reference< XSQLQueryComposer > xComposer;
if (xComposerFac.is())
xComposer = xComposerFac->createQueryComposer();
if (xComposer.is())
{
::rtl::OUString sActiveCommand;
_rxForm->getPropertyValue(FM_PROP_ACTIVECOMMAND) >>= sActiveCommand;
xComposer->setQuery(sActiveCommand);
Reference< XTablesSupplier > xSupTab(xComposer, UNO_QUERY);
if(xSupTab.is()) if(xSupTab.is())
{ {
Reference< XNameAccess > xNames = xSupTab->getTables(); Reference< XNameAccess > xNames = xSupTab->getTables();
@ -165,7 +155,6 @@ namespace svx
} }
} }
} }
}
catch(Exception&) catch(Exception&)
{ {
OSL_ENSURE(sal_False, "OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !"); OSL_ENSURE(sal_False, "OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !");
@ -460,34 +449,10 @@ namespace svx
String sObjectKind = (CommandType::TABLE == nObjectType) ? String('1') : String('0'); String sObjectKind = (CommandType::TABLE == nObjectType) ? String('1') : String('0');
// check if the SQL-statement is modified // check if the SQL-statement is modified
sal_Bool bHasFilterOrSort(sal_False);
::rtl::OUString sCompleteStatement; ::rtl::OUString sCompleteStatement;
try try
{ {
::rtl::OUString sFilter, sSort;
if (::cppu::any2bool(_rxLivingForm->getPropertyValue(FM_PROP_APPLYFILTER)))
_rxLivingForm->getPropertyValue(FM_PROP_FILTER) >>= sFilter;
_rxLivingForm->getPropertyValue(FM_PROP_SORT) >>= sSort;
bHasFilterOrSort = (sFilter.getLength()>0) || (sSort.getLength()>0);
_rxLivingForm->getPropertyValue(FM_PROP_ACTIVECOMMAND) >>= sCompleteStatement; _rxLivingForm->getPropertyValue(FM_PROP_ACTIVECOMMAND) >>= sCompleteStatement;
// create a composer
Reference< XSQLQueryComposerFactory > xFactory( xConnection, UNO_QUERY );
Reference< XSQLQueryComposer > xComposer;
if (xFactory.is())
xComposer = xFactory->createQueryComposer();
// let the composer compose
if (xComposer.is())
{
xComposer->setQuery(sCompleteStatement);
xComposer->setFilter(sFilter);
xComposer->setOrder(sSort);
sCompleteStatement = xComposer->getComposedQuery();
}
// Usually, I would expect the result of the composing to be the same as the ActiveCommand property
// But this code here is pretty old, and I don't know wha the side effects are if I remove it now ...
} }
catch(Exception&) catch(Exception&)
{ {
@ -499,7 +464,7 @@ namespace svx
,sConnectionResource ,sConnectionResource
,nObjectType ,nObjectType
,sObjectName,xConnection ,sObjectName,xConnection
,!((CommandType::QUERY == nObjectType) && !bHasFilterOrSort) ,!((CommandType::QUERY == nObjectType))
,sCompleteStatement); ,sCompleteStatement);
} }

View File

@ -48,6 +48,8 @@
#include <com/sun/star/form/XBoundComponent.hpp> #include <com/sun/star/form/XBoundComponent.hpp>
#include <com/sun/star/script/XEventAttacherManager.hpp> #include <com/sun/star/script/XEventAttacherManager.hpp>
#include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp> #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
#include <com/sun/star/sdbc/ColumnValue.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp>
#include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/DataType.hpp>
#include <com/sun/star/sdbc/XStatement.hpp> #include <com/sun/star/sdbc/XStatement.hpp>
@ -85,6 +87,7 @@ using namespace ::svt;
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::sdb;
using namespace ::com::sun::star::beans; using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::form; using namespace ::com::sun::star::form;
@ -3042,43 +3045,22 @@ void DbFilterField::Update()
if (!xForm.is()) if (!xForm.is())
return; return;
Reference<XPropertySet> xFormProp(xForm,UNO_QUERY);
Reference< XTablesSupplier > xSupTab;
xFormProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SingleSelectQueryComposer"))) >>= xSupTab;
Reference< XConnection > xConnection(getRowSetConnection(xForm)); Reference< XConnection > xConnection(getRowSetConnection(xForm));
if (!xConnection.is()) if (!xSupTab.is())
return;
Reference< ::com::sun::star::sdb::XSQLQueryComposerFactory > xFactory(xConnection, UNO_QUERY);
if (!xFactory.is())
{
DBG_ERROR("DbFilterField::Update : used the right place to request the ::com::sun::star::sdb::XSQLQueryComposerFactory interface ?");
return;
}
Reference< ::com::sun::star::sdb::XSQLQueryComposer > xComposer = xFactory->createQueryComposer();
try
{
Reference< ::com::sun::star::beans::XPropertySet > xFormAsSet(xForm, UNO_QUERY);
::rtl::OUString sStatement;
xFormAsSet->getPropertyValue(FM_PROP_ACTIVECOMMAND) >>= sStatement;
xComposer->setQuery(sStatement);
}
catch(const Exception&)
{
::comphelper::disposeComponent(xComposer);
return;
}
Reference< ::com::sun::star::beans::XPropertySet > xComposerAsSet(xComposer, UNO_QUERY);
if (!xComposerAsSet.is())
return; return;
// search the field // search the field
Reference< ::com::sun::star::container::XNameAccess > xFieldNames; Reference< XColumnsSupplier > xSupCol(xSupTab,UNO_QUERY);
Reference< ::com::sun::star::container::XNameAccess > xTablesNames; Reference< ::com::sun::star::container::XNameAccess > xFieldNames = xSupCol->getColumns();
Reference< ::com::sun::star::beans::XPropertySet > xComposerFieldAsSet; if (!xFieldNames->hasByName(aName))
return;
::cppu::extractInterface(xFieldNames, xComposerAsSet->getPropertyValue(FM_PROP_SELECTED_FIELDS)); Reference< ::com::sun::star::container::XNameAccess > xTablesNames = xSupTab->getTables();
::cppu::extractInterface(xTablesNames, xComposerAsSet->getPropertyValue(FM_PROP_SELECTED_TABLES)); Reference< ::com::sun::star::beans::XPropertySet > xComposerFieldAsSet(xFieldNames->getByName(aName),UNO_QUERY);
::cppu::extractInterface(xComposerFieldAsSet, xFieldNames->getByName(aName));
if (xComposerFieldAsSet.is() && ::comphelper::hasProperty(FM_PROP_TABLENAME, xComposerFieldAsSet) && if (xComposerFieldAsSet.is() && ::comphelper::hasProperty(FM_PROP_TABLENAME, xComposerFieldAsSet) &&
::comphelper::hasProperty(FM_PROP_FIELDSOURCE, xComposerFieldAsSet)) ::comphelper::hasProperty(FM_PROP_FIELDSOURCE, xComposerFieldAsSet))