xref: /trunk/main/dbaccess/source/ui/inc/DExport.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef DBAUI_DATABASEEXPORT_HXX
28 #define DBAUI_DATABASEEXPORT_HXX
29 
30 #include <com/sun/star/sdbc/XResultSet.hpp>
31 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/util/XNumberFormatter.hpp>
34 #include <com/sun/star/container/XNameAccess.hpp>
35 #include <com/sun/star/container/XIndexAccess.hpp>
36 #include <com/sun/star/lang/Locale.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/util/Date.hpp>
39 #include <vector>
40 #include <tools/string.hxx>
41 #include <comphelper/stl_types.hxx>
42 #include "TypeInfo.hxx"
43 #include "WTypeSelect.hxx"
44 #include "commontypes.hxx"
45 #include "IUpdateHelper.hxx"
46 #include "WTypeSelect.hxx"
47 
48 namespace com { namespace sun { namespace star {
49     namespace awt{
50         struct FontDescriptor;
51     }
52     namespace sdbc{
53         class XPreparedStatement;
54         class XDatabaseMetaData;
55     }
56 }}}
57 
58 #define COLUMN_POSITION_NOT_FOUND   ((sal_Int32)-1)
59 
60 class Window;
61 class SvNumberFormatter;
62 namespace dbaui
63 {
64     class OFieldDescription;
65     class OTypeInfo;
66     class OWizTypeSelect;
67     class ODatabaseExport
68     {
69     public:
70         DECLARE_STL_MAP(::rtl::OUString,OFieldDescription*,::comphelper::UStringMixLess,TColumns);
71         typedef ::std::vector<TColumns::const_iterator>             TColumnVector;
72         typedef ::std::vector< ::std::pair<sal_Int32,sal_Int32> >   TPositions;
73 
74     protected:
75         TPositions                      m_vColumns;     // Welche Spalten "ubernommen werden sollen
76         ::std::vector<sal_Int32>        m_vColumnTypes; // FeldTypen f"ur schnelleren Zugriff
77         ::std::vector<sal_Int32>        m_vColumnSize;
78         ::std::vector<sal_Int16>        m_vNumberFormat;
79         ::com::sun::star::lang::Locale  m_aLocale;
80 
81         TColumns                        m_aDestColumns; // container for new created columns
82         TColumnVector                   m_vDestVector;
83 
84         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >       m_xTable;       // dest table
85         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>     m_xTables;      // container
86         SharedConnection                                                                m_xConnection;  // dest conn
87 
88         ::boost::shared_ptr<IUpdateHelper>                                              m_pUpdateHelper;
89         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >          m_xResultSet;   //
90         ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >    m_xFormatter;   // a number formatter working with the connection's NumberFormatsSupplier
91         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory> m_xFactory;
92         ::com::sun::star::util::Date                                                    m_aNullDate;
93 
94         SvNumberFormatter*  m_pFormatter;
95         SvStream&           m_rInputStream;
96         //dyf add 2006/06/01
97         //for save the selected tablename
98         ::rtl::OUString     m_sDefaultTableName;
99         //dyf add end
100         String              m_sTextToken;       // Zellen Inhalt
101         String              m_sNumToken;        /// SDNUM value
102         String              m_sValToken;        /// SDVAL value
103         TOTypeInfoSP        m_pTypeInfo;    // contains the default type
104         const TColumnVector* m_pColumnList;
105         const OTypeInfoMap* m_pInfoMap;
106         sal_Int32           m_nColumnPos;       // aktuelle Spaltenposition
107         sal_Int32           m_nRows;        // Anzahl der Zeilen die durchsucht werden sollen
108         sal_Int32           m_nRowCount;    // current count of rows
109         rtl_TextEncoding    m_nDefToken;        // Sprache
110         sal_Bool            m_bError;           // Fehler und Abbruchstatus
111         sal_Bool            m_bInTbl;           // Ist gesetzt, wenn der Parser sich in der RTF Tabelle befindet
112         sal_Bool            m_bHead;        // ist true, wenn die Kopfzeile noch nicht gelesen wurde
113         sal_Bool            m_bDontAskAgain;// Falls beim Einf"ugen ein Fehler auftritt, soll die Fehlermeldung nicht
114         sal_Bool            m_bIsAutoIncrement; // if PKey is set by user
115         sal_Bool            m_bFoundTable;      // set to true when a table was found
116         sal_Bool            m_bCheckOnly;
117         bool                m_bAppendFirstLine;
118 
119 
120         virtual sal_Bool        CreateTable(int nToken)         = 0;
121         virtual TypeSelectionPageFactory
122                                 getTypeSelectionPageFactory()   = 0;
123 
124         void                    CreateDefaultColumn(const ::rtl::OUString& _rColumnName);
125         sal_Int16               CheckString(const String& aToken, sal_Int16 _nOldNumberFormat);
126         void                    adjustFormat();
127         void                    eraseTokens();
128         void                    insertValueIntoColumn();
129         sal_Bool                createRowSet();
130         void                    showErrorDialog(const ::com::sun::star::sdbc::SQLException& e);
131         void                    ensureFormatter();
132 
133         /** executeWizard calls a wizard to create/append data
134             @param  _sTableName the tablename
135             @param  _aTextColor the text color of the new created table
136             @param  _rFont      the font of the new table
137 
138             @return true when an error occurs
139         */
140         sal_Bool                executeWizard(  const ::rtl::OUString& _sTableName,
141                                                 const ::com::sun::star::uno::Any& _aTextColor,
142                                                 const ::com::sun::star::awt::FontDescriptor& _rFont);
143 
144         virtual ~ODatabaseExport();
145     public:
146         ODatabaseExport(
147             const SharedConnection& _rxConnection,
148             const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
149             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM,
150             const TColumnVector* rList,
151             const OTypeInfoMap* _pInfoMap,
152             SvStream& _rInputStream
153         );
154 
155         // wird f"ur auto. Typ-Erkennung gebraucht
156         ODatabaseExport(
157             sal_Int32 nRows,
158             const TPositions& _rColumnPositions,
159             const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
160             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rM,
161             const TColumnVector* rList,
162             const OTypeInfoMap* _pInfoMap,
163             sal_Bool _bAutoIncrementEnabled,
164             SvStream& _rInputStream
165         );
166 
167         void    SetColumnTypes(const TColumnVector* rList,const OTypeInfoMap* _pInfoMap);
168 
169         //dyf add 20070601
170         inline void                    SetTableName(const ::rtl::OUString &_sTableName){ m_sDefaultTableName = _sTableName ; }
171         //dyf add end
172 
173         virtual void release() = 0;
174 
175         void enableCheckOnly() { m_bCheckOnly = sal_True; }
176         sal_Bool isCheckEnabled() const { return m_bCheckOnly; }
177 
178         static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > createPreparedStatment( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>& _xMetaData
179                                                        ,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDestTable
180                                                        ,const TPositions& _rvColumns);
181     };
182 }
183 
184 #endif // DBAUI_DATABASEEXPORT_HXX
185 
186 
187 
188 
189 
190