21#include <osl/diagnose.h>
22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <com/sun/star/sdb/CommandType.hpp>
24#include <com/sun/star/sdbc/XConnection.hpp>
25#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
47 : m_nFormatFlags(nFormats)
55 OUString sDataSource, sDatabaseLocation, sConnectionResource, sCommand, sFieldName;
62 sal_Int32 nCommandType = CommandType::TABLE;
66 sDataSource.isEmpty() ? sDatabaseLocation : sDataSource,
67 sConnectionResource, nCommandType, sCommand, sFieldName );
79 const OUString& _rFieldName,
const Reference< XPropertySet >& _rxColumn,
81 :m_nFormatFlags(_nFormats)
83 OSL_ENSURE(_rxForm.is(),
"OColumnTransferable::OColumnTransferable: invalid form!");
86 sal_Int32 nCommandType = CommandType::TABLE;
87 OUString sDatasource,sURL;
89 bool bTryToParse =
true;
100 OSL_FAIL(
"OColumnTransferable::OColumnTransferable: could not collect essential data source attributes !");
105 if (bTryToParse && (CommandType::COMMAND == nCommandType))
109 Reference< XTablesSupplier > xSupTab;
110 _rxForm->getPropertyValue(
"SingleSelectQueryComposer") >>= xSupTab;
114 Reference< XNameAccess > xNames = xSupTab->getTables();
117 Sequence< OUString > aTables = xNames->getElementNames();
118 if (1 == aTables.getLength())
120 sCommand = aTables[0];
121 nCommandType = CommandType::TABLE;
128 OSL_FAIL(
"OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !");
132 implConstruct(sDatasource, sURL,nCommandType, sCommand, _rFieldName);
138 if (_rxConnection.is())
150 OSL_ENSURE(
static_cast<SotClipboardFormatId>(-1) != s_nFormat,
"OColumnTransferable::getDescriptorFormatId: bad exchange id!");
157 ,
const OUString& _rConnectionResource
158 ,
const sal_Int32 _nCommandType
159 ,
const OUString& _rCommand
160 ,
const OUString& _rFieldName)
163 const OUString sSeparator(&cSeparator, 1);
172 switch (_nCommandType)
174 case CommandType::TABLE:
177 case CommandType::QUERY:
192 if ( !_rConnectionResource.isEmpty() )
205 AddFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE);
208 AddFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE);
220 case SotClipboardFormatId::SBA_FIELDDATAEXCHANGE:
221 case SotClipboardFormatId::SBA_CTRLDATAEXCHANGE:
238 return std::any_of(_rFlavors.begin(), _rFlavors.end(),
240 return (bFieldFormat && (SotClipboardFormatId::SBA_FIELDDATAEXCHANGE == rCheck.mnSotId))
241 || (bControlFormat && (SotClipboardFormatId::SBA_CTRLDATAEXCHANGE == rCheck.mnSotId))
242 || (bDescriptorFormat && (nFormatId == rCheck.mnSotId));
257 OSL_ENSURE(bSuccess,
"OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
259 Any aDescriptor = _rData.
GetAny(aFlavor, OUString());
262 Sequence< PropertyValue > aDescriptorProps;
263 bSuccess = aDescriptor >>= aDescriptorProps;
264 OSL_ENSURE(bSuccess,
"OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
271 OUString sDatasource, sCommand, sFieldName,sDatabaseLocation,sConnectionResource;
272 sal_Int32 nCommandType = CommandType::COMMAND;
275 if (
extractColumnDescriptor(_rData, sDatasource, sDatabaseLocation,sConnectionResource,nCommandType, sCommand, sFieldName))
278 if ( !sDatasource.isEmpty() )
280 if ( !sDatabaseLocation.isEmpty() )
282 if ( !sConnectionResource.isEmpty() )
294 ,OUString& _rDatasource
295 ,OUString& _rDatabaseLocation
296 ,OUString& _rConnectionResource
297 ,sal_Int32& _nCommandType
299 ,OUString& _rFieldName)
319 if (_rData.
HasFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE))
320 nRecognizedFormat = SotClipboardFormatId::SBA_FIELDDATAEXCHANGE;
321 if (_rData.
HasFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE))
322 nRecognizedFormat = SotClipboardFormatId::SBA_CTRLDATAEXCHANGE;
323 if (nRecognizedFormat == SotClipboardFormatId::NONE)
326 OUString sFieldDescription;
327 (void)_rData.
GetString(nRecognizedFormat, sFieldDescription);
331 _rDatasource = sFieldDescription.getToken(0, cSeparator, nIdx);
332 _rCommand = sFieldDescription.getToken(0, cSeparator, nIdx);
334 _rFieldName = sFieldDescription.getToken(0, cSeparator, nIdx);
344 const OUString& _rDatasource,
345 const sal_Int32 _nCommandType,
346 const OUString& _rCommand)
348 construct(_rDatasource,OUString(),_nCommandType,_rCommand,
nullptr,(CommandType::COMMAND == _nCommandType),_rCommand);
352 const OUString& _rDatasource,
353 const sal_Int32 _nCommandType,
354 const OUString& _rCommand,
355 const Reference< XConnection >& _rxConnection)
357 OSL_ENSURE(_rxConnection.is(),
"Wrong Update used.!");
358 construct(_rDatasource,OUString(),_nCommandType,_rCommand,_rxConnection,(CommandType::COMMAND == _nCommandType),_rCommand);
364 OUString sDatasourceName,sConnectionResource;
365 sal_Int32 nObjectType = CommandType::COMMAND;
366 OUString sObjectName;
367 Reference< XConnection > xConnection;
373 _rxLivingForm->getPropertyValue(
FM_PROP_URL) >>= sConnectionResource;
378 OSL_FAIL(
"ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes !");
383 OUString sCompleteStatement;
388 catch (
const Exception&)
390 OSL_FAIL(
"ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes (part two) !");
397 ,sObjectName,xConnection
398 ,CommandType::QUERY != nObjectType
399 ,sCompleteStatement);
405 sal_Int32 nObjectType = CommandType::COMMAND;
409 case CommandType::TABLE:
410 AddFormat(SotClipboardFormatId::DBACCESS_TABLE);
412 case CommandType::QUERY:
413 AddFormat(SotClipboardFormatId::DBACCESS_QUERY);
415 case CommandType::COMMAND:
416 AddFormat(SotClipboardFormatId::DBACCESS_COMMAND);
421 AddFormat(SotClipboardFormatId::SBA_DATAEXCHANGE);
430 case SotClipboardFormatId::DBACCESS_TABLE:
431 case SotClipboardFormatId::DBACCESS_QUERY:
432 case SotClipboardFormatId::DBACCESS_COMMAND:
435 case SotClipboardFormatId::SBA_DATAEXCHANGE:
445 return std::any_of(_rFlavors.begin(), _rFlavors.end(),
447 return SotClipboardFormatId::DBACCESS_TABLE == rCheck.mnSotId
448 || SotClipboardFormatId::DBACCESS_QUERY == rCheck.mnSotId
449 || SotClipboardFormatId::DBACCESS_COMMAND == rCheck.mnSotId;
457 if ( _rData.
HasFormat( SotClipboardFormatId::DBACCESS_TABLE ) )
458 nKnownFormatId = SotClipboardFormatId::DBACCESS_TABLE;
459 if ( _rData.
HasFormat( SotClipboardFormatId::DBACCESS_QUERY ) )
460 nKnownFormatId = SotClipboardFormatId::DBACCESS_QUERY;
461 if ( _rData.
HasFormat( SotClipboardFormatId::DBACCESS_COMMAND ) )
462 nKnownFormatId = SotClipboardFormatId::DBACCESS_COMMAND;
464 if (SotClipboardFormatId::NONE != nKnownFormatId)
470 OSL_ENSURE(bSuccess,
"OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
472 Any aDescriptor = _rData.
GetAny(aFlavor, OUString());
475 Sequence< PropertyValue > aDescriptorProps;
476 bSuccess = aDescriptor >>= aDescriptorProps;
477 OSL_ENSURE(bSuccess,
"OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
483 OSL_FAIL(
"OColumnTransferable::extractColumnDescriptor: unsupported formats only!" );
491 const OUString sSeparator(&cSeparator, 1);
493 for (
const Any& rSelRow : _rSelRows )
495 sal_Int32 nSelectedRow( 0 );
496 OSL_VERIFY( rSelRow >>= nSelectedRow );
510 ,
const OUString& _rConnectionResource
511 ,
const sal_Int32 _nCommandType
512 ,
const OUString& _rCommand
513 ,
const Reference< XConnection >& _rxConnection
515 ,
const OUString& _sActiveCommand)
519 if ( !_rConnectionResource.isEmpty() )
521 if ( _rxConnection.is() )
528 OUString sObjectName = _rCommand;
532 bool bTreatAsStatement = (CommandType::COMMAND == _nCommandType);
536 const OUString sSeparator(&cSeparator, 1);
546 switch (_nCommandType)
548 case CommandType::TABLE:
551 case CommandType::QUERY:
554 case CommandType::COMMAND:
580 OSL_ENSURE(
static_cast<SotClipboardFormatId>(-1) != s_nFormat,
"OColumnTransferable::getDescriptorFormatId: bad exchange id!");
604 return std::all_of(_rFlavors.begin(), _rFlavors.end(),
605 [&nFormatId](
const DataFlavorEx& rCheck) { return nFormatId == rCheck.mnSotId; });
610 Sequence< PropertyValue > aList;
617 OSL_ENSURE(bSuccess,
"OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
619 _rData.
GetAny(aFlavor, OUString()) >>= aList;
static bool GetFormatDataFlavor(SotClipboardFormatId nFormat, css::datatransfer::DataFlavor &rFlavor)
static SotClipboardFormatId GetFormat(const css::datatransfer::DataFlavor &rFlavor)
static SotClipboardFormatId RegisterFormatName(const OUString &rName)
bool GetString(SotClipboardFormatId nFormat, OUString &rStr) const
css::uno::Any GetAny(SotClipboardFormatId nFormat, const OUString &rDestDoc) const
bool HasFormat(SotClipboardFormatId nFormat) const
bool SetAny(const css::uno::Any &rAny)
bool SetString(const OUString &rString)
void AddFormat(SotClipboardFormatId nFormat)
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
void setDescriptor(const ODataAccessDescriptor &rDescriptor)
construct the transferable from a data access descriptor
static SotClipboardFormatId getDescriptorFormatId()
SVX_DLLPRIVATE void implConstruct(const OUString &_rDatasource, const OUString &_rConnectionResource, const sal_Int32 _nCommandType, const OUString &_rCommand, const OUString &_rFieldName)
OUString m_sCompatibleFormat
static bool canExtractColumnDescriptor(const DataFlavorExVector &_rFlavors, ColumnTransferFormatFlags _nFormats)
checks whether or not a column descriptor can be extracted from the data flavor vector given
OColumnTransferable(ColumnTransferFormatFlags nFormats)
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
virtual void AddSupportedFormats() override
ODataAccessDescriptor m_aDescriptor
ColumnTransferFormatFlags m_nFormatFlags
class encapsulating the css::sdb::DataAccessDescriptor service.
css::uno::Sequence< css::beans::PropertyValue > const & createPropertyValueSequence()
returns the descriptor as property value sequence
bool has(DataAccessDescriptorProperty _eWhich) const
checks whether or not a given property is present in the descriptor
void clear()
empties the descriptor
void setDataSource(const OUString &_sDataSourceNameOrLocation)
set the data source name, if it is not file URL
static bool canExtractObjectDescriptor(const DataFlavorExVector &_rFlavors)
checks whether or not an object descriptor can be extracted from the data flavor vector given
void Update(const OUString &_rDatasource, const sal_Int32 _nCommandType, const OUString &_rCommand, const css::uno::Reference< css::sdbc::XConnection > &_rxConnection)
should be used copying and the connection is needed.
OUString m_sCompatibleObjectDescription
virtual void AddSupportedFormats() override
static ODataAccessDescriptor extractObjectDescriptor(const TransferableDataHelper &_rData)
extracts an object descriptor from the transferable given
ODataAccessObjectTransferable()
ODataAccessDescriptor m_aDescriptor
virtual void ObjectReleased() override
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
void addCompatibleSelectionDescription(const css::uno::Sequence< css::uno::Any > &_rSelRows)
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)
virtual void AddSupportedFormats() override
static SotClipboardFormatId getDescriptorFormatId()
void setDescriptors(const css::uno::Sequence< css::beans::PropertyValue > &rDescriptors)
static css::uno::Sequence< css::beans::PropertyValue > extractDescriptor(const TransferableDataHelper &_rData)
extracts an object descriptor from the transferable given
static bool canExtractDescriptor(const DataFlavorExVector &_rFlavors)
checks whether or not an object descriptor can be extracted from the data flavor vector given
css::uno::Sequence< css::beans::PropertyValue > m_aDescriptors
OMultiColumnTransferable()
virtual void ObjectReleased() override
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
ColumnTransferFormatFlags
::std::vector< DataFlavorEx > DataFlavorExVector
constexpr OUStringLiteral FM_PROP_ACTIVE_CONNECTION
constexpr OUStringLiteral FM_PROP_COMMAND
constexpr OUStringLiteral FM_PROP_ACTIVECOMMAND
constexpr OUStringLiteral FM_PROP_ESCAPE_PROCESSING
constexpr OUStringLiteral FM_PROP_URL
constexpr OUStringLiteral FM_PROP_COMMANDTYPE
constexpr OUStringLiteral FM_PROP_DATASOURCE
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
@ ConnectionResource
database file URL (string)
@ ColumnObject
column name (string)
@ ColumnName
the cursor (XResultSet)
@ DatabaseLocation
data source name (string)
@ Connection
database driver URL (string)
@ CommandType
command (string)
@ Command
connection (XConnection)