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