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