xref: /trunk/main/dbaccess/source/ui/misc/WCPage.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "WCPage.hxx"
32*cdf0e10cSrcweir #include "WCopyTable.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #ifndef DBACCESS_SOURCE_UI_MISC_DEFAULTOBJECTNAMECHECK_HXX
35*cdf0e10cSrcweir #include "defaultobjectnamecheck.hxx"
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
38*cdf0e10cSrcweir #include <tools/debug.hxx>
39*cdf0e10cSrcweir #endif
40*cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_
41*cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
42*cdf0e10cSrcweir #endif
43*cdf0e10cSrcweir #ifndef _DBU_MISC_HRC_
44*cdf0e10cSrcweir #include "dbu_misc.hrc"
45*cdf0e10cSrcweir #endif
46*cdf0e10cSrcweir #ifndef DBAUI_WIZARD_PAGES_HRC
47*cdf0e10cSrcweir #include "WizardPages.hrc"
48*cdf0e10cSrcweir #endif
49*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_
50*cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
51*cdf0e10cSrcweir #endif
52*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
53*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
54*cdf0e10cSrcweir #endif
55*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_
56*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
57*cdf0e10cSrcweir #endif
58*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
59*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
60*cdf0e10cSrcweir #endif
61*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
62*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
63*cdf0e10cSrcweir #endif
64*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_APPLICATION_COPYTABLEOPERATION_HPP_
65*cdf0e10cSrcweir #include <com/sun/star/sdb/application/CopyTableOperation.hpp>
66*cdf0e10cSrcweir #endif
67*cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX
68*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
69*cdf0e10cSrcweir #endif
70*cdf0e10cSrcweir #ifndef _DBHELPER_DBEXCEPTION_HXX_
71*cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
72*cdf0e10cSrcweir #endif
73*cdf0e10cSrcweir #ifndef _CONNECTIVITY_DBTOOLS_HXX_
74*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
75*cdf0e10cSrcweir #endif
76*cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
77*cdf0e10cSrcweir #include "UITools.hxx"
78*cdf0e10cSrcweir #endif
79*cdf0e10cSrcweir #ifndef _DBAUI_MODULE_DBU_HXX_
80*cdf0e10cSrcweir #include "moduledbu.hxx"
81*cdf0e10cSrcweir #endif
82*cdf0e10cSrcweir #ifndef _CPPUHELPER_EXC_HLP_HXX_
83*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
84*cdf0e10cSrcweir #endif
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir using namespace ::dbaui;
87*cdf0e10cSrcweir using namespace ::dbtools;
88*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
89*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
90*cdf0e10cSrcweir using namespace ::com::sun::star::container;
91*cdf0e10cSrcweir using namespace ::com::sun::star::util;
92*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
93*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
94*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir namespace CopyTableOperation = ::com::sun::star::sdb::application::CopyTableOperation;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir //========================================================================
99*cdf0e10cSrcweir // Klasse OCopyTable
100*cdf0e10cSrcweir //========================================================================
101*cdf0e10cSrcweir DBG_NAME(OCopyTable)
102*cdf0e10cSrcweir //------------------------------------------------------------------------
103*cdf0e10cSrcweir OCopyTable::OCopyTable( Window * pParent )
104*cdf0e10cSrcweir     :OWizardPage( pParent, ModuleRes(TAB_WIZ_COPYTABLE) )
105*cdf0e10cSrcweir     ,m_ftTableName(         this, ModuleRes( FT_TABLENAME       ) )
106*cdf0e10cSrcweir     ,m_edTableName(         this, ModuleRes( ET_TABLENAME       ) )
107*cdf0e10cSrcweir     ,m_aFL_Options(         this, ModuleRes( FL_OPTIONS         ) )
108*cdf0e10cSrcweir     ,m_aRB_DefData(         this, ModuleRes( RB_DEFDATA         ) )
109*cdf0e10cSrcweir     ,m_aRB_Def(             this, ModuleRes( RB_DEF             ) )
110*cdf0e10cSrcweir     ,m_aRB_View(            this, ModuleRes( RB_VIEW            ) )
111*cdf0e10cSrcweir     ,m_aRB_AppendData(      this, ModuleRes( RB_APPENDDATA      ) )
112*cdf0e10cSrcweir     ,m_aCB_UseHeaderLine(   this, ModuleRes( CB_USEHEADERLINE   ) )
113*cdf0e10cSrcweir     ,m_aCB_PrimaryColumn(   this, ModuleRes( CB_PRIMARY_COLUMN  ) )
114*cdf0e10cSrcweir     ,m_aFT_KeyName(         this, ModuleRes( FT_KEYNAME         ) )
115*cdf0e10cSrcweir     ,m_edKeyName(           this, ModuleRes( ET_KEYNAME         ) )
116*cdf0e10cSrcweir     ,m_pPage2(NULL)
117*cdf0e10cSrcweir     ,m_pPage3(NULL)
118*cdf0e10cSrcweir     ,m_bUseHeaderAllowed(sal_True)
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir     DBG_CTOR(OCopyTable,NULL);
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     m_edTableName.SetMaxTextLen( EDIT_NOLIMIT );
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir     if ( m_pParent->m_xDestConnection.is() )
125*cdf0e10cSrcweir     {
126*cdf0e10cSrcweir         if ( !m_pParent->supportsViews() )
127*cdf0e10cSrcweir             m_aRB_View.Disable();
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir         m_aCB_UseHeaderLine.Check(sal_True);
130*cdf0e10cSrcweir         m_bPKeyAllowed = m_pParent->supportsPrimaryKey();
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir         m_aCB_PrimaryColumn.Enable(m_bPKeyAllowed);
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir         m_aRB_AppendData.SetClickHdl(   LINK( this, OCopyTable, AppendDataClickHdl  ) );
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir         m_aRB_DefData.SetClickHdl(      LINK( this, OCopyTable, RadioChangeHdl      ) );
137*cdf0e10cSrcweir         m_aRB_Def.SetClickHdl(          LINK( this, OCopyTable, RadioChangeHdl      ) );
138*cdf0e10cSrcweir         m_aRB_View.SetClickHdl(         LINK( this, OCopyTable, RadioChangeHdl      ) );
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         m_aCB_PrimaryColumn.SetClickHdl(LINK( this, OCopyTable, KeyClickHdl         ) );
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         m_aFT_KeyName.Enable(sal_False);
143*cdf0e10cSrcweir         m_edKeyName.Enable(sal_False);
144*cdf0e10cSrcweir         ::rtl::OUString sKeyName(RTL_CONSTASCII_USTRINGPARAM("ID"));
145*cdf0e10cSrcweir         sKeyName = m_pParent->createUniqueName(sKeyName);
146*cdf0e10cSrcweir         m_edKeyName.SetText(sKeyName);
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir         sal_Int32 nMaxLen = m_pParent->getMaxColumnNameLength();
149*cdf0e10cSrcweir         m_edKeyName.SetMaxTextLen(nMaxLen ? (xub_StrLen)nMaxLen : EDIT_NOLIMIT);
150*cdf0e10cSrcweir     }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     FreeResource();
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     SetText(String(ModuleRes(STR_COPYTABLE_TITLE_COPY)));
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir //------------------------------------------------------------------------
158*cdf0e10cSrcweir OCopyTable::~OCopyTable()
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir     DBG_DTOR(OCopyTable,NULL);
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir //------------------------------------------------------------------------
163*cdf0e10cSrcweir IMPL_LINK( OCopyTable, AppendDataClickHdl, Button*, /*pButton*/ )
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir     DBG_CHKTHIS(OCopyTable,NULL);
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     SetAppendDataRadio();
168*cdf0e10cSrcweir     return 0;
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir //--------dyf ADD
171*cdf0e10cSrcweir void OCopyTable::SetAppendDataRadio()
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir     m_pParent->EnableButton(OCopyTableWizard::WIZARD_NEXT,sal_True);
174*cdf0e10cSrcweir     m_aFT_KeyName.Enable(sal_False);
175*cdf0e10cSrcweir     m_aCB_PrimaryColumn.Enable(sal_False);
176*cdf0e10cSrcweir     m_edKeyName.Enable(sal_False);
177*cdf0e10cSrcweir     m_pParent->setOperation(CopyTableOperation::AppendData);
178*cdf0e10cSrcweir }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir //--------add end
181*cdf0e10cSrcweir //------------------------------------------------------------------------
182*cdf0e10cSrcweir IMPL_LINK( OCopyTable, RadioChangeHdl, Button*, pButton )
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir     DBG_CHKTHIS(OCopyTable,NULL);
185*cdf0e10cSrcweir     m_pParent->EnableButton(OCopyTableWizard::WIZARD_NEXT,pButton != &m_aRB_View);
186*cdf0e10cSrcweir     sal_Bool bKey = m_bPKeyAllowed && pButton != &m_aRB_View;
187*cdf0e10cSrcweir     m_aFT_KeyName.Enable(bKey && m_aCB_PrimaryColumn.IsChecked());
188*cdf0e10cSrcweir     m_edKeyName.Enable(bKey && m_aCB_PrimaryColumn.IsChecked());
189*cdf0e10cSrcweir     m_aCB_PrimaryColumn.Enable(bKey);
190*cdf0e10cSrcweir     m_aCB_UseHeaderLine.Enable(m_bUseHeaderAllowed && IsOptionDefData());
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     // set typ what to do
193*cdf0e10cSrcweir     if( IsOptionDefData() )
194*cdf0e10cSrcweir         m_pParent->setOperation( CopyTableOperation::CopyDefinitionAndData );
195*cdf0e10cSrcweir     else if( IsOptionDef() )
196*cdf0e10cSrcweir         m_pParent->setOperation( CopyTableOperation::CopyDefinitionOnly );
197*cdf0e10cSrcweir     else if( IsOptionView() )
198*cdf0e10cSrcweir         m_pParent->setOperation( CopyTableOperation::CreateAsView );
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir     return 0;
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir //------------------------------------------------------------------------
203*cdf0e10cSrcweir IMPL_LINK( OCopyTable, KeyClickHdl, Button*, /*pButton*/ )
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir     DBG_CHKTHIS(OCopyTable,NULL);
206*cdf0e10cSrcweir     m_edKeyName.Enable(m_aCB_PrimaryColumn.IsChecked());
207*cdf0e10cSrcweir     m_aFT_KeyName.Enable(m_aCB_PrimaryColumn.IsChecked());
208*cdf0e10cSrcweir     return 0;
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir //------------------------------------------------------------------------
211*cdf0e10cSrcweir sal_Bool OCopyTable::LeavePage()
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir     DBG_CHKTHIS(OCopyTable,NULL);
214*cdf0e10cSrcweir     m_pParent->m_bCreatePrimaryKeyColumn    = (m_bPKeyAllowed && m_aCB_PrimaryColumn.IsEnabled()) ? m_aCB_PrimaryColumn.IsChecked() : sal_False;
215*cdf0e10cSrcweir     m_pParent->m_aKeyName                   = m_pParent->m_bCreatePrimaryKeyColumn ? m_edKeyName.GetText() : String();
216*cdf0e10cSrcweir     m_pParent->setUseHeaderLine( m_aCB_UseHeaderLine.IsChecked() );
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir     // first check if the table already exists in the database
219*cdf0e10cSrcweir     if( m_pParent->getOperation() != CopyTableOperation::AppendData )
220*cdf0e10cSrcweir     {
221*cdf0e10cSrcweir         m_pParent->clearDestColumns();
222*cdf0e10cSrcweir         DynamicTableOrQueryNameCheck aNameCheck( m_pParent->m_xDestConnection, CommandType::TABLE );
223*cdf0e10cSrcweir         SQLExceptionInfo aErrorInfo;
224*cdf0e10cSrcweir         if ( !aNameCheck.isNameValid( m_edTableName.GetText(), aErrorInfo ) )
225*cdf0e10cSrcweir         {
226*cdf0e10cSrcweir             aErrorInfo.append( SQLExceptionInfo::SQL_CONTEXT, String( ModuleRes( STR_SUGGEST_APPEND_TABLE_DATA ) ) );
227*cdf0e10cSrcweir             m_pParent->showError(aErrorInfo.get());
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir             return sal_False;
230*cdf0e10cSrcweir         }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir         // have to check the length of the table name
233*cdf0e10cSrcweir         Reference< XDatabaseMetaData > xMeta = m_pParent->m_xDestConnection->getMetaData();
234*cdf0e10cSrcweir         ::rtl::OUString sCatalog;
235*cdf0e10cSrcweir         ::rtl::OUString sSchema;
236*cdf0e10cSrcweir         ::rtl::OUString sTable;
237*cdf0e10cSrcweir         ::dbtools::qualifiedNameComponents( xMeta,
238*cdf0e10cSrcweir                                             m_edTableName.GetText(),
239*cdf0e10cSrcweir                                             sCatalog,
240*cdf0e10cSrcweir                                             sSchema,
241*cdf0e10cSrcweir                                             sTable,
242*cdf0e10cSrcweir                                             ::dbtools::eInDataManipulation);
243*cdf0e10cSrcweir         sal_Int32 nMaxLength = xMeta->getMaxTableNameLength();
244*cdf0e10cSrcweir         if ( nMaxLength && sTable.getLength() > nMaxLength )
245*cdf0e10cSrcweir         {
246*cdf0e10cSrcweir             String sError(ModuleRes(STR_INVALID_TABLE_NAME_LENGTH));
247*cdf0e10cSrcweir             m_pParent->showError(sError);
248*cdf0e10cSrcweir             return sal_False;
249*cdf0e10cSrcweir         }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir         // now we have to check if the name of the primary key already exists
252*cdf0e10cSrcweir         if (    m_pParent->m_bCreatePrimaryKeyColumn
253*cdf0e10cSrcweir             &&  m_pParent->m_aKeyName != m_pParent->createUniqueName(m_pParent->m_aKeyName) )
254*cdf0e10cSrcweir         {
255*cdf0e10cSrcweir             String aInfoString( ModuleRes(STR_WIZ_PKEY_ALREADY_DEFINED) );
256*cdf0e10cSrcweir             aInfoString += String(' ');
257*cdf0e10cSrcweir             aInfoString += String(m_pParent->m_aKeyName);
258*cdf0e10cSrcweir             m_pParent->showError(aInfoString);
259*cdf0e10cSrcweir             return sal_False;
260*cdf0e10cSrcweir         }
261*cdf0e10cSrcweir     }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir     if ( !m_edTableName.GetSavedValue().Equals(m_edTableName.GetText()) )
264*cdf0e10cSrcweir     { // table exists and name has changed
265*cdf0e10cSrcweir         if ( m_pParent->getOperation() == CopyTableOperation::AppendData )
266*cdf0e10cSrcweir         {
267*cdf0e10cSrcweir             if(!checkAppendData())
268*cdf0e10cSrcweir                 return sal_False;
269*cdf0e10cSrcweir         }
270*cdf0e10cSrcweir         else if ( m_nOldOperation == CopyTableOperation::AppendData )
271*cdf0e10cSrcweir         {
272*cdf0e10cSrcweir             m_edTableName.SaveValue();
273*cdf0e10cSrcweir             return LeavePage();
274*cdf0e10cSrcweir         }
275*cdf0e10cSrcweir     }
276*cdf0e10cSrcweir     else
277*cdf0e10cSrcweir     { // table exist and is not new or doesn't exist and so on
278*cdf0e10cSrcweir         if ( CopyTableOperation::AppendData == m_pParent->getOperation() )
279*cdf0e10cSrcweir         {
280*cdf0e10cSrcweir             if( !checkAppendData() )
281*cdf0e10cSrcweir                 return sal_False;
282*cdf0e10cSrcweir         }
283*cdf0e10cSrcweir     }
284*cdf0e10cSrcweir     m_pParent->m_sName = m_edTableName.GetText();
285*cdf0e10cSrcweir     m_edTableName.SaveValue();
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir     if(!m_pParent->m_sName.getLength())
288*cdf0e10cSrcweir     {
289*cdf0e10cSrcweir         String sError(ModuleRes(STR_INVALID_TABLE_NAME));
290*cdf0e10cSrcweir         m_pParent->showError(sError);
291*cdf0e10cSrcweir         return sal_False;
292*cdf0e10cSrcweir     }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir     return sal_True;
295*cdf0e10cSrcweir }
296*cdf0e10cSrcweir //------------------------------------------------------------------------
297*cdf0e10cSrcweir void OCopyTable::ActivatePage()
298*cdf0e10cSrcweir {
299*cdf0e10cSrcweir     DBG_CHKTHIS(OCopyTable,NULL);
300*cdf0e10cSrcweir     m_pParent->GetOKButton().Enable( sal_True );
301*cdf0e10cSrcweir     m_nOldOperation = m_pParent->getOperation();
302*cdf0e10cSrcweir     m_edTableName.GrabFocus();
303*cdf0e10cSrcweir     m_aCB_UseHeaderLine.Check(m_pParent->UseHeaderLine());
304*cdf0e10cSrcweir }
305*cdf0e10cSrcweir //------------------------------------------------------------------------
306*cdf0e10cSrcweir String OCopyTable::GetTitle() const
307*cdf0e10cSrcweir {
308*cdf0e10cSrcweir     DBG_CHKTHIS(OCopyTable,NULL);
309*cdf0e10cSrcweir     return String(ModuleRes(STR_WIZ_TABLE_COPY));
310*cdf0e10cSrcweir }
311*cdf0e10cSrcweir //------------------------------------------------------------------------
312*cdf0e10cSrcweir void OCopyTable::Reset()
313*cdf0e10cSrcweir {
314*cdf0e10cSrcweir     DBG_CHKTHIS(OCopyTable,NULL);
315*cdf0e10cSrcweir     m_bFirstTime = sal_False;
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir     m_edTableName.SetText( m_pParent->m_sName );
318*cdf0e10cSrcweir     m_edTableName.SaveValue();
319*cdf0e10cSrcweir }
320*cdf0e10cSrcweir //------------------------------------------------------------------------
321*cdf0e10cSrcweir sal_Bool OCopyTable::checkAppendData()
322*cdf0e10cSrcweir {
323*cdf0e10cSrcweir     DBG_CHKTHIS(OCopyTable,NULL);
324*cdf0e10cSrcweir     m_pParent->clearDestColumns();
325*cdf0e10cSrcweir     Reference< XPropertySet > xTable;
326*cdf0e10cSrcweir     Reference< XTablesSupplier > xSup( m_pParent->m_xDestConnection, UNO_QUERY );
327*cdf0e10cSrcweir     Reference<XNameAccess> xTables;
328*cdf0e10cSrcweir     if(xSup.is())
329*cdf0e10cSrcweir         xTables = xSup->getTables();
330*cdf0e10cSrcweir     if(xTables.is() && xTables->hasByName(m_edTableName.GetText()))
331*cdf0e10cSrcweir     {
332*cdf0e10cSrcweir         const ODatabaseExport::TColumnVector* pSrcColumns = m_pParent->getSrcVector();
333*cdf0e10cSrcweir         const sal_uInt32 nSrcSize = pSrcColumns->size();
334*cdf0e10cSrcweir         m_pParent->m_vColumnPos.resize( nSrcSize, ODatabaseExport::TPositions::value_type( COLUMN_POSITION_NOT_FOUND, COLUMN_POSITION_NOT_FOUND ) );
335*cdf0e10cSrcweir         m_pParent->m_vColumnTypes.resize( nSrcSize , COLUMN_POSITION_NOT_FOUND );
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir         // set new destination
338*cdf0e10cSrcweir         xTables->getByName( m_edTableName.GetText() ) >>= xTable;
339*cdf0e10cSrcweir         ObjectCopySource aTableCopySource( m_pParent->m_xDestConnection, xTable );
340*cdf0e10cSrcweir         m_pParent->loadData( aTableCopySource, m_pParent->m_vDestColumns, m_pParent->m_aDestVec );
341*cdf0e10cSrcweir         // #90027#
342*cdf0e10cSrcweir         const ODatabaseExport::TColumnVector* pDestColumns          = m_pParent->getDestVector();
343*cdf0e10cSrcweir         ODatabaseExport::TColumnVector::const_iterator aDestIter    = pDestColumns->begin();
344*cdf0e10cSrcweir         ODatabaseExport::TColumnVector::const_iterator aDestEnd     = pDestColumns->end();
345*cdf0e10cSrcweir         const sal_uInt32 nDestSize = pDestColumns->size();
346*cdf0e10cSrcweir         sal_Bool bNotConvert;
347*cdf0e10cSrcweir         sal_uInt32 i = 0;
348*cdf0e10cSrcweir         for(sal_Int32 nPos = 1;aDestIter != aDestEnd && i < nDestSize && i < nSrcSize;++aDestIter,++nPos,++i)
349*cdf0e10cSrcweir         {
350*cdf0e10cSrcweir             bNotConvert = sal_True;
351*cdf0e10cSrcweir             m_pParent->m_vColumnPos[i] = ODatabaseExport::TPositions::value_type(nPos,nPos);
352*cdf0e10cSrcweir             TOTypeInfoSP pTypeInfo = m_pParent->convertType((*aDestIter)->second->getSpecialTypeInfo(),bNotConvert);
353*cdf0e10cSrcweir             if ( !bNotConvert )
354*cdf0e10cSrcweir             {
355*cdf0e10cSrcweir                 m_pParent->showColumnTypeNotSupported((*aDestIter)->first);
356*cdf0e10cSrcweir                 return sal_False;
357*cdf0e10cSrcweir             }
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir             if ( pTypeInfo.get() )
360*cdf0e10cSrcweir                 m_pParent->m_vColumnTypes[i] = pTypeInfo->nType;
361*cdf0e10cSrcweir             else
362*cdf0e10cSrcweir                 m_pParent->m_vColumnTypes[i] = DataType::VARCHAR;
363*cdf0e10cSrcweir         }
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir     }
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir     if ( !xTable.is() )
368*cdf0e10cSrcweir     {
369*cdf0e10cSrcweir         String sError(ModuleRes(STR_INVALID_TABLE_NAME));
370*cdf0e10cSrcweir         m_pParent->showError(sError);
371*cdf0e10cSrcweir         return sal_False;
372*cdf0e10cSrcweir     }
373*cdf0e10cSrcweir     return sal_True;
374*cdf0e10cSrcweir }
375*cdf0e10cSrcweir // -----------------------------------------------------------------------------
376*cdf0e10cSrcweir void OCopyTable::setCreatePrimaryKey( bool _bDoCreate, const ::rtl::OUString& _rSuggestedName )
377*cdf0e10cSrcweir {
378*cdf0e10cSrcweir     bool bCreatePK = m_bPKeyAllowed && _bDoCreate;
379*cdf0e10cSrcweir     m_aCB_PrimaryColumn.Check( bCreatePK );
380*cdf0e10cSrcweir     m_edKeyName.SetText( _rSuggestedName );
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir     m_aFT_KeyName.Enable( bCreatePK );
383*cdf0e10cSrcweir     m_edKeyName.Enable( bCreatePK );
384*cdf0e10cSrcweir }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir // -----------------------------------------------------------------------------
387*cdf0e10cSrcweir //---dyf add 2006/7/10
388*cdf0e10cSrcweir void OCopyTable::setCreateStyleAction()
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir     // reselect the last action before
391*cdf0e10cSrcweir     switch(m_pParent->getOperation())
392*cdf0e10cSrcweir     {
393*cdf0e10cSrcweir         case CopyTableOperation::CopyDefinitionAndData:
394*cdf0e10cSrcweir             m_aRB_DefData.Check(sal_True);
395*cdf0e10cSrcweir             RadioChangeHdl(&m_aRB_DefData);
396*cdf0e10cSrcweir             break;
397*cdf0e10cSrcweir         case CopyTableOperation::CopyDefinitionOnly:
398*cdf0e10cSrcweir             m_aRB_Def.Check(sal_True);
399*cdf0e10cSrcweir             RadioChangeHdl(&m_aRB_Def);
400*cdf0e10cSrcweir             break;
401*cdf0e10cSrcweir         case CopyTableOperation::AppendData:
402*cdf0e10cSrcweir             m_aRB_AppendData.Check(sal_True);
403*cdf0e10cSrcweir             SetAppendDataRadio();
404*cdf0e10cSrcweir             break;
405*cdf0e10cSrcweir         case CopyTableOperation::CreateAsView:
406*cdf0e10cSrcweir             if ( m_aRB_View.IsEnabled() )
407*cdf0e10cSrcweir             {
408*cdf0e10cSrcweir                 m_aRB_View.Check(sal_True);
409*cdf0e10cSrcweir                 RadioChangeHdl(&m_aRB_View);
410*cdf0e10cSrcweir             }
411*cdf0e10cSrcweir             else
412*cdf0e10cSrcweir             {
413*cdf0e10cSrcweir                 m_aRB_DefData.Check(sal_True);
414*cdf0e10cSrcweir                 RadioChangeHdl(&m_aRB_DefData);
415*cdf0e10cSrcweir             }
416*cdf0e10cSrcweir     }
417*cdf0e10cSrcweir }
418*cdf0e10cSrcweir //---add end
419