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