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 DBAUI_DATABASEEXPORT_HXX
20 : #define DBAUI_DATABASEEXPORT_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 <vector>
32 : #include <tools/string.hxx>
33 : #include <comphelper/stl_types.hxx>
34 : #include "TypeInfo.hxx"
35 : #include "WTypeSelect.hxx"
36 : #include "commontypes.hxx"
37 : #include "IUpdateHelper.hxx"
38 :
39 : namespace com { namespace sun { namespace star {
40 : namespace awt{
41 : struct FontDescriptor;
42 : }
43 : namespace sdbc{
44 : class XPreparedStatement;
45 : class XDatabaseMetaData;
46 : }
47 : }}}
48 :
49 : #define COLUMN_POSITION_NOT_FOUND ((sal_Int32)-1)
50 :
51 : class SvNumberFormatter;
52 : namespace dbaui
53 : {
54 : class OFieldDescription;
55 : class ODatabaseExport
56 : {
57 : public:
58 : DECLARE_STL_MAP(::rtl::OUString,OFieldDescription*,::comphelper::UStringMixLess,TColumns);
59 : typedef ::std::vector<TColumns::const_iterator> TColumnVector;
60 : typedef ::std::vector< ::std::pair<sal_Int32,sal_Int32> > TPositions;
61 :
62 : protected:
63 : TPositions m_vColumns; ///< columns to be used
64 : ::std::vector<sal_Int32> m_vColumnTypes; ///< ColumnTypes for faster access
65 : ::std::vector<sal_Int32> m_vColumnSize;
66 : ::std::vector<sal_Int16> m_vNumberFormat;
67 : ::com::sun::star::lang::Locale m_aLocale;
68 :
69 : TColumns m_aDestColumns; ///< container for new created columns
70 : TColumnVector m_vDestVector;
71 :
72 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTable; ///< dest table
73 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xTables; ///< container
74 : SharedConnection m_xConnection; ///< dest conn
75 :
76 : ::boost::shared_ptr<IUpdateHelper> m_pUpdateHelper;
77 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > m_xResultSet;
78 : ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > m_xFormatter; ///< a number formatter working with the connection's NumberFormatsSupplier
79 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> m_xContext;
80 : ::com::sun::star::util::Date m_aNullDate;
81 :
82 : SvNumberFormatter* m_pFormatter;
83 : SvStream& m_rInputStream;
84 : /// for saving the selected tablename
85 : ::rtl::OUString m_sDefaultTableName;
86 :
87 : String m_sTextToken; ///< cell content
88 : String m_sNumToken; ///< SDNUM value
89 : String m_sValToken; ///< SDVAL value
90 : TOTypeInfoSP m_pTypeInfo; ///< contains the default type
91 : const TColumnVector* m_pColumnList;
92 : const OTypeInfoMap* m_pInfoMap;
93 : sal_Int32 m_nColumnPos; ///< current column position
94 : sal_Int32 m_nRows; ///< number of rows to be searched
95 : sal_Int32 m_nRowCount; ///< current count of rows
96 : rtl_TextEncoding m_nDefToken; ///< language
97 : sal_Bool m_bError; ///< error and termination code
98 : sal_Bool m_bInTbl; ///< true, if parser is in RTF table
99 : sal_Bool m_bHead; ///< true, if the header hasn't been read yet
100 : sal_Bool m_bDontAskAgain;///< if there is an error when pasting, don't show it again
101 : sal_Bool m_bIsAutoIncrement; ///< if PKey is set by user
102 : sal_Bool m_bFoundTable; ///< set to true when a table was found
103 : sal_Bool m_bCheckOnly;
104 : bool m_bAppendFirstLine;
105 :
106 :
107 : virtual sal_Bool CreateTable(int nToken) = 0;
108 : virtual TypeSelectionPageFactory
109 : getTypeSelectionPageFactory() = 0;
110 :
111 : void CreateDefaultColumn(const ::rtl::OUString& _rColumnName);
112 : sal_Int16 CheckString(const String& aToken, sal_Int16 _nOldNumberFormat);
113 : void adjustFormat();
114 : void eraseTokens();
115 : void insertValueIntoColumn();
116 : sal_Bool createRowSet();
117 : void showErrorDialog(const ::com::sun::star::sdbc::SQLException& e);
118 : void ensureFormatter();
119 :
120 : /** executeWizard calls a wizard to create/append data
121 :
122 : @param _sTableName the tablename
123 : @param _aTextColor the text color of the new created table
124 : @param _rFont the font of the new table
125 :
126 : @return true when an error occurs
127 : */
128 : sal_Bool executeWizard( const ::rtl::OUString& _sTableName,
129 : const ::com::sun::star::uno::Any& _aTextColor,
130 : const ::com::sun::star::awt::FontDescriptor& _rFont);
131 :
132 : virtual ~ODatabaseExport();
133 :
134 : public:
135 : ODatabaseExport(
136 : const SharedConnection& _rxConnection,
137 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
138 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
139 : const TColumnVector* rList,
140 : const OTypeInfoMap* _pInfoMap,
141 : SvStream& _rInputStream
142 : );
143 :
144 : // required for automatic type recognition
145 : ODatabaseExport(
146 : sal_Int32 nRows,
147 : const TPositions& _rColumnPositions,
148 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter >& _rxNumberF,
149 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
150 : const TColumnVector* rList,
151 : const OTypeInfoMap* _pInfoMap,
152 : sal_Bool _bAutoIncrementEnabled,
153 : SvStream& _rInputStream
154 : );
155 :
156 : void SetColumnTypes(const TColumnVector* rList,const OTypeInfoMap* _pInfoMap);
157 :
158 0 : inline void SetTableName(const ::rtl::OUString &_sTableName){ m_sDefaultTableName = _sTableName ; }
159 :
160 : virtual void release() = 0;
161 :
162 0 : void enableCheckOnly() { m_bCheckOnly = sal_True; }
163 0 : sal_Bool isCheckEnabled() const { return m_bCheckOnly; }
164 :
165 : static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > createPreparedStatment( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>& _xMetaData
166 : ,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xDestTable
167 : ,const TPositions& _rvColumns);
168 : };
169 : }
170 :
171 : #endif
172 :
173 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|