LibreOffice Module sw (master) 1
dbmgr.hxx
Go to the documentation of this file.
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_SW_INC_DBMGR_HXX
20#define INCLUDED_SW_INC_DBMGR_HXX
21
22#include <rtl/ustring.hxx>
23#include <tools/solar.h>
24#include <tools/long.hxx>
25#include <i18nlangtag/lang.h>
26#include <com/sun/star/util/Date.hpp>
27#include "swdllapi.h"
28#include "swdbdata.hxx"
29#include <com/sun/star/uno/Reference.h>
30#include <com/sun/star/uno/Sequence.hxx>
31#include <com/sun/star/lang/Locale.hpp>
32#include <com/sun/star/beans/PropertyValue.hpp>
33
34#include <memory>
35#include <utility>
36#include <vector>
37
38namespace com::sun::star{
39 namespace sdbc{
40 class XConnection;
41 class XStatement;
42 class XDataSource;
43 class XResultSet;
44 }
45 namespace beans{
46
47 class XPropertySet;
48 }
49 namespace sdbcx{
50 class XColumnsSupplier;
51 }
52 namespace util{
53 class XNumberFormatter;
54 }
55 namespace mail{
56 class XSmtpService;
57 }
58 namespace embed { class XStorage; }
59 namespace frame { class XStorable; }
60}
61namespace svx {
62 class ODataAccessDescriptor;
63}
64
66{
67 css::util::Date aNullDate;
68 css::uno::Reference< css::util::XNumberFormatter> xFormatter;
69 css::lang::Locale aLocale;
70};
71
72namespace weld {
73 class ComboBox;
74 class Window;
75}
76
77class SwView;
78class SwWrtShell;
79class ListBox;
81class SwXMailMerge;
83class SwCalc;
84class INetURLObject;
85class SwDocShell;
86
88{
94};
95
96// Administration of (new) logical databases.
97enum class SwDBSelect
98{
100};
101
102struct SwDSParam : public SwDBData
103{
104 css::util::Date aNullDate;
105
106 css::uno::Reference<css::util::XNumberFormatter> xFormatter;
107 css::uno::Reference< css::sdbc::XConnection> xConnection;
108 css::uno::Reference< css::sdbc::XStatement> xStatement;
109 css::uno::Reference< css::sdbc::XResultSet> xResultSet;
110 css::uno::Sequence< css::uno::Any > aSelection;
114
115 SwDSParam(const SwDBData& rData) :
116 SwDBData(rData),
117 bScrollable(false),
118 bEndOfDB(false),
120 {}
121
122 SwDSParam(const SwDBData& rData,
123 css::uno::Reference< css::sdbc::XResultSet> xResSet,
124 const css::uno::Sequence< css::uno::Any >& rSelection) :
125 SwDBData(rData),
126 xResultSet(std::move(xResSet)),
127 aSelection(rSelection),
128 bScrollable(true),
129 bEndOfDB(false),
131 {}
132
133 bool HasValidRecord() const
134 { return( !bEndOfDB && xResultSet.is() ); }
135};
136
137typedef std::vector<std::unique_ptr<SwDSParam>> SwDSParams_t;
138
140{
144
152
159 css::uno::Sequence< css::beans::PropertyValue > aSaveToFilterData;
174 OUString sPrefix;
189 OUString sSubject;
190 OUString sMailBody;
192 css::uno::Sequence< OUString > aCopiesTo;
193 css::uno::Sequence< OUString > aBlindCopiesTo;
194 css::uno::Reference< css::mail::XSmtpService > xSmtpServer;
205 OUString sDBcolumn;
206
210
217 css::uno::Sequence< css::beans::PropertyValue > aPrintOptions;
221
223 SwWrtShell& rShell,
224 const svx::ODataAccessDescriptor& rDesc ) :
226 rSh(rShell),
227 rDescriptor(rDesc),
228 bCreateSingleFile( false ),
229 bPrefixIsFilename( false ),
230 bSendAsHTML( true ),
231 bSendAsAttachment( false ),
232 pMailMergeConfigItem( nullptr )
233 {
235 bCreateSingleFile = true;
236 }
237};
238
239class SwDoc;
240
242{
243 struct SwDBManager_Impl;
246
247 enum class MergeStatus
248 {
249 Ok = 0, Cancel, Error
250 };
251
254 bool m_bInMerge : 1;
255 bool m_bMergeSilent : 1;
257 std::unique_ptr<SwDBManager_Impl> m_pImpl;
261
263 static std::vector<std::pair<SwDocShell*, OUString>> s_aUncommittedRegistrations;
264
266 std::vector<OUString> m_aNotUsedConnections;
267
269 void SetAsUsed(const OUString& rName);
270
273
274 SAL_DLLPRIVATE SwDSParam* FindDSData(const SwDBData& rData, bool bCreate);
275 SAL_DLLPRIVATE SwDSParam* FindDSConnection(const OUString& rSource, bool bCreate);
276
278 SAL_DLLPRIVATE void ImportFromConnection( SwWrtShell* pSh);
279
281 SAL_DLLPRIVATE void ImportDBEntry(SwWrtShell* pSh);
282
284 SAL_DLLPRIVATE bool MergeMailFiles( SwWrtShell* pSh,
285 const SwMergeDescriptor& rMergeDescriptor );
286
287 SAL_DLLPRIVATE bool ToNextMergeRecord();
288 SAL_DLLPRIVATE bool IsValidMergeRecord() const;
289 SAL_DLLPRIVATE void ImplDestroy();
290
291 SwDBManager(SwDBManager const&) = delete;
293
294public:
295 SwDBManager(SwDoc* pDoc);
296 ~SwDBManager();
297
299 const SwXMailMerge * GetMailMergeEvtSrc() const { return m_pMergeEvtSrc; }
300 void SetMailMergeEvtSrc( const SwXMailMerge *pSrc ) { m_pMergeEvtSrc = pSrc; }
301
302 bool IsMergeSilent() const { return m_bMergeSilent; }
303 void SetMergeSilent( bool bVal ) { m_bMergeSilent = bVal; }
304
306 bool Merge( const SwMergeDescriptor& rMergeDesc );
307 void MergeCancel();
308
309 bool IsMergeOk() const { return MergeStatus::Ok == m_aMergeStatus; }
310 bool IsMergeError() const { return MergeStatus::Error <= m_aMergeStatus; }
311
312 static std::shared_ptr<SwMailMergeConfigItem> PerformMailMerge(SwView const * pView);
313
315 bool IsInitDBFields() const { return m_bInitDBFields; }
316 void SetInitDBFields(bool b) { m_bInitDBFields = b; }
317
319 bool GetTableNames(weld::ComboBox& rBox, const OUString& rDBName);
320
322 void GetColumnNames(weld::ComboBox& rBox,
323 const OUString& rDBName, const OUString& rTableName);
325 css::uno::Reference< css::sdbc::XConnection> const & xConnection,
326 const OUString& rTableName);
327
328 static sal_uLong GetColumnFormat( css::uno::Reference< css::sdbc::XDataSource> const & xSource,
329 css::uno::Reference< css::sdbc::XConnection> const & xConnection,
330 css::uno::Reference< css::beans::XPropertySet> const & xColumn,
331 SvNumberFormatter* pNFormatr,
332 LanguageType nLanguage );
333
334 sal_uLong GetColumnFormat( const OUString& rDBName,
335 const OUString& rTableName,
336 const OUString& rColNm,
337 SvNumberFormatter* pNFormatr,
338 LanguageType nLanguage );
339 sal_Int32 GetColumnType( const OUString& rDBName,
340 const OUString& rTableName,
341 const OUString& rColNm );
342
343 bool IsInMerge() const { return m_bInMerge; }
344
345 void ExecuteFormLetter(SwWrtShell& rSh,
346 const css::uno::Sequence< css::beans::PropertyValue>& rProperties);
347
348 static void InsertText(SwWrtShell& rSh,
349 const css::uno::Sequence< css::beans::PropertyValue>& rProperties);
350
352 bool IsDataSourceOpen(const OUString& rDataSource,
353 const OUString& rTableOrQuery, bool bMergeShell);
354
356 bool OpenDataSource(const OUString& rDataSource, const OUString& rTableOrQuery);
357 sal_uInt32 GetSelectedRecordId(const OUString& rDataSource, const OUString& rTableOrQuery, sal_Int32 nCommandType = -1);
358 bool GetColumnCnt(const OUString& rSourceName, const OUString& rTableName,
359 const OUString& rColumnName, sal_uInt32 nAbsRecordId, LanguageType nLanguage,
360 OUString& rResult, double* pNumber);
363 css::uno::Reference< css::sdbc::XConnection> const &
364 RegisterConnection(OUString const& rSource);
365
366 void CreateDSData(const SwDBData& rData)
367 { FindDSData(rData, true); }
368 const SwDSParams_t& GetDSParamArray() const { return m_DataSourceParams; }
369
371 void CloseAll(bool bIncludingMerge = true);
372
373 bool GetMergeColumnCnt(const OUString& rColumnName, LanguageType nLanguage,
374 OUString &rResult, double *pNumber);
375 bool FillCalcWithMergeData(SvNumberFormatter *pDocFormatter,
376 LanguageType nLanguage, SwCalc &aCalc);
377 void ToNextRecord(const OUString& rDataSource, const OUString& rTableOrQuery);
378
379 sal_uInt32 GetSelectedRecordId();
380 bool ToRecordId(sal_Int32 nSet);
381
382 static const SwDBData& GetAddressDBName();
383
384 static OUString GetDBField(
385 css::uno::Reference< css::beans::XPropertySet > const & xColumnProp,
386 const SwDBFormatData& rDBFormatData,
387 double *pNumber = nullptr);
388
389 static css::uno::Reference< css::sdbc::XConnection>
390 GetConnection(const OUString& rDataSource,
391 css::uno::Reference< css::sdbc::XDataSource>& rxSource,
392 const SwView* pView);
393
394 static css::uno::Reference< css::sdbcx::XColumnsSupplier>
395 GetColumnSupplier(css::uno::Reference< css::sdbc::XConnection> const & xConnection,
396 const OUString& rTableOrQuery,
397 SwDBSelect eTableOrQuery = SwDBSelect::UNKNOWN);
398
399 static css::uno::Sequence<OUString> GetExistingDatabaseNames();
400
408 static OUString LoadAndRegisterDataSource(weld::Window* pParent, SwDocShell* pDocShell = nullptr);
409
416 static OUString LoadAndRegisterDataSource(std::u16string_view rURI, const OUString *pDestDir);
417
419 void LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const SwDocShell& rDocShell);
420
422 static void RevokeDataSource(const OUString& rName);
423
433 static css::uno::Reference< css::sdbc::XDataSource>
434 getDataSourceAsParent(const css::uno::Reference< css::sdbc::XConnection>& _xConnection,const OUString& _sDataSourceName);
435
449 static css::uno::Reference< css::sdbc::XResultSet>
450 createCursor(const OUString& _sDataSourceName,
451 const OUString& _sCommand,
452 sal_Int32 _nCommandType,
453 const css::uno::Reference< css::sdbc::XConnection>& _xConnection,
454 const SwView* pView);
455
456 void setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell);
457 const OUString& getEmbeddedName() const;
458
459 // rOwnURL should be taken using INetURLObject::GetMainURL(INetURLObject::DecodeMechanism::NONE)
460 static void StoreEmbeddedDataSource(const css::uno::Reference<css::frame::XStorable>& xStorable,
461 const css::uno::Reference<css::embed::XStorage>& xStorage,
462 const OUString& rStreamRelPath,
463 const OUString& rOwnURL, bool bCopyTo = false);
464
465 SwDoc* getDoc() const;
467 void releaseRevokeListener();
468
470 void RevokeLastRegistrations();
471
473 void CommitLastRegistrations();
474
476 void RevokeNotUsedConnections();
477};
478
479namespace sw
480{
482{
483 UNKNOWN = 0,
484 ODB,
485 CALC,
486 DBASE,
487 FLAT,
488 MSJET,
489 MSACE,
490 WRITER
491};
492
494}
495
496#endif
497
498/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: calc.hxx:200
std::vector< OUString > m_aNotUsedConnections
Not used connections.
Definition: dbmgr.hxx:266
bool IsInMerge() const
Definition: dbmgr.hxx:343
const SwXMailMerge * m_pMergeEvtSrc
!= 0 if mail merge events are to be send
Definition: dbmgr.hxx:258
SwDBManager & operator=(SwDBManager const &)=delete
static std::vector< std::pair< SwDocShell *, OUString > > s_aUncommittedRegistrations
Store last registrations to revoke or commit.
Definition: dbmgr.hxx:263
bool m_bInMerge
merge process active
Definition: dbmgr.hxx:254
void CreateDSData(const SwDBData &rData)
Definition: dbmgr.hxx:366
const SwDSParams_t & GetDSParamArray() const
Definition: dbmgr.hxx:368
static sal_uLong GetColumnFormat(css::uno::Reference< css::sdbc::XDataSource > const &xSource, css::uno::Reference< css::sdbc::XConnection > const &xConnection, css::uno::Reference< css::beans::XPropertySet > const &xColumn, SvNumberFormatter *pNFormatr, LanguageType nLanguage)
void SetMergeSilent(bool bVal)
Definition: dbmgr.hxx:303
const SwXMailMerge * GetMailMergeEvtSrc() const
MailMergeEvent source.
Definition: dbmgr.hxx:299
SwDBManager(SwDBManager const &)=delete
bool IsMergeOk() const
Definition: dbmgr.hxx:309
bool m_bMergeSilent
suppress display of dialogs/boxes (used when called over API)
Definition: dbmgr.hxx:255
static void GetColumnNames(weld::ComboBox &rBox, css::uno::Reference< css::sdbc::XConnection > const &xConnection, const OUString &rTableName)
OUString m_sEmbeddedName
Name of the embedded database that's included in the current document.
Definition: dbmgr.hxx:260
bool IsMergeSilent() const
Definition: dbmgr.hxx:302
SwDSParams_t m_DataSourceParams
Definition: dbmgr.hxx:256
bool m_bInitDBFields
Definition: dbmgr.hxx:253
bool IsInitDBFields() const
Initialize data fields that lack name of database.
Definition: dbmgr.hxx:315
void SetMailMergeEvtSrc(const SwXMailMerge *pSrc)
Definition: dbmgr.hxx:300
SwDoc * m_pDoc
The document that owns this manager.
Definition: dbmgr.hxx:272
MergeStatus m_aMergeStatus
current / last merge status
Definition: dbmgr.hxx:252
void SetInitDBFields(bool b)
Definition: dbmgr.hxx:316
bool IsMergeError() const
Definition: dbmgr.hxx:310
std::unique_ptr< SwDBManager_Impl > m_pImpl
Definition: dbmgr.hxx:257
Definition: doc.hxx:197
Definition: view.hxx:146
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
Gives UNO access to the global mail merge functionality, via the com.sun.star.text....
DBManagerOptions
Definition: dbmgr.hxx:88
@ DBMGR_MERGE_EMAIL
Send mail merge as email.
Definition: dbmgr.hxx:91
@ DBMGR_MERGE
Data records in fields.
Definition: dbmgr.hxx:89
@ DBMGR_MERGE_SHELL
Create merge doc and keep the doc shell.
Definition: dbmgr.hxx:93
@ DBMGR_MERGE_PRINTER
Print mail merge.
Definition: dbmgr.hxx:90
@ DBMGR_MERGE_FILE
Save mail merge as files.
Definition: dbmgr.hxx:92
SwDBSelect
Definition: dbmgr.hxx:98
std::vector< std::unique_ptr< SwDSParam > > SwDSParams_t
Definition: dbmgr.hxx:137
WRITER
UNKNOWN
CALC
OUString sAttachmentName
Definition: dbmgr.hxx:191
css::uno::Sequence< OUString > aBlindCopiesTo
Definition: dbmgr.hxx:193
bool bSendAsAttachment
Definition: dbmgr.hxx:196
OUString sSubject
Definition: dbmgr.hxx:189
css::uno::Sequence< OUString > aCopiesTo
Definition: dbmgr.hxx:192
css::uno::Reference< css::mail::XSmtpService > xSmtpServer
Definition: dbmgr.hxx:194
OUString sMailBody
Definition: dbmgr.hxx:190
OUString sPrefix
Basename incl.
Definition: dbmgr.hxx:174
OUString sDBPasswordColumn
DB column to fetch password.
Definition: dbmgr.hxx:209
bool bPrefixIsFilename
Use the sPrefix as the target filename also overwriting an existing target file.
Definition: dbmgr.hxx:182
OUString sDBcolumn
DB column to fetch EMail of Filename from.
Definition: dbmgr.hxx:205
css::uno::Sequence< css::beans::PropertyValue > aPrintOptions
Definition: dbmgr.hxx:217
OUString sSaveToFilter
Definition: dbmgr.hxx:157
css::uno::Sequence< css::beans::PropertyValue > aSaveToFilterData
Definition: dbmgr.hxx:159
OUString sSaveToFilterOptions
Definition: dbmgr.hxx:158
class SAL_NO_VTABLE XPropertySet
Error
Dialog to specify the properties of date form field.
DBConnURIType GetDBunoType(const INetURLObject &rURL)
Definition: dbmgr.cxx:2544
DBConnURIType
Definition: dbmgr.hxx:482
long Long
QPRO_FUNC_TYPE nType
sal_uIntPtr sal_uLong
css::util::Date aNullDate
Definition: dbmgr.hxx:67
css::uno::Reference< css::util::XNumberFormatter > xFormatter
Definition: dbmgr.hxx:68
css::lang::Locale aLocale
Definition: dbmgr.hxx:69
css::uno::Reference< css::util::XNumberFormatter > xFormatter
Definition: dbmgr.hxx:106
SwDSParam(const SwDBData &rData)
Definition: dbmgr.hxx:115
css::uno::Reference< css::sdbc::XResultSet > xResultSet
Definition: dbmgr.hxx:109
css::uno::Reference< css::sdbc::XStatement > xStatement
Definition: dbmgr.hxx:108
bool bEndOfDB
Definition: dbmgr.hxx:112
css::util::Date aNullDate
Definition: dbmgr.hxx:104
SwDSParam(const SwDBData &rData, css::uno::Reference< css::sdbc::XResultSet > xResSet, const css::uno::Sequence< css::uno::Any > &rSelection)
Definition: dbmgr.hxx:122
css::uno::Reference< css::sdbc::XConnection > xConnection
Definition: dbmgr.hxx:107
bool bScrollable
Definition: dbmgr.hxx:111
css::uno::Sequence< css::uno::Any > aSelection
Definition: dbmgr.hxx:110
bool HasValidRecord() const
Definition: dbmgr.hxx:133
tools::Long nSelectionIndex
Definition: dbmgr.hxx:113
const svx::ODataAccessDescriptor & rDescriptor
Definition: dbmgr.hxx:143
const DBManagerOptions nMergeType
Definition: dbmgr.hxx:141
SwMergeDescriptor(const DBManagerOptions nType, SwWrtShell &rShell, const svx::ODataAccessDescriptor &rDesc)
Definition: dbmgr.hxx:222
SwMailMergeConfigItem * pMailMergeConfigItem
Definition: dbmgr.hxx:220
bool bCreateSingleFile
Create a single or multiple results.
Definition: dbmgr.hxx:151
SwWrtShell & rSh
Definition: dbmgr.hxx:142
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
TABLE