21 #include <osl/diagnose.h>
22 #include <com/sun/star/sdb/CommandType.hpp>
23 #include <com/sun/star/sdbc/XConnection.hpp>
24 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
25 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
46 : m_nFormatFlags(nFormats)
54 OUString sDataSource, sDatabaseLocation, sConnectionResource, sCommand, sFieldName;
61 sal_Int32 nCommandType = CommandType::TABLE;
65 sDataSource.isEmpty() ? sDatabaseLocation : sDataSource,
66 sConnectionResource, nCommandType, sCommand, sFieldName );
78 const OUString& _rFieldName,
const Reference< XPropertySet >& _rxColumn,
80 :m_nFormatFlags(_nFormats)
82 OSL_ENSURE(_rxForm.is(),
"OColumnTransferable::OColumnTransferable: invalid form!");
85 sal_Int32 nCommandType = CommandType::TABLE;
86 OUString sDatasource,sURL;
88 bool bTryToParse =
true;
93 _rxForm->getPropertyValue(FM_PROP_DATASOURCE) >>= sDatasource;
99 OSL_FAIL(
"OColumnTransferable::OColumnTransferable: could not collect essential data source attributes !");
104 if (bTryToParse && (CommandType::COMMAND == nCommandType))
108 Reference< XTablesSupplier > xSupTab;
109 _rxForm->getPropertyValue(
"SingleSelectQueryComposer") >>= xSupTab;
113 Reference< XNameAccess > xNames = xSupTab->getTables();
117 if (1 == aTables.getLength())
119 sCommand = aTables[0];
120 nCommandType = CommandType::TABLE;
127 OSL_FAIL(
"OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !");
131 implConstruct(sDatasource, sURL,nCommandType, sCommand, _rFieldName);
137 if (_rxConnection.is())
146 if (static_cast<SotClipboardFormatId>(-1) == s_nFormat)
149 OSL_ENSURE(static_cast<SotClipboardFormatId>(-1) != s_nFormat,
"OColumnTransferable::getDescriptorFormatId: bad exchange id!");
156 ,
const OUString& _rConnectionResource
157 ,
const sal_Int32 _nCommandType
158 ,
const OUString& _rCommand
159 ,
const OUString& _rFieldName)
162 const OUString sSeparator(&cSeparator, 1);
171 switch (_nCommandType)
173 case CommandType::TABLE:
176 case CommandType::QUERY:
188 if ((
m_nFormatFlags & ColumnTransferFormatFlags::COLUMN_DESCRIPTOR) == ColumnTransferFormatFlags::COLUMN_DESCRIPTOR)
191 if ( !_rConnectionResource.isEmpty() )
204 AddFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE);
207 AddFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE);
209 if (ColumnTransferFormatFlags::COLUMN_DESCRIPTOR & m_nFormatFlags)
219 case SotClipboardFormatId::SBA_FIELDDATAEXCHANGE:
220 case SotClipboardFormatId::SBA_CTRLDATAEXCHANGE:
235 bool bDescriptorFormat = bool(_nFormats & ColumnTransferFormatFlags::COLUMN_DESCRIPTOR);
237 return std::any_of(_rFlavors.begin(), _rFlavors.end(),
239 return (bFieldFormat && (SotClipboardFormatId::SBA_FIELDDATAEXCHANGE == rCheck.mnSotId))
240 || (bControlFormat && (SotClipboardFormatId::SBA_CTRLDATAEXCHANGE == rCheck.mnSotId))
241 || (bDescriptorFormat && (nFormatId == rCheck.mnSotId));
256 OSL_ENSURE(bSuccess,
"OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
258 Any aDescriptor = _rData.
GetAny(aFlavor, OUString());
261 Sequence< PropertyValue > aDescriptorProps;
262 bSuccess = aDescriptor >>= aDescriptorProps;
263 OSL_ENSURE(bSuccess,
"OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
270 OUString sDatasource, sCommand, sFieldName,sDatabaseLocation,sConnectionResource;
271 sal_Int32 nCommandType = CommandType::COMMAND;
274 if (
extractColumnDescriptor(_rData, sDatasource, sDatabaseLocation,sConnectionResource,nCommandType, sCommand, sFieldName))
277 if ( !sDatasource.isEmpty() )
279 if ( !sDatabaseLocation.isEmpty() )
281 if ( !sConnectionResource.isEmpty() )
293 ,OUString& _rDatasource
294 ,OUString& _rDatabaseLocation
295 ,OUString& _rConnectionResource
296 ,sal_Int32& _nCommandType
298 ,OUString& _rFieldName)
318 if (_rData.
HasFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE))
319 nRecognizedFormat = SotClipboardFormatId::SBA_FIELDDATAEXCHANGE;
320 if (_rData.
HasFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE))
321 nRecognizedFormat = SotClipboardFormatId::SBA_CTRLDATAEXCHANGE;
322 if (nRecognizedFormat == SotClipboardFormatId::NONE)
325 OUString sFieldDescription;
326 (
void)const_cast<TransferableDataHelper&>(_rData).GetString(nRecognizedFormat, sFieldDescription);
330 _rDatasource = sFieldDescription.getToken(0, cSeparator, nIdx);
331 _rCommand = sFieldDescription.getToken(0, cSeparator, nIdx);
332 _nCommandType = sFieldDescription.getToken(0, cSeparator, nIdx).toInt32();
333 _rFieldName = sFieldDescription.getToken(0, cSeparator, nIdx);
340 const OUString& _rDatasource
341 ,
const sal_Int32 _nCommandType
342 ,
const OUString& _rCommand
345 construct(_rDatasource,OUString(),_nCommandType,_rCommand,
nullptr,(CommandType::COMMAND == _nCommandType),_rCommand);
349 const OUString& _rDatasource
350 ,
const sal_Int32 _nCommandType
351 ,
const OUString& _rCommand
352 ,
const Reference< XConnection >& _rxConnection)
354 OSL_ENSURE(_rxConnection.is(),
"Wrong ctor used.!");
355 construct(_rDatasource,OUString(),_nCommandType,_rCommand,_rxConnection,(CommandType::COMMAND == _nCommandType),_rCommand);
362 OUString sDatasourceName,sConnectionResource;
363 sal_Int32 nObjectType = CommandType::COMMAND;
364 OUString sObjectName;
365 Reference< XConnection > xConnection;
370 _rxLivingForm->getPropertyValue(FM_PROP_DATASOURCE) >>= sDatasourceName;
371 _rxLivingForm->getPropertyValue(
FM_PROP_URL) >>= sConnectionResource;
376 OSL_FAIL(
"ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes !");
381 OUString sCompleteStatement;
386 catch (
const Exception&)
388 OSL_FAIL(
"ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes (part two) !");
395 ,sObjectName,xConnection
396 ,CommandType::QUERY != nObjectType
397 ,sCompleteStatement);
403 sal_Int32 nObjectType = CommandType::COMMAND;
407 case CommandType::TABLE:
408 AddFormat(SotClipboardFormatId::DBACCESS_TABLE);
410 case CommandType::QUERY:
411 AddFormat(SotClipboardFormatId::DBACCESS_QUERY);
413 case CommandType::COMMAND:
414 AddFormat(SotClipboardFormatId::DBACCESS_COMMAND);
419 AddFormat(SotClipboardFormatId::SBA_DATAEXCHANGE);
428 case SotClipboardFormatId::DBACCESS_TABLE:
429 case SotClipboardFormatId::DBACCESS_QUERY:
430 case SotClipboardFormatId::DBACCESS_COMMAND:
433 case SotClipboardFormatId::SBA_DATAEXCHANGE:
443 return std::any_of(_rFlavors.begin(), _rFlavors.end(),
445 return SotClipboardFormatId::DBACCESS_TABLE == rCheck.mnSotId
446 || SotClipboardFormatId::DBACCESS_QUERY == rCheck.mnSotId
447 || SotClipboardFormatId::DBACCESS_COMMAND == rCheck.mnSotId;
455 if ( _rData.
HasFormat( SotClipboardFormatId::DBACCESS_TABLE ) )
456 nKnownFormatId = SotClipboardFormatId::DBACCESS_TABLE;
457 if ( _rData.
HasFormat( SotClipboardFormatId::DBACCESS_QUERY ) )
458 nKnownFormatId = SotClipboardFormatId::DBACCESS_QUERY;
459 if ( _rData.
HasFormat( SotClipboardFormatId::DBACCESS_COMMAND ) )
460 nKnownFormatId = SotClipboardFormatId::DBACCESS_COMMAND;
462 if (SotClipboardFormatId::NONE != nKnownFormatId)
468 OSL_ENSURE(bSuccess,
"OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
470 Any aDescriptor = _rData.
GetAny(aFlavor, OUString());
473 Sequence< PropertyValue > aDescriptorProps;
474 bSuccess = aDescriptor >>= aDescriptorProps;
475 OSL_ENSURE(bSuccess,
"OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
481 OSL_FAIL(
"OColumnTransferable::extractColumnDescriptor: unsupported formats only!" );
489 const OUString sSeparator(&cSeparator, 1);
491 for (
const Any& rSelRow : _rSelRows )
493 sal_Int32 nSelectedRow( 0 );
494 OSL_VERIFY( rSelRow >>= nSelectedRow );
508 ,
const OUString& _rConnectionResource
509 ,
const sal_Int32 _nCommandType
510 ,
const OUString& _rCommand
511 ,
const Reference< XConnection >& _rxConnection
513 ,
const OUString& _sActiveCommand)
517 if ( !_rConnectionResource.isEmpty() )
519 if ( _rxConnection.is() )
526 OUString sObjectName = _rCommand;
530 bool bTreatAsStatement = (CommandType::COMMAND == _nCommandType);
534 const OUString sSeparator(&cSeparator, 1);
544 switch (_nCommandType)
546 case CommandType::TABLE:
549 case CommandType::QUERY:
552 case CommandType::COMMAND:
575 if (static_cast<SotClipboardFormatId>(-1) == s_nFormat)
578 OSL_ENSURE(static_cast<SotClipboardFormatId>(-1) != s_nFormat,
"OColumnTransferable::getDescriptorFormatId: bad exchange id!");
602 return std::all_of(_rFlavors.begin(), _rFlavors.end(),
603 [&nFormatId](
const DataFlavorEx& rCheck) {
return nFormatId == rCheck.mnSotId; });
608 Sequence< PropertyValue > aList;
615 OSL_ENSURE(bSuccess,
"OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
617 _rData.
GetAny(aFlavor, OUString()) >>= aList;
void setDescriptors(const css::uno::Sequence< css::beans::PropertyValue > &rDescriptors)
OUString m_sCompatibleFormat
static SotClipboardFormatId RegisterFormatName(const OUString &rName)
ODataAccessDescriptor m_aDescriptor
css::uno::Any GetAny(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
void setDataSource(const OUString &_sDataSourceNameOrLocation)
set the data source name, if it is not file URL
::std::vector< DataFlavorEx > DataFlavorExVector
css::uno::Sequence< css::beans::PropertyValue > m_aDescriptors
database driver URL (string)
void setDescriptor(const ODataAccessDescriptor &rDescriptor)
construct the transferable from a data access descriptor
css::uno::Sequence< css::beans::PropertyValue > const & createPropertyValueSequence()
returns the descriptor as property value sequence
bool HasFormat(SotClipboardFormatId nFormat) const
database file URL (string)
void AddFormat(SotClipboardFormatId nFormat)
OColumnTransferable(ColumnTransferFormatFlags nFormats)
SVX_DLLPRIVATE void construct(const OUString &_rDatasourceOrLocation, const OUString &_rConnectionResource, const sal_Int32 _nCommandType, const OUString &_rCommand, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, bool _bAddCommand, const OUString &_sActiveCommand)
ODataAccessObjectTransferable(const OUString &_rDatasourceOrLocation, const sal_Int32 _nCommandType, const OUString &_rCommand, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection)
should be used copying and the connection is needed.
static bool extractColumnDescriptor(const TransferableDataHelper &_rData, OUString &_rDatasource, OUString &_rDatabaseLocation, OUString &_rConnectionResource, sal_Int32 &_nCommandType, OUString &_rCommand, OUString &_rFieldName)
extracts a column descriptor from the transferable given
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
static bool canExtractColumnDescriptor(const DataFlavorExVector &_rFlavors, ColumnTransferFormatFlags _nFormats)
checks whether or not a column descriptor can be extracted from the data flavor vector given ...
SVX_DLLPRIVATE void implConstruct(const OUString &_rDatasource, const OUString &_rConnectionResource, const sal_Int32 _nCommandType, const OUString &_rCommand, const OUString &_rFieldName)
void clear()
empties the descriptor
static bool canExtractObjectDescriptor(const DataFlavorExVector &_rFlavors)
checks whether or not an object descriptor can be extracted from the data flavor vector given ...
#define FM_PROP_ESCAPE_PROCESSING
ColumnTransferFormatFlags const m_nFormatFlags
virtual void AddSupportedFormats() override
OUString m_sCompatibleObjectDescription
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
static SotClipboardFormatId getDescriptorFormatId()
static SotClipboardFormatId GetFormat(const css::datatransfer::DataFlavor &rFlavor)
class encapsulating the css::sdb::DataAccessDescriptor service.
bool has(DataAccessDescriptorProperty _eWhich) const
checks whether or not a given property is present in the descriptor
#define FM_PROP_ACTIVE_CONNECTION
static bool canExtractDescriptor(const DataFlavorExVector &_rFlavors)
checks whether or not an object descriptor can be extracted from the data flavor vector given ...
#define FM_PROP_ACTIVECOMMAND
#define FM_PROP_COMMANDTYPE
data source name (string)
ODataAccessDescriptor m_aDescriptor
virtual void AddSupportedFormats() override
virtual void AddSupportedFormats() override
virtual void ObjectReleased() override
bool SetAny(const css::uno::Any &rAny)
static SotClipboardFormatId getDescriptorFormatId()
void addCompatibleSelectionDescription(const css::uno::Sequence< css::uno::Any > &_rSelRows)
static ODataAccessDescriptor extractObjectDescriptor(const TransferableDataHelper &_rData)
extracts an object descriptor from the transferable given
static css::uno::Sequence< css::beans::PropertyValue > extractDescriptor(const TransferableDataHelper &_rData)
extracts an object descriptor from the transferable given
bool SetString(const OUString &rString, const css::datatransfer::DataFlavor &rFlavor)
virtual void ObjectReleased() override
OMultiColumnTransferable()
ColumnTransferFormatFlags
static bool GetFormatDataFlavor(SotClipboardFormatId nFormat, css::datatransfer::DataFlavor &rFlavor)
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)