Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef INCLUDED_DBACCESS_SOURCE_UI_INC_DEXPORT_HXX
20 : #define INCLUDED_DBACCESS_SOURCE_UI_INC_DEXPORT_HXX
21 :
22 : #include <com/sun/star/sdbc/XResultSet.hpp>
23 : #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
24 : #include <com/sun/star/beans/XPropertySet.hpp>
25 : #include <com/sun/star/util/XNumberFormatter.hpp>
26 : #include <com/sun/star/container/XNameAccess.hpp>
27 : #include <com/sun/star/container/XIndexAccess.hpp>
28 : #include <com/sun/star/lang/Locale.hpp>
29 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 : #include <com/sun/star/util/Date.hpp>
31 : #include <com/sun/star/uno/XComponentContext.hpp>
32 : #include <map>
33 : #include <vector>
34 : #include <comphelper/stl_types.hxx>
35 : #include "TypeInfo.hxx"
36 : #include "WTypeSelect.hxx"
37 : #include "commontypes.hxx"
38 : #include "IUpdateHelper.hxx"
39 :
40 : namespace com { namespace sun { namespace star {
41 : namespace awt{
42 : struct FontDescriptor;
43 : }
44 : namespace sdbc{
45 : class XPreparedStatement;
46 : class XDatabaseMetaData;
47 : }
48 : }}}
49 :
50 : #define COLUMN_POSITION_NOT_FOUND ((sal_Int32)-1)
51 :
52 : class SvNumberFormatter;
53 : namespace dbaui
54 : {
55 : class OFieldDescription;
56 : class ODatabaseExport
57 : {
58 : public:
59 : typedef std::map<OUString, OFieldDescription*, ::comphelper::UStringMixLess> TColumns;
60 : typedef ::std::vector<TColumns::const_iterator> TColumnVector;
61 : typedef ::std::vector< ::std::pair<sal_Int32,sal_Int32> > TPositions;
62 :
63 : protected:
64 : TPositions m_vColumns; ///< columns to be used
65 : ::std::vector<sal_Int32> m_vColumnTypes; ///< ColumnTypes for faster access
66 : ::std::vector<sal_Int32> m_vColumnSize;
67 : ::std::vector<sal_Int16> m_vNumberFormat;
68 : ::com::sun::star::lang::Locale m_aLocale;
69 :
70 : TColumns m_aDestColumns; ///< container for new created columns
71 : TColumnVector m_vDestVector;
72 :
73 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTable; ///< dest table
74 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xTables; ///< container
75 : SharedConnection m_xConnection; ///< dest conn
76 :
77 : ::boost::shared_ptr<IUpdateHelper> m_pUpdateHelper;
78 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > m_xResultSet;
79 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > m_xFormatter; ///< a number formatter working with the connection's NumberFormatsSupplier
80 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> m_xContext;
81 : ::com::sun::star::util::Date m_aNullDate;
82 :
83 : SvNumberFormatter* m_pFormatter;
84 : SvStream& m_rInputStream;
85 : /// for saving the selected tablename
86 : OUString m_sDefaultTableName;
87 :
88 : OUString m_sTextToken; ///< cell content
89 : OUString m_sNumToken; ///< SDNUM value
90 : OUString m_sValToken; ///< SDVAL value
91 : TOTypeInfoSP m_pTypeInfo; ///< contains the default type
92 : const TColumnVector* m_pColumnList;
93 : const OTypeInfoMap* m_pInfoMap;
94 : sal_Int32 m_nColumnPos; ///< current column position
95 : sal_Int32 m_nRows; ///< number of rows to be searched
96 : sal_Int32 m_nRowCount; ///< current count of rows
97 : rtl_TextEncoding m_nDefToken; ///< language
98 : bool m_bError; ///< error and termination code
99 : bool m_bInTbl; ///< true, if parser is in RTF table
100 : bool m_bHead; ///< true, if the header hasn't been read yet
101 : bool m_bDontAskAgain;///< if there is an error when pasting, don't show it again
102 : bool m_bIsAutoIncrement; ///< if PKey is set by user
103 : bool m_bFoundTable; ///< set to true when a table was found
104 : bool m_bCheckOnly;
105 : bool m_bAppendFirstLine;
106 :
107 :
108 : virtual bool CreateTable(int nToken) = 0;
109 : virtual TypeSelectionPageFactory
110 : getTypeSelectionPageFactory() = 0;
111 :
112 : void CreateDefaultColumn(const OUString& _rColumnName);
113 : sal_Int16 CheckString(const OUString& aToken, sal_Int16 _nOldNumberFormat);
114 : void adjustFormat();
115 : void eraseTokens();
116 : void insertValueIntoColumn();
117 : bool createRowSet();
118 : void showErrorDialog(const ::com::sun::star::sdbc::SQLException& e);
119 : void ensureFormatter();
120 :
121 : /** executeWizard calls a wizard to create/append data
122 :
123 : @param _sTableName the tablename
124 : @param _aTextColor the text color of the new created table
125 : @param _rFont the font of the new table
126 :
127 : @return true when an error occurs
128 : */
129 : bool executeWizard( const OUString& _sTableName,
130 : const ::com::sun::star::uno::Any& _aTextColor,
131 : const ::com::sun::star::awt::FontDescriptor& _rFont);
132 :
133 : virtual ~ODatabaseExport();
134 :
135 : public:
136 : ODatabaseExport(
137 : const SharedConnection& _rxConnection,
138 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
139 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
140 : const TColumnVector* rList,
141 : const OTypeInfoMap* _pInfoMap,
142 : SvStream& _rInputStream
143 : );
144 :
145 : // required for automatic type recognition
146 : ODatabaseExport(
147 : sal_Int32 nRows,
148 : const TPositions& _rColumnPositions,
149 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
150 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
151 : const TColumnVector* rList,
152 : const OTypeInfoMap* _pInfoMap,
153 : bool _bAutoIncrementEnabled,
154 : SvStream& _rInputStream
155 : );
156 :
157 : void SetColumnTypes(const TColumnVector* rList,const OTypeInfoMap* _pInfoMap);
158 :
159 0 : inline void SetTableName(const OUString &_sTableName){ m_sDefaultTableName = _sTableName ; }
160 :
161 : virtual void release() = 0;
162 :
163 0 : void enableCheckOnly() { m_bCheckOnly = true; }
164 0 : bool isCheckEnabled() const { return m_bCheckOnly; }
165 :
166 : static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > createPreparedStatment( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>& _xMetaData
167 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDestTable
168 : ,const TPositions& _rvColumns);
169 : };
170 : }
171 :
172 : #endif
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|