1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "dbu_misc.hrc"
28cdf0e10cSrcweir #include "dbustrings.hrc"
29cdf0e10cSrcweir #include "moduledbu.hxx"
30cdf0e10cSrcweir #include "sqlmessage.hxx"
31cdf0e10cSrcweir #include "UITools.hxx"
32cdf0e10cSrcweir #include "WColumnSelect.hxx"
33cdf0e10cSrcweir #include "WCopyTable.hxx"
34cdf0e10cSrcweir #include "WCPage.hxx"
35cdf0e10cSrcweir #include "WExtendPages.hxx"
36cdf0e10cSrcweir #include "WizardPages.hrc"
37cdf0e10cSrcweir #include "WNameMatch.hxx"
38cdf0e10cSrcweir #include "WTypeSelect.hxx"
39cdf0e10cSrcweir 
40cdf0e10cSrcweir /** === begin UNO includes === **/
41cdf0e10cSrcweir #include <com/sun/star/sdb/application/CopyTableOperation.hpp>
42cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
43cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
44cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
45cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
46cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
47cdf0e10cSrcweir #include <com/sun/star/sdbcx/KeyType.hpp>
48cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAppend.hpp>
49cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
50cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
51cdf0e10cSrcweir #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
52cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
53cdf0e10cSrcweir #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
54cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
55cdf0e10cSrcweir /** === end UNO includes === **/
56cdf0e10cSrcweir 
57cdf0e10cSrcweir #include <comphelper/extract.hxx>
58cdf0e10cSrcweir #include <comphelper/types.hxx>
59cdf0e10cSrcweir #include <comphelper/interaction.hxx>
60cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
61cdf0e10cSrcweir #include <connectivity/dbmetadata.hxx>
62cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
63cdf0e10cSrcweir 
64cdf0e10cSrcweir #include <rtl/logfile.hxx>
65cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
66cdf0e10cSrcweir #include <tools/debug.hxx>
67cdf0e10cSrcweir #include <tools/diagnose_ex.h>
68cdf0e10cSrcweir #include <vcl/lstbox.hxx>
69cdf0e10cSrcweir #include <vcl/msgbox.hxx>
70cdf0e10cSrcweir #include <vcl/waitobj.hxx>
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #include <functional>
73cdf0e10cSrcweir 
74cdf0e10cSrcweir using namespace ::dbaui;
75cdf0e10cSrcweir using namespace ::com::sun::star::uno;
76cdf0e10cSrcweir using namespace ::com::sun::star::beans;
77cdf0e10cSrcweir using namespace ::com::sun::star::container;
78cdf0e10cSrcweir using namespace ::com::sun::star::util;
79cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
80cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
81cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
82cdf0e10cSrcweir using namespace ::com::sun::star::lang;
83cdf0e10cSrcweir using namespace ::com::sun::star::task;
84cdf0e10cSrcweir using namespace dbtools;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir namespace CopyTableOperation = ::com::sun::star::sdb::application::CopyTableOperation;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir #define MAX_PAGES	4	// max. Pages die angezeigt werden
89cdf0e10cSrcweir 
90cdf0e10cSrcweir DBG_NAME(OCopyTableWizard)
91cdf0e10cSrcweir namespace
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     //....................................................................
clearColumns(ODatabaseExport::TColumns & _rColumns,ODatabaseExport::TColumnVector & _rColumnsVec)94cdf0e10cSrcweir 	void clearColumns(ODatabaseExport::TColumns& _rColumns, ODatabaseExport::TColumnVector& _rColumnsVec)
95cdf0e10cSrcweir 	{
96cdf0e10cSrcweir 		ODatabaseExport::TColumns::iterator aIter = _rColumns.begin();
97cdf0e10cSrcweir 		ODatabaseExport::TColumns::iterator aEnd  = _rColumns.end();
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 		for(;aIter != aEnd;++aIter)
100cdf0e10cSrcweir 			delete aIter->second;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 		_rColumnsVec.clear();
103cdf0e10cSrcweir 		_rColumns.clear();
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir //========================================================================
108cdf0e10cSrcweir //= ICopyTableSourceObject
109cdf0e10cSrcweir //========================================================================
110cdf0e10cSrcweir //------------------------------------------------------------------------
~ICopyTableSourceObject()111cdf0e10cSrcweir ICopyTableSourceObject::~ICopyTableSourceObject()
112cdf0e10cSrcweir {
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir //========================================================================
116cdf0e10cSrcweir //= ObjectCopySource
117cdf0e10cSrcweir //========================================================================
118cdf0e10cSrcweir //------------------------------------------------------------------------
ObjectCopySource(const Reference<XConnection> & _rxConnection,const Reference<XPropertySet> & _rxObject)119cdf0e10cSrcweir ObjectCopySource::ObjectCopySource( const Reference< XConnection >& _rxConnection, const Reference< XPropertySet >& _rxObject )
120cdf0e10cSrcweir     :m_xConnection( _rxConnection, UNO_SET_THROW )
121cdf0e10cSrcweir     ,m_xMetaData( _rxConnection->getMetaData(), UNO_SET_THROW )
122cdf0e10cSrcweir     ,m_xObject( _rxObject, UNO_SET_THROW )
123cdf0e10cSrcweir     ,m_xObjectPSI( _rxObject->getPropertySetInfo(), UNO_SET_THROW )
124cdf0e10cSrcweir     ,m_xObjectColumns( Reference< XColumnsSupplier >( _rxObject, UNO_QUERY_THROW )->getColumns(), UNO_SET_THROW )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir //------------------------------------------------------------------------
getQualifiedObjectName() const129cdf0e10cSrcweir ::rtl::OUString ObjectCopySource::getQualifiedObjectName() const
130cdf0e10cSrcweir {
131cdf0e10cSrcweir     ::rtl::OUString sName;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	if ( !m_xObjectPSI->hasPropertyByName( PROPERTY_COMMAND ) )
134cdf0e10cSrcweir 		sName = ::dbtools::composeTableName( m_xMetaData, m_xObject, ::dbtools::eInDataManipulation, false, false, false );
135cdf0e10cSrcweir 	else
136cdf0e10cSrcweir 		m_xObject->getPropertyValue( PROPERTY_NAME ) >>= sName;
137cdf0e10cSrcweir     return sName;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir //------------------------------------------------------------------------
isView() const141cdf0e10cSrcweir bool ObjectCopySource::isView() const
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	bool bIsView = false;
144cdf0e10cSrcweir     try
145cdf0e10cSrcweir     {
146cdf0e10cSrcweir         if ( m_xObjectPSI->hasPropertyByName( PROPERTY_TYPE ) )
147cdf0e10cSrcweir         {
148cdf0e10cSrcweir             ::rtl::OUString sObjectType;
149cdf0e10cSrcweir             OSL_VERIFY( m_xObject->getPropertyValue( PROPERTY_TYPE ) >>= sObjectType );
150cdf0e10cSrcweir             bIsView = sObjectType.equalsAscii( "VIEW" );
151cdf0e10cSrcweir         }
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir     catch( const Exception& )
154cdf0e10cSrcweir     {
155cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir     return bIsView;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir //------------------------------------------------------------------------
copyUISettingsTo(const Reference<XPropertySet> & _rxObject) const161cdf0e10cSrcweir void ObjectCopySource::copyUISettingsTo( const Reference< XPropertySet >& _rxObject ) const
162cdf0e10cSrcweir {
163cdf0e10cSrcweir     const ::rtl::OUString aCopyProperties[] = {
164cdf0e10cSrcweir         PROPERTY_FONT, PROPERTY_ROW_HEIGHT, PROPERTY_TEXTCOLOR,PROPERTY_TEXTLINECOLOR,PROPERTY_TEXTEMPHASIS,PROPERTY_TEXTRELIEF
165cdf0e10cSrcweir     };
166cdf0e10cSrcweir     for ( size_t i=0; i < sizeof( aCopyProperties ) / sizeof( aCopyProperties[0] ); ++i )
167cdf0e10cSrcweir     {
168cdf0e10cSrcweir 		if ( m_xObjectPSI->hasPropertyByName( aCopyProperties[i] ) )
169cdf0e10cSrcweir 			_rxObject->setPropertyValue( aCopyProperties[i], m_xObject->getPropertyValue( aCopyProperties[i] ) );
170cdf0e10cSrcweir     }
171cdf0e10cSrcweir }
172cdf0e10cSrcweir //------------------------------------------------------------------------
copyFilterAndSortingTo(const Reference<XConnection> & _xConnection,const Reference<XPropertySet> & _rxObject) const173cdf0e10cSrcweir void ObjectCopySource::copyFilterAndSortingTo( const Reference< XConnection >& _xConnection,const Reference< XPropertySet >& _rxObject ) const
174cdf0e10cSrcweir {
175cdf0e10cSrcweir     ::std::pair< ::rtl::OUString, ::rtl::OUString > aProperties[] = {
176cdf0e10cSrcweir                  ::std::pair< ::rtl::OUString, ::rtl::OUString >(PROPERTY_FILTER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" AND ")))
177cdf0e10cSrcweir                 ,::std::pair< ::rtl::OUString, ::rtl::OUString >(PROPERTY_ORDER,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ORDER BY ")))
178cdf0e10cSrcweir     };
179cdf0e10cSrcweir 
180cdf0e10cSrcweir     size_t i = 0;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     try
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir         const String sSourceName = (::dbtools::composeTableNameForSelect(m_xConnection,m_xObject) + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".")));
185cdf0e10cSrcweir         const ::rtl::OUString sTargetName = ::dbtools::composeTableNameForSelect(_xConnection,_rxObject);
186cdf0e10cSrcweir         const String sTargetNameTemp = (sTargetName + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".")));
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         ::rtl::OUString sStatement(RTL_CONSTASCII_USTRINGPARAM("SELECT * FROM "));
189cdf0e10cSrcweir         sStatement += sTargetName;
190cdf0e10cSrcweir         sStatement += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" WHERE 0=1"));
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         for ( i=0; i < sizeof( aProperties ) / sizeof( aProperties[0] ); ++i )
194cdf0e10cSrcweir         {
195cdf0e10cSrcweir 		    if ( m_xObjectPSI->hasPropertyByName( aProperties[i].first ) )
196cdf0e10cSrcweir             {
197cdf0e10cSrcweir                 ::rtl::OUString sFilter;
198cdf0e10cSrcweir                 m_xObject->getPropertyValue( aProperties[i].first ) >>= sFilter;
199cdf0e10cSrcweir                 if ( sFilter.getLength() )
200cdf0e10cSrcweir                 {
201cdf0e10cSrcweir                     sStatement += aProperties[i].second;
202cdf0e10cSrcweir                     String sReplace = sFilter;
203cdf0e10cSrcweir                     sReplace.SearchAndReplace(sSourceName,sTargetNameTemp);
204cdf0e10cSrcweir                     sFilter = sReplace;
205cdf0e10cSrcweir                     _rxObject->setPropertyValue( aProperties[i].first, makeAny(sFilter) );
206cdf0e10cSrcweir                     sStatement += sFilter;
207cdf0e10cSrcweir                 }
208cdf0e10cSrcweir             }
209cdf0e10cSrcweir         }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir         _xConnection->createStatement()->executeQuery(sStatement);
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 		if ( m_xObjectPSI->hasPropertyByName( PROPERTY_APPLYFILTER ) )
214cdf0e10cSrcweir 			_rxObject->setPropertyValue( PROPERTY_APPLYFILTER, m_xObject->getPropertyValue( PROPERTY_APPLYFILTER ) );
215cdf0e10cSrcweir     }
216cdf0e10cSrcweir     catch(Exception&)
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir     }
219cdf0e10cSrcweir }
220cdf0e10cSrcweir //------------------------------------------------------------------------
getColumnNames() const221cdf0e10cSrcweir Sequence< ::rtl::OUString > ObjectCopySource::getColumnNames() const
222cdf0e10cSrcweir {
223cdf0e10cSrcweir     return m_xObjectColumns->getElementNames();
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir //------------------------------------------------------------------------
getPrimaryKeyColumnNames() const227cdf0e10cSrcweir Sequence< ::rtl::OUString > ObjectCopySource::getPrimaryKeyColumnNames() const
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     const Reference<XNameAccess> xPrimaryKeyColumns = getPrimaryKeyColumns_throw(m_xObject);
230cdf0e10cSrcweir     Sequence< ::rtl::OUString > aKeyColNames;
231cdf0e10cSrcweir     if ( xPrimaryKeyColumns.is() )
232cdf0e10cSrcweir         aKeyColNames = xPrimaryKeyColumns->getElementNames();
233cdf0e10cSrcweir     return aKeyColNames;
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir //------------------------------------------------------------------------
createFieldDescription(const::rtl::OUString & _rColumnName) const237cdf0e10cSrcweir OFieldDescription* ObjectCopySource::createFieldDescription( const ::rtl::OUString& _rColumnName ) const
238cdf0e10cSrcweir {
239cdf0e10cSrcweir     Reference< XPropertySet > xColumn( m_xObjectColumns->getByName( _rColumnName ), UNO_QUERY_THROW );
240cdf0e10cSrcweir     return new OFieldDescription( xColumn );
241cdf0e10cSrcweir }
242cdf0e10cSrcweir //------------------------------------------------------------------------
getSelectStatement() const243cdf0e10cSrcweir ::rtl::OUString ObjectCopySource::getSelectStatement() const
244cdf0e10cSrcweir {
245cdf0e10cSrcweir     ::rtl::OUString sSelectStatement;
246cdf0e10cSrcweir     if ( m_xObjectPSI->hasPropertyByName( PROPERTY_COMMAND ) )
247cdf0e10cSrcweir     {   // query
248cdf0e10cSrcweir         OSL_VERIFY( m_xObject->getPropertyValue( PROPERTY_COMMAND ) >>= sSelectStatement );
249cdf0e10cSrcweir     }
250cdf0e10cSrcweir     else
251cdf0e10cSrcweir     {   // table
252cdf0e10cSrcweir         ::rtl::OUStringBuffer aSQL;
253cdf0e10cSrcweir         aSQL.appendAscii( "SELECT " );
254cdf0e10cSrcweir 
255cdf0e10cSrcweir         // we need to create the sql stmt with column names
256cdf0e10cSrcweir         // otherwise it is possible that names don't match
257cdf0e10cSrcweir         const ::rtl::OUString sQuote = m_xMetaData->getIdentifierQuoteString();
258cdf0e10cSrcweir 
259cdf0e10cSrcweir         Sequence< ::rtl::OUString > aColumnNames = getColumnNames();
260cdf0e10cSrcweir         const ::rtl::OUString* pColumnName = aColumnNames.getConstArray();
261cdf0e10cSrcweir         const ::rtl::OUString* pEnd = pColumnName + aColumnNames.getLength();
262cdf0e10cSrcweir         for ( ; pColumnName != pEnd; )
263cdf0e10cSrcweir         {
264cdf0e10cSrcweir             aSQL.append( ::dbtools::quoteName( sQuote, *pColumnName++ ) );
265cdf0e10cSrcweir 
266cdf0e10cSrcweir             if ( pColumnName == pEnd )
267cdf0e10cSrcweir                 aSQL.appendAscii( " " );
268cdf0e10cSrcweir             else
269cdf0e10cSrcweir                 aSQL.appendAscii( ", " );
270cdf0e10cSrcweir         }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir         aSQL.appendAscii( "FROM " );
273cdf0e10cSrcweir         aSQL.append( ::dbtools::composeTableNameForSelect( m_xConnection, m_xObject ) );
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         sSelectStatement = aSQL.makeStringAndClear();
276cdf0e10cSrcweir     }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir     return sSelectStatement;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir //------------------------------------------------------------------------
getPreparedSelectStatement() const282cdf0e10cSrcweir ::utl::SharedUNOComponent< XPreparedStatement > ObjectCopySource::getPreparedSelectStatement() const
283cdf0e10cSrcweir {
284cdf0e10cSrcweir     ::utl::SharedUNOComponent< XPreparedStatement > xStatement(
285cdf0e10cSrcweir         m_xConnection->prepareStatement( getSelectStatement() ),
286cdf0e10cSrcweir         ::utl::SharedUNOComponent< XPreparedStatement >::TakeOwnership
287cdf0e10cSrcweir     );
288cdf0e10cSrcweir     return xStatement;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir //========================================================================
292cdf0e10cSrcweir //= NamedTableCopySource
293cdf0e10cSrcweir //========================================================================
294cdf0e10cSrcweir //------------------------------------------------------------------------
NamedTableCopySource(const Reference<XConnection> & _rxConnection,const::rtl::OUString & _rTableName)295cdf0e10cSrcweir NamedTableCopySource::NamedTableCopySource( const Reference< XConnection >& _rxConnection, const ::rtl::OUString& _rTableName )
296cdf0e10cSrcweir     :m_xConnection( _rxConnection, UNO_SET_THROW )
297cdf0e10cSrcweir     ,m_xMetaData( _rxConnection->getMetaData(), UNO_SET_THROW )
298cdf0e10cSrcweir     ,m_sTableName( _rTableName )
299cdf0e10cSrcweir     ,m_aColumnInfo()
300cdf0e10cSrcweir {
301cdf0e10cSrcweir     ::dbtools::qualifiedNameComponents( m_xMetaData, m_sTableName, m_sTableCatalog, m_sTableSchema, m_sTableBareName, ::dbtools::eComplete );
302cdf0e10cSrcweir     impl_ensureColumnInfo_throw();
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir //------------------------------------------------------------------------
getQualifiedObjectName() const306cdf0e10cSrcweir ::rtl::OUString NamedTableCopySource::getQualifiedObjectName() const
307cdf0e10cSrcweir {
308cdf0e10cSrcweir     return m_sTableName;
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir //------------------------------------------------------------------------
isView() const312cdf0e10cSrcweir bool NamedTableCopySource::isView() const
313cdf0e10cSrcweir {
314cdf0e10cSrcweir     ::rtl::OUString sTableType;
315cdf0e10cSrcweir     try
316cdf0e10cSrcweir     {
317cdf0e10cSrcweir         Reference< XResultSet > xTableDesc( m_xMetaData->getTables( makeAny( m_sTableCatalog ), m_sTableSchema, m_sTableBareName,
318cdf0e10cSrcweir             Sequence< ::rtl::OUString >() ) );
319cdf0e10cSrcweir         Reference< XRow > xTableDescRow( xTableDesc, UNO_QUERY_THROW );
320cdf0e10cSrcweir         OSL_VERIFY( xTableDesc->next() );
321cdf0e10cSrcweir         sTableType = xTableDescRow->getString( 4 );
322cdf0e10cSrcweir         OSL_ENSURE( !xTableDescRow->wasNull(), "NamedTableCopySource::isView: invalid table type!" );
323cdf0e10cSrcweir     }
324cdf0e10cSrcweir     catch( const Exception& )
325cdf0e10cSrcweir     {
326cdf0e10cSrcweir 	    DBG_UNHANDLED_EXCEPTION();
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir     return sTableType.equalsAscii( "VIEW" );
329cdf0e10cSrcweir }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir //------------------------------------------------------------------------
copyUISettingsTo(const Reference<XPropertySet> &) const332cdf0e10cSrcweir void NamedTableCopySource::copyUISettingsTo( const Reference< XPropertySet >& /*_rxObject*/ ) const
333cdf0e10cSrcweir {
334cdf0e10cSrcweir     // not supported: we do not have UI settings to copy
335cdf0e10cSrcweir }
336cdf0e10cSrcweir // -----------------------------------------------------------------------------
copyFilterAndSortingTo(const Reference<XConnection> &,const Reference<XPropertySet> &) const337cdf0e10cSrcweir void NamedTableCopySource::copyFilterAndSortingTo( const Reference< XConnection >& ,const Reference< XPropertySet >& /*_rxObject*/ ) const
338cdf0e10cSrcweir {
339cdf0e10cSrcweir }
340cdf0e10cSrcweir //------------------------------------------------------------------------
impl_ensureColumnInfo_throw()341cdf0e10cSrcweir void NamedTableCopySource::impl_ensureColumnInfo_throw()
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     if ( !m_aColumnInfo.empty() )
344cdf0e10cSrcweir         return;
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     Reference< XResultSetMetaDataSupplier > xStatementMetaSupp( impl_ensureStatement_throw().getTyped(), UNO_QUERY_THROW );
347cdf0e10cSrcweir     Reference< XResultSetMetaData > xStatementMeta( xStatementMetaSupp->getMetaData(), UNO_SET_THROW );
348cdf0e10cSrcweir 
349cdf0e10cSrcweir     sal_Int32 nColCount( xStatementMeta->getColumnCount() );
350cdf0e10cSrcweir     for ( sal_Int32 i = 1; i <= nColCount; ++i )
351cdf0e10cSrcweir     {
352cdf0e10cSrcweir         OFieldDescription aDesc;
353cdf0e10cSrcweir 
354cdf0e10cSrcweir         aDesc.SetName(          xStatementMeta->getColumnName(      i ) );
355cdf0e10cSrcweir         aDesc.SetHelpText(      xStatementMeta->getColumnLabel(     i ) );
356cdf0e10cSrcweir         aDesc.SetTypeValue(     xStatementMeta->getColumnType(      i ) );
357cdf0e10cSrcweir         aDesc.SetTypeName(      xStatementMeta->getColumnTypeName(  i ) );
358cdf0e10cSrcweir         aDesc.SetPrecision(     xStatementMeta->getPrecision(       i ) );
359cdf0e10cSrcweir         aDesc.SetScale(         xStatementMeta->getScale(           i ) );
360cdf0e10cSrcweir         aDesc.SetIsNullable(    xStatementMeta->isNullable(         i ) );
361cdf0e10cSrcweir         aDesc.SetCurrency(      xStatementMeta->isCurrency(         i ) );
362cdf0e10cSrcweir         aDesc.SetAutoIncrement( xStatementMeta->isAutoIncrement(    i ) );
363cdf0e10cSrcweir 
364cdf0e10cSrcweir         m_aColumnInfo.push_back( aDesc );
365cdf0e10cSrcweir     }
366cdf0e10cSrcweir }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir //------------------------------------------------------------------------
impl_ensureStatement_throw()369cdf0e10cSrcweir ::utl::SharedUNOComponent< XPreparedStatement > NamedTableCopySource::impl_ensureStatement_throw()
370cdf0e10cSrcweir {
371cdf0e10cSrcweir     if ( !m_xStatement.is() )
372cdf0e10cSrcweir         m_xStatement.set( m_xConnection->prepareStatement( getSelectStatement() ), UNO_SET_THROW );
373cdf0e10cSrcweir     return m_xStatement;
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir //------------------------------------------------------------------------
getColumnNames() const377cdf0e10cSrcweir Sequence< ::rtl::OUString > NamedTableCopySource::getColumnNames() const
378cdf0e10cSrcweir {
379cdf0e10cSrcweir     Sequence< ::rtl::OUString > aNames( m_aColumnInfo.size() );
380cdf0e10cSrcweir     for (   ::std::vector< OFieldDescription >::const_iterator col = m_aColumnInfo.begin();
381cdf0e10cSrcweir             col != m_aColumnInfo.end();
382cdf0e10cSrcweir             ++col
383cdf0e10cSrcweir         )
384cdf0e10cSrcweir         aNames[ col - m_aColumnInfo.begin() ] = col->GetName();
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     return aNames;
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir //------------------------------------------------------------------------
getPrimaryKeyColumnNames() const390cdf0e10cSrcweir Sequence< ::rtl::OUString > NamedTableCopySource::getPrimaryKeyColumnNames() const
391cdf0e10cSrcweir {
392cdf0e10cSrcweir     Sequence< ::rtl::OUString > aPKColNames;
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     try
395cdf0e10cSrcweir     {
396cdf0e10cSrcweir         Reference< XResultSet > xPKDesc( m_xMetaData->getPrimaryKeys( makeAny( m_sTableCatalog ), m_sTableSchema, m_sTableBareName ) );
397cdf0e10cSrcweir         Reference< XRow > xPKDescRow( xPKDesc, UNO_QUERY_THROW );
398cdf0e10cSrcweir         while ( xPKDesc->next() )
399cdf0e10cSrcweir         {
400cdf0e10cSrcweir             sal_Int32 len( aPKColNames.getLength() );
401cdf0e10cSrcweir             aPKColNames.realloc( len + 1 );
402cdf0e10cSrcweir             aPKColNames[ len ] = xPKDescRow->getString( 4 );    // COLUMN_NAME
403cdf0e10cSrcweir         }
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir     catch( const Exception& )
406cdf0e10cSrcweir     {
407cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
408cdf0e10cSrcweir     }
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     return aPKColNames;
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir //------------------------------------------------------------------------
createFieldDescription(const::rtl::OUString & _rColumnName) const414cdf0e10cSrcweir OFieldDescription* NamedTableCopySource::createFieldDescription( const ::rtl::OUString& _rColumnName ) const
415cdf0e10cSrcweir {
416cdf0e10cSrcweir     for (   ::std::vector< OFieldDescription >::const_iterator col = m_aColumnInfo.begin();
417cdf0e10cSrcweir             col != m_aColumnInfo.end();
418cdf0e10cSrcweir             ++col
419cdf0e10cSrcweir         )
420cdf0e10cSrcweir         if ( col->GetName() == _rColumnName )
421cdf0e10cSrcweir             return new OFieldDescription( *col );
422cdf0e10cSrcweir 
423cdf0e10cSrcweir     return NULL;
424cdf0e10cSrcweir }
425cdf0e10cSrcweir //------------------------------------------------------------------------
getSelectStatement() const426cdf0e10cSrcweir ::rtl::OUString NamedTableCopySource::getSelectStatement() const
427cdf0e10cSrcweir {
428cdf0e10cSrcweir     ::rtl::OUStringBuffer aSQL;
429cdf0e10cSrcweir     aSQL.appendAscii( "SELECT * FROM " );
430cdf0e10cSrcweir 
431cdf0e10cSrcweir     aSQL.append( ::dbtools::composeTableNameForSelect( m_xConnection, m_sTableCatalog, m_sTableSchema, m_sTableBareName ) );
432cdf0e10cSrcweir 
433cdf0e10cSrcweir     return aSQL.makeStringAndClear();
434cdf0e10cSrcweir }
435cdf0e10cSrcweir 
436cdf0e10cSrcweir //------------------------------------------------------------------------
getPreparedSelectStatement() const437cdf0e10cSrcweir ::utl::SharedUNOComponent< XPreparedStatement > NamedTableCopySource::getPreparedSelectStatement() const
438cdf0e10cSrcweir {
439cdf0e10cSrcweir     return const_cast< NamedTableCopySource* >( this )->impl_ensureStatement_throw();
440cdf0e10cSrcweir }
441cdf0e10cSrcweir 
442cdf0e10cSrcweir // ========================================================
443cdf0e10cSrcweir // DummyCopySource
444cdf0e10cSrcweir // ========================================================
445cdf0e10cSrcweir class DummyCopySource : public ICopyTableSourceObject
446cdf0e10cSrcweir {
447cdf0e10cSrcweir public:
DummyCopySource()448cdf0e10cSrcweir     DummyCopySource() { }
449cdf0e10cSrcweir 
450cdf0e10cSrcweir     static const DummyCopySource& Instance();
451cdf0e10cSrcweir 
452cdf0e10cSrcweir     // ICopyTableSourceObject overridables
453cdf0e10cSrcweir     virtual ::rtl::OUString     getQualifiedObjectName() const;
454cdf0e10cSrcweir     virtual bool                isView() const;
455cdf0e10cSrcweir     virtual void                copyUISettingsTo( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject ) const;
456cdf0e10cSrcweir     virtual void                copyFilterAndSortingTo(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject ) const;
457cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
458cdf0e10cSrcweir                                 getColumnNames() const;
459cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
460cdf0e10cSrcweir                                 getPrimaryKeyColumnNames() const;
461cdf0e10cSrcweir     virtual OFieldDescription*  createFieldDescription( const ::rtl::OUString& _rColumnName ) const;
462cdf0e10cSrcweir     virtual ::rtl::OUString     getSelectStatement() const;
463cdf0e10cSrcweir     virtual ::utl::SharedUNOComponent< XPreparedStatement >
464cdf0e10cSrcweir                                 getPreparedSelectStatement() const;
465cdf0e10cSrcweir };
466cdf0e10cSrcweir 
467cdf0e10cSrcweir //------------------------------------------------------------------------
Instance()468cdf0e10cSrcweir const DummyCopySource& DummyCopySource::Instance()
469cdf0e10cSrcweir {
470cdf0e10cSrcweir     static DummyCopySource s_aTheInstance;
471cdf0e10cSrcweir     return s_aTheInstance;
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
474cdf0e10cSrcweir //------------------------------------------------------------------------
getQualifiedObjectName() const475cdf0e10cSrcweir ::rtl::OUString DummyCopySource::getQualifiedObjectName() const
476cdf0e10cSrcweir {
477cdf0e10cSrcweir     OSL_ENSURE( false, "DummyCopySource::getQualifiedObjectName: not to be called!" );
478cdf0e10cSrcweir     return ::rtl::OUString();
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir //------------------------------------------------------------------------
isView() const482cdf0e10cSrcweir bool DummyCopySource::isView() const
483cdf0e10cSrcweir {
484cdf0e10cSrcweir     OSL_ENSURE( false, "DummyCopySource::isView: not to be called!" );
485cdf0e10cSrcweir     return false;
486cdf0e10cSrcweir }
487cdf0e10cSrcweir 
488cdf0e10cSrcweir //------------------------------------------------------------------------
copyUISettingsTo(const Reference<XPropertySet> &) const489cdf0e10cSrcweir void DummyCopySource::copyUISettingsTo( const Reference< XPropertySet >& /*_rxObject*/ ) const
490cdf0e10cSrcweir {
491cdf0e10cSrcweir     // no support
492cdf0e10cSrcweir }
493cdf0e10cSrcweir // -----------------------------------------------------------------------------
copyFilterAndSortingTo(const Reference<XConnection> &,const Reference<XPropertySet> &) const494cdf0e10cSrcweir void DummyCopySource::copyFilterAndSortingTo( const Reference< XConnection >& ,const Reference< XPropertySet >& /*_rxObject*/ ) const
495cdf0e10cSrcweir {
496cdf0e10cSrcweir }
497cdf0e10cSrcweir //------------------------------------------------------------------------
getColumnNames() const498cdf0e10cSrcweir Sequence< ::rtl::OUString > DummyCopySource::getColumnNames() const
499cdf0e10cSrcweir {
500cdf0e10cSrcweir     return Sequence< ::rtl::OUString >();
501cdf0e10cSrcweir }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir //------------------------------------------------------------------------
getPrimaryKeyColumnNames() const504cdf0e10cSrcweir Sequence< ::rtl::OUString > DummyCopySource::getPrimaryKeyColumnNames() const
505cdf0e10cSrcweir {
506cdf0e10cSrcweir     OSL_ENSURE( false, "DummyCopySource::getPrimaryKeyColumnNames: not to be called!" );
507cdf0e10cSrcweir     return Sequence< ::rtl::OUString >();
508cdf0e10cSrcweir }
509cdf0e10cSrcweir 
510cdf0e10cSrcweir //------------------------------------------------------------------------
createFieldDescription(const::rtl::OUString &) const511cdf0e10cSrcweir OFieldDescription* DummyCopySource::createFieldDescription( const ::rtl::OUString& /*_rColumnName*/ ) const
512cdf0e10cSrcweir {
513cdf0e10cSrcweir     OSL_ENSURE( false, "DummyCopySource::createFieldDescription: not to be called!" );
514cdf0e10cSrcweir     return NULL;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir //------------------------------------------------------------------------
getSelectStatement() const517cdf0e10cSrcweir ::rtl::OUString DummyCopySource::getSelectStatement() const
518cdf0e10cSrcweir {
519cdf0e10cSrcweir     OSL_ENSURE( false, "DummyCopySource::getSelectStatement: not to be called!" );
520cdf0e10cSrcweir     return ::rtl::OUString();
521cdf0e10cSrcweir }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir //------------------------------------------------------------------------
getPreparedSelectStatement() const524cdf0e10cSrcweir ::utl::SharedUNOComponent< XPreparedStatement > DummyCopySource::getPreparedSelectStatement() const
525cdf0e10cSrcweir {
526cdf0e10cSrcweir     OSL_ENSURE( false, "DummyCopySource::getPreparedSelectStatement: not to be called!" );
527cdf0e10cSrcweir     return ::utl::SharedUNOComponent< XPreparedStatement >();
528cdf0e10cSrcweir }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir //------------------------------------------------------------------------
531cdf0e10cSrcweir namespace
532cdf0e10cSrcweir {
lcl_canCreateViewFor_nothrow(const Reference<XConnection> & _rxConnection)533cdf0e10cSrcweir     bool lcl_canCreateViewFor_nothrow( const Reference< XConnection >& _rxConnection )
534cdf0e10cSrcweir     {
535cdf0e10cSrcweir 	    Reference< XViewsSupplier > xSup( _rxConnection, UNO_QUERY );
536cdf0e10cSrcweir 	    Reference< XDataDescriptorFactory > xViewFac;
537cdf0e10cSrcweir 	    if ( xSup.is() )
538cdf0e10cSrcweir 		    xViewFac.set( xSup->getViews(), UNO_QUERY );
539cdf0e10cSrcweir         return xViewFac.is();
540cdf0e10cSrcweir     }
541cdf0e10cSrcweir 
lcl_sameConnection_throw(const Reference<XConnection> & _rxLHS,const Reference<XConnection> & _rxRHS)542cdf0e10cSrcweir     bool lcl_sameConnection_throw( const Reference< XConnection >& _rxLHS, const Reference< XConnection >& _rxRHS )
543cdf0e10cSrcweir     {
544cdf0e10cSrcweir         Reference< XDatabaseMetaData > xMetaLHS( _rxLHS->getMetaData(), UNO_QUERY_THROW );
545cdf0e10cSrcweir         Reference< XDatabaseMetaData > xMetaRHS( _rxRHS->getMetaData(), UNO_QUERY_THROW );
546cdf0e10cSrcweir         return xMetaLHS->getURL().equals( xMetaRHS->getURL() );
547cdf0e10cSrcweir     }
548cdf0e10cSrcweir }
549cdf0e10cSrcweir 
550cdf0e10cSrcweir //========================================================================
551cdf0e10cSrcweir //= OCopyTableWizard
552cdf0e10cSrcweir //========================================================================
553cdf0e10cSrcweir //------------------------------------------------------------------------
OCopyTableWizard(Window * pParent,const::rtl::OUString & _rDefaultName,sal_Int16 _nOperation,const ICopyTableSourceObject & _rSourceObject,const Reference<XConnection> & _xSourceConnection,const Reference<XConnection> & _xConnection,const Reference<XMultiServiceFactory> & _rxORB,const Reference<XInteractionHandler> & _xInteractionHandler)554cdf0e10cSrcweir OCopyTableWizard::OCopyTableWizard( Window * pParent, const ::rtl::OUString& _rDefaultName, sal_Int16 _nOperation,
555cdf0e10cSrcweir         const ICopyTableSourceObject& _rSourceObject, const Reference< XConnection >& _xSourceConnection,
556cdf0e10cSrcweir         const Reference< XConnection >& _xConnection, const Reference< XMultiServiceFactory >& _rxORB,
557cdf0e10cSrcweir         const Reference< XInteractionHandler>&   _xInteractionHandler)
558cdf0e10cSrcweir 	: WizardDialog( pParent, ModuleRes(WIZ_RTFCOPYTABLE))
559cdf0e10cSrcweir     ,m_pbHelp( this , ModuleRes(PB_HELP))
560cdf0e10cSrcweir 	,m_pbCancel( this , ModuleRes(PB_CANCEL))
561cdf0e10cSrcweir 	,m_pbPrev( this , ModuleRes(PB_PREV))
562cdf0e10cSrcweir 	,m_pbNext( this , ModuleRes(PB_NEXT))
563cdf0e10cSrcweir 	,m_pbFinish( this , ModuleRes(PB_OK))
564cdf0e10cSrcweir 	,m_mNameMapping(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers())
565cdf0e10cSrcweir     ,m_xDestConnection( _xConnection )
566cdf0e10cSrcweir 	,m_rSourceObject( _rSourceObject )
567cdf0e10cSrcweir     ,m_xFormatter( getNumberFormatter( _xConnection, _rxORB ) )
568cdf0e10cSrcweir 	,m_xFactory(_rxORB)
569cdf0e10cSrcweir     ,m_xInteractionHandler(_xInteractionHandler)
570cdf0e10cSrcweir 	,m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES))
571cdf0e10cSrcweir 	,m_nPageCount(0)
572cdf0e10cSrcweir 	,m_bDeleteSourceColumns(sal_True)
573cdf0e10cSrcweir     ,m_bInterConnectionCopy( _xSourceConnection != _xConnection )
574cdf0e10cSrcweir     ,m_sName( _rDefaultName )
575cdf0e10cSrcweir 	,m_nOperation( _nOperation )
576cdf0e10cSrcweir     ,m_ePressed( WIZARD_NONE )
577cdf0e10cSrcweir     ,m_bCreatePrimaryKeyColumn(sal_False)
578cdf0e10cSrcweir {
579cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::OCopyTableWizard" );
580cdf0e10cSrcweir 	DBG_CTOR(OCopyTableWizard,NULL);
581cdf0e10cSrcweir 	construct();
582cdf0e10cSrcweir 
583cdf0e10cSrcweir     // extract table name
584cdf0e10cSrcweir     ::rtl::OUString sInitialTableName( _rDefaultName );
585cdf0e10cSrcweir 	try
586cdf0e10cSrcweir 	{
587cdf0e10cSrcweir         m_sSourceName = m_rSourceObject.getQualifiedObjectName();
588cdf0e10cSrcweir         OSL_ENSURE( m_sSourceName.getLength() > 0, "OCopyTableWizard::OCopyTableWizard: unable to retrieve the source object's name!" );
589cdf0e10cSrcweir 
590cdf0e10cSrcweir         if ( !sInitialTableName.getLength() )
591cdf0e10cSrcweir             sInitialTableName = m_sSourceName;
592cdf0e10cSrcweir 
593cdf0e10cSrcweir         if ( !m_sName.getLength() )
594cdf0e10cSrcweir         {
595cdf0e10cSrcweir 		    if ( _xSourceConnection == m_xDestConnection )
596cdf0e10cSrcweir 		    {
597cdf0e10cSrcweir 			    Reference< XTablesSupplier > xSup( m_xDestConnection, UNO_QUERY_THROW );
598cdf0e10cSrcweir 			    m_sName = ::dbtools::createUniqueName( xSup->getTables(), sInitialTableName, sal_False );
599cdf0e10cSrcweir 		    }
600cdf0e10cSrcweir 		    else
601cdf0e10cSrcweir 			    m_sName = sInitialTableName;
602cdf0e10cSrcweir         }
603cdf0e10cSrcweir 	}
604cdf0e10cSrcweir 	catch ( const Exception& )
605cdf0e10cSrcweir 	{
606cdf0e10cSrcweir         m_sName = sInitialTableName;
607cdf0e10cSrcweir 	}
608cdf0e10cSrcweir 
609cdf0e10cSrcweir 	::dbaui::fillTypeInfo( _xSourceConnection, m_sTypeNames, m_aTypeInfo, m_aTypeInfoIndex );
610cdf0e10cSrcweir 	::dbaui::fillTypeInfo( m_xDestConnection, m_sTypeNames, m_aDestTypeInfo, m_aDestTypeInfoIndex );
611cdf0e10cSrcweir     impl_loadSourceData();
612cdf0e10cSrcweir 
613cdf0e10cSrcweir     bool bAllowViews = true;
614cdf0e10cSrcweir     // if the source is a, don't allow creating views #100644# (oj)
615cdf0e10cSrcweir     // (fs: Hmm? A SELECT * FROM <view> would be created, where #100644# claims this is nonsense. Why?
616cdf0e10cSrcweir     if ( m_rSourceObject.isView() )
617cdf0e10cSrcweir         bAllowViews = false;
618cdf0e10cSrcweir     // no views if the target connection does not support creating them
619cdf0e10cSrcweir     if ( !lcl_canCreateViewFor_nothrow( m_xDestConnection ) )
620cdf0e10cSrcweir         bAllowViews = false;
621cdf0e10cSrcweir     // no views if we're copying to a different database
622cdf0e10cSrcweir     if ( !lcl_sameConnection_throw( _xSourceConnection, m_xDestConnection ) )
623cdf0e10cSrcweir         bAllowViews = false;
624cdf0e10cSrcweir 
625cdf0e10cSrcweir 	if ( m_bInterConnectionCopy )
626cdf0e10cSrcweir 	{
627cdf0e10cSrcweir 		Reference< XDatabaseMetaData > xSrcMeta = _xSourceConnection->getMetaData();
628cdf0e10cSrcweir 		::rtl::OUString sCatalog;
629cdf0e10cSrcweir 		::rtl::OUString sSchema;
630cdf0e10cSrcweir 		::rtl::OUString sTable;
631cdf0e10cSrcweir 		::dbtools::qualifiedNameComponents(	xSrcMeta,
632cdf0e10cSrcweir 											m_sName,
633cdf0e10cSrcweir 											sCatalog,
634cdf0e10cSrcweir 											sSchema,
635cdf0e10cSrcweir 											sTable,
636cdf0e10cSrcweir 											::dbtools::eInDataManipulation);
637cdf0e10cSrcweir 
638cdf0e10cSrcweir 		m_sName = ::dbtools::composeTableName(m_xDestConnection->getMetaData(),sCatalog,sSchema,sTable,sal_False,::dbtools::eInTableDefinitions);
639cdf0e10cSrcweir 	}
640cdf0e10cSrcweir 
641cdf0e10cSrcweir 	OCopyTable* pPage1( new OCopyTable( this ) );
642cdf0e10cSrcweir     pPage1->disallowUseHeaderLine();
643cdf0e10cSrcweir     if ( !bAllowViews )
644cdf0e10cSrcweir         pPage1->disallowViews();
645cdf0e10cSrcweir 	pPage1->setCreateStyleAction();
646cdf0e10cSrcweir 	AddWizardPage(pPage1);
647cdf0e10cSrcweir 
648cdf0e10cSrcweir     AddWizardPage( new OWizNameMatching( this ) );
649cdf0e10cSrcweir 	AddWizardPage( new OWizColumnSelect( this ) );
650cdf0e10cSrcweir 	AddWizardPage( new OWizNormalExtend( this ) );
651cdf0e10cSrcweir 	ActivatePage();
652cdf0e10cSrcweir }
653cdf0e10cSrcweir 
654cdf0e10cSrcweir // -----------------------------------------------------------------------------
OCopyTableWizard(Window * pParent,const::rtl::OUString & _rDefaultName,sal_Int16 _nOperation,const ODatabaseExport::TColumns & _rSourceColumns,const ODatabaseExport::TColumnVector & _rSourceColVec,const Reference<XConnection> & _xConnection,const Reference<XNumberFormatter> & _xFormatter,TypeSelectionPageFactory _pTypeSelectionPageFactory,SvStream & _rTypeSelectionPageArg,const Reference<XMultiServiceFactory> & _rM)655cdf0e10cSrcweir OCopyTableWizard::OCopyTableWizard( Window* pParent, const ::rtl::OUString& _rDefaultName, sal_Int16 _nOperation,
656cdf0e10cSrcweir         const ODatabaseExport::TColumns& _rSourceColumns, const ODatabaseExport::TColumnVector& _rSourceColVec,
657cdf0e10cSrcweir         const Reference< XConnection >& _xConnection, const Reference< XNumberFormatter >&	_xFormatter,
658cdf0e10cSrcweir         TypeSelectionPageFactory _pTypeSelectionPageFactory, SvStream& _rTypeSelectionPageArg, const Reference< XMultiServiceFactory >& _rM )
659cdf0e10cSrcweir 	:WizardDialog( pParent, ModuleRes(WIZ_RTFCOPYTABLE))
660cdf0e10cSrcweir 	,m_vSourceColumns(_rSourceColumns)
661cdf0e10cSrcweir     ,m_pbHelp( this , ModuleRes(PB_HELP))
662cdf0e10cSrcweir 	,m_pbCancel( this , ModuleRes(PB_CANCEL))
663cdf0e10cSrcweir 	,m_pbPrev( this , ModuleRes(PB_PREV))
664cdf0e10cSrcweir 	,m_pbNext( this , ModuleRes(PB_NEXT))
665cdf0e10cSrcweir 	,m_pbFinish( this , ModuleRes(PB_OK))
666cdf0e10cSrcweir 	,m_mNameMapping(_xConnection->getMetaData().is() && _xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers())
667cdf0e10cSrcweir     ,m_xDestConnection( _xConnection )
668cdf0e10cSrcweir     ,m_rSourceObject( DummyCopySource::Instance() )
669cdf0e10cSrcweir 	,m_xFormatter(_xFormatter)
670cdf0e10cSrcweir 	,m_xFactory(_rM)
671cdf0e10cSrcweir 	,m_sTypeNames(ModuleRes(STR_TABLEDESIGN_DBFIELDTYPES))
672cdf0e10cSrcweir 	,m_nPageCount(0)
673cdf0e10cSrcweir 	,m_bDeleteSourceColumns(sal_False)
674cdf0e10cSrcweir     ,m_bInterConnectionCopy( false )
675cdf0e10cSrcweir 	,m_sName(_rDefaultName)
676cdf0e10cSrcweir     ,m_nOperation( _nOperation )
677cdf0e10cSrcweir     ,m_ePressed( WIZARD_NONE )
678cdf0e10cSrcweir 	,m_bCreatePrimaryKeyColumn(sal_False)
679cdf0e10cSrcweir {
680cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::OCopyTableWizard" );
681cdf0e10cSrcweir 	DBG_CTOR(OCopyTableWizard,NULL);
682cdf0e10cSrcweir 	construct();
683cdf0e10cSrcweir     ODatabaseExport::TColumnVector::const_iterator aIter = _rSourceColVec.begin();
684cdf0e10cSrcweir     ODatabaseExport::TColumnVector::const_iterator aEnd = _rSourceColVec.end();
685cdf0e10cSrcweir     for (; aIter != aEnd ; ++aIter)
686cdf0e10cSrcweir     {
687cdf0e10cSrcweir         m_vSourceVec.push_back(m_vSourceColumns.find((*aIter)->first));
688cdf0e10cSrcweir     }
689cdf0e10cSrcweir 
690cdf0e10cSrcweir 	::dbaui::fillTypeInfo( _xConnection, m_sTypeNames, m_aTypeInfo, m_aTypeInfoIndex );
691cdf0e10cSrcweir 	::dbaui::fillTypeInfo( _xConnection, m_sTypeNames, m_aDestTypeInfo, m_aDestTypeInfoIndex );
692cdf0e10cSrcweir 
693cdf0e10cSrcweir     m_xInteractionHandler.set( m_xFactory->createInstance( SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY);
694cdf0e10cSrcweir 
695cdf0e10cSrcweir     OCopyTable* pPage1( new OCopyTable( this ) );
696cdf0e10cSrcweir     pPage1->disallowViews();
697cdf0e10cSrcweir 	pPage1->setCreateStyleAction();
698cdf0e10cSrcweir     AddWizardPage( pPage1 );
699cdf0e10cSrcweir 
700cdf0e10cSrcweir     AddWizardPage( new OWizNameMatching( this ) );
701cdf0e10cSrcweir 	AddWizardPage( new OWizColumnSelect( this ) );
702cdf0e10cSrcweir     AddWizardPage( (*_pTypeSelectionPageFactory)( this, _rTypeSelectionPageArg ) );
703cdf0e10cSrcweir 
704cdf0e10cSrcweir     ActivatePage();
705cdf0e10cSrcweir }
706cdf0e10cSrcweir 
707cdf0e10cSrcweir // -----------------------------------------------------------------------------
construct()708cdf0e10cSrcweir void OCopyTableWizard::construct()
709cdf0e10cSrcweir {
710cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::construct" );
711cdf0e10cSrcweir     AddButton( &m_pbHelp, WIZARDDIALOG_BUTTON_STDOFFSET_X );
712cdf0e10cSrcweir 	AddButton( &m_pbCancel, WIZARDDIALOG_BUTTON_STDOFFSET_X );
713cdf0e10cSrcweir     AddButton( &m_pbPrev );
714cdf0e10cSrcweir 	AddButton( &m_pbNext, WIZARDDIALOG_BUTTON_STDOFFSET_X );
715cdf0e10cSrcweir 	AddButton( &m_pbFinish );
716cdf0e10cSrcweir 
717cdf0e10cSrcweir 	m_pbPrev.SetClickHdl( LINK( this, OCopyTableWizard, ImplPrevHdl ) );
718cdf0e10cSrcweir 	m_pbNext.SetClickHdl( LINK( this, OCopyTableWizard, ImplNextHdl ) );
719cdf0e10cSrcweir 	m_pbFinish.SetClickHdl( LINK( this, OCopyTableWizard, ImplOKHdl ) );
720cdf0e10cSrcweir 
721cdf0e10cSrcweir 	SetActivatePageHdl( LINK( this, OCopyTableWizard, ImplActivateHdl ) );
722cdf0e10cSrcweir 
723cdf0e10cSrcweir 	SetPrevButton( &m_pbPrev );
724cdf0e10cSrcweir 	SetNextButton( &m_pbNext );
725cdf0e10cSrcweir 
726cdf0e10cSrcweir 	ShowButtonFixedLine( sal_True );
727cdf0e10cSrcweir 
728cdf0e10cSrcweir 	m_pbNext.GrabFocus();
729cdf0e10cSrcweir 
730cdf0e10cSrcweir 	if (m_vDestColumns.size())
731cdf0e10cSrcweir 		// source is a html or rtf table
732cdf0e10cSrcweir 		m_pbNext.SetStyle(m_pbFinish.GetStyle() | WB_DEFBUTTON);
733cdf0e10cSrcweir 	else
734cdf0e10cSrcweir 		m_pbFinish.SetStyle(m_pbFinish.GetStyle() | WB_DEFBUTTON);
735cdf0e10cSrcweir 
736cdf0e10cSrcweir 	FreeResource();
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 	m_pTypeInfo = TOTypeInfoSP(new OTypeInfo());
739cdf0e10cSrcweir 	m_pTypeInfo->aUIName = m_sTypeNames.GetToken(TYPE_OTHER);
740cdf0e10cSrcweir 	m_bAddPKFirstTime = sal_True;
741cdf0e10cSrcweir }
742cdf0e10cSrcweir //------------------------------------------------------------------------
~OCopyTableWizard()743cdf0e10cSrcweir OCopyTableWizard::~OCopyTableWizard()
744cdf0e10cSrcweir {
745cdf0e10cSrcweir 	DBG_DTOR(OCopyTableWizard,NULL);
746cdf0e10cSrcweir 	for ( ;; )
747cdf0e10cSrcweir     {
748cdf0e10cSrcweir         TabPage *pPage = GetPage(0);
749cdf0e10cSrcweir         if ( pPage == NULL )
750cdf0e10cSrcweir             break;
751cdf0e10cSrcweir 		RemovePage( pPage );
752cdf0e10cSrcweir 		delete pPage;
753cdf0e10cSrcweir 	}
754cdf0e10cSrcweir 
755cdf0e10cSrcweir 	if ( m_bDeleteSourceColumns )
756cdf0e10cSrcweir 		clearColumns(m_vSourceColumns,m_vSourceVec);
757cdf0e10cSrcweir 
758cdf0e10cSrcweir 	clearColumns(m_vDestColumns,m_aDestVec);
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 	// clear the type information
761cdf0e10cSrcweir 	m_aTypeInfoIndex.clear();
762cdf0e10cSrcweir 	m_aTypeInfo.clear();
763cdf0e10cSrcweir 	m_aDestTypeInfoIndex.clear();
764cdf0e10cSrcweir }
765cdf0e10cSrcweir // -----------------------------------------------------------------------
IMPL_LINK(OCopyTableWizard,ImplPrevHdl,PushButton *,EMPTYARG)766cdf0e10cSrcweir IMPL_LINK( OCopyTableWizard, ImplPrevHdl, PushButton*, EMPTYARG )
767cdf0e10cSrcweir {
768cdf0e10cSrcweir 	m_ePressed = WIZARD_PREV;
769cdf0e10cSrcweir 	if ( GetCurLevel() )
770cdf0e10cSrcweir 	{
771cdf0e10cSrcweir 		if ( getOperation() != CopyTableOperation::AppendData )
772cdf0e10cSrcweir 		{
773cdf0e10cSrcweir 			if(GetCurLevel() == 2)
774cdf0e10cSrcweir 				ShowPage(GetCurLevel()-2);
775cdf0e10cSrcweir 			else
776cdf0e10cSrcweir 				ShowPrevPage();
777cdf0e10cSrcweir 		}
778cdf0e10cSrcweir 		else
779cdf0e10cSrcweir 			ShowPrevPage();
780cdf0e10cSrcweir 	}
781cdf0e10cSrcweir 	return 0;
782cdf0e10cSrcweir }
783cdf0e10cSrcweir 
784cdf0e10cSrcweir // -----------------------------------------------------------------------
785cdf0e10cSrcweir 
IMPL_LINK(OCopyTableWizard,ImplNextHdl,PushButton *,EMPTYARG)786cdf0e10cSrcweir IMPL_LINK( OCopyTableWizard, ImplNextHdl, PushButton*, EMPTYARG )
787cdf0e10cSrcweir {
788cdf0e10cSrcweir 	m_ePressed = WIZARD_NEXT;
789cdf0e10cSrcweir 	if ( GetCurLevel() < MAX_PAGES )
790cdf0e10cSrcweir 	{
791cdf0e10cSrcweir 		if ( getOperation() != CopyTableOperation::AppendData )
792cdf0e10cSrcweir 		{
793cdf0e10cSrcweir 			if(GetCurLevel() == 0)
794cdf0e10cSrcweir 				ShowPage(GetCurLevel()+2);
795cdf0e10cSrcweir 			else
796cdf0e10cSrcweir 				ShowNextPage();
797cdf0e10cSrcweir 		}
798cdf0e10cSrcweir 		else
799cdf0e10cSrcweir 			ShowNextPage();
800cdf0e10cSrcweir 	}
801cdf0e10cSrcweir 	return 0;
802cdf0e10cSrcweir }
803cdf0e10cSrcweir // -----------------------------------------------------------------------
CheckColumns(sal_Int32 & _rnBreakPos)804cdf0e10cSrcweir sal_Bool OCopyTableWizard::CheckColumns(sal_Int32& _rnBreakPos)
805cdf0e10cSrcweir {
806cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::CheckColumns" );
807cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
808cdf0e10cSrcweir 	m_vColumnPos.clear();
809cdf0e10cSrcweir 	m_vColumnTypes.clear();
810cdf0e10cSrcweir 
811cdf0e10cSrcweir 	OSL_ENSURE( m_xDestConnection.is(), "OCopyTableWizard::CheckColumns: No connection!" );
812cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
813cdf0e10cSrcweir 	// Wenn Datenbank PrimaryKeys verarbeiten kann, PrimaryKey anlegen
814cdf0e10cSrcweir 	if ( m_xDestConnection.is() )
815cdf0e10cSrcweir 	{
816cdf0e10cSrcweir 		sal_Bool bPKeyAllowed = supportsPrimaryKey();
817cdf0e10cSrcweir 
818cdf0e10cSrcweir 		sal_Bool bContainsColumns = !m_vDestColumns.empty();
819cdf0e10cSrcweir 
820cdf0e10cSrcweir 		if ( bPKeyAllowed && shouldCreatePrimaryKey() )
821cdf0e10cSrcweir 		{
822cdf0e10cSrcweir 			// add extra column for the primary key
823cdf0e10cSrcweir 			TOTypeInfoSP pTypeInfo = queryPrimaryKeyType(m_aDestTypeInfo);
824cdf0e10cSrcweir 			if ( pTypeInfo.get() )
825cdf0e10cSrcweir 			{
826cdf0e10cSrcweir 				if ( m_bAddPKFirstTime )
827cdf0e10cSrcweir 				{
828cdf0e10cSrcweir 					OFieldDescription* pField = new OFieldDescription();
829cdf0e10cSrcweir 					pField->SetName(m_aKeyName);
830cdf0e10cSrcweir 					pField->FillFromTypeInfo(pTypeInfo,sal_True,sal_True);
831cdf0e10cSrcweir 					pField->SetPrimaryKey(sal_True);
832cdf0e10cSrcweir 					m_bAddPKFirstTime = sal_False;
833cdf0e10cSrcweir 					insertColumn(0,pField);
834cdf0e10cSrcweir 				}
835cdf0e10cSrcweir 				m_vColumnPos.push_back(ODatabaseExport::TPositions::value_type(1,1));
836cdf0e10cSrcweir 				m_vColumnTypes.push_back(pTypeInfo->nType);
837cdf0e10cSrcweir 			}
838cdf0e10cSrcweir 		}
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 		if ( bContainsColumns )
841cdf0e10cSrcweir 		{	// we have dest columns so look for the matching column
842cdf0e10cSrcweir 			ODatabaseExport::TColumnVector::const_iterator aSrcIter = m_vSourceVec.begin();
843cdf0e10cSrcweir             ODatabaseExport::TColumnVector::const_iterator aSrcEnd = m_vSourceVec.end();
844cdf0e10cSrcweir 			for(;aSrcIter != aSrcEnd;++aSrcIter)
845cdf0e10cSrcweir 			{
846cdf0e10cSrcweir 				ODatabaseExport::TColumns::iterator aDestIter = m_vDestColumns.find(m_mNameMapping[(*aSrcIter)->first]);
847cdf0e10cSrcweir 
848cdf0e10cSrcweir 				if ( aDestIter != m_vDestColumns.end() )
849cdf0e10cSrcweir 				{
850cdf0e10cSrcweir 					ODatabaseExport::TColumnVector::const_iterator aFind = ::std::find(m_aDestVec.begin(),m_aDestVec.end(),aDestIter);
851cdf0e10cSrcweir 					sal_Int32 nPos = (aFind - m_aDestVec.begin())+1;
852cdf0e10cSrcweir 					m_vColumnPos.push_back(ODatabaseExport::TPositions::value_type(nPos,nPos));
853cdf0e10cSrcweir 					m_vColumnTypes.push_back((*aFind)->second->GetType());
854cdf0e10cSrcweir 				}
855cdf0e10cSrcweir 				else
856cdf0e10cSrcweir 				{
857cdf0e10cSrcweir 					m_vColumnPos.push_back( ODatabaseExport::TPositions::value_type( COLUMN_POSITION_NOT_FOUND, COLUMN_POSITION_NOT_FOUND ) );
858cdf0e10cSrcweir 					m_vColumnTypes.push_back(0);
859cdf0e10cSrcweir 				}
860cdf0e10cSrcweir 			}
861cdf0e10cSrcweir 		}
862cdf0e10cSrcweir 		else
863cdf0e10cSrcweir 		{
864cdf0e10cSrcweir             Reference< XDatabaseMetaData > xMetaData( m_xDestConnection->getMetaData() );
865cdf0e10cSrcweir 			::rtl::OUString sExtraChars = xMetaData->getExtraNameCharacters();
866cdf0e10cSrcweir 			sal_Int32 nMaxNameLen		= getMaxColumnNameLength();
867cdf0e10cSrcweir 
868cdf0e10cSrcweir 			ODatabaseExport::TColumnVector::const_iterator aSrcIter = m_vSourceVec.begin();
869cdf0e10cSrcweir             ODatabaseExport::TColumnVector::const_iterator aSrcEnd = m_vSourceVec.end();
870cdf0e10cSrcweir 			for(_rnBreakPos=0;aSrcIter != aSrcEnd && bRet ;++aSrcIter,++_rnBreakPos)
871cdf0e10cSrcweir 			{
872cdf0e10cSrcweir 				OFieldDescription* pField = new OFieldDescription(*(*aSrcIter)->second);
873cdf0e10cSrcweir 				pField->SetName(convertColumnName(TExportColumnFindFunctor(&m_vDestColumns),(*aSrcIter)->first,sExtraChars,nMaxNameLen));
874cdf0e10cSrcweir 				TOTypeInfoSP pType = convertType((*aSrcIter)->second->getSpecialTypeInfo(),bRet);
875cdf0e10cSrcweir 				pField->SetType(pType);
876cdf0e10cSrcweir 				if ( !bPKeyAllowed )
877cdf0e10cSrcweir 					pField->SetPrimaryKey(sal_False);
878cdf0e10cSrcweir 
879cdf0e10cSrcweir 				// now create a column
880cdf0e10cSrcweir 				insertColumn(m_vDestColumns.size(),pField);
881cdf0e10cSrcweir 				m_vColumnPos.push_back(ODatabaseExport::TPositions::value_type(m_vDestColumns.size(),m_vDestColumns.size()));
882cdf0e10cSrcweir 				m_vColumnTypes.push_back((*aSrcIter)->second->GetType());
883cdf0e10cSrcweir 			}
884cdf0e10cSrcweir 		}
885cdf0e10cSrcweir 	}
886cdf0e10cSrcweir 	return bRet;
887cdf0e10cSrcweir }
888cdf0e10cSrcweir // -----------------------------------------------------------------------
IMPL_LINK(OCopyTableWizard,ImplOKHdl,OKButton *,EMPTYARG)889cdf0e10cSrcweir IMPL_LINK( OCopyTableWizard, ImplOKHdl, OKButton*, EMPTYARG )
890cdf0e10cSrcweir {
891cdf0e10cSrcweir 	m_ePressed = WIZARD_FINISH;
892cdf0e10cSrcweir 	sal_Bool bFinish = DeactivatePage() != 0;
893cdf0e10cSrcweir 
894cdf0e10cSrcweir 	if(bFinish)
895cdf0e10cSrcweir 	{
896cdf0e10cSrcweir 		WaitObject aWait(this);
897cdf0e10cSrcweir 		switch(getOperation())
898cdf0e10cSrcweir 		{
899cdf0e10cSrcweir 			case CopyTableOperation::CopyDefinitionAndData:
900cdf0e10cSrcweir 			case CopyTableOperation::CopyDefinitionOnly:
901cdf0e10cSrcweir 			{
902cdf0e10cSrcweir 				sal_Bool bOnFirstPage = GetCurLevel() == 0;
903cdf0e10cSrcweir 				if ( bOnFirstPage )
904cdf0e10cSrcweir 				{
905cdf0e10cSrcweir 					// we came from the first page so we have to clear
906cdf0e10cSrcweir 					// all column information already collected
907cdf0e10cSrcweir 					clearDestColumns();
908cdf0e10cSrcweir 					m_mNameMapping.clear();
909cdf0e10cSrcweir 				}
910cdf0e10cSrcweir 				sal_Int32 nBreakPos = 0;
911cdf0e10cSrcweir 				sal_Bool bCheckOk = CheckColumns(nBreakPos);
912cdf0e10cSrcweir 				if ( bOnFirstPage && !bCheckOk )
913cdf0e10cSrcweir 				{
914cdf0e10cSrcweir 					showColumnTypeNotSupported(m_vSourceVec[nBreakPos-1]->first);
915cdf0e10cSrcweir 					OWizTypeSelect* pPage = static_cast<OWizTypeSelect*>(GetPage(3));
916cdf0e10cSrcweir 					if ( pPage )
917cdf0e10cSrcweir 					{
918cdf0e10cSrcweir                         m_mNameMapping.clear();
919cdf0e10cSrcweir 						pPage->setDisplayRow(nBreakPos);
920cdf0e10cSrcweir 						ShowPage(3);
921cdf0e10cSrcweir 						return 0;
922cdf0e10cSrcweir 					}
923cdf0e10cSrcweir 				}
924cdf0e10cSrcweir                 if ( m_xDestConnection.is() )
925cdf0e10cSrcweir 	            {
926cdf0e10cSrcweir                     if ( supportsPrimaryKey() )
927cdf0e10cSrcweir                     {
928cdf0e10cSrcweir                         ODatabaseExport::TColumns::iterator aFind = ::std::find_if(m_vDestColumns.begin(),m_vDestColumns.end()
929cdf0e10cSrcweir                             ,::std::compose1(::std::mem_fun(&OFieldDescription::IsPrimaryKey),::std::select2nd<ODatabaseExport::TColumns::value_type>()));
930cdf0e10cSrcweir                         if ( aFind == m_vDestColumns.end() && m_xInteractionHandler.is() )
931cdf0e10cSrcweir                         {
932cdf0e10cSrcweir 
933cdf0e10cSrcweir                             String sTitle(ModuleRes(STR_TABLEDESIGN_NO_PRIM_KEY_HEAD));
934cdf0e10cSrcweir 			                String sMsg(ModuleRes(STR_TABLEDESIGN_NO_PRIM_KEY));
935cdf0e10cSrcweir                             SQLContext aError;
936cdf0e10cSrcweir                             aError.Message = sMsg;
937cdf0e10cSrcweir                             ::rtl::Reference< ::comphelper::OInteractionRequest > xRequest( new ::comphelper::OInteractionRequest( makeAny( aError ) ) );
938cdf0e10cSrcweir                             ::rtl::Reference< ::comphelper::OInteractionApprove > xYes = new ::comphelper::OInteractionApprove;
939cdf0e10cSrcweir                             xRequest->addContinuation( xYes.get() );
940cdf0e10cSrcweir                             xRequest->addContinuation( new ::comphelper::OInteractionDisapprove );
941cdf0e10cSrcweir                             ::rtl::Reference< ::comphelper::OInteractionAbort > xAbort = new ::comphelper::OInteractionAbort;
942cdf0e10cSrcweir                             xRequest->addContinuation( xAbort.get() );
943cdf0e10cSrcweir 
944cdf0e10cSrcweir                             m_xInteractionHandler->handle( xRequest.get() );
945cdf0e10cSrcweir 
946cdf0e10cSrcweir                             if ( xYes->wasSelected() )
947cdf0e10cSrcweir                             {
948cdf0e10cSrcweir                                 OCopyTable* pPage = static_cast<OCopyTable*>(GetPage(0));
949cdf0e10cSrcweir                                 m_bCreatePrimaryKeyColumn = sal_True;
950cdf0e10cSrcweir                                 m_aKeyName = pPage->GetKeyName();
951cdf0e10cSrcweir                                 if ( !m_aKeyName.getLength() )
952cdf0e10cSrcweir                                     m_aKeyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ID" ) );
953cdf0e10cSrcweir                                 m_aKeyName = createUniqueName( m_aKeyName );
954cdf0e10cSrcweir                                 sal_Int32 nBreakPos2 = 0;
955cdf0e10cSrcweir 			                    CheckColumns(nBreakPos2);
956cdf0e10cSrcweir                             }
957cdf0e10cSrcweir                             else if ( xAbort->wasSelected() )
958cdf0e10cSrcweir                             {
959cdf0e10cSrcweir                                 ShowPage(3);
960cdf0e10cSrcweir                                 return 0;
961cdf0e10cSrcweir                             }
962cdf0e10cSrcweir                         }
963cdf0e10cSrcweir                     }
964cdf0e10cSrcweir                 }
965cdf0e10cSrcweir 				break;
966cdf0e10cSrcweir 			}
967cdf0e10cSrcweir 			case CopyTableOperation::AppendData:
968cdf0e10cSrcweir 			case CopyTableOperation::CreateAsView:
969cdf0e10cSrcweir 				break;
970cdf0e10cSrcweir 			default:
971cdf0e10cSrcweir 			{
972cdf0e10cSrcweir 				OSL_ENSURE(sal_False, "OCopyTableWizard::ImplOKHdl: invalid creation style!");
973cdf0e10cSrcweir 			}
974cdf0e10cSrcweir 		}
975cdf0e10cSrcweir 
976cdf0e10cSrcweir 		EndDialog(RET_OK);
977cdf0e10cSrcweir 	}
978cdf0e10cSrcweir 	return bFinish;
979cdf0e10cSrcweir }
980cdf0e10cSrcweir //------------------------------------------------------------------------
shouldCreatePrimaryKey() const981cdf0e10cSrcweir sal_Bool OCopyTableWizard::shouldCreatePrimaryKey() const
982cdf0e10cSrcweir {
983cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::shouldCreatePrimaryKey" );
984cdf0e10cSrcweir 	return m_bCreatePrimaryKeyColumn;
985cdf0e10cSrcweir }
986cdf0e10cSrcweir 
987cdf0e10cSrcweir // -----------------------------------------------------------------------
setCreatePrimaryKey(bool _bDoCreate,const::rtl::OUString & _rSuggestedName)988cdf0e10cSrcweir void OCopyTableWizard::setCreatePrimaryKey( bool _bDoCreate, const ::rtl::OUString& _rSuggestedName )
989cdf0e10cSrcweir {
990cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::setCreatePrimaryKey" );
991cdf0e10cSrcweir     m_bCreatePrimaryKeyColumn = _bDoCreate;
992cdf0e10cSrcweir     if ( _rSuggestedName.getLength() )
993cdf0e10cSrcweir         m_aKeyName = _rSuggestedName;
994cdf0e10cSrcweir 
995cdf0e10cSrcweir     OCopyTable* pSettingsPage = dynamic_cast< OCopyTable* >( GetPage( 0 ) );
996cdf0e10cSrcweir     OSL_ENSURE( pSettingsPage, "OCopyTableWizard::setCreatePrimaryKey: page should have been added in the ctor!" );
997cdf0e10cSrcweir     if ( pSettingsPage )
998cdf0e10cSrcweir         pSettingsPage->setCreatePrimaryKey( _bDoCreate, _rSuggestedName );
999cdf0e10cSrcweir }
1000cdf0e10cSrcweir 
1001cdf0e10cSrcweir // -----------------------------------------------------------------------
IMPL_LINK(OCopyTableWizard,ImplActivateHdl,WizardDialog *,EMPTYARG)1002cdf0e10cSrcweir IMPL_LINK( OCopyTableWizard, ImplActivateHdl, WizardDialog*, EMPTYARG )
1003cdf0e10cSrcweir {
1004cdf0e10cSrcweir 	OWizardPage* pCurrent = (OWizardPage*)GetPage(GetCurLevel());
1005cdf0e10cSrcweir 	if(pCurrent)
1006cdf0e10cSrcweir 	{
1007cdf0e10cSrcweir 		sal_Bool bFirstTime = pCurrent->IsFirstTime();
1008cdf0e10cSrcweir 		if(bFirstTime)
1009cdf0e10cSrcweir 			pCurrent->Reset();
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir 		CheckButtons();
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir 		SetText(pCurrent->GetTitle());
1014cdf0e10cSrcweir 
1015cdf0e10cSrcweir 		Invalidate();
1016cdf0e10cSrcweir 	}
1017cdf0e10cSrcweir 	return 0;
1018cdf0e10cSrcweir }
1019cdf0e10cSrcweir // -----------------------------------------------------------------------
CheckButtons()1020cdf0e10cSrcweir void OCopyTableWizard::CheckButtons()
1021cdf0e10cSrcweir {
1022cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::CheckButtons" );
1023cdf0e10cSrcweir 	if(GetCurLevel() == 0) // erste Seite hat kein PrevButton
1024cdf0e10cSrcweir 	{
1025cdf0e10cSrcweir 		if(m_nPageCount > 1)
1026cdf0e10cSrcweir 			m_pbNext.Enable(sal_True);
1027cdf0e10cSrcweir 		else
1028cdf0e10cSrcweir 			m_pbNext.Enable(sal_False);
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir 		m_pbPrev.Enable(sal_False);
1031cdf0e10cSrcweir 	}
1032cdf0e10cSrcweir 	else if(GetCurLevel() == m_nPageCount-1) // letzte Seite hat keinen Next Button
1033cdf0e10cSrcweir 	{
1034cdf0e10cSrcweir 		m_pbNext.Enable(sal_False);
1035cdf0e10cSrcweir 		m_pbPrev.Enable(sal_True);
1036cdf0e10cSrcweir 	}
1037cdf0e10cSrcweir 	else
1038cdf0e10cSrcweir 	{
1039cdf0e10cSrcweir 		m_pbPrev.Enable(sal_True);
1040cdf0e10cSrcweir 		// next has already his state
1041cdf0e10cSrcweir 	}
1042cdf0e10cSrcweir }
1043cdf0e10cSrcweir // -----------------------------------------------------------------------
EnableButton(Wizard_Button_Style eStyle,sal_Bool bEnable)1044cdf0e10cSrcweir void OCopyTableWizard::EnableButton(Wizard_Button_Style eStyle,sal_Bool bEnable)
1045cdf0e10cSrcweir {
1046cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::EnableButton" );
1047cdf0e10cSrcweir //	CheckButtons();
1048cdf0e10cSrcweir 	Button* pButton;
1049cdf0e10cSrcweir 	if(eStyle == WIZARD_NEXT)
1050cdf0e10cSrcweir 		pButton = &m_pbNext;
1051cdf0e10cSrcweir 	else if(eStyle == WIZARD_PREV)
1052cdf0e10cSrcweir 		pButton = &m_pbPrev;
1053cdf0e10cSrcweir 	else
1054cdf0e10cSrcweir 		pButton = &m_pbFinish;
1055cdf0e10cSrcweir 	pButton->Enable(bEnable);
1056cdf0e10cSrcweir 
1057cdf0e10cSrcweir }
1058cdf0e10cSrcweir // -----------------------------------------------------------------------
DeactivatePage()1059cdf0e10cSrcweir long OCopyTableWizard::DeactivatePage()
1060cdf0e10cSrcweir {
1061cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::DeactivatePage" );
1062cdf0e10cSrcweir 	OWizardPage* pPage = (OWizardPage*)GetPage(GetCurLevel());
1063cdf0e10cSrcweir 	return pPage ? pPage->LeavePage() : sal_False;
1064cdf0e10cSrcweir }
1065cdf0e10cSrcweir // -----------------------------------------------------------------------
AddWizardPage(OWizardPage * pPage)1066cdf0e10cSrcweir void OCopyTableWizard::AddWizardPage(OWizardPage* pPage)
1067cdf0e10cSrcweir {
1068cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::AddWizardPage" );
1069cdf0e10cSrcweir 	AddPage(pPage);
1070cdf0e10cSrcweir 	++m_nPageCount;
1071cdf0e10cSrcweir }
1072cdf0e10cSrcweir // -----------------------------------------------------------------------------
insertColumn(sal_Int32 _nPos,OFieldDescription * _pField)1073cdf0e10cSrcweir void OCopyTableWizard::insertColumn(sal_Int32 _nPos,OFieldDescription* _pField)
1074cdf0e10cSrcweir {
1075cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::insertColumn" );
1076cdf0e10cSrcweir 	OSL_ENSURE(_pField,"FieldDescrioption is null!");
1077cdf0e10cSrcweir 	if ( _pField )
1078cdf0e10cSrcweir 	{
1079cdf0e10cSrcweir 		ODatabaseExport::TColumns::iterator aFind = m_vDestColumns.find(_pField->GetName());
1080cdf0e10cSrcweir 		if ( aFind != m_vDestColumns.end() )
1081cdf0e10cSrcweir 		{
1082cdf0e10cSrcweir 			delete aFind->second;
1083cdf0e10cSrcweir 			m_vDestColumns.erase(aFind);
1084cdf0e10cSrcweir 		}
1085cdf0e10cSrcweir 
1086cdf0e10cSrcweir 		m_aDestVec.insert(m_aDestVec.begin() + _nPos,
1087cdf0e10cSrcweir 			m_vDestColumns.insert(ODatabaseExport::TColumns::value_type(_pField->GetName(),_pField)).first);
1088cdf0e10cSrcweir         m_mNameMapping[_pField->GetName()] = _pField->GetName();
1089cdf0e10cSrcweir 	}
1090cdf0e10cSrcweir }
1091cdf0e10cSrcweir // -----------------------------------------------------------------------------
replaceColumn(sal_Int32 _nPos,OFieldDescription * _pField,const::rtl::OUString & _sOldName)1092cdf0e10cSrcweir void OCopyTableWizard::replaceColumn(sal_Int32 _nPos,OFieldDescription* _pField,const ::rtl::OUString& _sOldName)
1093cdf0e10cSrcweir {
1094cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::replaceColumn" );
1095cdf0e10cSrcweir 	OSL_ENSURE(_pField,"FieldDescrioption is null!");
1096cdf0e10cSrcweir 	if ( _pField )
1097cdf0e10cSrcweir 	{
1098cdf0e10cSrcweir 		m_vDestColumns.erase(_sOldName);
1099cdf0e10cSrcweir 		OSL_ENSURE( m_vDestColumns.find(_pField->GetName()) == m_vDestColumns.end(),"Column with that name already exist!");
1100cdf0e10cSrcweir 
1101cdf0e10cSrcweir 		m_aDestVec[_nPos] =
1102cdf0e10cSrcweir 			m_vDestColumns.insert(ODatabaseExport::TColumns::value_type(_pField->GetName(),_pField)).first;
1103cdf0e10cSrcweir 	}
1104cdf0e10cSrcweir }
1105cdf0e10cSrcweir // -----------------------------------------------------------------------------
impl_loadSourceData()1106cdf0e10cSrcweir void OCopyTableWizard::impl_loadSourceData()
1107cdf0e10cSrcweir {
1108cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::impl_loadSourceData" );
1109cdf0e10cSrcweir     loadData( m_rSourceObject, m_vSourceColumns, m_vSourceVec );
1110cdf0e10cSrcweir }
1111cdf0e10cSrcweir 
1112cdf0e10cSrcweir // -----------------------------------------------------------------------------
loadData(const ICopyTableSourceObject & _rSourceObject,ODatabaseExport::TColumns & _rColumns,ODatabaseExport::TColumnVector & _rColVector)1113cdf0e10cSrcweir void OCopyTableWizard::loadData(  const ICopyTableSourceObject& _rSourceObject, ODatabaseExport::TColumns& _rColumns, ODatabaseExport::TColumnVector& _rColVector )
1114cdf0e10cSrcweir {
1115cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::loadData" );
1116cdf0e10cSrcweir     ODatabaseExport::TColumns::iterator colEnd = _rColumns.end();
1117cdf0e10cSrcweir 	for ( ODatabaseExport::TColumns::iterator col = _rColumns.begin(); col != colEnd; ++col )
1118cdf0e10cSrcweir 		delete col->second;
1119cdf0e10cSrcweir 
1120cdf0e10cSrcweir 	_rColVector.clear();
1121cdf0e10cSrcweir 	_rColumns.clear();
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir 	OFieldDescription* pActFieldDescr = NULL;
1124cdf0e10cSrcweir 	String aType;
1125cdf0e10cSrcweir 	::rtl::OUString sCreateParam(RTL_CONSTASCII_USTRINGPARAM("x"));
1126cdf0e10cSrcweir 	//////////////////////////////////////////////////////////////////////
1127cdf0e10cSrcweir 	// ReadOnly-Flag
1128cdf0e10cSrcweir 	// Bei Drop darf keine Zeile editierbar sein.
1129cdf0e10cSrcweir 	// Bei Add duerfen nur die leeren Zeilen editierbar sein.
1130cdf0e10cSrcweir 	// Bei Add und Drop koennen alle Zeilen editiert werden.
1131cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aColumns( _rSourceObject.getColumnNames() );
1132cdf0e10cSrcweir 	const ::rtl::OUString* pColumn      = aColumns.getConstArray();
1133cdf0e10cSrcweir 	const ::rtl::OUString* pColumnEnd   = pColumn + aColumns.getLength();
1134cdf0e10cSrcweir 
1135cdf0e10cSrcweir 	for ( ; pColumn != pColumnEnd; ++pColumn )
1136cdf0e10cSrcweir 	{
1137cdf0e10cSrcweir 		// get the properties of the column
1138cdf0e10cSrcweir 		pActFieldDescr = _rSourceObject.createFieldDescription( *pColumn );
1139cdf0e10cSrcweir         OSL_ENSURE( pActFieldDescr, "OCopyTableWizard::loadData: illegal field description!" );
1140cdf0e10cSrcweir         if ( !pActFieldDescr )
1141cdf0e10cSrcweir             continue;
1142cdf0e10cSrcweir 
1143cdf0e10cSrcweir 		sal_Int32 nType			  = pActFieldDescr->GetType();
1144cdf0e10cSrcweir 		sal_Int32 nScale		  = pActFieldDescr->GetScale();
1145cdf0e10cSrcweir 		sal_Int32 nPrecision	  = pActFieldDescr->GetPrecision();
1146cdf0e10cSrcweir 		sal_Bool bAutoIncrement   = pActFieldDescr->IsAutoIncrement();
1147cdf0e10cSrcweir 		::rtl::OUString sTypeName = pActFieldDescr->GetTypeName();
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir 		// search for type
1150cdf0e10cSrcweir 		sal_Bool bForce;
1151cdf0e10cSrcweir 		TOTypeInfoSP pTypeInfo = ::dbaui::getTypeInfoFromType(m_aTypeInfo,nType,sTypeName,sCreateParam,nPrecision,nScale,bAutoIncrement,bForce);
1152cdf0e10cSrcweir 		if ( !pTypeInfo.get() )
1153cdf0e10cSrcweir 			pTypeInfo = m_pTypeInfo;
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir 		pActFieldDescr->FillFromTypeInfo(pTypeInfo,sal_True,sal_False);
1156cdf0e10cSrcweir 		_rColVector.push_back(_rColumns.insert(ODatabaseExport::TColumns::value_type(pActFieldDescr->GetName(),pActFieldDescr)).first);
1157cdf0e10cSrcweir 	}
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir     // determine which coumns belong to the primary key
1160cdf0e10cSrcweir     Sequence< ::rtl::OUString > aPrimaryKeyColumns( _rSourceObject.getPrimaryKeyColumnNames() );
1161cdf0e10cSrcweir     const ::rtl::OUString* pKeyColName  = aPrimaryKeyColumns.getConstArray();
1162cdf0e10cSrcweir     const ::rtl::OUString* pKeyColEnd   = pKeyColName + aPrimaryKeyColumns.getLength();
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir     for( ; pKeyColName != pKeyColEnd; ++pKeyColName )
1165cdf0e10cSrcweir     {
1166cdf0e10cSrcweir         ODatabaseExport::TColumns::iterator keyPos = _rColumns.find( *pKeyColName );
1167cdf0e10cSrcweir         if ( keyPos != _rColumns.end() )
1168cdf0e10cSrcweir         {
1169cdf0e10cSrcweir             keyPos->second->SetPrimaryKey( sal_True );
1170cdf0e10cSrcweir             keyPos->second->SetIsNullable( ColumnValue::NO_NULLS );
1171cdf0e10cSrcweir         }
1172cdf0e10cSrcweir     }
1173cdf0e10cSrcweir }
1174cdf0e10cSrcweir // -----------------------------------------------------------------------------
clearDestColumns()1175cdf0e10cSrcweir void OCopyTableWizard::clearDestColumns()
1176cdf0e10cSrcweir {
1177cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::clearDestColumns" );
1178cdf0e10cSrcweir 	clearColumns(m_vDestColumns,m_aDestVec);
1179cdf0e10cSrcweir     m_bAddPKFirstTime = sal_True;
1180cdf0e10cSrcweir     m_mNameMapping.clear();
1181cdf0e10cSrcweir }
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir // -----------------------------------------------------------------------------
appendColumns(Reference<XColumnsSupplier> & _rxColSup,const ODatabaseExport::TColumnVector * _pVec,sal_Bool _bKeyColumns) const1184cdf0e10cSrcweir void OCopyTableWizard::appendColumns( Reference<XColumnsSupplier>& _rxColSup, const ODatabaseExport::TColumnVector* _pVec, sal_Bool _bKeyColumns) const
1185cdf0e10cSrcweir {
1186cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::appendColumns" );
1187cdf0e10cSrcweir 	// now append the columns
1188cdf0e10cSrcweir 	OSL_ENSURE(_rxColSup.is(),"No columns supplier");
1189cdf0e10cSrcweir 	if(!_rxColSup.is())
1190cdf0e10cSrcweir 		return;
1191cdf0e10cSrcweir 	Reference<XNameAccess> xColumns = _rxColSup->getColumns();
1192cdf0e10cSrcweir 	OSL_ENSURE(xColumns.is(),"No columns");
1193cdf0e10cSrcweir 	Reference<XDataDescriptorFactory> xColumnFactory(xColumns,UNO_QUERY);
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir 	Reference<XAppend> xAppend(xColumns,UNO_QUERY);
1196cdf0e10cSrcweir 	OSL_ENSURE(xAppend.is(),"No XAppend Interface!");
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir 	ODatabaseExport::TColumnVector::const_iterator aIter = _pVec->begin();
1199cdf0e10cSrcweir     ODatabaseExport::TColumnVector::const_iterator aEnd = _pVec->end();
1200cdf0e10cSrcweir 	for(;aIter != aEnd;++aIter)
1201cdf0e10cSrcweir 	{
1202cdf0e10cSrcweir 		OFieldDescription* pField = (*aIter)->second;
1203cdf0e10cSrcweir 		if(!pField)
1204cdf0e10cSrcweir 			continue;
1205cdf0e10cSrcweir 
1206cdf0e10cSrcweir 		Reference<XPropertySet> xColumn;
1207cdf0e10cSrcweir 		if(pField->IsPrimaryKey() || !_bKeyColumns)
1208cdf0e10cSrcweir 			xColumn = xColumnFactory->createDataDescriptor();
1209cdf0e10cSrcweir 		if(xColumn.is())
1210cdf0e10cSrcweir 		{
1211cdf0e10cSrcweir 			if(!_bKeyColumns)
1212cdf0e10cSrcweir 				dbaui::setColumnProperties(xColumn,pField);
1213cdf0e10cSrcweir 			else
1214cdf0e10cSrcweir 				xColumn->setPropertyValue(PROPERTY_NAME,makeAny(pField->GetName()));
1215cdf0e10cSrcweir 
1216cdf0e10cSrcweir 			xAppend->appendByDescriptor(xColumn);
1217cdf0e10cSrcweir 			xColumn = NULL;
1218cdf0e10cSrcweir 			// now only the settings are missing
1219cdf0e10cSrcweir 			if(xColumns->hasByName(pField->GetName()))
1220cdf0e10cSrcweir 			{
1221cdf0e10cSrcweir                 xColumn.set(xColumns->getByName(pField->GetName()),UNO_QUERY);
1222cdf0e10cSrcweir                 OSL_ENSURE(xColumn.is(),"OCopyTableWizard::appendColumns: Column is NULL!");
1223cdf0e10cSrcweir 				if ( xColumn.is() )
1224cdf0e10cSrcweir 					pField->copyColumnSettingsTo(xColumn);
1225cdf0e10cSrcweir 			}
1226cdf0e10cSrcweir 			else
1227cdf0e10cSrcweir 			{
1228cdf0e10cSrcweir 				OSL_ENSURE(sal_False, "OCopyTableWizard::appendColumns: invalid field name!");
1229cdf0e10cSrcweir 			}
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir 		}
1232cdf0e10cSrcweir 	}
1233cdf0e10cSrcweir }
1234cdf0e10cSrcweir // -----------------------------------------------------------------------------
appendKey(Reference<XKeysSupplier> & _rxSup,const ODatabaseExport::TColumnVector * _pVec) const1235cdf0e10cSrcweir void OCopyTableWizard::appendKey( Reference<XKeysSupplier>& _rxSup, const ODatabaseExport::TColumnVector* _pVec) const
1236cdf0e10cSrcweir {
1237cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::appendKey" );
1238cdf0e10cSrcweir 	if(!_rxSup.is())
1239cdf0e10cSrcweir 		return; // the database doesn't support keys
1240cdf0e10cSrcweir 	OSL_ENSURE(_rxSup.is(),"No XKeysSupplier!");
1241cdf0e10cSrcweir 	Reference<XDataDescriptorFactory> xKeyFactory(_rxSup->getKeys(),UNO_QUERY);
1242cdf0e10cSrcweir 	OSL_ENSURE(xKeyFactory.is(),"No XDataDescriptorFactory Interface!");
1243cdf0e10cSrcweir 	if ( !xKeyFactory.is() )
1244cdf0e10cSrcweir 		return;
1245cdf0e10cSrcweir 	Reference<XAppend> xAppend(xKeyFactory,UNO_QUERY);
1246cdf0e10cSrcweir 	OSL_ENSURE(xAppend.is(),"No XAppend Interface!");
1247cdf0e10cSrcweir 
1248cdf0e10cSrcweir 	Reference<XPropertySet> xKey = xKeyFactory->createDataDescriptor();
1249cdf0e10cSrcweir 	OSL_ENSURE(xKey.is(),"Key is null!");
1250cdf0e10cSrcweir 	xKey->setPropertyValue(PROPERTY_TYPE,makeAny(KeyType::PRIMARY));
1251cdf0e10cSrcweir 
1252cdf0e10cSrcweir 	Reference<XColumnsSupplier> xColSup(xKey,UNO_QUERY);
1253cdf0e10cSrcweir 	if(xColSup.is())
1254cdf0e10cSrcweir 	{
1255cdf0e10cSrcweir 		appendColumns(xColSup,_pVec,sal_True);
1256cdf0e10cSrcweir 		Reference<XNameAccess> xColumns = xColSup->getColumns();
1257cdf0e10cSrcweir 		if(xColumns.is() && xColumns->getElementNames().getLength())
1258cdf0e10cSrcweir 			xAppend->appendByDescriptor(xKey);
1259cdf0e10cSrcweir 	}
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir }
1262cdf0e10cSrcweir // -----------------------------------------------------------------------------
createView() const1263cdf0e10cSrcweir Reference< XPropertySet > OCopyTableWizard::createView() const
1264cdf0e10cSrcweir {
1265cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::createView" );
1266cdf0e10cSrcweir     ::rtl::OUString sCommand( m_rSourceObject.getSelectStatement() );
1267cdf0e10cSrcweir     OSL_ENSURE( sCommand.getLength(), "OCopyTableWizard::createView: no statement in the source object!" );
1268cdf0e10cSrcweir         // there are legitimate cases in which getSelectStatement does not provide a statement,
1269cdf0e10cSrcweir         // but in all those cases, this method here should never be called.
1270cdf0e10cSrcweir     return ::dbaui::createView( m_sName, m_xDestConnection, sCommand );
1271cdf0e10cSrcweir }
1272cdf0e10cSrcweir // -----------------------------------------------------------------------------
createTable()1273cdf0e10cSrcweir Reference< XPropertySet > OCopyTableWizard::createTable()
1274cdf0e10cSrcweir {
1275cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::createTable" );
1276cdf0e10cSrcweir     Reference< XPropertySet > xTable;
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir 	Reference<XTablesSupplier> xSup( m_xDestConnection, UNO_QUERY );
1279cdf0e10cSrcweir 	Reference< XNameAccess > xTables;
1280cdf0e10cSrcweir 	if(xSup.is())
1281cdf0e10cSrcweir 		xTables = xSup->getTables();
1282cdf0e10cSrcweir 	if ( getOperation() != CopyTableOperation::AppendData )
1283cdf0e10cSrcweir 	{
1284cdf0e10cSrcweir 		Reference<XDataDescriptorFactory> xFact(xTables,UNO_QUERY);
1285cdf0e10cSrcweir 		OSL_ENSURE(xFact.is(),"No XDataDescriptorFactory available!");
1286cdf0e10cSrcweir 		if(!xFact.is())
1287cdf0e10cSrcweir 			return NULL;
1288cdf0e10cSrcweir 
1289cdf0e10cSrcweir 		xTable = xFact->createDataDescriptor();
1290cdf0e10cSrcweir 		OSL_ENSURE(xTable.is(),"Could not create a new object!");
1291cdf0e10cSrcweir 		if(!xTable.is())
1292cdf0e10cSrcweir 			return NULL;
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir 		::rtl::OUString sCatalog,sSchema,sTable;
1295cdf0e10cSrcweir         Reference< XDatabaseMetaData> xMetaData = m_xDestConnection->getMetaData();
1296cdf0e10cSrcweir 		::dbtools::qualifiedNameComponents(xMetaData,
1297cdf0e10cSrcweir 											m_sName,
1298cdf0e10cSrcweir 											sCatalog,
1299cdf0e10cSrcweir 											sSchema,
1300cdf0e10cSrcweir 											sTable,
1301cdf0e10cSrcweir 											::dbtools::eInDataManipulation);
1302cdf0e10cSrcweir 
1303cdf0e10cSrcweir         if ( !sCatalog.getLength() && xMetaData->supportsCatalogsInTableDefinitions() )
1304cdf0e10cSrcweir         {
1305cdf0e10cSrcweir             sCatalog = m_xDestConnection->getCatalog();
1306cdf0e10cSrcweir         }
1307cdf0e10cSrcweir 
1308cdf0e10cSrcweir         if ( !sSchema.getLength() && xMetaData->supportsSchemasInTableDefinitions() )
1309cdf0e10cSrcweir         {
1310cdf0e10cSrcweir             sSchema = xMetaData->getUserName();
1311cdf0e10cSrcweir         }
1312cdf0e10cSrcweir 
1313cdf0e10cSrcweir 		xTable->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(sCatalog));
1314cdf0e10cSrcweir 		xTable->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(sSchema));
1315cdf0e10cSrcweir 		xTable->setPropertyValue(PROPERTY_NAME,makeAny(sTable));
1316cdf0e10cSrcweir 
1317cdf0e10cSrcweir 		Reference< XColumnsSupplier > xSuppDestinationColumns( xTable, UNO_QUERY );
1318cdf0e10cSrcweir 		// now append the columns
1319cdf0e10cSrcweir 		const ODatabaseExport::TColumnVector* pVec = getDestVector();
1320cdf0e10cSrcweir 		appendColumns( xSuppDestinationColumns, pVec );
1321cdf0e10cSrcweir 		// now append the primary key
1322cdf0e10cSrcweir 		Reference<XKeysSupplier> xKeySup(xTable,UNO_QUERY);
1323cdf0e10cSrcweir 		appendKey(xKeySup,pVec);
1324cdf0e10cSrcweir 
1325cdf0e10cSrcweir 		Reference<XAppend> xAppend(xTables,UNO_QUERY);
1326cdf0e10cSrcweir 		if(xAppend.is())
1327cdf0e10cSrcweir 			xAppend->appendByDescriptor(xTable);
1328cdf0e10cSrcweir 
1329cdf0e10cSrcweir 		//	xTable = NULL;
1330cdf0e10cSrcweir 		// we need to reget the table because after appending it it is no longer valid
1331cdf0e10cSrcweir 		if(xTables->hasByName(m_sName))
1332cdf0e10cSrcweir 			xTables->getByName(m_sName) >>= xTable;
1333cdf0e10cSrcweir 		else
1334cdf0e10cSrcweir 		{
1335cdf0e10cSrcweir 			::rtl::OUString sComposedName(
1336cdf0e10cSrcweir                 ::dbtools::composeTableName( m_xDestConnection->getMetaData(), xTable, ::dbtools::eInDataManipulation, false, false, false ) );
1337cdf0e10cSrcweir 			if(xTables->hasByName(sComposedName))
1338cdf0e10cSrcweir 			{
1339cdf0e10cSrcweir 				xTables->getByName(sComposedName) >>= xTable;
1340cdf0e10cSrcweir 				m_sName = sComposedName;
1341cdf0e10cSrcweir 			}
1342cdf0e10cSrcweir 			else
1343cdf0e10cSrcweir 				xTable = NULL;
1344cdf0e10cSrcweir 		}
1345cdf0e10cSrcweir 		if(xTable.is())
1346cdf0e10cSrcweir 		{
1347cdf0e10cSrcweir             xSuppDestinationColumns.set( xTable, UNO_QUERY_THROW );
1348cdf0e10cSrcweir 			// insert new table name into table filter
1349cdf0e10cSrcweir 			::dbaui::appendToFilter( m_xDestConnection, m_sName, GetFactory(), this );
1350cdf0e10cSrcweir 
1351cdf0e10cSrcweir             // copy ui settings
1352cdf0e10cSrcweir             m_rSourceObject.copyUISettingsTo( xTable );
1353cdf0e10cSrcweir             //copy filter and sorting
1354cdf0e10cSrcweir             m_rSourceObject.copyFilterAndSortingTo(m_xDestConnection,xTable);
1355cdf0e10cSrcweir 			// set column mappings
1356cdf0e10cSrcweir 			Reference<XNameAccess> xNameAccess = xSuppDestinationColumns->getColumns();
1357cdf0e10cSrcweir 			Sequence< ::rtl::OUString> aSeq = xNameAccess->getElementNames();
1358cdf0e10cSrcweir 			const ::rtl::OUString* pIter = aSeq.getConstArray();
1359cdf0e10cSrcweir 			const ::rtl::OUString* pEnd	  = pIter + aSeq.getLength();
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir 			::std::vector<int> aAlreadyFound(m_vColumnPos.size(),0);
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir 			for(sal_Int32 nNewPos=1;pIter != pEnd;++pIter,++nNewPos)
1364cdf0e10cSrcweir 			{
1365cdf0e10cSrcweir 				ODatabaseExport::TColumns::const_iterator aDestIter = m_vDestColumns.find(*pIter);
1366cdf0e10cSrcweir 
1367cdf0e10cSrcweir 				if ( aDestIter != m_vDestColumns.end() )
1368cdf0e10cSrcweir 				{
1369cdf0e10cSrcweir 					ODatabaseExport::TColumnVector::const_iterator aFind = ::std::find(m_aDestVec.begin(),m_aDestVec.end(),aDestIter);
1370cdf0e10cSrcweir 					sal_Int32 nPos = (aFind - m_aDestVec.begin())+1;
1371cdf0e10cSrcweir 
1372cdf0e10cSrcweir 					ODatabaseExport::TPositions::iterator aPosFind = ::std::find_if(
1373cdf0e10cSrcweir                         m_vColumnPos.begin(),
1374cdf0e10cSrcweir                         m_vColumnPos.end(),
1375cdf0e10cSrcweir 						::std::compose1(    ::std::bind2nd( ::std::equal_to< sal_Int32 >(), nPos ),
1376cdf0e10cSrcweir                                             ::std::select1st< ODatabaseExport::TPositions::value_type >()
1377cdf0e10cSrcweir                         )
1378cdf0e10cSrcweir                     );
1379cdf0e10cSrcweir 
1380cdf0e10cSrcweir 					if ( m_vColumnPos.end() != aPosFind )
1381cdf0e10cSrcweir 					{
1382cdf0e10cSrcweir 						aPosFind->second = nNewPos;
1383cdf0e10cSrcweir 						OSL_ENSURE( m_vColumnTypes.size() > size_t( aPosFind - m_vColumnPos.begin() ),
1384cdf0e10cSrcweir                             "Invalid index for vector!" );
1385cdf0e10cSrcweir 						m_vColumnTypes[ aPosFind - m_vColumnPos.begin() ] = (*aFind)->second->GetType();
1386cdf0e10cSrcweir 					}
1387cdf0e10cSrcweir 				}
1388cdf0e10cSrcweir 			}
1389cdf0e10cSrcweir 		}
1390cdf0e10cSrcweir 	}
1391cdf0e10cSrcweir 	else if(xTables.is() && xTables->hasByName(m_sName))
1392cdf0e10cSrcweir 		xTables->getByName(m_sName) >>= xTable;
1393cdf0e10cSrcweir 
1394cdf0e10cSrcweir 	return xTable;
1395cdf0e10cSrcweir }
1396cdf0e10cSrcweir 
1397cdf0e10cSrcweir // -----------------------------------------------------------------------------
supportsPrimaryKey(const Reference<XConnection> & _rxConnection)1398cdf0e10cSrcweir bool OCopyTableWizard::supportsPrimaryKey( const Reference< XConnection >& _rxConnection )
1399cdf0e10cSrcweir {
1400cdf0e10cSrcweir     OSL_PRECOND( _rxConnection.is(), "OCopyTableWizard::supportsPrimaryKey: invalid connection!" );
1401cdf0e10cSrcweir 	if ( !_rxConnection.is() )
1402cdf0e10cSrcweir         return false;
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir     ::dbtools::DatabaseMetaData aMetaData( _rxConnection );
1405cdf0e10cSrcweir     return aMetaData.supportsPrimaryKeys();
1406cdf0e10cSrcweir }
1407cdf0e10cSrcweir 
1408cdf0e10cSrcweir // -----------------------------------------------------------------------------
supportsViews(const Reference<XConnection> & _rxConnection)1409cdf0e10cSrcweir bool OCopyTableWizard::supportsViews( const Reference< XConnection >& _rxConnection )
1410cdf0e10cSrcweir {
1411cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::supportsViews" );
1412cdf0e10cSrcweir     OSL_PRECOND( _rxConnection.is(), "OCopyTableWizard::supportsViews: invalid connection!" );
1413cdf0e10cSrcweir     if ( !_rxConnection.is() )
1414cdf0e10cSrcweir         return false;
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir     bool bSupportsViews( false );
1417cdf0e10cSrcweir     try
1418cdf0e10cSrcweir     {
1419cdf0e10cSrcweir         Reference< XDatabaseMetaData > xMetaData( _rxConnection->getMetaData(), UNO_SET_THROW );
1420cdf0e10cSrcweir 	    Reference< XViewsSupplier > xViewSups( _rxConnection, UNO_QUERY );
1421cdf0e10cSrcweir         bSupportsViews = xViewSups.is();
1422cdf0e10cSrcweir 	    if ( !bSupportsViews )
1423cdf0e10cSrcweir 	    {
1424cdf0e10cSrcweir 		    try
1425cdf0e10cSrcweir 		    {
1426cdf0e10cSrcweir 			    Reference< XResultSet > xRs( xMetaData->getTableTypes(), UNO_SET_THROW );
1427cdf0e10cSrcweir                 Reference< XRow > xRow( xRs, UNO_QUERY_THROW );
1428cdf0e10cSrcweir 				while ( xRs->next() )
1429cdf0e10cSrcweir 				{
1430cdf0e10cSrcweir 					::rtl::OUString sValue = xRow->getString( 1 );
1431cdf0e10cSrcweir 					if ( !xRow->wasNull() && sValue.equalsIgnoreAsciiCaseAscii( "View" ) )
1432cdf0e10cSrcweir 					{
1433cdf0e10cSrcweir 						bSupportsViews = true;
1434cdf0e10cSrcweir 						break;
1435cdf0e10cSrcweir 					}
1436cdf0e10cSrcweir 				}
1437cdf0e10cSrcweir 		    }
1438cdf0e10cSrcweir 		    catch( const SQLException& )
1439cdf0e10cSrcweir 		    {
1440cdf0e10cSrcweir                 DBG_UNHANDLED_EXCEPTION();
1441cdf0e10cSrcweir 		    }
1442cdf0e10cSrcweir 	    }
1443cdf0e10cSrcweir     }
1444cdf0e10cSrcweir     catch( const Exception& )
1445cdf0e10cSrcweir     {
1446cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
1447cdf0e10cSrcweir     }
1448cdf0e10cSrcweir     return bSupportsViews;
1449cdf0e10cSrcweir }
1450cdf0e10cSrcweir 
1451cdf0e10cSrcweir // -----------------------------------------------------------------------------
getMaxColumnNameLength() const1452cdf0e10cSrcweir sal_Int32 OCopyTableWizard::getMaxColumnNameLength() const
1453cdf0e10cSrcweir {
1454cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::getMaxColumnNameLength" );
1455cdf0e10cSrcweir 	sal_Int32 nLen = 0;
1456cdf0e10cSrcweir 	if ( m_xDestConnection.is() )
1457cdf0e10cSrcweir 	{
1458cdf0e10cSrcweir 		try
1459cdf0e10cSrcweir 		{
1460cdf0e10cSrcweir 			Reference< XDatabaseMetaData > xMetaData( m_xDestConnection->getMetaData(), UNO_SET_THROW );
1461cdf0e10cSrcweir 			nLen = xMetaData->getMaxColumnNameLength();
1462cdf0e10cSrcweir 		}
1463cdf0e10cSrcweir 		catch(const Exception&)
1464cdf0e10cSrcweir 		{
1465cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
1466cdf0e10cSrcweir 		}
1467cdf0e10cSrcweir 	}
1468cdf0e10cSrcweir 	return nLen;
1469cdf0e10cSrcweir }
1470cdf0e10cSrcweir // -----------------------------------------------------------------------------
setOperation(const sal_Int16 _nOperation)1471cdf0e10cSrcweir void OCopyTableWizard::setOperation( const sal_Int16 _nOperation )
1472cdf0e10cSrcweir {
1473cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::setOperation" );
1474cdf0e10cSrcweir 	m_nOperation = _nOperation;
1475cdf0e10cSrcweir }
1476cdf0e10cSrcweir // -----------------------------------------------------------------------------
getOperation() const1477cdf0e10cSrcweir sal_Int16 OCopyTableWizard::getOperation() const
1478cdf0e10cSrcweir {
1479cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::getOperation" );
1480cdf0e10cSrcweir 	return m_nOperation;
1481cdf0e10cSrcweir }
1482cdf0e10cSrcweir // -----------------------------------------------------------------------------
convertColumnName(const TColumnFindFunctor & _rCmpFunctor,const::rtl::OUString & _sColumnName,const::rtl::OUString & _sExtraChars,sal_Int32 _nMaxNameLen)1483cdf0e10cSrcweir ::rtl::OUString OCopyTableWizard::convertColumnName(const TColumnFindFunctor&	_rCmpFunctor,
1484cdf0e10cSrcweir 													const ::rtl::OUString&	_sColumnName,
1485cdf0e10cSrcweir 													const ::rtl::OUString&	_sExtraChars,
1486cdf0e10cSrcweir 													sal_Int32				_nMaxNameLen)
1487cdf0e10cSrcweir {
1488cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::convertColumnName" );
1489cdf0e10cSrcweir 	::rtl::OUString sAlias = _sColumnName;
1490cdf0e10cSrcweir 	if ( isSQL92CheckEnabled( m_xDestConnection ) )
1491cdf0e10cSrcweir 		sAlias = ::dbtools::convertName2SQLName(_sColumnName,_sExtraChars);
1492cdf0e10cSrcweir 	if((_nMaxNameLen && sAlias.getLength() > _nMaxNameLen) || _rCmpFunctor(sAlias))
1493cdf0e10cSrcweir 	{
1494cdf0e10cSrcweir 		sal_Int32 nDiff = 1;
1495cdf0e10cSrcweir 		do
1496cdf0e10cSrcweir 		{
1497cdf0e10cSrcweir 			++nDiff;
1498cdf0e10cSrcweir 			if(_nMaxNameLen && sAlias.getLength() >= _nMaxNameLen)
1499cdf0e10cSrcweir 				sAlias = sAlias.copy(0,sAlias.getLength() - (sAlias.getLength()-_nMaxNameLen+nDiff));
1500cdf0e10cSrcweir 
1501cdf0e10cSrcweir 			::rtl::OUString sName(sAlias);
1502cdf0e10cSrcweir 			sal_Int32 nPos = 1;
1503cdf0e10cSrcweir 			sName += ::rtl::OUString::valueOf(nPos);
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir 			while(_rCmpFunctor(sName))
1506cdf0e10cSrcweir 			{
1507cdf0e10cSrcweir 				sName = sAlias;
1508cdf0e10cSrcweir 				sName += ::rtl::OUString::valueOf(++nPos);
1509cdf0e10cSrcweir 			}
1510cdf0e10cSrcweir 			sAlias = sName;
1511cdf0e10cSrcweir 			// we have to check again, it could happen that the name is already to long
1512cdf0e10cSrcweir 		}
1513cdf0e10cSrcweir 		while(_nMaxNameLen && sAlias.getLength() > _nMaxNameLen);
1514cdf0e10cSrcweir 	}
1515cdf0e10cSrcweir 	OSL_ENSURE(m_mNameMapping.find(_sColumnName) == m_mNameMapping.end(),"name doubled!");
1516cdf0e10cSrcweir 	m_mNameMapping[_sColumnName] = sAlias;
1517cdf0e10cSrcweir 	return sAlias;
1518cdf0e10cSrcweir }
1519cdf0e10cSrcweir 
1520cdf0e10cSrcweir // -----------------------------------------------------------------------------
removeColumnNameFromNameMap(const::rtl::OUString & _sName)1521cdf0e10cSrcweir void OCopyTableWizard::removeColumnNameFromNameMap(const ::rtl::OUString& _sName)
1522cdf0e10cSrcweir {
1523cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::removeColumnNameFromNameMap" );
1524cdf0e10cSrcweir     m_mNameMapping.erase(_sName);
1525cdf0e10cSrcweir }
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir // -----------------------------------------------------------------------------
supportsType(sal_Int32 _nDataType,sal_Int32 & _rNewDataType)1528cdf0e10cSrcweir sal_Bool OCopyTableWizard::supportsType(sal_Int32 _nDataType,sal_Int32& _rNewDataType)
1529cdf0e10cSrcweir {
1530cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::supportsType" );
1531cdf0e10cSrcweir 	sal_Bool bRet = m_aDestTypeInfo.find(_nDataType) != m_aDestTypeInfo.end();
1532cdf0e10cSrcweir 	if ( bRet )
1533cdf0e10cSrcweir 		_rNewDataType = _nDataType;
1534cdf0e10cSrcweir 	return bRet;
1535cdf0e10cSrcweir }
1536cdf0e10cSrcweir 
1537cdf0e10cSrcweir // -----------------------------------------------------------------------------
convertType(const TOTypeInfoSP & _pType,sal_Bool & _bNotConvert)1538cdf0e10cSrcweir TOTypeInfoSP OCopyTableWizard::convertType(const TOTypeInfoSP& _pType,sal_Bool& _bNotConvert)
1539cdf0e10cSrcweir {
1540cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::convertType" );
1541cdf0e10cSrcweir 	if ( !m_bInterConnectionCopy )
1542cdf0e10cSrcweir         // no need to convert if the source and destination connection are the same
1543cdf0e10cSrcweir 		return _pType;
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir 	sal_Bool bForce;
1546cdf0e10cSrcweir 	TOTypeInfoSP pType = ::dbaui::getTypeInfoFromType(m_aDestTypeInfo,_pType->nType,_pType->aTypeName,_pType->aCreateParams,_pType->nPrecision,_pType->nMaximumScale,_pType->bAutoIncrement,bForce);
1547cdf0e10cSrcweir 	if ( !pType.get() || bForce )
1548cdf0e10cSrcweir 	{ // no type found so we have to find the correct one ourself
1549cdf0e10cSrcweir 		sal_Int32 nDefaultType = DataType::VARCHAR;
1550cdf0e10cSrcweir 		switch(_pType->nType)
1551cdf0e10cSrcweir 		{
1552cdf0e10cSrcweir 			case DataType::TINYINT:
1553cdf0e10cSrcweir 				if(supportsType(DataType::SMALLINT,nDefaultType))
1554cdf0e10cSrcweir 					break;
1555cdf0e10cSrcweir 				// run through
1556cdf0e10cSrcweir 			case DataType::SMALLINT:
1557cdf0e10cSrcweir 				if(supportsType(DataType::INTEGER,nDefaultType))
1558cdf0e10cSrcweir 					break;
1559cdf0e10cSrcweir 				// run through
1560cdf0e10cSrcweir 			case DataType::INTEGER:
1561cdf0e10cSrcweir 				if(supportsType(DataType::FLOAT,nDefaultType))
1562cdf0e10cSrcweir 					break;
1563cdf0e10cSrcweir 				// run through
1564cdf0e10cSrcweir 			case DataType::FLOAT:
1565cdf0e10cSrcweir 				if(supportsType(DataType::REAL,nDefaultType))
1566cdf0e10cSrcweir 					break;
1567cdf0e10cSrcweir 				// run through
1568cdf0e10cSrcweir 			case DataType::DATE:
1569cdf0e10cSrcweir 			case DataType::TIME:
1570cdf0e10cSrcweir 				if( DataType::DATE == _pType->nType || DataType::TIME == _pType->nType )
1571cdf0e10cSrcweir 				{
1572cdf0e10cSrcweir 					if(supportsType(DataType::TIMESTAMP,nDefaultType))
1573cdf0e10cSrcweir 						break;
1574cdf0e10cSrcweir 				}
1575cdf0e10cSrcweir 				// run through
1576cdf0e10cSrcweir 			case DataType::TIMESTAMP:
1577cdf0e10cSrcweir 			case DataType::REAL:
1578cdf0e10cSrcweir 			case DataType::BIGINT:
1579cdf0e10cSrcweir 				if ( supportsType(DataType::DOUBLE,nDefaultType) )
1580cdf0e10cSrcweir 					break;
1581cdf0e10cSrcweir 				// run through
1582cdf0e10cSrcweir 			case DataType::DOUBLE:
1583cdf0e10cSrcweir 				if ( supportsType(DataType::NUMERIC,nDefaultType) )
1584cdf0e10cSrcweir 					break;
1585cdf0e10cSrcweir 				// run through
1586cdf0e10cSrcweir 			case DataType::NUMERIC:
1587cdf0e10cSrcweir 				supportsType(DataType::DECIMAL,nDefaultType);
1588cdf0e10cSrcweir 				break;
1589cdf0e10cSrcweir 			case DataType::DECIMAL:
1590cdf0e10cSrcweir 				if ( supportsType(DataType::NUMERIC,nDefaultType) )
1591cdf0e10cSrcweir 					break;
1592cdf0e10cSrcweir 				if ( supportsType(DataType::DOUBLE,nDefaultType) )
1593cdf0e10cSrcweir 					break;
1594cdf0e10cSrcweir 				break;
1595cdf0e10cSrcweir 			case DataType::VARCHAR:
1596cdf0e10cSrcweir 				if ( supportsType(DataType::LONGVARCHAR,nDefaultType) )
1597cdf0e10cSrcweir 					break;
1598cdf0e10cSrcweir 				break;
1599cdf0e10cSrcweir 			case DataType::LONGVARCHAR:
1600cdf0e10cSrcweir 				if ( supportsType(DataType::CLOB,nDefaultType) )
1601cdf0e10cSrcweir 					break;
1602cdf0e10cSrcweir 				break;
1603cdf0e10cSrcweir             case DataType::BINARY:
1604cdf0e10cSrcweir 				if ( supportsType(DataType::VARBINARY,nDefaultType) )
1605cdf0e10cSrcweir 					break;
1606cdf0e10cSrcweir 				break;
1607cdf0e10cSrcweir             case DataType::VARBINARY:
1608cdf0e10cSrcweir 				if ( supportsType(DataType::LONGVARBINARY,nDefaultType) )
1609cdf0e10cSrcweir 					break;
1610cdf0e10cSrcweir 				break;
1611cdf0e10cSrcweir             case DataType::LONGVARBINARY:
1612cdf0e10cSrcweir 				if ( supportsType(DataType::BLOB,nDefaultType) )
1613cdf0e10cSrcweir 					break;
1614cdf0e10cSrcweir                 if ( supportsType(DataType::LONGVARCHAR,nDefaultType) )
1615cdf0e10cSrcweir 					break;
1616cdf0e10cSrcweir                 if ( supportsType(DataType::CLOB,nDefaultType) )
1617cdf0e10cSrcweir 					break;
1618cdf0e10cSrcweir 				break;
1619cdf0e10cSrcweir 			default:
1620cdf0e10cSrcweir 				nDefaultType = DataType::VARCHAR;
1621cdf0e10cSrcweir 		}
1622cdf0e10cSrcweir 		pType = ::dbaui::getTypeInfoFromType(m_aDestTypeInfo,nDefaultType,_pType->aTypeName,_pType->aCreateParams,_pType->nPrecision,_pType->nMaximumScale,_pType->bAutoIncrement,bForce);
1623cdf0e10cSrcweir 		if ( !pType.get() )
1624cdf0e10cSrcweir 		{
1625cdf0e10cSrcweir 			_bNotConvert = sal_False;
1626cdf0e10cSrcweir 			::rtl::OUString sCreate(RTL_CONSTASCII_USTRINGPARAM("x"));
1627cdf0e10cSrcweir 			pType = ::dbaui::getTypeInfoFromType(m_aDestTypeInfo,DataType::VARCHAR,_pType->aTypeName,sCreate,50,0,sal_False,bForce);
1628cdf0e10cSrcweir 			if ( !pType.get() )
1629cdf0e10cSrcweir 				pType = m_pTypeInfo;
1630cdf0e10cSrcweir 		}
1631cdf0e10cSrcweir 		else if ( bForce )
1632cdf0e10cSrcweir 			_bNotConvert = sal_False;
1633cdf0e10cSrcweir 	}
1634cdf0e10cSrcweir 	return pType;
1635cdf0e10cSrcweir }
1636cdf0e10cSrcweir // -----------------------------------------------------------------------------
createUniqueName(const::rtl::OUString & _sName)1637cdf0e10cSrcweir ::rtl::OUString OCopyTableWizard::createUniqueName(const ::rtl::OUString& _sName)
1638cdf0e10cSrcweir {
1639cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::createUniqueName" );
1640cdf0e10cSrcweir 	::rtl::OUString sName = _sName;
1641cdf0e10cSrcweir     Sequence< ::rtl::OUString > aColumnNames( m_rSourceObject.getColumnNames() );
1642cdf0e10cSrcweir 	if ( aColumnNames.getLength() )
1643cdf0e10cSrcweir 		sName = ::dbtools::createUniqueName( aColumnNames, sName, sal_False );
1644cdf0e10cSrcweir 	else
1645cdf0e10cSrcweir 	{
1646cdf0e10cSrcweir 		if ( m_vSourceColumns.find(sName) != m_vSourceColumns.end())
1647cdf0e10cSrcweir 		{
1648cdf0e10cSrcweir 			sal_Int32 nPos = 0;
1649cdf0e10cSrcweir 			while(m_vSourceColumns.find(sName) != m_vSourceColumns.end())
1650cdf0e10cSrcweir 			{
1651cdf0e10cSrcweir 				sName = _sName;
1652cdf0e10cSrcweir 				sName += ::rtl::OUString::valueOf(++nPos);
1653cdf0e10cSrcweir 			}
1654cdf0e10cSrcweir 		}
1655cdf0e10cSrcweir 	}
1656cdf0e10cSrcweir 	return sName;
1657cdf0e10cSrcweir }
1658cdf0e10cSrcweir // -----------------------------------------------------------------------------
showColumnTypeNotSupported(const::rtl::OUString & _rColumnName)1659cdf0e10cSrcweir void OCopyTableWizard::showColumnTypeNotSupported(const ::rtl::OUString& _rColumnName)
1660cdf0e10cSrcweir {
1661cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OCopyTableWizard::showColumnTypeNotSupported" );
1662cdf0e10cSrcweir 	String sMessage( ModuleRes( STR_UNKNOWN_TYPE_FOUND ) );
1663cdf0e10cSrcweir 	sMessage.SearchAndReplaceAscii("#1",_rColumnName);
1664cdf0e10cSrcweir     showError(sMessage);
1665cdf0e10cSrcweir }
1666cdf0e10cSrcweir //-------------------------------------------------------------------------------
showError(const::rtl::OUString & _sErrorMesage)1667cdf0e10cSrcweir void OCopyTableWizard::showError(const ::rtl::OUString& _sErrorMesage)
1668cdf0e10cSrcweir {
1669cdf0e10cSrcweir     SQLExceptionInfo aInfo(_sErrorMesage);
1670cdf0e10cSrcweir     showError(aInfo.get());
1671cdf0e10cSrcweir }
1672cdf0e10cSrcweir //-------------------------------------------------------------------------------
showError(const Any & _aError)1673cdf0e10cSrcweir void OCopyTableWizard::showError(const Any& _aError)
1674cdf0e10cSrcweir {
1675cdf0e10cSrcweir     if ( _aError.hasValue() && m_xInteractionHandler.is() )
1676cdf0e10cSrcweir     {
1677cdf0e10cSrcweir         try
1678cdf0e10cSrcweir         {
1679cdf0e10cSrcweir             ::rtl::Reference< ::comphelper::OInteractionRequest > xRequest( new ::comphelper::OInteractionRequest( _aError ) );
1680cdf0e10cSrcweir             m_xInteractionHandler->handle( xRequest.get() );
1681cdf0e10cSrcweir         }
1682cdf0e10cSrcweir         catch( const Exception& )
1683cdf0e10cSrcweir         {
1684cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
1685cdf0e10cSrcweir         }
1686cdf0e10cSrcweir     }
1687cdf0e10cSrcweir }
1688cdf0e10cSrcweir 
1689