xref: /aoo42x/main/svx/source/fmcomp/dbaexchange.cxx (revision f6e50924)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <svx/dbaexchange.hxx>
27cdf0e10cSrcweir #include <osl/diagnose.h>
28cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
29cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
31cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
32cdf0e10cSrcweir #ifndef _SVX_FMPROP_HRC
33cdf0e10cSrcweir #include "fmprop.hrc"
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #include <comphelper/extract.hxx>
36cdf0e10cSrcweir #include <sot/formats.hxx>
37cdf0e10cSrcweir #include <sot/exchange.hxx>
38cdf0e10cSrcweir #include <comphelper/propertysetinfo.hxx>
39cdf0e10cSrcweir #ifndef _SVX_FMPROP_HRC
40cdf0e10cSrcweir #include "fmprop.hrc"
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #include <tools/urlobj.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //........................................................................
45cdf0e10cSrcweir namespace svx
46cdf0e10cSrcweir {
47cdf0e10cSrcweir //........................................................................
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
50cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
51cdf0e10cSrcweir 	using namespace ::com::sun::star::sdb;
52cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
53cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
54cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbcx;
55cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
56cdf0e10cSrcweir 	using namespace ::com::sun::star::datatransfer;
57cdf0e10cSrcweir 	using namespace ::comphelper;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	//====================================================================
60cdf0e10cSrcweir 	//= OColumnTransferable
61cdf0e10cSrcweir 	//====================================================================
62cdf0e10cSrcweir 	//--------------------------------------------------------------------
OColumnTransferable(const::rtl::OUString & _rDatasource,const::rtl::OUString & _rConnectionResource,const sal_Int32 _nCommandType,const::rtl::OUString & _rCommand,const::rtl::OUString & _rFieldName,sal_Int32 _nFormats)63cdf0e10cSrcweir 	OColumnTransferable::OColumnTransferable(const ::rtl::OUString&	_rDatasource
64cdf0e10cSrcweir 											,const ::rtl::OUString& _rConnectionResource
65cdf0e10cSrcweir 											,const sal_Int32		_nCommandType
66cdf0e10cSrcweir 											,const ::rtl::OUString&	_rCommand
67cdf0e10cSrcweir 											,const ::rtl::OUString&	_rFieldName
68cdf0e10cSrcweir 											,sal_Int32	_nFormats)
69cdf0e10cSrcweir 		:m_nFormatFlags(_nFormats)
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 		implConstruct(_rDatasource,_rConnectionResource,_nCommandType, _rCommand, _rFieldName);
72cdf0e10cSrcweir 	}
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	//--------------------------------------------------------------------
OColumnTransferable(const ODataAccessDescriptor & _rDescriptor,sal_Int32 _nFormats)75cdf0e10cSrcweir 	OColumnTransferable::OColumnTransferable(const ODataAccessDescriptor& _rDescriptor, sal_Int32 _nFormats )
76cdf0e10cSrcweir 		:m_nFormatFlags(_nFormats)
77cdf0e10cSrcweir 	{
78cdf0e10cSrcweir         ::rtl::OUString sDataSource, sDatabaseLocation, sConnectionResource, sCommand, sFieldName;
79cdf0e10cSrcweir         if ( _rDescriptor.has( daDataSource ) )         _rDescriptor[ daDataSource ] >>= sDataSource;
80cdf0e10cSrcweir         if ( _rDescriptor.has( daDatabaseLocation ) )   _rDescriptor[ daDatabaseLocation ] >>= sDatabaseLocation;
81cdf0e10cSrcweir         if ( _rDescriptor.has( daConnectionResource ) ) _rDescriptor[ daConnectionResource ] >>= sConnectionResource;
82cdf0e10cSrcweir         if ( _rDescriptor.has( daCommand ) )            _rDescriptor[ daCommand ] >>= sCommand;
83cdf0e10cSrcweir         if ( _rDescriptor.has( daColumnName ) )         _rDescriptor[ daColumnName ] >>= sFieldName;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         sal_Int32 nCommandType = CommandType::TABLE;
86cdf0e10cSrcweir         OSL_VERIFY( _rDescriptor[ daCommandType ] >>= nCommandType );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         implConstruct(
90cdf0e10cSrcweir             sDataSource.getLength() ? sDataSource : sDatabaseLocation,
91cdf0e10cSrcweir             sConnectionResource, nCommandType, sCommand, sFieldName );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         if ( m_nFormatFlags & CTF_COLUMN_DESCRIPTOR )
94cdf0e10cSrcweir         {
95cdf0e10cSrcweir             if ( _rDescriptor.has( daConnection ) )
96cdf0e10cSrcweir                 m_aDescriptor[ daConnection ] = _rDescriptor[ daConnection ];
97cdf0e10cSrcweir             if ( _rDescriptor.has( daColumnObject ) )
98cdf0e10cSrcweir                 m_aDescriptor[ daColumnObject ] = _rDescriptor[ daColumnObject ];
99cdf0e10cSrcweir         }
100cdf0e10cSrcweir 	}
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	//--------------------------------------------------------------------
OColumnTransferable(const Reference<XPropertySet> & _rxForm,const::rtl::OUString & _rFieldName,const Reference<XPropertySet> & _rxColumn,const Reference<XConnection> & _rxConnection,sal_Int32 _nFormats)103cdf0e10cSrcweir 	OColumnTransferable::OColumnTransferable(const Reference< XPropertySet >& _rxForm,
104cdf0e10cSrcweir 			const ::rtl::OUString& _rFieldName, const Reference< XPropertySet >& _rxColumn,
105cdf0e10cSrcweir 			const Reference< XConnection >& _rxConnection, sal_Int32 _nFormats)
106cdf0e10cSrcweir 		:m_nFormatFlags(_nFormats)
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		OSL_ENSURE(_rxForm.is(), "OColumnTransferable::OColumnTransferable: invalid form!");
109cdf0e10cSrcweir 		// collect the necessary information from the form
110cdf0e10cSrcweir 		::rtl::OUString sCommand;
111cdf0e10cSrcweir 		sal_Int32		nCommandType = CommandType::TABLE;
112cdf0e10cSrcweir 		::rtl::OUString sDatasource,sURL;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 		sal_Bool		bTryToParse = sal_True;
115cdf0e10cSrcweir 		try
116cdf0e10cSrcweir 		{
117cdf0e10cSrcweir 			_rxForm->getPropertyValue(FM_PROP_COMMANDTYPE)	>>= nCommandType;
118cdf0e10cSrcweir 			_rxForm->getPropertyValue(FM_PROP_COMMAND)		>>= sCommand;
119cdf0e10cSrcweir 			_rxForm->getPropertyValue(FM_PROP_DATASOURCE)	>>= sDatasource;
120cdf0e10cSrcweir 			_rxForm->getPropertyValue(FM_PROP_URL)			>>= sURL;
121cdf0e10cSrcweir 			bTryToParse = ::cppu::any2bool(_rxForm->getPropertyValue(FM_PROP_ESCAPE_PROCESSING));
122cdf0e10cSrcweir 		}
123cdf0e10cSrcweir 		catch(Exception&)
124cdf0e10cSrcweir 		{
125cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "OColumnTransferable::OColumnTransferable: could not collect essential data source attributes !");
126cdf0e10cSrcweir 		}
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		// If the data source is an SQL-statement and simple enough (means "select <field list> from <table> where ....")
129cdf0e10cSrcweir 		// we are able to fake the drag information we are about to create.
130cdf0e10cSrcweir 		if (bTryToParse && (CommandType::COMMAND == nCommandType))
131cdf0e10cSrcweir 		{
132cdf0e10cSrcweir 			try
133cdf0e10cSrcweir 			{
134cdf0e10cSrcweir                 Reference< XTablesSupplier > xSupTab;
135cdf0e10cSrcweir                 _rxForm->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SingleSelectQueryComposer"))) >>= xSupTab;
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 				if(xSupTab.is())
138cdf0e10cSrcweir 				{
139cdf0e10cSrcweir 					Reference< XNameAccess > xNames = xSupTab->getTables();
140cdf0e10cSrcweir 					if (xNames.is())
141cdf0e10cSrcweir 					{
142cdf0e10cSrcweir 						Sequence< ::rtl::OUString > aTables = xNames->getElementNames();
143cdf0e10cSrcweir 						if (1 == aTables.getLength())
144cdf0e10cSrcweir 						{
145cdf0e10cSrcweir 							sCommand		= aTables[0];
146cdf0e10cSrcweir 							nCommandType	= CommandType::TABLE;
147cdf0e10cSrcweir 						}
148cdf0e10cSrcweir 					}
149cdf0e10cSrcweir 				}
150cdf0e10cSrcweir 			}
151cdf0e10cSrcweir 			catch(Exception&)
152cdf0e10cSrcweir 			{
153cdf0e10cSrcweir 				OSL_ENSURE(sal_False, "OColumnTransferable::OColumnTransferable: could not collect essential data source attributes (part two) !");
154cdf0e10cSrcweir 			}
155cdf0e10cSrcweir 		}
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 		implConstruct(sDatasource, sURL,nCommandType, sCommand, _rFieldName);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 		if ((m_nFormatFlags & CTF_COLUMN_DESCRIPTOR) == CTF_COLUMN_DESCRIPTOR)
160cdf0e10cSrcweir 		{
161cdf0e10cSrcweir 			if (_rxColumn.is())
162cdf0e10cSrcweir 				m_aDescriptor[daColumnObject] <<= _rxColumn;
163cdf0e10cSrcweir 			if (_rxConnection.is())
164cdf0e10cSrcweir 				m_aDescriptor[daConnection] <<= _rxConnection;
165cdf0e10cSrcweir 		}
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	//--------------------------------------------------------------------
getDescriptorFormatId()169cdf0e10cSrcweir 	sal_uInt32 OColumnTransferable::getDescriptorFormatId()
170cdf0e10cSrcweir 	{
171cdf0e10cSrcweir 		static sal_uInt32 s_nFormat = (sal_uInt32)-1;
172cdf0e10cSrcweir 		if ((sal_uInt32)-1 == s_nFormat)
173cdf0e10cSrcweir 		{
174cdf0e10cSrcweir 			s_nFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.ColumnDescriptorTransfer\""));
175cdf0e10cSrcweir 			OSL_ENSURE((sal_uInt32)-1 != s_nFormat, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
176cdf0e10cSrcweir 		}
177cdf0e10cSrcweir 		return s_nFormat;
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	//--------------------------------------------------------------------
implConstruct(const::rtl::OUString & _rDatasource,const::rtl::OUString & _rConnectionResource,const sal_Int32 _nCommandType,const::rtl::OUString & _rCommand,const::rtl::OUString & _rFieldName)181cdf0e10cSrcweir 	void OColumnTransferable::implConstruct( const ::rtl::OUString& _rDatasource
182cdf0e10cSrcweir 											,const ::rtl::OUString& _rConnectionResource
183cdf0e10cSrcweir 											,const sal_Int32 _nCommandType
184cdf0e10cSrcweir 											,const ::rtl::OUString& _rCommand
185cdf0e10cSrcweir 											, const ::rtl::OUString& _rFieldName)
186cdf0e10cSrcweir 	{
187cdf0e10cSrcweir 		const sal_Unicode		cSeparator = sal_Unicode(11);
188cdf0e10cSrcweir 		const ::rtl::OUString	sSeparator(&cSeparator, 1);
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 		m_sCompatibleFormat = ::rtl::OUString();
191cdf0e10cSrcweir 		m_sCompatibleFormat += _rDatasource;
192cdf0e10cSrcweir 		m_sCompatibleFormat += sSeparator;
193cdf0e10cSrcweir 		m_sCompatibleFormat += _rCommand;
194cdf0e10cSrcweir 		m_sCompatibleFormat += sSeparator;
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 		sal_Unicode cCommandType;
197cdf0e10cSrcweir 		switch (_nCommandType)
198cdf0e10cSrcweir 		{
199cdf0e10cSrcweir 			case CommandType::TABLE:
200cdf0e10cSrcweir 				cCommandType = '0';
201cdf0e10cSrcweir 				break;
202cdf0e10cSrcweir 			case CommandType::QUERY:
203cdf0e10cSrcweir 				cCommandType = '1';
204cdf0e10cSrcweir 				break;
205cdf0e10cSrcweir 			default:
206cdf0e10cSrcweir 				cCommandType = '2';
207cdf0e10cSrcweir 				break;
208cdf0e10cSrcweir 		}
209cdf0e10cSrcweir 		m_sCompatibleFormat += ::rtl::OUString(&cCommandType, 1);
210cdf0e10cSrcweir 		m_sCompatibleFormat += sSeparator;
211cdf0e10cSrcweir 		m_sCompatibleFormat += _rFieldName;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 		m_aDescriptor.clear();
214cdf0e10cSrcweir 		if ((m_nFormatFlags & CTF_COLUMN_DESCRIPTOR) == CTF_COLUMN_DESCRIPTOR)
215cdf0e10cSrcweir 		{
216cdf0e10cSrcweir 			m_aDescriptor.setDataSource(_rDatasource);
217cdf0e10cSrcweir 			if ( _rConnectionResource.getLength() )
218cdf0e10cSrcweir 				m_aDescriptor[daConnectionResource]	<<= _rConnectionResource;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 			m_aDescriptor[daCommand]		<<= _rCommand;
221cdf0e10cSrcweir 			m_aDescriptor[daCommandType]	<<= _nCommandType;
222cdf0e10cSrcweir 			m_aDescriptor[daColumnName]		<<= _rFieldName;
223cdf0e10cSrcweir 		}
224cdf0e10cSrcweir 	}
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 	//--------------------------------------------------------------------
AddSupportedFormats()227cdf0e10cSrcweir 	void OColumnTransferable::AddSupportedFormats()
228cdf0e10cSrcweir 	{
229cdf0e10cSrcweir 		if (CTF_CONTROL_EXCHANGE & m_nFormatFlags)
230cdf0e10cSrcweir 			AddFormat(SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE);
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 		if (CTF_FIELD_DESCRIPTOR & m_nFormatFlags)
233cdf0e10cSrcweir 			AddFormat(SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE);
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 		if (CTF_COLUMN_DESCRIPTOR & m_nFormatFlags)
236cdf0e10cSrcweir 			AddFormat(getDescriptorFormatId());
237cdf0e10cSrcweir 	}
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 	//--------------------------------------------------------------------
GetData(const DataFlavor & _rFlavor)240cdf0e10cSrcweir 	sal_Bool OColumnTransferable::GetData( const DataFlavor& _rFlavor )
241cdf0e10cSrcweir 	{
242cdf0e10cSrcweir 		const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
243cdf0e10cSrcweir 		switch (nFormatId)
244cdf0e10cSrcweir 		{
245cdf0e10cSrcweir 			case SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE:
246cdf0e10cSrcweir 			case SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE:
247cdf0e10cSrcweir 				return SetString(m_sCompatibleFormat, _rFlavor);
248cdf0e10cSrcweir 		}
249cdf0e10cSrcweir 		if (nFormatId == getDescriptorFormatId())
250cdf0e10cSrcweir 			return SetAny( makeAny( m_aDescriptor.createPropertyValueSequence() ), _rFlavor );
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 		return sal_False;
253cdf0e10cSrcweir 	}
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	//--------------------------------------------------------------------
canExtractColumnDescriptor(const DataFlavorExVector & _rFlavors,sal_Int32 _nFormats)256cdf0e10cSrcweir 	sal_Bool OColumnTransferable::canExtractColumnDescriptor(const DataFlavorExVector& _rFlavors, sal_Int32 _nFormats)
257cdf0e10cSrcweir 	{
258cdf0e10cSrcweir 		sal_Bool bFieldFormat		= 0 != (_nFormats & CTF_FIELD_DESCRIPTOR);
259cdf0e10cSrcweir 		sal_Bool bControlFormat		= 0 != (_nFormats & CTF_CONTROL_EXCHANGE);
260cdf0e10cSrcweir 		sal_Bool bDescriptorFormat	= 0 != (_nFormats & CTF_COLUMN_DESCRIPTOR);
261cdf0e10cSrcweir 		for (	DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
262cdf0e10cSrcweir 				aCheck != _rFlavors.end();
263cdf0e10cSrcweir 				++aCheck
264cdf0e10cSrcweir 			)
265cdf0e10cSrcweir 		{
266cdf0e10cSrcweir 			if (bFieldFormat && (SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE == aCheck->mnSotId))
267cdf0e10cSrcweir 				return sal_True;
268cdf0e10cSrcweir 			if (bControlFormat && (SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE == aCheck->mnSotId))
269cdf0e10cSrcweir 				return sal_True;
270cdf0e10cSrcweir 			if (bDescriptorFormat && (getDescriptorFormatId() == aCheck->mnSotId))
271cdf0e10cSrcweir 				return sal_True;
272cdf0e10cSrcweir 		}
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 		return sal_False;
275cdf0e10cSrcweir 	}
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 	//--------------------------------------------------------------------
extractColumnDescriptor(const TransferableDataHelper & _rData)278cdf0e10cSrcweir 	ODataAccessDescriptor OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper& _rData)
279cdf0e10cSrcweir 	{
280cdf0e10cSrcweir 		if (_rData.HasFormat(getDescriptorFormatId()))
281cdf0e10cSrcweir 		{
282cdf0e10cSrcweir 			// the object has a real descriptor object (not just the old compatible format)
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 			// extract the any from the transferable
285cdf0e10cSrcweir 			DataFlavor aFlavor;
286cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
287cdf0e10cSrcweir 			sal_Bool bSuccess =
288cdf0e10cSrcweir #endif
289cdf0e10cSrcweir 			SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor);
290cdf0e10cSrcweir 			OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 			Any aDescriptor = _rData.GetAny(aFlavor);
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 			// extract the property value sequence
295cdf0e10cSrcweir 			Sequence< PropertyValue > aDescriptorProps;
296cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
297cdf0e10cSrcweir 			bSuccess =
298cdf0e10cSrcweir #endif
299cdf0e10cSrcweir 			aDescriptor >>= aDescriptorProps;
300cdf0e10cSrcweir 			OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 			// build the real descriptor
303cdf0e10cSrcweir 			return ODataAccessDescriptor(aDescriptorProps);
304cdf0e10cSrcweir 		}
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 		// only the old (compatible) format exists -> use the other extract method ...
307cdf0e10cSrcweir 		::rtl::OUString sDatasource, sCommand, sFieldName,sDatabaseLocation,sConnectionResource;
308cdf0e10cSrcweir 		sal_Int32 nCommandType = CommandType::COMMAND;
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 		ODataAccessDescriptor aDescriptor;
311cdf0e10cSrcweir 		if (extractColumnDescriptor(_rData, sDatasource, sDatabaseLocation,sConnectionResource,nCommandType, sCommand, sFieldName))
312cdf0e10cSrcweir 		{
313cdf0e10cSrcweir 			// and build an own descriptor
314cdf0e10cSrcweir 			if ( sDatasource.getLength() )
315cdf0e10cSrcweir 				aDescriptor[daDataSource]	<<= sDatasource;
316cdf0e10cSrcweir 			if ( sDatabaseLocation.getLength() )
317cdf0e10cSrcweir 				aDescriptor[daDatabaseLocation] <<= sDatabaseLocation;
318cdf0e10cSrcweir 			if ( sConnectionResource.getLength() )
319cdf0e10cSrcweir 				aDescriptor[daConnectionResource]	<<= sConnectionResource;
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 			aDescriptor[daCommand]		<<= sCommand;
322cdf0e10cSrcweir 			aDescriptor[daCommandType]	<<= nCommandType;
323cdf0e10cSrcweir 			aDescriptor[daColumnName]	<<= sFieldName;
324cdf0e10cSrcweir 		}
325cdf0e10cSrcweir 		return aDescriptor;
326cdf0e10cSrcweir 	}
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 	//--------------------------------------------------------------------
extractColumnDescriptor(const TransferableDataHelper & _rData,::rtl::OUString & _rDatasource,::rtl::OUString & _rDatabaseLocation,::rtl::OUString & _rConnectionResource,sal_Int32 & _nCommandType,::rtl::OUString & _rCommand,::rtl::OUString & _rFieldName)329cdf0e10cSrcweir 	sal_Bool OColumnTransferable::extractColumnDescriptor(const TransferableDataHelper& _rData
330cdf0e10cSrcweir 											,::rtl::OUString& _rDatasource
331cdf0e10cSrcweir 											,::rtl::OUString& _rDatabaseLocation
332cdf0e10cSrcweir 											,::rtl::OUString& _rConnectionResource
333cdf0e10cSrcweir 											,sal_Int32& _nCommandType
334cdf0e10cSrcweir 											,::rtl::OUString& _rCommand
335cdf0e10cSrcweir 											,::rtl::OUString& _rFieldName)
336cdf0e10cSrcweir 	{
337cdf0e10cSrcweir 		if ( _rData.HasFormat(getDescriptorFormatId()) )
338cdf0e10cSrcweir 		{
339cdf0e10cSrcweir 			ODataAccessDescriptor aDescriptor = extractColumnDescriptor(_rData);
340cdf0e10cSrcweir 			if ( aDescriptor.has(daDataSource) )
341cdf0e10cSrcweir 				aDescriptor[daDataSource]			>>= _rDatasource;
342cdf0e10cSrcweir 			if ( aDescriptor.has(daDatabaseLocation) )
343cdf0e10cSrcweir 				aDescriptor[daDatabaseLocation]		>>= _rDatabaseLocation;
344cdf0e10cSrcweir 			if ( aDescriptor.has(daConnectionResource) )
345cdf0e10cSrcweir 				aDescriptor[daConnectionResource]	>>= _rConnectionResource;
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 			aDescriptor[daCommand]				>>= _rCommand;
348cdf0e10cSrcweir 			aDescriptor[daCommandType]			>>= _nCommandType;
349cdf0e10cSrcweir 			aDescriptor[daColumnName]			>>= _rFieldName;
350cdf0e10cSrcweir 			return sal_True;
351cdf0e10cSrcweir 		}
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 		// check if we have a (string) format we can use ....
354cdf0e10cSrcweir 		SotFormatStringId	nRecognizedFormat = 0;
355cdf0e10cSrcweir 		if (_rData.HasFormat(SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE))
356cdf0e10cSrcweir 			nRecognizedFormat = SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE;
357cdf0e10cSrcweir 		if (_rData.HasFormat(SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE))
358cdf0e10cSrcweir 			nRecognizedFormat = SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE;
359cdf0e10cSrcweir 		if (!nRecognizedFormat)
360cdf0e10cSrcweir 			return sal_False;
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 		String sFieldDescription;
363cdf0e10cSrcweir 		const_cast<TransferableDataHelper&>(_rData).GetString(nRecognizedFormat, sFieldDescription);
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 		const sal_Unicode cSeparator = sal_Unicode(11);
366cdf0e10cSrcweir 		_rDatasource	= sFieldDescription.GetToken(0, cSeparator);
367cdf0e10cSrcweir 		_rCommand		= sFieldDescription.GetToken(1, cSeparator);
368cdf0e10cSrcweir 		_nCommandType	= sFieldDescription.GetToken(2, cSeparator).ToInt32();
369cdf0e10cSrcweir 		_rFieldName		= sFieldDescription.GetToken(3, cSeparator);
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 		return sal_True;
372cdf0e10cSrcweir 	}
373cdf0e10cSrcweir 
374cdf0e10cSrcweir 	//--------------------------------------------------------------------
addDataToContainer(TransferDataContainer * _pContainer)375cdf0e10cSrcweir 	void OColumnTransferable::addDataToContainer( TransferDataContainer* _pContainer )
376cdf0e10cSrcweir 	{
377cdf0e10cSrcweir 		OSL_ENSURE( _pContainer, "OColumnTransferable::addDataToContainer: invalid container!" );
378cdf0e10cSrcweir 		if ( _pContainer )
379cdf0e10cSrcweir 		{
380cdf0e10cSrcweir 			if ( m_nFormatFlags & CTF_FIELD_DESCRIPTOR )
381cdf0e10cSrcweir 				_pContainer->CopyAny( SOT_FORMATSTR_ID_SBA_FIELDDATAEXCHANGE, makeAny( m_sCompatibleFormat ) );
382cdf0e10cSrcweir 
383cdf0e10cSrcweir 			if ( m_nFormatFlags & CTF_CONTROL_EXCHANGE )
384cdf0e10cSrcweir 				_pContainer->CopyAny( SOT_FORMATSTR_ID_SBA_CTRLDATAEXCHANGE, makeAny( m_sCompatibleFormat ) );
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 			if ( m_nFormatFlags & CTF_COLUMN_DESCRIPTOR )
387cdf0e10cSrcweir 			{
388cdf0e10cSrcweir 				Any aContent = makeAny( m_aDescriptor.createPropertyValueSequence() );
389cdf0e10cSrcweir 				_pContainer->CopyAny(
390cdf0e10cSrcweir                     sal::static_int_cast< sal_uInt16 >( getDescriptorFormatId() ),
391cdf0e10cSrcweir                     aContent );
392cdf0e10cSrcweir 			}
393cdf0e10cSrcweir 		}
394cdf0e10cSrcweir 	}
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 	//====================================================================
397cdf0e10cSrcweir 	//= ODataAccessObjectTransferable
398cdf0e10cSrcweir 	//====================================================================
ODataAccessObjectTransferable(const::rtl::OUString & _rDatasource,const::rtl::OUString & _rConnectionResource,const sal_Int32 _nCommandType,const::rtl::OUString & _rCommand)399cdf0e10cSrcweir 	ODataAccessObjectTransferable::ODataAccessObjectTransferable(
400cdf0e10cSrcweir 			const ::rtl::OUString&	_rDatasource
401cdf0e10cSrcweir 			,const ::rtl::OUString& _rConnectionResource
402cdf0e10cSrcweir 			,const sal_Int32		_nCommandType
403cdf0e10cSrcweir 			,const ::rtl::OUString&	_rCommand
404cdf0e10cSrcweir 		)
405cdf0e10cSrcweir 	{
406cdf0e10cSrcweir 		construct(_rDatasource,_rConnectionResource,_nCommandType,_rCommand,NULL,(CommandType::COMMAND == _nCommandType),_rCommand);
407cdf0e10cSrcweir 	}
408cdf0e10cSrcweir 	//--------------------------------------------------------------------
ODataAccessObjectTransferable(const::rtl::OUString & _rDatasource,const::rtl::OUString & _rConnectionResource,const sal_Int32 _nCommandType,const::rtl::OUString & _rCommand,const Reference<XConnection> & _rxConnection)409cdf0e10cSrcweir 	ODataAccessObjectTransferable::ODataAccessObjectTransferable(
410cdf0e10cSrcweir 					const ::rtl::OUString&	_rDatasource
411cdf0e10cSrcweir 					,const ::rtl::OUString& _rConnectionResource
412cdf0e10cSrcweir 					,const sal_Int32		_nCommandType
413cdf0e10cSrcweir 					,const ::rtl::OUString&	_rCommand
414cdf0e10cSrcweir 					,const Reference< XConnection >& _rxConnection)
415cdf0e10cSrcweir 	{
416cdf0e10cSrcweir 		OSL_ENSURE(_rxConnection.is(),"Wrong ctor used.!");
417cdf0e10cSrcweir 		construct(_rDatasource,_rConnectionResource,_nCommandType,_rCommand,_rxConnection,(CommandType::COMMAND == _nCommandType),_rCommand);
418cdf0e10cSrcweir 	}
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
ODataAccessObjectTransferable(const Reference<XPropertySet> & _rxLivingForm)421cdf0e10cSrcweir 	ODataAccessObjectTransferable::ODataAccessObjectTransferable(const Reference< XPropertySet >& _rxLivingForm)
422cdf0e10cSrcweir 	{
423cdf0e10cSrcweir 		// collect some properties of the form
424cdf0e10cSrcweir 		::rtl::OUString sDatasourceName,sConnectionResource;
425cdf0e10cSrcweir 		sal_Int32		nObjectType = CommandType::COMMAND;
426cdf0e10cSrcweir 		::rtl::OUString sObjectName;
427cdf0e10cSrcweir 		Reference< XConnection > xConnection;
428cdf0e10cSrcweir 		try
429cdf0e10cSrcweir 		{
430cdf0e10cSrcweir 			_rxLivingForm->getPropertyValue(FM_PROP_COMMANDTYPE) >>= nObjectType;
431cdf0e10cSrcweir 			_rxLivingForm->getPropertyValue(FM_PROP_COMMAND) >>= sObjectName;
432cdf0e10cSrcweir 			_rxLivingForm->getPropertyValue(FM_PROP_DATASOURCE) >>= sDatasourceName;
433cdf0e10cSrcweir 			_rxLivingForm->getPropertyValue(FM_PROP_URL) >>= sConnectionResource;
434cdf0e10cSrcweir 			_rxLivingForm->getPropertyValue(FM_PROP_ACTIVE_CONNECTION) >>= xConnection;
435cdf0e10cSrcweir 		}
436cdf0e10cSrcweir 		catch(Exception&)
437cdf0e10cSrcweir 		{
438cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes !");
439cdf0e10cSrcweir 			return;
440cdf0e10cSrcweir 		}
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 		String sObjectKind = (CommandType::TABLE == nObjectType) ? String('1') : String('0');
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 		// check if the SQL-statement is modified
445cdf0e10cSrcweir 		::rtl::OUString sCompleteStatement;
446cdf0e10cSrcweir 		try
447cdf0e10cSrcweir 		{
448cdf0e10cSrcweir 			_rxLivingForm->getPropertyValue(FM_PROP_ACTIVECOMMAND) >>= sCompleteStatement;
449cdf0e10cSrcweir 		}
450cdf0e10cSrcweir 		catch(Exception&)
451cdf0e10cSrcweir 		{
452cdf0e10cSrcweir 			OSL_ENSURE(sal_False, "ODataAccessObjectTransferable::ODataAccessObjectTransferable: could not collect essential form attributes (part two) !");
453cdf0e10cSrcweir 			return;
454cdf0e10cSrcweir 		}
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 		construct(	sDatasourceName
457cdf0e10cSrcweir 					,sConnectionResource
458cdf0e10cSrcweir 					,nObjectType
459cdf0e10cSrcweir 					,sObjectName,xConnection
460cdf0e10cSrcweir 					,!((CommandType::QUERY == nObjectType))
461cdf0e10cSrcweir 					,sCompleteStatement);
462cdf0e10cSrcweir 	}
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
AddSupportedFormats()465cdf0e10cSrcweir 	void ODataAccessObjectTransferable::AddSupportedFormats()
466cdf0e10cSrcweir 	{
467cdf0e10cSrcweir 		sal_Int32 nObjectType = CommandType::COMMAND;
468cdf0e10cSrcweir 		m_aDescriptor[daCommandType] >>= nObjectType;
469cdf0e10cSrcweir 		switch (nObjectType)
470cdf0e10cSrcweir 		{
471cdf0e10cSrcweir 			case CommandType::TABLE:
472cdf0e10cSrcweir 				AddFormat(SOT_FORMATSTR_ID_DBACCESS_TABLE);
473cdf0e10cSrcweir 				break;
474cdf0e10cSrcweir 			case CommandType::QUERY:
475cdf0e10cSrcweir 				AddFormat(SOT_FORMATSTR_ID_DBACCESS_QUERY);
476cdf0e10cSrcweir 				break;
477cdf0e10cSrcweir 			case CommandType::COMMAND:
478cdf0e10cSrcweir 				AddFormat(SOT_FORMATSTR_ID_DBACCESS_COMMAND);
479cdf0e10cSrcweir 				break;
480cdf0e10cSrcweir 		}
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 		sal_Int32 nDescriptorLen = m_sCompatibleObjectDescription.getLength();
483cdf0e10cSrcweir 		if (nDescriptorLen)
484cdf0e10cSrcweir 		{
485cdf0e10cSrcweir 			if (m_sCompatibleObjectDescription.getStr()[nDescriptorLen] == 11)
486cdf0e10cSrcweir 				m_sCompatibleObjectDescription = m_sCompatibleObjectDescription.copy(0, nDescriptorLen - 1);
487cdf0e10cSrcweir 
488cdf0e10cSrcweir 			if (nDescriptorLen)
489cdf0e10cSrcweir 				AddFormat(SOT_FORMATSTR_ID_SBA_DATAEXCHANGE);
490cdf0e10cSrcweir 		}
491cdf0e10cSrcweir 	}
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetData(const DataFlavor & rFlavor)494cdf0e10cSrcweir 	sal_Bool ODataAccessObjectTransferable::GetData( const DataFlavor& rFlavor )
495cdf0e10cSrcweir 	{
496cdf0e10cSrcweir 		sal_uIntPtr nFormat = SotExchange::GetFormat(rFlavor);
497cdf0e10cSrcweir 		switch (nFormat)
498cdf0e10cSrcweir 		{
499cdf0e10cSrcweir 			case SOT_FORMATSTR_ID_DBACCESS_TABLE:
500cdf0e10cSrcweir 			case SOT_FORMATSTR_ID_DBACCESS_QUERY:
501cdf0e10cSrcweir 			case SOT_FORMATSTR_ID_DBACCESS_COMMAND:
502cdf0e10cSrcweir 				return SetAny( makeAny(m_aDescriptor.createPropertyValueSequence()), rFlavor );
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 			case SOT_FORMATSTR_ID_SBA_DATAEXCHANGE:
505cdf0e10cSrcweir 				return SetString(m_sCompatibleObjectDescription, rFlavor);
506cdf0e10cSrcweir 		}
507cdf0e10cSrcweir 		return sal_False;
508cdf0e10cSrcweir 	}
509cdf0e10cSrcweir 
510cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
canExtractObjectDescriptor(const DataFlavorExVector & _rFlavors)511cdf0e10cSrcweir 	sal_Bool ODataAccessObjectTransferable::canExtractObjectDescriptor(const DataFlavorExVector& _rFlavors)
512cdf0e10cSrcweir 	{
513cdf0e10cSrcweir 		for (	DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
514cdf0e10cSrcweir 				aCheck != _rFlavors.end();
515cdf0e10cSrcweir 				++aCheck
516cdf0e10cSrcweir 			)
517cdf0e10cSrcweir 		{
518cdf0e10cSrcweir 			if (SOT_FORMATSTR_ID_DBACCESS_TABLE == aCheck->mnSotId)
519cdf0e10cSrcweir 				return sal_True;
520cdf0e10cSrcweir 			if (SOT_FORMATSTR_ID_DBACCESS_QUERY == aCheck->mnSotId)
521cdf0e10cSrcweir 				return sal_True;
522cdf0e10cSrcweir 			if (SOT_FORMATSTR_ID_DBACCESS_COMMAND == aCheck->mnSotId)
523cdf0e10cSrcweir 				return sal_True;
524cdf0e10cSrcweir 		}
525cdf0e10cSrcweir 		return sal_False;
526cdf0e10cSrcweir 	}
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
extractObjectDescriptor(const TransferableDataHelper & _rData)529cdf0e10cSrcweir 	ODataAccessDescriptor ODataAccessObjectTransferable::extractObjectDescriptor(const TransferableDataHelper& _rData)
530cdf0e10cSrcweir 	{
531cdf0e10cSrcweir 		sal_Int32 nKnownFormatId = 0;
532cdf0e10cSrcweir 		if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_TABLE ) )
533cdf0e10cSrcweir 			nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_TABLE;
534cdf0e10cSrcweir 		if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_QUERY ) )
535cdf0e10cSrcweir 			nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_QUERY;
536cdf0e10cSrcweir 		if ( _rData.HasFormat( SOT_FORMATSTR_ID_DBACCESS_COMMAND ) )
537cdf0e10cSrcweir 			nKnownFormatId = SOT_FORMATSTR_ID_DBACCESS_COMMAND;
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 		if (0 != nKnownFormatId)
540cdf0e10cSrcweir 		{
541cdf0e10cSrcweir 			// extract the any from the transferable
542cdf0e10cSrcweir 			DataFlavor aFlavor;
543cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
544cdf0e10cSrcweir 			sal_Bool bSuccess =
545cdf0e10cSrcweir #endif
546cdf0e10cSrcweir 			SotExchange::GetFormatDataFlavor(nKnownFormatId, aFlavor);
547cdf0e10cSrcweir 			OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 			Any aDescriptor = _rData.GetAny(aFlavor);
550cdf0e10cSrcweir 
551cdf0e10cSrcweir 			// extract the property value sequence
552cdf0e10cSrcweir 			Sequence< PropertyValue > aDescriptorProps;
553cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
554cdf0e10cSrcweir 			bSuccess =
555cdf0e10cSrcweir #endif
556cdf0e10cSrcweir 			aDescriptor >>= aDescriptorProps;
557cdf0e10cSrcweir 			OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid clipboard format!");
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 			// build the real descriptor
560cdf0e10cSrcweir 			return ODataAccessDescriptor(aDescriptorProps);
561cdf0e10cSrcweir 		}
562cdf0e10cSrcweir 
563cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "OColumnTransferable::extractColumnDescriptor: unsupported formats only!" );
564cdf0e10cSrcweir 		return ODataAccessDescriptor();
565cdf0e10cSrcweir 	}
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
addCompatibleSelectionDescription(const Sequence<Any> & _rSelRows)568cdf0e10cSrcweir 	void ODataAccessObjectTransferable::addCompatibleSelectionDescription( const Sequence< Any >& _rSelRows )
569cdf0e10cSrcweir 	{
570cdf0e10cSrcweir 		const sal_Unicode		cSeparator(11);
571cdf0e10cSrcweir 		const ::rtl::OUString	sSeparator(&cSeparator, 1);
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 		const Any* pSelRows = _rSelRows.getConstArray();
574cdf0e10cSrcweir 		const Any* pSelRowsEnd = pSelRows + _rSelRows.getLength();
575cdf0e10cSrcweir 		for ( ; pSelRows < pSelRowsEnd; ++pSelRows )
576cdf0e10cSrcweir 		{
577cdf0e10cSrcweir 			sal_Int32 nSelectedRow( 0 );
578cdf0e10cSrcweir 			OSL_VERIFY( *pSelRows >>= nSelectedRow );
579cdf0e10cSrcweir 
580cdf0e10cSrcweir 			m_sCompatibleObjectDescription += ::rtl::OUString::valueOf((sal_Int32)nSelectedRow);
581cdf0e10cSrcweir 			m_sCompatibleObjectDescription += sSeparator;
582cdf0e10cSrcweir 		}
583cdf0e10cSrcweir 	}
584cdf0e10cSrcweir 
585cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
ObjectReleased()586cdf0e10cSrcweir 	void ODataAccessObjectTransferable::ObjectReleased()
587cdf0e10cSrcweir 	{
588cdf0e10cSrcweir 		m_aDescriptor.clear();
589cdf0e10cSrcweir 	}
590cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
construct(const::rtl::OUString & _rDatasource,const::rtl::OUString & _rConnectionResource,const sal_Int32 _nCommandType,const::rtl::OUString & _rCommand,const Reference<XConnection> & _rxConnection,sal_Bool _bAddCommand,const::rtl::OUString & _sActiveCommand)591cdf0e10cSrcweir 	void ODataAccessObjectTransferable::construct(	const ::rtl::OUString&	_rDatasource
592cdf0e10cSrcweir 													,const ::rtl::OUString& _rConnectionResource
593cdf0e10cSrcweir 													,const sal_Int32		_nCommandType
594cdf0e10cSrcweir 													,const ::rtl::OUString&	_rCommand
595cdf0e10cSrcweir 													,const Reference< XConnection >& _rxConnection
596cdf0e10cSrcweir 													,sal_Bool _bAddCommand
597cdf0e10cSrcweir 													,const ::rtl::OUString& _sActiveCommand)
598cdf0e10cSrcweir 	{
599cdf0e10cSrcweir 		m_aDescriptor.setDataSource(_rDatasource);
600cdf0e10cSrcweir 		// build the descriptor (the property sequence)
601cdf0e10cSrcweir 		if ( _rConnectionResource.getLength() )
602cdf0e10cSrcweir 			m_aDescriptor[daConnectionResource]	<<= _rConnectionResource;
603cdf0e10cSrcweir 		if ( _rxConnection.is() )
604cdf0e10cSrcweir 			m_aDescriptor[daConnection]		<<= _rxConnection;
605cdf0e10cSrcweir 		m_aDescriptor[daCommand]		<<= _rCommand;
606cdf0e10cSrcweir 		m_aDescriptor[daCommandType]	<<= _nCommandType;
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 		// extract the single values from the sequence
609cdf0e10cSrcweir 
610cdf0e10cSrcweir 		::rtl::OUString sObjectName;
611cdf0e10cSrcweir 		::rtl::OUString sDatasourceName = _rDatasource;
612cdf0e10cSrcweir 		sObjectName = _rCommand;
613cdf0e10cSrcweir 
614cdf0e10cSrcweir 		// for compatibility: create a string which can be used for the SOT_FORMATSTR_ID_SBA_DATAEXCHANGE format
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 		sal_Bool bTreatAsStatement = (CommandType::COMMAND == _nCommandType);
617cdf0e10cSrcweir 			// statements are - in this old and ugly format - described as queries
618cdf0e10cSrcweir 
619cdf0e10cSrcweir 		const sal_Unicode		cSeparator = sal_Unicode(11);
620cdf0e10cSrcweir 		const ::rtl::OUString	sSeparator(&cSeparator, 1);
621cdf0e10cSrcweir 
622cdf0e10cSrcweir 		const sal_Unicode		cTableMark = '1';
623cdf0e10cSrcweir 		const sal_Unicode		cQueryMark = '0';
624cdf0e10cSrcweir 
625cdf0e10cSrcweir 		// build the descriptor string
626cdf0e10cSrcweir 		m_sCompatibleObjectDescription += sDatasourceName;
627cdf0e10cSrcweir 		m_sCompatibleObjectDescription += sSeparator;
628cdf0e10cSrcweir 		m_sCompatibleObjectDescription += bTreatAsStatement ? ::rtl::OUString() : sObjectName;
629cdf0e10cSrcweir 		m_sCompatibleObjectDescription += sSeparator;
630cdf0e10cSrcweir 		switch (_nCommandType)
631cdf0e10cSrcweir 		{
632cdf0e10cSrcweir 			case CommandType::TABLE:
633cdf0e10cSrcweir 				m_sCompatibleObjectDescription += ::rtl::OUString(&cTableMark, 1);
634cdf0e10cSrcweir 				break;
635cdf0e10cSrcweir 			case CommandType::QUERY:
636cdf0e10cSrcweir 				m_sCompatibleObjectDescription += ::rtl::OUString(&cQueryMark, 1);
637cdf0e10cSrcweir 				break;
638cdf0e10cSrcweir 			case CommandType::COMMAND:
639cdf0e10cSrcweir 				m_sCompatibleObjectDescription += ::rtl::OUString(&cQueryMark, 1);
640cdf0e10cSrcweir 				// think of it as a query
641cdf0e10cSrcweir 				break;
642cdf0e10cSrcweir 		}
643cdf0e10cSrcweir 		m_sCompatibleObjectDescription += sSeparator;
644cdf0e10cSrcweir 		m_sCompatibleObjectDescription += _bAddCommand ? _sActiveCommand : ::rtl::OUString();
645cdf0e10cSrcweir 		m_sCompatibleObjectDescription += sSeparator;
646cdf0e10cSrcweir 	}
647cdf0e10cSrcweir 
648cdf0e10cSrcweir     //--------------------------------------------------------------------
OMultiColumnTransferable(const Sequence<PropertyValue> & _aDescriptors)649cdf0e10cSrcweir     OMultiColumnTransferable::OMultiColumnTransferable(const Sequence< PropertyValue >& _aDescriptors) : m_aDescriptors(_aDescriptors)
650cdf0e10cSrcweir     {
651cdf0e10cSrcweir     }
652cdf0e10cSrcweir     //--------------------------------------------------------------------
getDescriptorFormatId()653cdf0e10cSrcweir     sal_uInt32 OMultiColumnTransferable::getDescriptorFormatId()
654cdf0e10cSrcweir 	{
655cdf0e10cSrcweir 		static sal_uInt32 s_nFormat = (sal_uInt32)-1;
656cdf0e10cSrcweir 		if ((sal_uInt32)-1 == s_nFormat)
657cdf0e10cSrcweir 		{
658cdf0e10cSrcweir 			s_nFormat = SotExchange::RegisterFormatName(String::CreateFromAscii("application/x-openoffice;windows_formatname=\"dbaccess.MultipleColumnDescriptorTransfer\""));
659cdf0e10cSrcweir 			OSL_ENSURE((sal_uInt32)-1 != s_nFormat, "OColumnTransferable::getDescriptorFormatId: bad exchange id!");
660cdf0e10cSrcweir 		}
661cdf0e10cSrcweir 		return s_nFormat;
662cdf0e10cSrcweir 	}
663cdf0e10cSrcweir     //--------------------------------------------------------------------
AddSupportedFormats()664cdf0e10cSrcweir 	void OMultiColumnTransferable::AddSupportedFormats()
665cdf0e10cSrcweir 	{
666cdf0e10cSrcweir 		AddFormat(getDescriptorFormatId());
667cdf0e10cSrcweir 	}
668cdf0e10cSrcweir     //--------------------------------------------------------------------
push_back(ODataAccessDescriptor & _aDescriptor)669cdf0e10cSrcweir 	void OMultiColumnTransferable::push_back(ODataAccessDescriptor& _aDescriptor)
670cdf0e10cSrcweir     {
671cdf0e10cSrcweir         const sal_Int32 nCount = m_aDescriptors.getLength();
672cdf0e10cSrcweir         m_aDescriptors.realloc(nCount+1);
673cdf0e10cSrcweir         m_aDescriptors[nCount].Value <<= _aDescriptor.createPropertyValueSequence();
674cdf0e10cSrcweir     }
675cdf0e10cSrcweir 	//--------------------------------------------------------------------
GetData(const DataFlavor & _rFlavor)676cdf0e10cSrcweir 	sal_Bool OMultiColumnTransferable::GetData( const DataFlavor& _rFlavor )
677cdf0e10cSrcweir 	{
678cdf0e10cSrcweir 		const sal_uInt32 nFormatId = SotExchange::GetFormat(_rFlavor);
679cdf0e10cSrcweir 		if (nFormatId == getDescriptorFormatId())
680cdf0e10cSrcweir         {
681cdf0e10cSrcweir 			return SetAny( makeAny( m_aDescriptors ), _rFlavor );
682cdf0e10cSrcweir         }
683cdf0e10cSrcweir 
684cdf0e10cSrcweir 		return sal_False;
685cdf0e10cSrcweir 	}
686cdf0e10cSrcweir 
687cdf0e10cSrcweir 	//--------------------------------------------------------------------
canExtractDescriptor(const DataFlavorExVector & _rFlavors)688cdf0e10cSrcweir 	sal_Bool OMultiColumnTransferable::canExtractDescriptor(const DataFlavorExVector& _rFlavors)
689cdf0e10cSrcweir 	{
690cdf0e10cSrcweir         DataFlavorExVector::const_iterator aCheck = _rFlavors.begin();
691cdf0e10cSrcweir 		for (	;
692cdf0e10cSrcweir 				aCheck != _rFlavors.end() && getDescriptorFormatId() == aCheck->mnSotId;
693cdf0e10cSrcweir 				++aCheck
694cdf0e10cSrcweir 			)
695cdf0e10cSrcweir             ;
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 		return aCheck == _rFlavors.end();
698cdf0e10cSrcweir 	}
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 	//--------------------------------------------------------------------
extractDescriptor(const TransferableDataHelper & _rData)701cdf0e10cSrcweir 	Sequence< PropertyValue > OMultiColumnTransferable::extractDescriptor(const TransferableDataHelper& _rData)
702cdf0e10cSrcweir 	{
703cdf0e10cSrcweir         Sequence< PropertyValue > aList;
704cdf0e10cSrcweir 		if (_rData.HasFormat(getDescriptorFormatId()))
705cdf0e10cSrcweir 		{
706cdf0e10cSrcweir 			// extract the any from the transferable
707cdf0e10cSrcweir 			DataFlavor aFlavor;
708cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
709cdf0e10cSrcweir 			sal_Bool bSuccess =
710cdf0e10cSrcweir #endif
711cdf0e10cSrcweir 			SotExchange::GetFormatDataFlavor(getDescriptorFormatId(), aFlavor);
712cdf0e10cSrcweir 			OSL_ENSURE(bSuccess, "OColumnTransferable::extractColumnDescriptor: invalid data format (no flavor)!");
713cdf0e10cSrcweir 
714cdf0e10cSrcweir 			_rData.GetAny(aFlavor) >>= aList;
715cdf0e10cSrcweir 		} // if (_rData.HasFormat(getDescriptorFormatId()))
716cdf0e10cSrcweir         return aList;
717cdf0e10cSrcweir 	}
718cdf0e10cSrcweir     // -----------------------------------------------------------------------------
ObjectReleased()719cdf0e10cSrcweir 	void OMultiColumnTransferable::ObjectReleased()
720cdf0e10cSrcweir 	{
721cdf0e10cSrcweir         m_aDescriptors.realloc(0);
722cdf0e10cSrcweir 	}
723cdf0e10cSrcweir 
724cdf0e10cSrcweir //........................................................................
725cdf0e10cSrcweir }	// namespace svx
726cdf0e10cSrcweir //........................................................................
727cdf0e10cSrcweir 
728cdf0e10cSrcweir 
729