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_aTableName;
::rtl::OUString m_sLabel;
sal_Bool m_bFunction;
sal_Bool m_bDbasePrecisionChanged;
sal_Bool m_bAggregateFunction;
@ -79,15 +80,17 @@ namespace connectivity
virtual void construct();
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 setFunction(sal_Bool _bFunction) { m_bFunction = _bFunction; }
void setAggregateFunction(sal_Bool _bFunction) { m_bAggregateFunction = _bFunction; }
void setIsSearchable( sal_Bool _bIsSearchable ) { m_bIsSearchable = _bIsSearchable; }
void setDbasePrecisionChanged(sal_Bool _bDbasePrecisionChanged) { m_bDbasePrecisionChanged = _bDbasePrecisionChanged; }
::rtl::OUString getRealName() const { return m_aRealName; }
::rtl::OUString getTableName() const { return m_aTableName; }
sal_Bool getFunction() const { return m_bFunction; }
::rtl::OUString getRealName() const { return m_aRealName; }
::rtl::OUString getLabel() const { return m_sLabel; }
::rtl::OUString getTableName() const { return m_aTableName; }
sal_Bool getFunction() const { return m_bFunction; }
sal_Bool getDbasePrecisionChanged() const { return m_bDbasePrecisionChanged; }
public:

View File

@ -129,9 +129,27 @@ using namespace ::com::sun::star::beans;
case DataType::TIMESTAMP:
{
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
if ( _rVal >>= aDateTime )
if ( bOk )
{
if (bQuote)
aRet.appendAscii("{TS '");
@ -145,7 +163,24 @@ using namespace ::com::sun::star::beans;
case DataType::DATE:
{
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)
aRet.appendAscii("{D '");
aRet.append(DBTypeConversion::toDateString(aDate));
@ -155,7 +190,24 @@ using namespace ::com::sun::star::beans;
case DataType::TIME:
{
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)
aRet.appendAscii("{T '");
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_VALUE() { return "Value"; }
const sal_Char* getPROPERTY_ID_ACTIVE_CONNECTION() { return "ActiveConnection"; }
const sal_Char* getPROPERTY_ID_LABEL() { return "Label"; }
//============================================================
//= error messages
@ -183,6 +184,7 @@ namespace dbtools
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_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_FILTER: { rtl_uString_newFromAscii(&pStr,getPROPERTY_ID_FILTER() ); 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_HY010 43
// FREE
#define PROPERTY_ID_LABEL 44
#define PROPERTY_ID_DELIMITER 45
#define PROPERTY_ID_FORMATKEY 46
#define PROPERTY_ID_LOCALE 47

View File

@ -155,6 +155,7 @@ OParseColumn* OParseColumn::createColumnForResultSet( const Reference< XResultSe
) );
pColumn->setIsSearchable( _rxResMetaData->isSearchable( _nColumnPos ) );
pColumn->setRealName(_rxResMetaData->getColumnName( _nColumnPos ));
pColumn->setLabel(sLabel);
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_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_LABEL), PROPERTY_ID_LABEL, 0, &m_sLabel, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
}
// -----------------------------------------------------------------------------
::cppu::IPropertyArrayHelper* OParseColumn::createArrayHelper() const

View File

@ -138,30 +138,19 @@ namespace svx
{
try
{
// need a query composer for this
Reference< XSQLQueryComposerFactory > xComposerFac;
_rxForm->getPropertyValue(FM_PROP_ACTIVE_CONNECTION) >>= xComposerFac;
Reference< XSQLQueryComposer > xComposer;
if (xComposerFac.is())
xComposer = xComposerFac->createQueryComposer();
Reference< XTablesSupplier > xSupTab;
_rxForm->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SingleSelectQueryComposer"))) >>= xSupTab;
if (xComposer.is())
if(xSupTab.is())
{
::rtl::OUString sActiveCommand;
_rxForm->getPropertyValue(FM_PROP_ACTIVECOMMAND) >>= sActiveCommand;
xComposer->setQuery(sActiveCommand);
Reference< XTablesSupplier > xSupTab(xComposer, UNO_QUERY);
if(xSupTab.is())
Reference< XNameAccess > xNames = xSupTab->getTables();
if (xNames.is())
{
Reference< XNameAccess > xNames = xSupTab->getTables();
if (xNames.is())
Sequence< ::rtl::OUString > aTables = xNames->getElementNames();
if (1 == aTables.getLength())
{
Sequence< ::rtl::OUString > aTables = xNames->getElementNames();
if (1 == aTables.getLength())
{
sCommand = aTables[0];
nCommandType = CommandType::TABLE;
}
sCommand = aTables[0];
nCommandType = CommandType::TABLE;
}
}
}
@ -460,34 +449,10 @@ namespace svx
String sObjectKind = (CommandType::TABLE == nObjectType) ? String('1') : String('0');
// check if the SQL-statement is modified
sal_Bool bHasFilterOrSort(sal_False);
::rtl::OUString sCompleteStatement;
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;
// 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&)
{
@ -499,7 +464,7 @@ namespace svx
,sConnectionResource
,nObjectType
,sObjectName,xConnection
,!((CommandType::QUERY == nObjectType) && !bHasFilterOrSort)
,!((CommandType::QUERY == nObjectType))
,sCompleteStatement);
}

View File

@ -48,6 +48,8 @@
#include <com/sun/star/form/XBoundComponent.hpp>
#include <com/sun/star/script/XEventAttacherManager.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/DataType.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::uno;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::sdb;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::form;
@ -3042,43 +3045,22 @@ void DbFilterField::Update()
if (!xForm.is())
return;
Reference<XPropertySet> xFormProp(xForm,UNO_QUERY);
Reference< XTablesSupplier > xSupTab;
xFormProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SingleSelectQueryComposer"))) >>= xSupTab;
Reference< XConnection > xConnection(getRowSetConnection(xForm));
if (!xConnection.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())
if (!xSupTab.is())
return;
// search the field
Reference< ::com::sun::star::container::XNameAccess > xFieldNames;
Reference< ::com::sun::star::container::XNameAccess > xTablesNames;
Reference< ::com::sun::star::beans::XPropertySet > xComposerFieldAsSet;
Reference< XColumnsSupplier > xSupCol(xSupTab,UNO_QUERY);
Reference< ::com::sun::star::container::XNameAccess > xFieldNames = xSupCol->getColumns();
if (!xFieldNames->hasByName(aName))
return;
::cppu::extractInterface(xFieldNames, xComposerAsSet->getPropertyValue(FM_PROP_SELECTED_FIELDS));
::cppu::extractInterface(xTablesNames, xComposerAsSet->getPropertyValue(FM_PROP_SELECTED_TABLES));
::cppu::extractInterface(xComposerFieldAsSet, xFieldNames->getByName(aName));
Reference< ::com::sun::star::container::XNameAccess > xTablesNames = xSupTab->getTables();
Reference< ::com::sun::star::beans::XPropertySet > xComposerFieldAsSet(xFieldNames->getByName(aName),UNO_QUERY);
if (xComposerFieldAsSet.is() && ::comphelper::hasProperty(FM_PROP_TABLENAME, xComposerFieldAsSet) &&
::comphelper::hasProperty(FM_PROP_FIELDSOURCE, xComposerFieldAsSet))