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 );
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;
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())
147 if (static_cast<SotClipboardFormatId>(-1) == s_nFormat)
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:
189 if ((
m_nFormatFlags & ColumnTransferFormatFlags::COLUMN_DESCRIPTOR) == ColumnTransferFormatFlags::COLUMN_DESCRIPTOR)
192 if ( !_rConnectionResource.isEmpty() )
205 AddFormat(SotClipboardFormatId::SBA_CTRLDATAEXCHANGE);
208 AddFormat(SotClipboardFormatId::SBA_FIELDDATAEXCHANGE);
210 if (ColumnTransferFormatFlags::COLUMN_DESCRIPTOR & m_nFormatFlags)
220 case SotClipboardFormatId::SBA_FIELDDATAEXCHANGE:
221 case SotClipboardFormatId::SBA_CTRLDATAEXCHANGE:
236 bool bDescriptorFormat = bool(_nFormats & ColumnTransferFormatFlags::COLUMN_DESCRIPTOR);
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,
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;
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
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:
577 if (static_cast<SotClipboardFormatId>(-1) == s_nFormat)
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;
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
ODataAccessObjectTransferable()
void setDataSource(const OUString &_sDataSourceNameOrLocation)
set the data source name, if it is not file URL
::std::vector< DataFlavorEx > DataFlavorExVector
ColumnTransferFormatFlags m_nFormatFlags
css::uno::Sequence< css::beans::PropertyValue > m_aDescriptors
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
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
constexpr OUStringLiteral FM_PROP_ESCAPE_PROCESSING
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)
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
bool SetString(const OUString &rString)
constexpr OUStringLiteral FM_PROP_DATASOURCE
static bool canExtractObjectDescriptor(const DataFlavorExVector &_rFlavors)
checks whether or not an object descriptor can be extracted from the data flavor vector given ...
constexpr OUStringLiteral FM_PROP_COMMANDTYPE
virtual void AddSupportedFormats() override
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
bool GetString(SotClipboardFormatId nFormat, OUString &rStr) const
OUString m_sCompatibleObjectDescription
constexpr OUStringLiteral FM_PROP_URL
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
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.
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
static bool canExtractDescriptor(const DataFlavorExVector &_rFlavors)
checks whether or not an object descriptor can be extracted from the data flavor vector given ...
data source name (string)
constexpr OUStringLiteral FM_PROP_COMMAND
ODataAccessDescriptor m_aDescriptor
virtual void AddSupportedFormats() override
virtual void AddSupportedFormats() override
virtual void ObjectReleased() override
bool SetAny(const css::uno::Any &rAny)
constexpr OUStringLiteral FM_PROP_ACTIVECOMMAND
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
virtual void ObjectReleased() override
OMultiColumnTransferable()
ColumnTransferFormatFlags
constexpr OUStringLiteral FM_PROP_ACTIVE_CONNECTION
static bool GetFormatDataFlavor(SotClipboardFormatId nFormat, css::datatransfer::DataFlavor &rFlavor)