xref: /AOO41X/main/dbaccess/source/ui/misc/DExport.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 "DExport.hxx"
32*cdf0e10cSrcweir #include "moduledbu.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAppend.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/sdbcx/KeyType.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/util/NumberFormat.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatTypes.hpp>
46*cdf0e10cSrcweir #include "dbustrings.hrc"
47*cdf0e10cSrcweir #include "dbu_misc.hrc"
48*cdf0e10cSrcweir #include <connectivity/dbconversion.hxx>
49*cdf0e10cSrcweir #include <sfx2/sfxhtml.hxx>
50*cdf0e10cSrcweir #include <svl/numuno.hxx>
51*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
52*cdf0e10cSrcweir #include <comphelper/extract.hxx>
53*cdf0e10cSrcweir #include "TypeInfo.hxx"
54*cdf0e10cSrcweir #include "FieldDescriptions.hxx"
55*cdf0e10cSrcweir #include "UITools.hxx"
56*cdf0e10cSrcweir #include <unotools/configmgr.hxx>
57*cdf0e10cSrcweir #include <memory>
58*cdf0e10cSrcweir #include <tools/debug.hxx>
59*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
60*cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
61*cdf0e10cSrcweir #include <com/sun/star/awt/FontDescriptor.hpp>
62*cdf0e10cSrcweir #include "WCopyTable.hxx"
63*cdf0e10cSrcweir #include "WExtendPages.hxx"
64*cdf0e10cSrcweir #include "WCPage.hxx"
65*cdf0e10cSrcweir #include <unotools/syslocale.hxx>
66*cdf0e10cSrcweir #include <svl/zforlist.hxx>
67*cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
68*cdf0e10cSrcweir #include <connectivity/FValue.hxx>
69*cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
70*cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
71*cdf0e10cSrcweir #include <com/sun/star/sdb/application/CopyTableOperation.hpp>
72*cdf0e10cSrcweir #include "sqlmessage.hxx"
73*cdf0e10cSrcweir #include "UpdateHelperImpl.hxx"
74*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
75*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
76*cdf0e10cSrcweir #include <rtl/logfile.hxx>
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir using namespace dbaui;
79*cdf0e10cSrcweir using namespace utl;
80*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
81*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
82*cdf0e10cSrcweir using namespace ::com::sun::star::container;
83*cdf0e10cSrcweir using namespace ::com::sun::star::util;
84*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
85*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
86*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
87*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
88*cdf0e10cSrcweir using namespace ::com::sun::star::awt;
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir namespace CopyTableOperation = ::com::sun::star::sdb::application::CopyTableOperation;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir // ==========================================================================
93*cdf0e10cSrcweir // ODatabaseExport
94*cdf0e10cSrcweir // ==========================================================================
95*cdf0e10cSrcweir DBG_NAME(ODatabaseExport)
96*cdf0e10cSrcweir ODatabaseExport::ODatabaseExport(sal_Int32 nRows,
97*cdf0e10cSrcweir 								 const TPositions &_rColumnPositions,
98*cdf0e10cSrcweir 								 const Reference< XNumberFormatter >& _rxNumberF,
99*cdf0e10cSrcweir 								 const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM,
100*cdf0e10cSrcweir 								 const TColumnVector* pList,
101*cdf0e10cSrcweir                                  const OTypeInfoMap* _pInfoMap,
102*cdf0e10cSrcweir                                  sal_Bool _bAutoIncrementEnabled,
103*cdf0e10cSrcweir                                  SvStream& _rInputStream)
104*cdf0e10cSrcweir     :m_vColumns(_rColumnPositions)
105*cdf0e10cSrcweir     ,m_aDestColumns(sal_True)
106*cdf0e10cSrcweir     ,m_xFormatter(_rxNumberF)
107*cdf0e10cSrcweir     ,m_xFactory(_rM)
108*cdf0e10cSrcweir     ,m_pFormatter(NULL)
109*cdf0e10cSrcweir     ,m_rInputStream( _rInputStream )
110*cdf0e10cSrcweir 	,m_pTypeInfo()
111*cdf0e10cSrcweir     ,m_pColumnList(pList)
112*cdf0e10cSrcweir 	,m_pInfoMap(_pInfoMap)
113*cdf0e10cSrcweir 	,m_nColumnPos(0)
114*cdf0e10cSrcweir 	,m_nRows(1)
115*cdf0e10cSrcweir 	,m_nRowCount(0)
116*cdf0e10cSrcweir 	,m_nDefToken( gsl_getSystemTextEncoding() )
117*cdf0e10cSrcweir     ,m_bError(sal_False)
118*cdf0e10cSrcweir 	,m_bInTbl(sal_False)
119*cdf0e10cSrcweir 	,m_bHead(sal_True)
120*cdf0e10cSrcweir 	,m_bDontAskAgain(sal_False)
121*cdf0e10cSrcweir     ,m_bIsAutoIncrement(_bAutoIncrementEnabled)
122*cdf0e10cSrcweir 	,m_bFoundTable(sal_False)
123*cdf0e10cSrcweir 	,m_bCheckOnly(sal_False)
124*cdf0e10cSrcweir     ,m_bAppendFirstLine(false)
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::ODatabaseExport" );
127*cdf0e10cSrcweir 	DBG_CTOR(ODatabaseExport,NULL);
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 	m_nRows += nRows;
130*cdf0e10cSrcweir 	sal_Int32 nCount = 0;
131*cdf0e10cSrcweir 	for(sal_Int32 j=0;j < (sal_Int32)m_vColumns.size();++j)
132*cdf0e10cSrcweir 		if ( m_vColumns[j].first != COLUMN_POSITION_NOT_FOUND )
133*cdf0e10cSrcweir 			++nCount;
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	m_vColumnSize.resize(nCount);
136*cdf0e10cSrcweir 	m_vNumberFormat.resize(nCount);
137*cdf0e10cSrcweir 	for(sal_Int32 i=0;i<nCount;++i)
138*cdf0e10cSrcweir 	{
139*cdf0e10cSrcweir 		m_vColumnSize[i] = 0;
140*cdf0e10cSrcweir 		m_vNumberFormat[i] = 0;
141*cdf0e10cSrcweir 	}
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 	try
144*cdf0e10cSrcweir 	{
145*cdf0e10cSrcweir 		SvtSysLocale aSysLocale;
146*cdf0e10cSrcweir 		m_aLocale = aSysLocale.GetLocaleData().getLocale();
147*cdf0e10cSrcweir 	}
148*cdf0e10cSrcweir 	catch(Exception&)
149*cdf0e10cSrcweir 	{
150*cdf0e10cSrcweir 	}
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	SetColumnTypes(pList,_pInfoMap);
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir //---------------------------------------------------------------------------
155*cdf0e10cSrcweir ODatabaseExport::ODatabaseExport(const SharedConnection& _rxConnection,
156*cdf0e10cSrcweir 								 const Reference< XNumberFormatter >& _rxNumberF,
157*cdf0e10cSrcweir 								 const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM,
158*cdf0e10cSrcweir 								 const TColumnVector* pList,
159*cdf0e10cSrcweir 								 const OTypeInfoMap* _pInfoMap,
160*cdf0e10cSrcweir                                  SvStream& _rInputStream)
161*cdf0e10cSrcweir     :m_aDestColumns(_rxConnection->getMetaData().is() && _rxConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers() == sal_True)
162*cdf0e10cSrcweir     ,m_xConnection(_rxConnection)
163*cdf0e10cSrcweir 	,m_xFormatter(_rxNumberF)
164*cdf0e10cSrcweir 	,m_xFactory(_rM)
165*cdf0e10cSrcweir     ,m_pFormatter(NULL)
166*cdf0e10cSrcweir     ,m_rInputStream( _rInputStream )
167*cdf0e10cSrcweir     ,m_pTypeInfo()
168*cdf0e10cSrcweir 	,m_pColumnList(NULL)
169*cdf0e10cSrcweir 	,m_pInfoMap(NULL)
170*cdf0e10cSrcweir 	,m_nColumnPos(0)
171*cdf0e10cSrcweir 	,m_nRows(1)
172*cdf0e10cSrcweir 	,m_nRowCount(0)
173*cdf0e10cSrcweir 	,m_nDefToken( gsl_getSystemTextEncoding() )
174*cdf0e10cSrcweir     ,m_bError(sal_False)
175*cdf0e10cSrcweir 	,m_bInTbl(sal_False)
176*cdf0e10cSrcweir 	,m_bHead(sal_True)
177*cdf0e10cSrcweir 	,m_bDontAskAgain(sal_False)
178*cdf0e10cSrcweir 	,m_bIsAutoIncrement(sal_False)
179*cdf0e10cSrcweir 	,m_bFoundTable(sal_False)
180*cdf0e10cSrcweir 	,m_bCheckOnly(sal_False)
181*cdf0e10cSrcweir     ,m_bAppendFirstLine(false)
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::ODatabaseExport" );
184*cdf0e10cSrcweir 	DBG_CTOR(ODatabaseExport,NULL);
185*cdf0e10cSrcweir 	try
186*cdf0e10cSrcweir 	{
187*cdf0e10cSrcweir 		SvtSysLocale aSysLocale;
188*cdf0e10cSrcweir 		m_aLocale = aSysLocale.GetLocaleData().getLocale();
189*cdf0e10cSrcweir 	}
190*cdf0e10cSrcweir 	catch(Exception&)
191*cdf0e10cSrcweir 	{
192*cdf0e10cSrcweir 	}
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	Reference<XTablesSupplier> xTablesSup(m_xConnection,UNO_QUERY);
195*cdf0e10cSrcweir 	if(xTablesSup.is())
196*cdf0e10cSrcweir 		m_xTables = xTablesSup->getTables();
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 	Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData();
199*cdf0e10cSrcweir 	Reference<XResultSet> xSet = xMeta.is() ? xMeta->getTypeInfo() : Reference<XResultSet>();
200*cdf0e10cSrcweir 	if(xSet.is())
201*cdf0e10cSrcweir 	{
202*cdf0e10cSrcweir 		::connectivity::ORowSetValue aValue;
203*cdf0e10cSrcweir 		::std::vector<sal_Int32> aTypes;
204*cdf0e10cSrcweir         ::std::vector<sal_Bool> aNullable;
205*cdf0e10cSrcweir 		Reference<XResultSetMetaData> xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(xSet,UNO_QUERY_THROW)->getMetaData();
206*cdf0e10cSrcweir 		Reference<XRow> xRow(xSet,UNO_QUERY_THROW);
207*cdf0e10cSrcweir 		while(xSet->next())
208*cdf0e10cSrcweir 		{
209*cdf0e10cSrcweir 			if ( aTypes.empty() )
210*cdf0e10cSrcweir 			{
211*cdf0e10cSrcweir 				sal_Int32 nCount = xResultSetMetaData->getColumnCount();
212*cdf0e10cSrcweir 				if ( nCount < 1 )
213*cdf0e10cSrcweir 					nCount = 18;
214*cdf0e10cSrcweir 				aTypes.reserve(nCount+1);
215*cdf0e10cSrcweir                 aNullable.reserve(nCount+1);
216*cdf0e10cSrcweir 				aTypes.push_back(-1);
217*cdf0e10cSrcweir                 aNullable.push_back(sal_False);
218*cdf0e10cSrcweir 				for (sal_Int32 j = 1; j <= nCount ; ++j)
219*cdf0e10cSrcweir                 {
220*cdf0e10cSrcweir                     aNullable.push_back(xResultSetMetaData->isNullable(j) != ColumnValue::NO_NULLS );
221*cdf0e10cSrcweir 					aTypes.push_back(xResultSetMetaData->getColumnType(j));
222*cdf0e10cSrcweir                 }
223*cdf0e10cSrcweir 			}
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 			sal_Int32 nPos = 1;
226*cdf0e10cSrcweir             OSL_ENSURE((nPos) < static_cast<sal_Int32>(aTypes.size()),"aTypes: Illegal index for vector");
227*cdf0e10cSrcweir 			aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
228*cdf0e10cSrcweir 			::rtl::OUString sTypeName = aValue;
229*cdf0e10cSrcweir 			++nPos;
230*cdf0e10cSrcweir             OSL_ENSURE((nPos) < static_cast<sal_Int32>(aTypes.size()),"aTypes: Illegal index for vector");
231*cdf0e10cSrcweir 			aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
232*cdf0e10cSrcweir 			sal_Int32 nType = aValue;
233*cdf0e10cSrcweir 			++nPos;
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 			if( nType == DataType::VARCHAR )
236*cdf0e10cSrcweir 			{
237*cdf0e10cSrcweir 				m_pTypeInfo					= TOTypeInfoSP(new OTypeInfo());
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 				m_pTypeInfo->aTypeName		= sTypeName;
240*cdf0e10cSrcweir 				m_pTypeInfo->nType			= nType;
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir                 OSL_ENSURE((nPos) < static_cast<sal_Int32>(aTypes.size()),"aTypes: Illegal index for vector");
243*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
244*cdf0e10cSrcweir 				m_pTypeInfo->nPrecision		= aValue;
245*cdf0e10cSrcweir 				++nPos;
246*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
247*cdf0e10cSrcweir 				m_pTypeInfo->aLiteralPrefix	= aValue;
248*cdf0e10cSrcweir 				++nPos;
249*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
250*cdf0e10cSrcweir 				m_pTypeInfo->aLiteralSuffix	= aValue;
251*cdf0e10cSrcweir 				++nPos;
252*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
253*cdf0e10cSrcweir 				m_pTypeInfo->aCreateParams	= aValue;
254*cdf0e10cSrcweir 				++nPos;
255*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
256*cdf0e10cSrcweir 				m_pTypeInfo->bNullable		= (sal_Int32)aValue == ColumnValue::NULLABLE;
257*cdf0e10cSrcweir 				++nPos;
258*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
259*cdf0e10cSrcweir 				m_pTypeInfo->bCaseSensitive	= (sal_Bool)aValue;
260*cdf0e10cSrcweir 				++nPos;
261*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
262*cdf0e10cSrcweir 				m_pTypeInfo->nSearchType		= aValue;
263*cdf0e10cSrcweir 				++nPos;
264*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
265*cdf0e10cSrcweir 				m_pTypeInfo->bUnsigned		= (sal_Bool)aValue;
266*cdf0e10cSrcweir 				++nPos;
267*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
268*cdf0e10cSrcweir 				m_pTypeInfo->bCurrency		= (sal_Bool)aValue;
269*cdf0e10cSrcweir 				++nPos;
270*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
271*cdf0e10cSrcweir 				m_pTypeInfo->bAutoIncrement	= (sal_Bool)aValue;
272*cdf0e10cSrcweir 				++nPos;
273*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
274*cdf0e10cSrcweir 				m_pTypeInfo->aLocalTypeName	= aValue;
275*cdf0e10cSrcweir 				++nPos;
276*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
277*cdf0e10cSrcweir 				m_pTypeInfo->nMinimumScale	= aValue;
278*cdf0e10cSrcweir 				++nPos;
279*cdf0e10cSrcweir 				aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
280*cdf0e10cSrcweir 				m_pTypeInfo->nMaximumScale	= aValue;
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 				// check if values are less than zero like it happens in a oracle jdbc driver
283*cdf0e10cSrcweir 				if( m_pTypeInfo->nPrecision < 0)
284*cdf0e10cSrcweir 					m_pTypeInfo->nPrecision = 0;
285*cdf0e10cSrcweir 				if( m_pTypeInfo->nMinimumScale < 0)
286*cdf0e10cSrcweir 					m_pTypeInfo->nMinimumScale = 0;
287*cdf0e10cSrcweir 				if( m_pTypeInfo->nMaximumScale < 0)
288*cdf0e10cSrcweir 					m_pTypeInfo->nMaximumScale = 0;
289*cdf0e10cSrcweir 				break;
290*cdf0e10cSrcweir 			}
291*cdf0e10cSrcweir 		}
292*cdf0e10cSrcweir 	} // if(xSet.is())
293*cdf0e10cSrcweir     if ( !m_pTypeInfo )
294*cdf0e10cSrcweir         m_pTypeInfo	= TOTypeInfoSP(new OTypeInfo());
295*cdf0e10cSrcweir 	SetColumnTypes(pList,_pInfoMap);
296*cdf0e10cSrcweir }
297*cdf0e10cSrcweir //---------------------------------------------------------------------------
298*cdf0e10cSrcweir ODatabaseExport::~ODatabaseExport()
299*cdf0e10cSrcweir {
300*cdf0e10cSrcweir 	DBG_DTOR(ODatabaseExport,NULL);
301*cdf0e10cSrcweir     m_pFormatter = NULL;
302*cdf0e10cSrcweir 	ODatabaseExport::TColumns::iterator aIter = m_aDestColumns.begin();
303*cdf0e10cSrcweir 	ODatabaseExport::TColumns::iterator aEnd  = m_aDestColumns.end();
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 	for(;aIter != aEnd;++aIter)
306*cdf0e10cSrcweir 		delete aIter->second;
307*cdf0e10cSrcweir 	m_vDestVector.clear();
308*cdf0e10cSrcweir 	m_aDestColumns.clear();
309*cdf0e10cSrcweir }
310*cdf0e10cSrcweir // -----------------------------------------------------------------------------
311*cdf0e10cSrcweir void ODatabaseExport::insertValueIntoColumn()
312*cdf0e10cSrcweir {
313*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::insertValueIntoColumn" );
314*cdf0e10cSrcweir     DBG_CHKTHIS(ODatabaseExport,NULL);
315*cdf0e10cSrcweir     if(m_nColumnPos < sal_Int32(m_vDestVector.size()))
316*cdf0e10cSrcweir     {
317*cdf0e10cSrcweir         OFieldDescription* pField = m_vDestVector[m_nColumnPos]->second;
318*cdf0e10cSrcweir         if(pField)
319*cdf0e10cSrcweir         {
320*cdf0e10cSrcweir             sal_Int32 nNewPos = m_bIsAutoIncrement ? m_nColumnPos+1 : m_nColumnPos;
321*cdf0e10cSrcweir             OSL_ENSURE((nNewPos) < static_cast<sal_Int32>(m_vColumns.size()),"m_vColumns: Illegal index for vector");
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir             if ( (nNewPos) < static_cast<sal_Int32>(m_vColumns.size() ) )
324*cdf0e10cSrcweir             {
325*cdf0e10cSrcweir                 sal_Int32 nPos = m_vColumns[nNewPos].first;
326*cdf0e10cSrcweir                 if ( nPos != COLUMN_POSITION_NOT_FOUND )
327*cdf0e10cSrcweir                 {
328*cdf0e10cSrcweir     //                  if(m_nDefToken != LANGUAGE_DONTKNOW) // falls Sprache anders als Systemsprache
329*cdf0e10cSrcweir     //                      m_pNF->ChangeIntl((LanguageType)m_nDefToken);
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir                     if ( !m_sTextToken.Len() && pField->IsNullable() )
332*cdf0e10cSrcweir                         m_pUpdateHelper->updateNull(nPos,pField->GetType());
333*cdf0e10cSrcweir                     else
334*cdf0e10cSrcweir                     {
335*cdf0e10cSrcweir                         sal_Int32 nNumberFormat = 0;
336*cdf0e10cSrcweir                         double fOutNumber = 0.0;
337*cdf0e10cSrcweir                         OSL_ENSURE((nNewPos) < static_cast<sal_Int32>(m_vColumnTypes.size()),"Illegal index for vector");
338*cdf0e10cSrcweir                         if (m_vColumnTypes[nNewPos] != DataType::VARCHAR && m_vColumnTypes[nNewPos] != DataType::CHAR && m_vColumnTypes[nNewPos] != DataType::LONGVARCHAR )
339*cdf0e10cSrcweir                         {
340*cdf0e10cSrcweir                             RTL_LOGFILE_CONTEXT_TRACE( aLogger, "ODatabaseExport::insertValueIntoColumn != DataType::VARCHAR" );
341*cdf0e10cSrcweir                             ensureFormatter();
342*cdf0e10cSrcweir                             bool bNumberFormatError = false;
343*cdf0e10cSrcweir                             if ( m_pFormatter && m_sNumToken.Len() )
344*cdf0e10cSrcweir                             {
345*cdf0e10cSrcweir                                 LanguageType eNumLang = LANGUAGE_NONE;
346*cdf0e10cSrcweir                                 sal_uInt32 nNumberFormat2( nNumberFormat );
347*cdf0e10cSrcweir                                 fOutNumber = SfxHTMLParser::GetTableDataOptionsValNum(nNumberFormat2,eNumLang,m_sTextToken,m_sNumToken,*m_pFormatter);
348*cdf0e10cSrcweir                                 if ( eNumLang != LANGUAGE_NONE )
349*cdf0e10cSrcweir                                 {
350*cdf0e10cSrcweir                                     nNumberFormat2 = m_pFormatter->GetFormatForLanguageIfBuiltIn( nNumberFormat2, eNumLang );
351*cdf0e10cSrcweir                                     m_pFormatter->IsNumberFormat( m_sTextToken, nNumberFormat2, fOutNumber );
352*cdf0e10cSrcweir                                 }
353*cdf0e10cSrcweir                                 nNumberFormat = static_cast<sal_Int32>(nNumberFormat2);
354*cdf0e10cSrcweir                             }
355*cdf0e10cSrcweir                             else
356*cdf0e10cSrcweir                             {
357*cdf0e10cSrcweir                                 Reference< XNumberFormatsSupplier >  xSupplier = m_xFormatter->getNumberFormatsSupplier();
358*cdf0e10cSrcweir                                 Reference<XNumberFormatTypes> xNumType(xSupplier->getNumberFormats(),UNO_QUERY);
359*cdf0e10cSrcweir                                 sal_Int16 nFormats[] = {
360*cdf0e10cSrcweir                                     NumberFormat::DATETIME
361*cdf0e10cSrcweir                                     ,NumberFormat::DATE
362*cdf0e10cSrcweir                                     ,NumberFormat::TIME
363*cdf0e10cSrcweir                                     ,NumberFormat::CURRENCY
364*cdf0e10cSrcweir                                     ,NumberFormat::NUMBER
365*cdf0e10cSrcweir                                     ,NumberFormat::LOGICAL
366*cdf0e10cSrcweir                                 };
367*cdf0e10cSrcweir                                 for (size_t i = 0; i < sizeof(nFormats)/sizeof(nFormats[0]); ++i)
368*cdf0e10cSrcweir                                 {
369*cdf0e10cSrcweir                                     try
370*cdf0e10cSrcweir                                     {
371*cdf0e10cSrcweir                                         nNumberFormat = m_xFormatter->detectNumberFormat(xNumType->getStandardFormat(nFormats[i],m_aLocale),m_sTextToken);
372*cdf0e10cSrcweir                                         break;
373*cdf0e10cSrcweir                                     }
374*cdf0e10cSrcweir                                     catch(Exception&)
375*cdf0e10cSrcweir                                     {
376*cdf0e10cSrcweir                                     }
377*cdf0e10cSrcweir                                 }
378*cdf0e10cSrcweir                                 try
379*cdf0e10cSrcweir                                 {
380*cdf0e10cSrcweir                                     fOutNumber = m_xFormatter->convertStringToNumber(nNumberFormat,m_sTextToken);
381*cdf0e10cSrcweir                                 }
382*cdf0e10cSrcweir                                 catch(Exception&)
383*cdf0e10cSrcweir                                 {
384*cdf0e10cSrcweir                                     bNumberFormatError = true;
385*cdf0e10cSrcweir                                     m_pUpdateHelper->updateString(nPos,m_sTextToken);
386*cdf0e10cSrcweir                                 }
387*cdf0e10cSrcweir                             }
388*cdf0e10cSrcweir                             if ( !bNumberFormatError )
389*cdf0e10cSrcweir                             {
390*cdf0e10cSrcweir                                 try
391*cdf0e10cSrcweir                                 {
392*cdf0e10cSrcweir                                     Reference< XNumberFormatsSupplier >  xSupplier = m_xFormatter->getNumberFormatsSupplier();
393*cdf0e10cSrcweir                                     Reference< XNumberFormats >         xFormats = xSupplier->getNumberFormats();
394*cdf0e10cSrcweir                                     Reference<XPropertySet> xProp = xFormats->getByKey(nNumberFormat);
395*cdf0e10cSrcweir                                     sal_Int16 nType = 0;
396*cdf0e10cSrcweir                                     xProp->getPropertyValue(PROPERTY_TYPE) >>= nType;
397*cdf0e10cSrcweir                                     switch(nType)
398*cdf0e10cSrcweir                                     {
399*cdf0e10cSrcweir                                         case NumberFormat::DATE:
400*cdf0e10cSrcweir                                             m_pUpdateHelper->updateDate(nPos,::dbtools::DBTypeConversion::toDate(fOutNumber,m_aNullDate));
401*cdf0e10cSrcweir                                             break;
402*cdf0e10cSrcweir                                         case NumberFormat::DATETIME:
403*cdf0e10cSrcweir                                             m_pUpdateHelper->updateTimestamp(nPos,::dbtools::DBTypeConversion::toDateTime(fOutNumber,m_aNullDate));
404*cdf0e10cSrcweir                                             break;
405*cdf0e10cSrcweir                                         case NumberFormat::TIME:
406*cdf0e10cSrcweir                                             m_pUpdateHelper->updateTime(nPos,::dbtools::DBTypeConversion::toTime(fOutNumber));
407*cdf0e10cSrcweir                                             break;
408*cdf0e10cSrcweir                                         default:
409*cdf0e10cSrcweir                                             m_pUpdateHelper->updateDouble(nPos,fOutNumber);
410*cdf0e10cSrcweir                                     }
411*cdf0e10cSrcweir                                 }
412*cdf0e10cSrcweir                                 catch(Exception&)
413*cdf0e10cSrcweir                                 {
414*cdf0e10cSrcweir                                     m_pUpdateHelper->updateString(nPos,m_sTextToken);
415*cdf0e10cSrcweir                                 }
416*cdf0e10cSrcweir                             }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir                         }
419*cdf0e10cSrcweir                         else
420*cdf0e10cSrcweir                             m_pUpdateHelper->updateString(nPos,m_sTextToken);
421*cdf0e10cSrcweir                     }
422*cdf0e10cSrcweir                 }
423*cdf0e10cSrcweir             }
424*cdf0e10cSrcweir             eraseTokens();
425*cdf0e10cSrcweir         }
426*cdf0e10cSrcweir     }
427*cdf0e10cSrcweir }
428*cdf0e10cSrcweir // -----------------------------------------------------------------------------
429*cdf0e10cSrcweir sal_Int16 ODatabaseExport::CheckString(const String& aCheckToken, sal_Int16 _nOldNumberFormat)
430*cdf0e10cSrcweir {
431*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::CheckString" );
432*cdf0e10cSrcweir     DBG_CHKTHIS(ODatabaseExport,NULL);
433*cdf0e10cSrcweir     double fOutNumber = 0.0;
434*cdf0e10cSrcweir     sal_Int16 nNumberFormat = 0;
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir     try
437*cdf0e10cSrcweir     {
438*cdf0e10cSrcweir         Reference< XNumberFormatsSupplier > xSupplier = m_xFormatter->getNumberFormatsSupplier();
439*cdf0e10cSrcweir         Reference< XNumberFormats >         xFormats = xSupplier->getNumberFormats();
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir         ensureFormatter();
442*cdf0e10cSrcweir         if ( m_pFormatter && m_sNumToken.Len() )
443*cdf0e10cSrcweir         {
444*cdf0e10cSrcweir             LanguageType eNumLang;
445*cdf0e10cSrcweir             sal_uInt32 nFormatKey(0);
446*cdf0e10cSrcweir             fOutNumber = SfxHTMLParser::GetTableDataOptionsValNum(nFormatKey,eNumLang,m_sTextToken,m_sNumToken,*m_pFormatter);
447*cdf0e10cSrcweir             if ( eNumLang != LANGUAGE_NONE )
448*cdf0e10cSrcweir             {
449*cdf0e10cSrcweir                 nFormatKey = m_pFormatter->GetFormatForLanguageIfBuiltIn( nFormatKey, eNumLang );
450*cdf0e10cSrcweir                 if ( !m_pFormatter->IsNumberFormat( m_sTextToken, nFormatKey, fOutNumber ) )
451*cdf0e10cSrcweir                     return NumberFormat::TEXT;
452*cdf0e10cSrcweir             }
453*cdf0e10cSrcweir             Reference<XPropertySet> xProp = xFormats->getByKey(nFormatKey);
454*cdf0e10cSrcweir             xProp->getPropertyValue(PROPERTY_TYPE) >>= nNumberFormat;
455*cdf0e10cSrcweir         }
456*cdf0e10cSrcweir         else
457*cdf0e10cSrcweir         {
458*cdf0e10cSrcweir             Reference<XNumberFormatTypes> xNumType(xFormats,UNO_QUERY);
459*cdf0e10cSrcweir             sal_Int32 nFormatKey = m_xFormatter->detectNumberFormat(xNumType->getStandardFormat(NumberFormat::ALL,m_aLocale),aCheckToken);
460*cdf0e10cSrcweir             fOutNumber = m_xFormatter->convertStringToNumber(nFormatKey,aCheckToken);
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir             Reference<XPropertySet> xProp = xFormats->getByKey(nFormatKey);
463*cdf0e10cSrcweir             sal_Int16 nType = 0;
464*cdf0e10cSrcweir             xProp->getPropertyValue(PROPERTY_TYPE) >>= nType;
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir             switch(nType)
467*cdf0e10cSrcweir             {
468*cdf0e10cSrcweir                 case NumberFormat::ALL:
469*cdf0e10cSrcweir                     nNumberFormat = NumberFormat::ALL;
470*cdf0e10cSrcweir                     break;
471*cdf0e10cSrcweir                 case NumberFormat::DEFINED:
472*cdf0e10cSrcweir                     nNumberFormat = NumberFormat::TEXT;
473*cdf0e10cSrcweir                     break;
474*cdf0e10cSrcweir                 case NumberFormat::DATE:
475*cdf0e10cSrcweir                     switch(_nOldNumberFormat)
476*cdf0e10cSrcweir                     {
477*cdf0e10cSrcweir                         case NumberFormat::DATETIME:
478*cdf0e10cSrcweir                         case NumberFormat::TEXT:
479*cdf0e10cSrcweir                         case NumberFormat::DATE:
480*cdf0e10cSrcweir                             nNumberFormat = _nOldNumberFormat;
481*cdf0e10cSrcweir                             break;
482*cdf0e10cSrcweir                         case NumberFormat::ALL:
483*cdf0e10cSrcweir                             nNumberFormat = NumberFormat::DATE;
484*cdf0e10cSrcweir                             break;
485*cdf0e10cSrcweir                         default:
486*cdf0e10cSrcweir                             nNumberFormat = NumberFormat::TEXT;
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir                     }
489*cdf0e10cSrcweir                     break;
490*cdf0e10cSrcweir                 case NumberFormat::TIME:
491*cdf0e10cSrcweir                     switch(_nOldNumberFormat)
492*cdf0e10cSrcweir                     {
493*cdf0e10cSrcweir                         case NumberFormat::DATETIME:
494*cdf0e10cSrcweir                         case NumberFormat::TEXT:
495*cdf0e10cSrcweir                         case NumberFormat::TIME:
496*cdf0e10cSrcweir                             nNumberFormat = _nOldNumberFormat;
497*cdf0e10cSrcweir                             break;
498*cdf0e10cSrcweir                         case NumberFormat::ALL:
499*cdf0e10cSrcweir                             nNumberFormat = NumberFormat::TIME;
500*cdf0e10cSrcweir                             break;
501*cdf0e10cSrcweir                         default:
502*cdf0e10cSrcweir                             nNumberFormat = NumberFormat::TEXT;
503*cdf0e10cSrcweir                             break;
504*cdf0e10cSrcweir                     }
505*cdf0e10cSrcweir                     break;
506*cdf0e10cSrcweir                 case NumberFormat::CURRENCY:
507*cdf0e10cSrcweir                     switch(_nOldNumberFormat)
508*cdf0e10cSrcweir                     {
509*cdf0e10cSrcweir                         case NumberFormat::NUMBER:
510*cdf0e10cSrcweir                             nNumberFormat = NumberFormat::CURRENCY;
511*cdf0e10cSrcweir                             break;
512*cdf0e10cSrcweir                         case NumberFormat::CURRENCY:
513*cdf0e10cSrcweir                             nNumberFormat = _nOldNumberFormat;
514*cdf0e10cSrcweir                             break;
515*cdf0e10cSrcweir                         case NumberFormat::ALL:
516*cdf0e10cSrcweir                             nNumberFormat = NumberFormat::CURRENCY;
517*cdf0e10cSrcweir                             break;
518*cdf0e10cSrcweir                         default:
519*cdf0e10cSrcweir                             nNumberFormat = NumberFormat::TEXT;
520*cdf0e10cSrcweir                             break;
521*cdf0e10cSrcweir                     }
522*cdf0e10cSrcweir                     break;
523*cdf0e10cSrcweir                 case NumberFormat::NUMBER:
524*cdf0e10cSrcweir                 case NumberFormat::SCIENTIFIC:
525*cdf0e10cSrcweir                 case NumberFormat::FRACTION:
526*cdf0e10cSrcweir                 case NumberFormat::PERCENT:
527*cdf0e10cSrcweir                     switch(_nOldNumberFormat)
528*cdf0e10cSrcweir                     {
529*cdf0e10cSrcweir                         case NumberFormat::NUMBER:
530*cdf0e10cSrcweir                             nNumberFormat = _nOldNumberFormat;
531*cdf0e10cSrcweir                             break;
532*cdf0e10cSrcweir                         case NumberFormat::CURRENCY:
533*cdf0e10cSrcweir                             nNumberFormat = NumberFormat::CURRENCY;
534*cdf0e10cSrcweir                             break;
535*cdf0e10cSrcweir                         case NumberFormat::ALL:
536*cdf0e10cSrcweir                             nNumberFormat = nType;
537*cdf0e10cSrcweir                             break;
538*cdf0e10cSrcweir                         default:
539*cdf0e10cSrcweir                             nNumberFormat = NumberFormat::TEXT;
540*cdf0e10cSrcweir                             break;
541*cdf0e10cSrcweir                     }
542*cdf0e10cSrcweir                     break;
543*cdf0e10cSrcweir                 case NumberFormat::TEXT:
544*cdf0e10cSrcweir                 case NumberFormat::UNDEFINED:
545*cdf0e10cSrcweir                 case NumberFormat::LOGICAL:
546*cdf0e10cSrcweir                     nNumberFormat = NumberFormat::TEXT; // Text "uberschreibt alles
547*cdf0e10cSrcweir                     break;
548*cdf0e10cSrcweir                 case NumberFormat::DATETIME:
549*cdf0e10cSrcweir                     switch(_nOldNumberFormat)
550*cdf0e10cSrcweir                     {
551*cdf0e10cSrcweir                         case NumberFormat::DATETIME:
552*cdf0e10cSrcweir                         case NumberFormat::TEXT:
553*cdf0e10cSrcweir                         case NumberFormat::TIME:
554*cdf0e10cSrcweir                             nNumberFormat = _nOldNumberFormat;
555*cdf0e10cSrcweir                             break;
556*cdf0e10cSrcweir                         case NumberFormat::ALL:
557*cdf0e10cSrcweir                             nNumberFormat = NumberFormat::DATETIME;
558*cdf0e10cSrcweir                             break;
559*cdf0e10cSrcweir                         default:
560*cdf0e10cSrcweir                             nNumberFormat = NumberFormat::TEXT;
561*cdf0e10cSrcweir                             break;
562*cdf0e10cSrcweir                     }
563*cdf0e10cSrcweir                     break;
564*cdf0e10cSrcweir                 default:
565*cdf0e10cSrcweir                     OSL_ENSURE(0,"ODatabaseExport: Unbekanntes Format");
566*cdf0e10cSrcweir             }
567*cdf0e10cSrcweir         }
568*cdf0e10cSrcweir     }
569*cdf0e10cSrcweir     catch(Exception&)
570*cdf0e10cSrcweir     {
571*cdf0e10cSrcweir         nNumberFormat = NumberFormat::TEXT; // Text "uberschreibt alles
572*cdf0e10cSrcweir     }
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir     return nNumberFormat;
575*cdf0e10cSrcweir }
576*cdf0e10cSrcweir // -----------------------------------------------------------------------------
577*cdf0e10cSrcweir void ODatabaseExport::SetColumnTypes(const TColumnVector* _pList,const OTypeInfoMap* _pInfoMap)
578*cdf0e10cSrcweir {
579*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::SetColumnTypes" );
580*cdf0e10cSrcweir 	DBG_CHKTHIS(ODatabaseExport,NULL);
581*cdf0e10cSrcweir 	if(_pList && _pInfoMap)
582*cdf0e10cSrcweir 	{
583*cdf0e10cSrcweir         OSL_ENSURE(m_vNumberFormat.size() == m_vColumnSize.size() && m_vColumnSize.size() == _pList->size(),"Illegal columns in list");
584*cdf0e10cSrcweir         Reference< XNumberFormatsSupplier > xSupplier = m_xFormatter->getNumberFormatsSupplier();
585*cdf0e10cSrcweir         Reference< XNumberFormats >         xFormats = xSupplier->getNumberFormats();
586*cdf0e10cSrcweir 		TColumnVector::const_iterator aIter = _pList->begin();
587*cdf0e10cSrcweir         TColumnVector::const_iterator aEnd = _pList->end();
588*cdf0e10cSrcweir         for(sal_Int32 i= 0;aIter != aEnd && (i) < static_cast<sal_Int32>(m_vNumberFormat.size()) && (i) < static_cast<sal_Int32>(m_vColumnSize.size()) ;++aIter,++i)
589*cdf0e10cSrcweir 		{
590*cdf0e10cSrcweir 			sal_Int32 nDataType;
591*cdf0e10cSrcweir 			sal_Int32 nLength(0),nScale(0);
592*cdf0e10cSrcweir 		    sal_Int16 nType = m_vNumberFormat[i] & ~NumberFormat::DEFINED;
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir 			switch ( nType )
595*cdf0e10cSrcweir 			{
596*cdf0e10cSrcweir 				case NumberFormat::ALL:
597*cdf0e10cSrcweir 					nDataType  = DataType::DOUBLE;
598*cdf0e10cSrcweir 					break;
599*cdf0e10cSrcweir 				case NumberFormat::DEFINED:
600*cdf0e10cSrcweir 					nDataType	= DataType::VARCHAR;
601*cdf0e10cSrcweir 					nLength		= ((m_vColumnSize[i] % 10 ) ? m_vColumnSize[i]/ 10 + 1: m_vColumnSize[i]/ 10) * 10;
602*cdf0e10cSrcweir 					break;
603*cdf0e10cSrcweir 				case NumberFormat::DATE:
604*cdf0e10cSrcweir 					nDataType  = DataType::DATE;
605*cdf0e10cSrcweir 					break;
606*cdf0e10cSrcweir 				case NumberFormat::TIME:
607*cdf0e10cSrcweir 					nDataType  = DataType::TIME;
608*cdf0e10cSrcweir 					break;
609*cdf0e10cSrcweir 				case NumberFormat::DATETIME:
610*cdf0e10cSrcweir 					nDataType  = DataType::TIMESTAMP;
611*cdf0e10cSrcweir 					break;
612*cdf0e10cSrcweir 				case NumberFormat::CURRENCY:
613*cdf0e10cSrcweir 					nDataType  = DataType::NUMERIC;
614*cdf0e10cSrcweir 					nScale		= 4;
615*cdf0e10cSrcweir 					nLength		= 19;
616*cdf0e10cSrcweir 					break;
617*cdf0e10cSrcweir 				case NumberFormat::NUMBER:
618*cdf0e10cSrcweir 				case NumberFormat::SCIENTIFIC:
619*cdf0e10cSrcweir 				case NumberFormat::FRACTION:
620*cdf0e10cSrcweir 				case NumberFormat::PERCENT:
621*cdf0e10cSrcweir 					nDataType  = DataType::DOUBLE;
622*cdf0e10cSrcweir 					break;
623*cdf0e10cSrcweir 				case NumberFormat::TEXT:
624*cdf0e10cSrcweir 				case NumberFormat::UNDEFINED:
625*cdf0e10cSrcweir 				case NumberFormat::LOGICAL:
626*cdf0e10cSrcweir 				default:
627*cdf0e10cSrcweir 					nDataType  = DataType::VARCHAR;
628*cdf0e10cSrcweir 					nLength		= ((m_vColumnSize[i] % 10 ) ? m_vColumnSize[i]/ 10 + 1: m_vColumnSize[i]/ 10) * 10;
629*cdf0e10cSrcweir 					break;
630*cdf0e10cSrcweir 			}
631*cdf0e10cSrcweir 			OTypeInfoMap::const_iterator aFind = _pInfoMap->find(nDataType);
632*cdf0e10cSrcweir 			if(aFind != _pInfoMap->end())
633*cdf0e10cSrcweir 			{
634*cdf0e10cSrcweir 				(*aIter)->second->SetType(aFind->second);
635*cdf0e10cSrcweir 				(*aIter)->second->SetPrecision(::std::min<sal_Int32>(aFind->second->nPrecision,nLength));
636*cdf0e10cSrcweir 				(*aIter)->second->SetScale(::std::min<sal_Int32>(aFind->second->nMaximumScale,nScale));
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir                 sal_Int32 nFormatKey = ::dbtools::getDefaultNumberFormat( nDataType,
639*cdf0e10cSrcweir 			                        (*aIter)->second->GetScale(),
640*cdf0e10cSrcweir 			                        (*aIter)->second->IsCurrency(),
641*cdf0e10cSrcweir 			                        Reference< XNumberFormatTypes>(xFormats,UNO_QUERY),
642*cdf0e10cSrcweir 			                        m_aLocale);
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir 			    (*aIter)->second->SetFormatKey(nFormatKey);
645*cdf0e10cSrcweir 			}
646*cdf0e10cSrcweir 		}
647*cdf0e10cSrcweir 	}
648*cdf0e10cSrcweir }
649*cdf0e10cSrcweir // -----------------------------------------------------------------------------
650*cdf0e10cSrcweir void ODatabaseExport::CreateDefaultColumn(const ::rtl::OUString& _rColumnName)
651*cdf0e10cSrcweir {
652*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::CreateDefaultColumn" );
653*cdf0e10cSrcweir 	DBG_CHKTHIS(ODatabaseExport,NULL);
654*cdf0e10cSrcweir 	Reference< XDatabaseMetaData>  xDestMetaData(m_xConnection->getMetaData());
655*cdf0e10cSrcweir 	sal_Int32 nMaxNameLen(xDestMetaData->getMaxColumnNameLength());
656*cdf0e10cSrcweir 	::rtl::OUString aAlias = _rColumnName;
657*cdf0e10cSrcweir 	if ( isSQL92CheckEnabled(m_xConnection) )
658*cdf0e10cSrcweir 		aAlias = ::dbtools::convertName2SQLName(_rColumnName,xDestMetaData->getExtraNameCharacters());
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir 	if(nMaxNameLen && aAlias.getLength() > nMaxNameLen)
661*cdf0e10cSrcweir 		aAlias = aAlias.copy(0, ::std::min<sal_Int32>( nMaxNameLen-1, aAlias.getLength() ) );
662*cdf0e10cSrcweir 
663*cdf0e10cSrcweir 	::rtl::OUString sName(aAlias);
664*cdf0e10cSrcweir 	if(m_aDestColumns.find(sName) != m_aDestColumns.end())
665*cdf0e10cSrcweir 	{
666*cdf0e10cSrcweir 		sal_Int32 nPos = 0;
667*cdf0e10cSrcweir 		sal_Int32 nCount = 2;
668*cdf0e10cSrcweir 		while(m_aDestColumns.find(sName) != m_aDestColumns.end())
669*cdf0e10cSrcweir 		{
670*cdf0e10cSrcweir 			sName = aAlias;
671*cdf0e10cSrcweir 			sName += ::rtl::OUString::valueOf(++nPos);
672*cdf0e10cSrcweir 			if(nMaxNameLen && sName.getLength() > nMaxNameLen)
673*cdf0e10cSrcweir 			{
674*cdf0e10cSrcweir 				aAlias = aAlias.copy(0,::std::min<sal_Int32>( nMaxNameLen-nCount, aAlias.getLength() ));
675*cdf0e10cSrcweir 				sName = aAlias;
676*cdf0e10cSrcweir 				sName += ::rtl::OUString::valueOf(nPos);
677*cdf0e10cSrcweir 				++nCount;
678*cdf0e10cSrcweir 			}
679*cdf0e10cSrcweir 		}
680*cdf0e10cSrcweir 	}
681*cdf0e10cSrcweir 	aAlias = sName;
682*cdf0e10cSrcweir 	// now create a column
683*cdf0e10cSrcweir 	OFieldDescription* pField = new OFieldDescription();
684*cdf0e10cSrcweir 	pField->SetType(m_pTypeInfo);
685*cdf0e10cSrcweir 	pField->SetName(aAlias);
686*cdf0e10cSrcweir 	pField->SetPrecision(::std::min<sal_Int32>((sal_Int32)255,m_pTypeInfo->nPrecision));
687*cdf0e10cSrcweir 	pField->SetScale(0);
688*cdf0e10cSrcweir 	pField->SetIsNullable(ColumnValue::NULLABLE);
689*cdf0e10cSrcweir 	pField->SetAutoIncrement(sal_False);
690*cdf0e10cSrcweir 	pField->SetPrimaryKey(sal_False);
691*cdf0e10cSrcweir 	pField->SetCurrency(sal_False);
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir 	TColumns::iterator aFind = m_aDestColumns.find( aAlias );
694*cdf0e10cSrcweir 	if ( aFind != m_aDestColumns.end() )
695*cdf0e10cSrcweir 	{
696*cdf0e10cSrcweir 		delete aFind->second;
697*cdf0e10cSrcweir 		m_aDestColumns.erase(aFind);
698*cdf0e10cSrcweir 	}
699*cdf0e10cSrcweir 
700*cdf0e10cSrcweir 	m_vDestVector.push_back(m_aDestColumns.insert(TColumns::value_type(aAlias,pField)).first);
701*cdf0e10cSrcweir }
702*cdf0e10cSrcweir // -----------------------------------------------------------------------------
703*cdf0e10cSrcweir sal_Bool ODatabaseExport::createRowSet()
704*cdf0e10cSrcweir {
705*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::createRowSet" );
706*cdf0e10cSrcweir 	DBG_CHKTHIS(ODatabaseExport,NULL);
707*cdf0e10cSrcweir     m_pUpdateHelper.reset(new OParameterUpdateHelper(createPreparedStatment(m_xConnection->getMetaData(),m_xTable,m_vColumns)));
708*cdf0e10cSrcweir 
709*cdf0e10cSrcweir 	return m_pUpdateHelper.get() != NULL;
710*cdf0e10cSrcweir }
711*cdf0e10cSrcweir // -----------------------------------------------------------------------------
712*cdf0e10cSrcweir sal_Bool ODatabaseExport::executeWizard(const ::rtl::OUString& _rTableName,const Any& _aTextColor,const FontDescriptor& _rFont)
713*cdf0e10cSrcweir {
714*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::executeWizard" );
715*cdf0e10cSrcweir 	DBG_CHKTHIS(ODatabaseExport,NULL);
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir     bool bHaveDefaultTable = ( m_sDefaultTableName.getLength() != 0 );
718*cdf0e10cSrcweir     ::rtl::OUString sTableName( bHaveDefaultTable ? m_sDefaultTableName : _rTableName );
719*cdf0e10cSrcweir     OCopyTableWizard aWizard(
720*cdf0e10cSrcweir         NULL,
721*cdf0e10cSrcweir         sTableName,
722*cdf0e10cSrcweir         bHaveDefaultTable ? CopyTableOperation::AppendData : CopyTableOperation::CopyDefinitionAndData,
723*cdf0e10cSrcweir         m_aDestColumns,
724*cdf0e10cSrcweir         m_vDestVector,
725*cdf0e10cSrcweir         m_xConnection,
726*cdf0e10cSrcweir         m_xFormatter,
727*cdf0e10cSrcweir         getTypeSelectionPageFactory(),
728*cdf0e10cSrcweir         m_rInputStream,
729*cdf0e10cSrcweir         m_xFactory
730*cdf0e10cSrcweir     );
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir 	sal_Bool bError = sal_False;
733*cdf0e10cSrcweir 	try
734*cdf0e10cSrcweir 	{
735*cdf0e10cSrcweir 		if (aWizard.Execute())
736*cdf0e10cSrcweir 		{
737*cdf0e10cSrcweir 			switch(aWizard.getOperation())
738*cdf0e10cSrcweir 			{
739*cdf0e10cSrcweir 				case CopyTableOperation::CopyDefinitionAndData:
740*cdf0e10cSrcweir 				case CopyTableOperation::AppendData:
741*cdf0e10cSrcweir 					{
742*cdf0e10cSrcweir 						m_xTable = aWizard.createTable();
743*cdf0e10cSrcweir 						bError = !m_xTable.is();
744*cdf0e10cSrcweir 						if(m_xTable.is())
745*cdf0e10cSrcweir 						{
746*cdf0e10cSrcweir 							m_xTable->setPropertyValue(PROPERTY_FONT,makeAny(_rFont));
747*cdf0e10cSrcweir 							if(_aTextColor.hasValue())
748*cdf0e10cSrcweir 								m_xTable->setPropertyValue(PROPERTY_TEXTCOLOR,_aTextColor);
749*cdf0e10cSrcweir 						}
750*cdf0e10cSrcweir 						m_bIsAutoIncrement	= aWizard.shouldCreatePrimaryKey();
751*cdf0e10cSrcweir 						m_vColumns			= aWizard.GetColumnPositions();
752*cdf0e10cSrcweir 						m_vColumnTypes		= aWizard.GetColumnTypes();
753*cdf0e10cSrcweir                         m_bAppendFirstLine	= !aWizard.UseHeaderLine();
754*cdf0e10cSrcweir 					}
755*cdf0e10cSrcweir 					break;
756*cdf0e10cSrcweir 				default:
757*cdf0e10cSrcweir 					bError = sal_True; // there is no error but I have nothing more to do
758*cdf0e10cSrcweir 			}
759*cdf0e10cSrcweir 		}
760*cdf0e10cSrcweir 		else
761*cdf0e10cSrcweir 			bError = sal_True;
762*cdf0e10cSrcweir 
763*cdf0e10cSrcweir 		if(!bError)
764*cdf0e10cSrcweir 			bError = !createRowSet();
765*cdf0e10cSrcweir 	}
766*cdf0e10cSrcweir 	catch( const SQLException&)
767*cdf0e10cSrcweir 	{
768*cdf0e10cSrcweir         ::dbaui::showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), &aWizard, m_xFactory );
769*cdf0e10cSrcweir 		bError = sal_True;
770*cdf0e10cSrcweir 	}
771*cdf0e10cSrcweir     catch( const Exception& )
772*cdf0e10cSrcweir     {
773*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
774*cdf0e10cSrcweir     }
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir 	return bError;
777*cdf0e10cSrcweir }
778*cdf0e10cSrcweir //---------------------------------------------------------------------------------
779*cdf0e10cSrcweir void ODatabaseExport::showErrorDialog(const ::com::sun::star::sdbc::SQLException& e)
780*cdf0e10cSrcweir {
781*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::showErrorDialog" );
782*cdf0e10cSrcweir 	if(!m_bDontAskAgain)
783*cdf0e10cSrcweir 	{
784*cdf0e10cSrcweir 		String aMsg(e.Message);
785*cdf0e10cSrcweir 		aMsg += '\n';
786*cdf0e10cSrcweir 		aMsg += String( ModuleRes( STR_QRY_CONTINUE ) );
787*cdf0e10cSrcweir 		OSQLWarningBox aBox( NULL, aMsg, WB_YES_NO | WB_DEF_NO );
788*cdf0e10cSrcweir 
789*cdf0e10cSrcweir 		if (aBox.Execute() == RET_YES)
790*cdf0e10cSrcweir 			m_bDontAskAgain = sal_True;
791*cdf0e10cSrcweir 		else
792*cdf0e10cSrcweir 			m_bError = sal_True;
793*cdf0e10cSrcweir 	} // if(!m_bDontAskAgain)
794*cdf0e10cSrcweir }
795*cdf0e10cSrcweir // -----------------------------------------------------------------------------
796*cdf0e10cSrcweir void ODatabaseExport::adjustFormat()
797*cdf0e10cSrcweir {
798*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::adjustFormat" );
799*cdf0e10cSrcweir     if ( m_sTextToken.Len() )
800*cdf0e10cSrcweir 	{
801*cdf0e10cSrcweir         sal_Int32 nNewPos = m_bIsAutoIncrement ? m_nColumnPos+1 : m_nColumnPos;
802*cdf0e10cSrcweir         OSL_ENSURE((nNewPos) < static_cast<sal_Int32>(m_vColumns.size()),"Illegal index for vector");
803*cdf0e10cSrcweir         if ( (nNewPos) < static_cast<sal_Int32>(m_vColumns.size()) )
804*cdf0e10cSrcweir         {
805*cdf0e10cSrcweir 		    sal_Int32 nColPos = m_vColumns[nNewPos].first;
806*cdf0e10cSrcweir 		    if( nColPos != sal::static_int_cast< long >(CONTAINER_ENTRY_NOTFOUND))
807*cdf0e10cSrcweir 		    {
808*cdf0e10cSrcweir                 --nColPos;
809*cdf0e10cSrcweir                 OSL_ENSURE((nColPos) < static_cast<sal_Int32>(m_vNumberFormat.size()),"m_vFormatKey: Illegal index for vector");
810*cdf0e10cSrcweir                 OSL_ENSURE((nColPos) < static_cast<sal_Int32>(m_vColumnSize.size()),"m_vColumnSize: Illegal index for vector");
811*cdf0e10cSrcweir 			    m_vNumberFormat[nColPos] = CheckString(m_sTextToken,m_vNumberFormat[nColPos]);
812*cdf0e10cSrcweir 			    m_vColumnSize[nColPos] = ::std::max<sal_Int32>((sal_Int32)m_vColumnSize[nColPos],(sal_Int32)m_sTextToken.Len());
813*cdf0e10cSrcweir 		    }
814*cdf0e10cSrcweir         }
815*cdf0e10cSrcweir 		eraseTokens();
816*cdf0e10cSrcweir 	}
817*cdf0e10cSrcweir }
818*cdf0e10cSrcweir // -----------------------------------------------------------------------------
819*cdf0e10cSrcweir void ODatabaseExport::eraseTokens()
820*cdf0e10cSrcweir {
821*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::eraseTokens" );
822*cdf0e10cSrcweir     m_sTextToken.Erase();
823*cdf0e10cSrcweir     m_sNumToken.Erase();
824*cdf0e10cSrcweir     m_sValToken.Erase();
825*cdf0e10cSrcweir }
826*cdf0e10cSrcweir // -----------------------------------------------------------------------------
827*cdf0e10cSrcweir void ODatabaseExport::ensureFormatter()
828*cdf0e10cSrcweir {
829*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::ensureFormatter" );
830*cdf0e10cSrcweir     if ( !m_pFormatter )
831*cdf0e10cSrcweir     {
832*cdf0e10cSrcweir         Reference< XNumberFormatsSupplier >  xSupplier = m_xFormatter->getNumberFormatsSupplier();
833*cdf0e10cSrcweir 	    Reference< XUnoTunnel > xTunnel(xSupplier,UNO_QUERY);
834*cdf0e10cSrcweir 	    SvNumberFormatsSupplierObj* pSupplierImpl = (SvNumberFormatsSupplierObj*)sal::static_int_cast< sal_IntPtr >(xTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
835*cdf0e10cSrcweir 	    m_pFormatter = pSupplierImpl ? pSupplierImpl->GetNumberFormatter() : NULL;
836*cdf0e10cSrcweir         Reference<XPropertySet> xNumberFormatSettings = xSupplier->getNumberFormatSettings();
837*cdf0e10cSrcweir         xNumberFormatSettings->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NullDate"))) >>= m_aNullDate;
838*cdf0e10cSrcweir     }
839*cdf0e10cSrcweir }
840*cdf0e10cSrcweir // -----------------------------------------------------------------------------
841*cdf0e10cSrcweir Reference< XPreparedStatement > ODatabaseExport::createPreparedStatment( const Reference<XDatabaseMetaData>& _xMetaData
842*cdf0e10cSrcweir                                                        ,const Reference<XPropertySet>& _xDestTable
843*cdf0e10cSrcweir                                                        ,const TPositions& _rvColumns)
844*cdf0e10cSrcweir {
845*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "ODatabaseExport::createPreparedStatment" );
846*cdf0e10cSrcweir     ::rtl::OUString aSql(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INSERT INTO ")));
847*cdf0e10cSrcweir 	::rtl::OUString sComposedTableName = ::dbtools::composeTableName( _xMetaData, _xDestTable, ::dbtools::eInDataManipulation, false, false, true );
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir 	aSql += sComposedTableName;
850*cdf0e10cSrcweir 	aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ( "));
851*cdf0e10cSrcweir 	// set values and column names
852*cdf0e10cSrcweir 	::rtl::OUString aValues(RTL_CONSTASCII_USTRINGPARAM(" VALUES ( "));
853*cdf0e10cSrcweir 	static ::rtl::OUString aPara(RTL_CONSTASCII_USTRINGPARAM("?,"));
854*cdf0e10cSrcweir 	static ::rtl::OUString aComma(RTL_CONSTASCII_USTRINGPARAM(","));
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir 	::rtl::OUString aQuote;
857*cdf0e10cSrcweir 	if ( _xMetaData.is() )
858*cdf0e10cSrcweir 		aQuote = _xMetaData->getIdentifierQuoteString();
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir 	Reference<XColumnsSupplier> xDestColsSup(_xDestTable,UNO_QUERY_THROW);
861*cdf0e10cSrcweir 
862*cdf0e10cSrcweir 	// create sql string and set column types
863*cdf0e10cSrcweir 	Sequence< ::rtl::OUString> aDestColumnNames = xDestColsSup->getColumns()->getElementNames();
864*cdf0e10cSrcweir     if ( aDestColumnNames.getLength() == 0 )
865*cdf0e10cSrcweir     {
866*cdf0e10cSrcweir         return Reference< XPreparedStatement > ();
867*cdf0e10cSrcweir     }
868*cdf0e10cSrcweir 	const ::rtl::OUString* pIter = aDestColumnNames.getConstArray();
869*cdf0e10cSrcweir 	::std::vector< ::rtl::OUString> aInsertList;
870*cdf0e10cSrcweir 	aInsertList.resize(aDestColumnNames.getLength()+1);
871*cdf0e10cSrcweir 	sal_Int32 i = 0;
872*cdf0e10cSrcweir 	for(sal_uInt32 j=0; j < aInsertList.size() ;++i,++j)
873*cdf0e10cSrcweir 	{
874*cdf0e10cSrcweir 		ODatabaseExport::TPositions::const_iterator aFind = ::std::find_if(_rvColumns.begin(),_rvColumns.end(),
875*cdf0e10cSrcweir 			::std::compose1(::std::bind2nd(::std::equal_to<sal_Int32>(),i+1),::std::select2nd<ODatabaseExport::TPositions::value_type>()));
876*cdf0e10cSrcweir 		if ( _rvColumns.end() != aFind && aFind->second != sal::static_int_cast< long >(CONTAINER_ENTRY_NOTFOUND) && aFind->first != sal::static_int_cast< long >(CONTAINER_ENTRY_NOTFOUND) )
877*cdf0e10cSrcweir 		{
878*cdf0e10cSrcweir             OSL_ENSURE((aFind->first) < static_cast<sal_Int32>(aInsertList.size()),"aInsertList: Illegal index for vector");
879*cdf0e10cSrcweir 			aInsertList[aFind->first] = ::dbtools::quoteName( aQuote,*(pIter+i));
880*cdf0e10cSrcweir 		}
881*cdf0e10cSrcweir 	}
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir 	i = 1;
884*cdf0e10cSrcweir 	// create the sql string
885*cdf0e10cSrcweir     ::std::vector< ::rtl::OUString>::iterator aInsertEnd = aInsertList.end();
886*cdf0e10cSrcweir 	for (::std::vector< ::rtl::OUString>::iterator aInsertIter = aInsertList.begin(); aInsertIter != aInsertEnd; ++aInsertIter)
887*cdf0e10cSrcweir 	{
888*cdf0e10cSrcweir 		if ( aInsertIter->getLength() )
889*cdf0e10cSrcweir 		{
890*cdf0e10cSrcweir 			aSql += *aInsertIter;
891*cdf0e10cSrcweir 			aSql += aComma;
892*cdf0e10cSrcweir 			aValues += aPara;
893*cdf0e10cSrcweir 		}
894*cdf0e10cSrcweir 	}
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir 	aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")")));
897*cdf0e10cSrcweir 	aValues = aValues.replaceAt(aValues.getLength()-1,1,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")")));
898*cdf0e10cSrcweir 
899*cdf0e10cSrcweir 	aSql += aValues;
900*cdf0e10cSrcweir 	// now create,fill and execute the prepared statement
901*cdf0e10cSrcweir 	return Reference< XPreparedStatement >(_xMetaData->getConnection()->prepareStatement(aSql));
902*cdf0e10cSrcweir }
903*cdf0e10cSrcweir // -----------------------------------------------------------------------------
904*cdf0e10cSrcweir 
905*cdf0e10cSrcweir 
906