LibreOffice Module sw (master)  1
dbmgr.cxx
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 
20 #include <sal/config.h>
21 
22 #include <cassert>
23 
24 #include <unotxdoc.hxx>
25 #include <sfx2/app.hxx>
26 #include <com/sun/star/sdb/CommandType.hpp>
27 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include <com/sun/star/lang/XEventListener.hpp>
30 #include <com/sun/star/uri/UriReferenceFactory.hpp>
31 #include <com/sun/star/uri/VndSunStarPkgUrlReferenceFactory.hpp>
32 #include <com/sun/star/util/NumberFormatter.hpp>
33 #include <com/sun/star/sdb/DatabaseContext.hpp>
34 #include <com/sun/star/sdb/TextConnectionSettings.hpp>
35 #include <com/sun/star/sdb/XCompletedConnection.hpp>
36 #include <com/sun/star/sdb/XCompletedExecution.hpp>
37 #include <com/sun/star/container/XChild.hpp>
38 #include <com/sun/star/text/MailMergeEvent.hpp>
39 #include <com/sun/star/frame/XStorable.hpp>
40 #include <com/sun/star/task/InteractionHandler.hpp>
41 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
42 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <vcl/errinf.hxx>
45 #include <vcl/print.hxx>
46 #include <sfx2/fcontnr.hxx>
47 #include <sfx2/filedlghelper.hxx>
48 #include <sfx2/viewfrm.hxx>
49 #include <dbconfig.hxx>
50 #include <unotools/tempfile.hxx>
51 #include <unotools/pathoptions.hxx>
52 #include <svl/zforlist.hxx>
53 #include <svl/stritem.hxx>
54 #include <sfx2/docfile.hxx>
55 #include <sfx2/docfilt.hxx>
56 #include <sfx2/progress.hxx>
57 #include <sfx2/dispatch.hxx>
58 #include <cmdid.h>
59 #include <swmodule.hxx>
60 #include <view.hxx>
61 #include <docsh.hxx>
62 #include <edtwin.hxx>
63 #include <wrtsh.hxx>
64 #include <fldbas.hxx>
65 #include <dbui.hxx>
66 #include <dbmgr.hxx>
67 #include <doc.hxx>
70 #include <IDocumentUndoRedo.hxx>
71 #include <swwait.hxx>
72 #include <swunohelper.hxx>
73 #include <strings.hrc>
74 #include <mmconfigitem.hxx>
75 #include <com/sun/star/sdbc/XRowSet.hpp>
76 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
77 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
78 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
79 #include <com/sun/star/sdb/XColumn.hpp>
80 #include <com/sun/star/sdbc/DataType.hpp>
81 #include <com/sun/star/sdbc/ResultSetType.hpp>
82 #include <com/sun/star/sdbc/SQLException.hpp>
83 #include <com/sun/star/mail/MailAttachment.hpp>
85 #include <comphelper/property.hxx>
87 #include <comphelper/string.hxx>
88 #include <comphelper/types.hxx>
89 #include <mailmergehelper.hxx>
90 #include <maildispatcher.hxx>
91 #include <svtools/htmlcfg.hxx>
93 #include <com/sun/star/util/XNumberFormatTypes.hpp>
94 #include <svl/numuno.hxx>
95 #include <connectivity/dbtools.hxx>
97 #include <unotools/charclass.hxx>
98 #include <tools/diagnose_ex.h>
99 
100 #include <unomailmerge.hxx>
101 #include <sfx2/event.hxx>
103 #include <osl/mutex.hxx>
104 #include <rtl/textenc.h>
105 #include <rtl/tencinfo.h>
106 #include <cppuhelper/implbase.hxx>
107 #include <ndindex.hxx>
108 #include <swevent.hxx>
109 #include <sal/log.hxx>
110 #include <swabstdlg.hxx>
111 #include <vector>
112 #include <section.hxx>
113 #include <rootfrm.hxx>
114 #include <calc.hxx>
115 #include <dbfld.hxx>
116 #include <IDocumentState.hxx>
117 #include <imaildsplistener.hxx>
118 #include <iodetect.hxx>
119 #include <IDocumentDeviceAccess.hxx>
120 
121 #include <memory>
123 
124 using namespace ::com::sun::star;
125 using namespace sw;
126 
127 #define DB_SEP_SPACE 0
128 #define DB_SEP_TAB 1
129 #define DB_SEP_RETURN 2
130 #define DB_SEP_NEWLINE 3
131 
132 namespace {
133 
134 void lcl_emitEvent(SfxEventHintId nEventId, sal_Int32 nStrId, SfxObjectShell* pDocShell)
135 {
136  SfxGetpApp()->NotifyEvent(SfxEventHint(nEventId,
137  SwDocShell::GetEventName(nStrId),
138  pDocShell));
139 }
140 
141 }
142 
143 std::vector<std::pair<SwDocShell*, OUString>> SwDBManager::m_aUncommittedRegistrations;
144 
145 namespace {
146 
147 enum class SwDBNextRecord { NEXT, FIRST };
148 
149 }
150 
151 static bool lcl_ToNextRecord( SwDSParam* pParam, const SwDBNextRecord action = SwDBNextRecord::NEXT );
152 
153 namespace {
154 
155 enum class WorkingDocType { SOURCE, TARGET, COPY };
156 
157 }
158 
160  const WorkingDocType aType, const SwWrtShell &rSourceWrtShell,
161  const vcl::Window *pSourceWindow,
162  SwDBManager** const ppDBManager,
163  SwView** const pView, SwWrtShell** const pWrtShell, SwDoc** const pDoc );
164 
165 static bool lcl_getCountFromResultSet( sal_Int32& rCount, const SwDSParam* pParam )
166 {
167  rCount = pParam->aSelection.getLength();
168  if ( rCount > 0 )
169  return true;
170 
171  uno::Reference<beans::XPropertySet> xPrSet(pParam->xResultSet, uno::UNO_QUERY);
172  if ( xPrSet.is() )
173  {
174  try
175  {
176  bool bFinal = false;
177  uno::Any aFinal = xPrSet->getPropertyValue("IsRowCountFinal");
178  aFinal >>= bFinal;
179  if(!bFinal)
180  {
181  pParam->xResultSet->last();
182  pParam->xResultSet->first();
183  }
184  uno::Any aCount = xPrSet->getPropertyValue("RowCount");
185  if( aCount >>= rCount )
186  return true;
187  }
188  catch(const uno::Exception&)
189  {
190  }
191  }
192  return false;
193 }
194 
196  : public cppu::WeakImplHelper< lang::XEventListener >
197 {
198 private:
200 
201  virtual void SAL_CALL disposing( const lang::EventObject& Source ) override;
202 
203 public:
205 
206  void Dispose() { m_pDBManager = nullptr; }
207 
208 };
209 
210 namespace {
211 
213 class SwDataSourceRemovedListener : public cppu::WeakImplHelper<sdb::XDatabaseRegistrationsListener>
214 {
215  uno::Reference<sdb::XDatabaseContext> m_xDatabaseContext;
216  SwDBManager* m_pDBManager;
217 
218 public:
219  explicit SwDataSourceRemovedListener(SwDBManager& rDBManager);
220  virtual ~SwDataSourceRemovedListener() override;
221  virtual void SAL_CALL registeredDatabaseLocation(const sdb::DatabaseRegistrationEvent& rEvent) override;
222  virtual void SAL_CALL revokedDatabaseLocation(const sdb::DatabaseRegistrationEvent& rEvent) override;
223  virtual void SAL_CALL changedDatabaseLocation(const sdb::DatabaseRegistrationEvent& rEvent) override;
224  virtual void SAL_CALL disposing(const lang::EventObject& rObject) override;
225  void Dispose();
226 };
227 
228 }
229 
230 SwDataSourceRemovedListener::SwDataSourceRemovedListener(SwDBManager& rDBManager)
231  : m_pDBManager(&rDBManager)
232 {
233  uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
234  m_xDatabaseContext = sdb::DatabaseContext::create(xComponentContext);
235  m_xDatabaseContext->addDatabaseRegistrationsListener(this);
236 }
237 
238 SwDataSourceRemovedListener::~SwDataSourceRemovedListener()
239 {
240  if (m_xDatabaseContext.is())
241  m_xDatabaseContext->removeDatabaseRegistrationsListener(this);
242 }
243 
244 void SAL_CALL SwDataSourceRemovedListener::registeredDatabaseLocation(const sdb::DatabaseRegistrationEvent& /*rEvent*/)
245 {
246 }
247 
248 void SAL_CALL SwDataSourceRemovedListener::revokedDatabaseLocation(const sdb::DatabaseRegistrationEvent& rEvent)
249 {
250  if (!m_pDBManager || m_pDBManager->getEmbeddedName().isEmpty())
251  return;
252 
253  SwDoc* pDoc = m_pDBManager->getDoc();
254  if (!pDoc)
255  return;
256 
257  SwDocShell* pDocShell = pDoc->GetDocShell();
258  if (!pDocShell)
259  return;
260 
262  OUString sTmpName = "vnd.sun.star.pkg://" +
264  sTmpName += "/" + m_pDBManager->getEmbeddedName();
265 
266  if (sTmpName != rEvent.OldLocation)
267  return;
268 
269  // The revoked database location is inside this document, then remove the
270  // embedding, as otherwise it would be back on the next reload of the
271  // document.
272  pDocShell->GetStorage()->removeElement(m_pDBManager->getEmbeddedName());
273  m_pDBManager->setEmbeddedName(OUString(), *pDocShell);
274 }
275 
276 void SAL_CALL SwDataSourceRemovedListener::changedDatabaseLocation(const sdb::DatabaseRegistrationEvent& rEvent)
277 {
278  if (rEvent.OldLocation != rEvent.NewLocation)
279  revokedDatabaseLocation(rEvent);
280 }
281 
282 void SwDataSourceRemovedListener::disposing(const lang::EventObject& /*rObject*/)
283 {
284  m_xDatabaseContext.clear();
285 }
286 
287 void SwDataSourceRemovedListener::Dispose()
288 {
289  m_pDBManager = nullptr;
290 }
291 
293 {
294  std::unique_ptr<SwDSParam> pMergeData;
299  uno::Reference< mail::XMailMessage> m_xLastMessage;
300 
301  explicit SwDBManager_Impl(SwDBManager& rDBManager)
302  : m_xDisposeListener(new ConnectionDisposedListener_Impl(rDBManager))
303  {}
304 
306  {
307  m_xDisposeListener->Dispose();
308  if (m_xDataSourceRemovedListener.is())
309  m_xDataSourceRemovedListener->Dispose();
310  }
311 };
312 
313 static void lcl_InitNumberFormatter(SwDSParam& rParam, uno::Reference<sdbc::XDataSource> const & xSource)
314 {
315  uno::Reference<uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
316  rParam.xFormatter = util::NumberFormatter::create(xContext);
317  uno::Reference<beans::XPropertySet> xSourceProps(
318  (xSource.is()
319  ? xSource
321  rParam.xConnection, rParam.sDataSource)),
322  uno::UNO_QUERY);
323  if(xSourceProps.is())
324  {
325  uno::Any aFormats = xSourceProps->getPropertyValue("NumberFormatsSupplier");
326  if(aFormats.hasValue())
327  {
328  uno::Reference<util::XNumberFormatsSupplier> xSuppl;
329  aFormats >>= xSuppl;
330  if(xSuppl.is())
331  {
332  uno::Reference< beans::XPropertySet > xSettings = xSuppl->getNumberFormatSettings();
333  uno::Any aNull = xSettings->getPropertyValue("NullDate");
334  aNull >>= rParam.aNullDate;
335  if(rParam.xFormatter.is())
336  rParam.xFormatter->attachNumberFormatsSupplier(xSuppl);
337  }
338  }
339  }
340 }
341 
342 static bool lcl_MoveAbsolute(SwDSParam* pParam, long nAbsPos)
343 {
344  bool bRet = false;
345  try
346  {
347  if(pParam->aSelection.hasElements())
348  {
349  if(pParam->aSelection.getLength() <= nAbsPos)
350  {
351  pParam->bEndOfDB = true;
352  bRet = false;
353  }
354  else
355  {
356  pParam->nSelectionIndex = nAbsPos;
357  sal_Int32 nPos = 0;
358  pParam->aSelection.getConstArray()[ pParam->nSelectionIndex ] >>= nPos;
359  pParam->bEndOfDB = !pParam->xResultSet->absolute( nPos );
360  bRet = !pParam->bEndOfDB;
361  }
362  }
363  else if(pParam->bScrollable)
364  {
365  bRet = pParam->xResultSet->absolute( nAbsPos );
366  }
367  else
368  {
369  OSL_FAIL("no absolute positioning available");
370  }
371  }
372  catch(const uno::Exception&)
373  {
374  }
375  return bRet;
376 }
377 
378 static void lcl_GetColumnCnt(SwDSParam *pParam,
379  const uno::Reference< beans::XPropertySet > &rColumnProps,
380  LanguageType nLanguage, OUString &rResult, double* pNumber)
381 {
382  SwDBFormatData aFormatData;
383  if(!pParam->xFormatter.is())
384  {
385  uno::Reference<sdbc::XDataSource> xSource = SwDBManager::getDataSourceAsParent(
386  pParam->xConnection,pParam->sDataSource);
387  lcl_InitNumberFormatter(*pParam, xSource );
388  }
389  aFormatData.aNullDate = pParam->aNullDate;
390  aFormatData.xFormatter = pParam->xFormatter;
391 
392  aFormatData.aLocale = LanguageTag( nLanguage ).getLocale();
393 
394  rResult = SwDBManager::GetDBField( rColumnProps, aFormatData, pNumber);
395 }
396 
397 static bool lcl_GetColumnCnt(SwDSParam* pParam, const OUString& rColumnName,
398  LanguageType nLanguage, OUString& rResult, double* pNumber)
399 {
400  uno::Reference< sdbcx::XColumnsSupplier > xColsSupp( pParam->xResultSet, uno::UNO_QUERY );
401  uno::Reference<container::XNameAccess> xCols;
402  try
403  {
404  xCols = xColsSupp->getColumns();
405  }
406  catch(const lang::DisposedException&)
407  {
408  }
409  if(!xCols.is() || !xCols->hasByName(rColumnName))
410  return false;
411  uno::Any aCol = xCols->getByName(rColumnName);
412  uno::Reference< beans::XPropertySet > xColumnProps;
413  aCol >>= xColumnProps;
414  lcl_GetColumnCnt( pParam, xColumnProps, nLanguage, rResult, pNumber );
415  return true;
416 };
417 
418 // import data
419 bool SwDBManager::Merge( const SwMergeDescriptor& rMergeDesc )
420 {
421  assert( !m_bInMerge && !m_pImpl->pMergeData && "merge already activated!" );
422 
423  SfxObjectShellLock xWorkObjSh;
424  SwWrtShell *pWorkShell = nullptr;
425  SwDoc *pWorkDoc = nullptr;
426  SwDBManager *pWorkDocOrigDBManager = nullptr;
427 
428  switch( rMergeDesc.nMergeType )
429  {
430  case DBMGR_MERGE_PRINTER:
431  case DBMGR_MERGE_EMAIL:
432  case DBMGR_MERGE_FILE:
433  case DBMGR_MERGE_SHELL:
434  {
435  SwDocShell *pSourceDocSh = rMergeDesc.rSh.GetView().GetDocShell();
436  if( pSourceDocSh->IsModified() )
437  {
438  pWorkDocOrigDBManager = this;
439  xWorkObjSh = lcl_CreateWorkingDocument(
440  WorkingDocType::SOURCE, rMergeDesc.rSh, nullptr,
441  &pWorkDocOrigDBManager, nullptr, &pWorkShell, &pWorkDoc );
442  }
443  [[fallthrough]];
444  }
445 
446  default:
447  if( !xWorkObjSh.Is() )
448  pWorkShell = &rMergeDesc.rSh;
449  break;
450  }
451 
452  SwDBData aData;
453  aData.nCommandType = sdb::CommandType::TABLE;
454  uno::Reference<sdbc::XResultSet> xResSet;
455  uno::Sequence<uno::Any> aSelection;
456  uno::Reference< sdbc::XConnection> xConnection;
457 
458  aData.sDataSource = rMergeDesc.rDescriptor.getDataSource();
461 
468 
469  if(aData.sDataSource.isEmpty() || aData.sCommand.isEmpty() || !xResSet.is())
470  {
471  return false;
472  }
473 
474  m_pImpl->pMergeData.reset(new SwDSParam(aData, xResSet, aSelection));
475  SwDSParam* pTemp = FindDSData(aData, false);
476  if(pTemp)
477  *pTemp = *m_pImpl->pMergeData;
478  else
479  {
480  // calls from the calculator may have added a connection with an invalid commandtype
481  //"real" data base connections added here have to re-use the already available
482  //DSData and set the correct CommandType
483  SwDBData aTempData(aData);
484  aData.nCommandType = -1;
485  pTemp = FindDSData(aData, false);
486  if(pTemp)
487  *pTemp = *m_pImpl->pMergeData;
488  else
489  {
490  m_DataSourceParams.push_back(std::make_unique<SwDSParam>(*m_pImpl->pMergeData));
491  try
492  {
493  uno::Reference<lang::XComponent> xComponent(m_DataSourceParams.back()->xConnection, uno::UNO_QUERY);
494  if(xComponent.is())
495  xComponent->addEventListener(m_pImpl->m_xDisposeListener.get());
496  }
497  catch(const uno::Exception&)
498  {
499  }
500  }
501  }
502  if(!m_pImpl->pMergeData->xConnection.is())
503  m_pImpl->pMergeData->xConnection = xConnection;
504  // add an XEventListener
505 
506  lcl_ToNextRecord(m_pImpl->pMergeData.get(), SwDBNextRecord::FIRST);
507 
508  uno::Reference<sdbc::XDataSource> xSource = SwDBManager::getDataSourceAsParent(xConnection,aData.sDataSource);
509 
510  lcl_InitNumberFormatter(*m_pImpl->pMergeData, xSource);
511 
512  pWorkShell->ChgDBData(aData);
513  m_bInMerge = true;
514 
515  if (IsInitDBFields())
516  {
517  // with database fields without DB-Name, use DB-Name from Doc
518  std::vector<OUString> aDBNames;
519  aDBNames.emplace_back();
520  SwDBData aInsertData = pWorkShell->GetDBData();
521  OUString sDBName = aInsertData.sDataSource
522  + OUStringChar(DB_DELIM) + aInsertData.sCommand
523  + OUStringChar(DB_DELIM)
524  + OUString::number(aInsertData.nCommandType);
525  pWorkShell->ChangeDBFields( aDBNames, sDBName);
526  SetInitDBFields(false);
527  }
528 
529  bool bRet = true;
530  switch(rMergeDesc.nMergeType)
531  {
532  case DBMGR_MERGE:
533  pWorkShell->StartAllAction();
534  pWorkShell->SwViewShell::UpdateFields( true );
535  pWorkShell->SetModified();
536  pWorkShell->EndAllAction();
537  break;
538 
539  case DBMGR_MERGE_PRINTER:
540  case DBMGR_MERGE_EMAIL:
541  case DBMGR_MERGE_FILE:
542  case DBMGR_MERGE_SHELL:
543  // save files and send them as e-Mail if required
544  bRet = MergeMailFiles(pWorkShell, rMergeDesc);
545  break;
546 
547  default:
548  // insert selected entries
549  // (was: InsertRecord)
550  ImportFromConnection(pWorkShell);
551  break;
552  }
553 
554  m_pImpl->pMergeData.reset();
555 
556  if( xWorkObjSh.Is() )
557  {
558  pWorkDoc->SetDBManager( pWorkDocOrigDBManager );
559  xWorkObjSh->DoClose();
560  }
561 
562  m_bInMerge = false;
563 
564  return bRet;
565 }
566 
568 {
569  if(m_pImpl->pMergeData && !m_pImpl->pMergeData->bEndOfDB)
570  {
571  pSh->StartAllAction();
572  pSh->StartUndo();
573  bool bGroupUndo(pSh->DoesGroupUndo());
574  pSh->DoGroupUndo(false);
575 
576  if( pSh->HasSelection() )
577  pSh->DelRight();
578 
579  std::unique_ptr<SwWait> pWait;
580 
581  {
582  sal_uLong i = 0;
583  do {
584 
585  ImportDBEntry(pSh);
586  if( 10 == ++i )
587  pWait.reset(new SwWait( *pSh->GetView().GetDocShell(), true));
588 
589  } while(ToNextMergeRecord());
590  }
591 
592  pSh->DoGroupUndo(bGroupUndo);
593  pSh->EndUndo();
594  pSh->EndAllAction();
595  }
596 }
597 
598 static OUString lcl_FindColumn(const OUString& sFormatStr,sal_uInt16 &nUsedPos, sal_uInt8 &nSeparator)
599 {
600  OUStringBuffer sReturn;
601  sal_uInt16 nLen = sFormatStr.getLength();
602  nSeparator = 0xff;
603  while(nUsedPos < nLen && nSeparator == 0xff)
604  {
605  sal_Unicode cCurrent = sFormatStr[nUsedPos];
606  switch(cCurrent)
607  {
608  case ',':
609  nSeparator = DB_SEP_SPACE;
610  break;
611  case ';':
612  nSeparator = DB_SEP_RETURN;
613  break;
614  case ':':
615  nSeparator = DB_SEP_TAB;
616  break;
617  case '#':
618  nSeparator = DB_SEP_NEWLINE;
619  break;
620  default:
621  sReturn.append(cCurrent);
622  }
623  nUsedPos++;
624 
625  }
626  return sReturn.makeStringAndClear();
627 }
628 
630 {
631  if(m_pImpl->pMergeData && !m_pImpl->pMergeData->bEndOfDB)
632  {
633  uno::Reference< sdbcx::XColumnsSupplier > xColsSupp( m_pImpl->pMergeData->xResultSet, uno::UNO_QUERY );
634  uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
635  OUString sFormatStr;
636  sal_uInt16 nFormatLen = sFormatStr.getLength();
637  if( nFormatLen )
638  {
639  const char cSpace = ' ';
640  const char cTab = '\t';
641  sal_uInt16 nUsedPos = 0;
642  sal_uInt8 nSeparator;
643  OUString sColumn = lcl_FindColumn(sFormatStr, nUsedPos, nSeparator);
644  while( !sColumn.isEmpty() )
645  {
646  if(!xCols->hasByName(sColumn))
647  return;
648  uno::Any aCol = xCols->getByName(sColumn);
649  uno::Reference< beans::XPropertySet > xColumnProp;
650  aCol >>= xColumnProp;
651  if(xColumnProp.is())
652  {
653  SwDBFormatData aDBFormat;
654  OUString sInsert = GetDBField( xColumnProp, aDBFormat);
655  if( DB_SEP_SPACE == nSeparator )
656  sInsert += OUStringChar(cSpace);
657  else if( DB_SEP_TAB == nSeparator)
658  sInsert += OUStringChar(cTab);
659  pSh->Insert(sInsert);
660  if( DB_SEP_RETURN == nSeparator)
661  pSh->SplitNode();
662  else if(DB_SEP_NEWLINE == nSeparator)
663  pSh->InsertLineBreak();
664  }
665  else
666  {
667  // column not found -> show error
668  OUString sInsert = "?" + sColumn + "?";
669  pSh->Insert(sInsert);
670  }
671  sColumn = lcl_FindColumn(sFormatStr, nUsedPos, nSeparator);
672  }
673  pSh->SplitNode();
674  }
675  else
676  {
677  OUStringBuffer sStr;
678  uno::Sequence<OUString> aColNames = xCols->getElementNames();
679  const OUString* pColNames = aColNames.getConstArray();
680  long nLength = aColNames.getLength();
681  for(long i = 0; i < nLength; i++)
682  {
683  uno::Any aCol = xCols->getByName(pColNames[i]);
684  uno::Reference< beans::XPropertySet > xColumnProp;
685  aCol >>= xColumnProp;
686  SwDBFormatData aDBFormat;
687  sStr.append(GetDBField( xColumnProp, aDBFormat));
688  if (i < nLength - 1)
689  sStr.append("\t");
690  }
691  pSh->SwEditShell::Insert2(sStr.makeStringAndClear());
692  pSh->SwFEShell::SplitNode(); // line feed
693  }
694  }
695 }
696 
697 bool SwDBManager::GetTableNames(weld::ComboBox& rBox, const OUString& rDBName)
698 {
699  bool bRet = false;
700  OUString sOldTableName(rBox.get_active_text());
701  rBox.clear();
702  SwDSParam* pParam = FindDSConnection(rDBName, false);
703  uno::Reference< sdbc::XConnection> xConnection;
704  if (pParam && pParam->xConnection.is())
705  xConnection = pParam->xConnection;
706  else
707  {
708  if ( !rDBName.isEmpty() )
709  xConnection = RegisterConnection( rDBName );
710  }
711  if (xConnection.is())
712  {
713  uno::Reference<sdbcx::XTablesSupplier> xTSupplier(xConnection, uno::UNO_QUERY);
714  if(xTSupplier.is())
715  {
716  uno::Reference<container::XNameAccess> xTables = xTSupplier->getTables();
717  const uno::Sequence<OUString> aTables = xTables->getElementNames();
718  for (const OUString& rTable : aTables)
719  rBox.append("0", rTable);
720  }
721  uno::Reference<sdb::XQueriesSupplier> xQSupplier(xConnection, uno::UNO_QUERY);
722  if(xQSupplier.is())
723  {
724  uno::Reference<container::XNameAccess> xQueries = xQSupplier->getQueries();
725  const uno::Sequence<OUString> aQueries = xQueries->getElementNames();
726  for (const OUString& rQuery : aQueries)
727  rBox.append("1", rQuery);
728  }
729  if (!sOldTableName.isEmpty())
730  rBox.set_active_text(sOldTableName);
731  bRet = true;
732  }
733  return bRet;
734 }
735 
736 // fill Listbox with column names of a database
738  const OUString& rDBName, const OUString& rTableName)
739 {
740  SwDBData aData;
741  aData.sDataSource = rDBName;
742  aData.sCommand = rTableName;
743  aData.nCommandType = -1;
744  SwDSParam* pParam = FindDSData(aData, false);
745  uno::Reference< sdbc::XConnection> xConnection;
746  if(pParam && pParam->xConnection.is())
747  xConnection = pParam->xConnection;
748  else
749  {
750  xConnection = RegisterConnection( rDBName );
751  }
752  GetColumnNames(rBox, xConnection, rTableName);
753 }
754 
756  uno::Reference< sdbc::XConnection> const & xConnection,
757  const OUString& rTableName)
758 {
759  rBox.clear();
760  uno::Reference< sdbcx::XColumnsSupplier> xColsSupp = SwDBManager::GetColumnSupplier(xConnection, rTableName);
761  if(xColsSupp.is())
762  {
763  uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
764  const uno::Sequence<OUString> aColNames = xCols->getElementNames();
765  for (const OUString& rColName : aColNames)
766  {
767  rBox.append_text(rColName);
768  }
769  ::comphelper::disposeComponent( xColsSupp );
770  }
771 }
772 
774  : m_aMergeStatus( MergeStatus::Ok )
775  , m_bInitDBFields(false)
776  , m_bInMerge(false)
777  , m_bMergeSilent(false)
778  , m_pImpl(new SwDBManager_Impl(*this))
779  , m_pMergeEvtSrc(nullptr)
780  , m_pDoc(pDoc)
781 {
782 }
783 
784 SwDBManager::~SwDBManager() COVERITY_NOEXCEPT_FALSE
785 {
787 
788  // copy required, m_DataSourceParams can be modified while disposing components
789  std::vector<uno::Reference<sdbc::XConnection>> aCopiedConnections;
790  for (const auto & pParam : m_DataSourceParams)
791  {
792  if(pParam->xConnection.is())
793  {
794  aCopiedConnections.push_back(pParam->xConnection);
795  }
796  }
797  for (const auto & xConnection : aCopiedConnections)
798  {
799  try
800  {
801  uno::Reference<lang::XComponent> xComp(xConnection, uno::UNO_QUERY);
802  if(xComp.is())
803  xComp->dispose();
804  }
805  catch(const uno::RuntimeException&)
806  {
807  //may be disposed already since multiple entries may have used the same connection
808  }
809  }
810 }
811 
812 static void lcl_RemoveSectionLinks( SwWrtShell& rWorkShell )
813 {
814  //reset all links of the sections of synchronized labels
815  size_t nSections = rWorkShell.GetSectionFormatCount();
816  for (size_t nSection = 0; nSection < nSections; ++nSection)
817  {
818  SwSectionData aSectionData( *rWorkShell.GetSectionFormat( nSection ).GetSection() );
819  if( aSectionData.GetType() == SectionType::FileLink )
820  {
821  aSectionData.SetType( SectionType::Content );
822  aSectionData.SetLinkFileName( OUString() );
823  rWorkShell.UpdateSection( nSection, aSectionData );
824  }
825  }
826  rWorkShell.SetLabelDoc( false );
827 }
828 
829 static void lcl_SaveDebugDoc( SfxObjectShell *xTargetDocShell,
830  const char *name, int no = 0 )
831 {
832  static OUString sTempDirURL;
833  if( sTempDirURL.isEmpty() )
834  {
835  SvtPathOptions aPathOpt;
836  utl::TempFile aTempDir( &aPathOpt.GetTempPath(), true );
837  if( aTempDir.IsValid() )
838  {
839  INetURLObject aTempDirURL( aTempDir.GetURL() );
840  sTempDirURL = aTempDirURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
841  SAL_INFO( "sw.mailmerge", "Dump directory: " << sTempDirURL );
842  }
843  }
844  if( sTempDirURL.isEmpty() )
845  return;
846 
847  const OUString sExt( ".odt" );
848  OUString basename = OUString::createFromAscii( name );
849  if (no > 0)
850  basename += OUString::number(no) + "-";
851  // aTempFile is not deleted, but that seems to be intentional
852  utl::TempFile aTempFile( basename, true, &sExt, &sTempDirURL );
853  INetURLObject aTempFileURL( aTempFile.GetURL() );
854  auto pDstMed = std::make_unique<SfxMedium>(
855  aTempFileURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ),
856  StreamMode::STD_READWRITE );
857  bool bAnyError = !xTargetDocShell->DoSaveAs( *pDstMed );
858  // xObjectShell->DoSaveCompleted crashes the mail merge unit tests, so skip it
859  bAnyError |= (ERRCODE_NONE != xTargetDocShell->GetError());
860  if( bAnyError )
861  SAL_WARN( "sw.mailmerge", "Error saving: " << aTempFile.GetURL() );
862  else
863  SAL_INFO( "sw.mailmerge", "Saved doc as: " << aTempFile.GetURL() );
864 }
865 
866 static bool lcl_SaveDoc(
867  const INetURLObject* pFileURL,
868  const std::shared_ptr<const SfxFilter>& pStoreToFilter,
869  const OUString* pStoreToFilterOptions,
870  const uno::Sequence< beans::PropertyValue >* pSaveToFilterData,
871  const bool bIsPDFexport,
872  SfxObjectShell* xObjectShell,
873  SwWrtShell& rWorkShell,
874  OUString * const decodedURL = nullptr )
875 {
876  OUString url = pFileURL->GetMainURL( INetURLObject::DecodeMechanism::NONE );
877  if( decodedURL )
878  (*decodedURL) = url;
879 
880  SfxMedium* pDstMed = new SfxMedium( url, StreamMode::STD_READWRITE );
881  pDstMed->SetFilter( pStoreToFilter );
882  if( pDstMed->GetItemSet() )
883  {
884  if( pStoreToFilterOptions )
885  pDstMed->GetItemSet()->Put( SfxStringItem(SID_FILE_FILTEROPTIONS,
886  *pStoreToFilterOptions));
887  if( pSaveToFilterData->hasElements() )
888  pDstMed->GetItemSet()->Put( SfxUnoAnyItem(SID_FILTER_DATA,
889  uno::makeAny(*pSaveToFilterData)));
890  }
891 
892  // convert fields to text if we are exporting to PDF.
893  // this prevents a second merge while updating the fields
894  // in SwXTextDocument::getRendererCount()
895  if( bIsPDFexport )
896  rWorkShell.ConvertFieldsToText();
897 
898  bool bAnyError = !xObjectShell->DoSaveAs(*pDstMed);
899  // Actually this should be a bool... so in case of email and individual
900  // files, where this is set, we skip the recently used handling
901  bAnyError |= !xObjectShell->DoSaveCompleted( pDstMed, !decodedURL );
902  bAnyError |= (ERRCODE_NONE != xObjectShell->GetError());
903  if( bAnyError )
904  {
905  // error message ??
906  ErrorHandler::HandleError( xObjectShell->GetError() );
907  }
908  return !bAnyError;
909 }
910 
912  const uno::Sequence< beans::PropertyValue >& rInPrintOptions,
913  uno::Sequence< beans::PropertyValue >& rOutPrintOptions)
914 {
915  // printing should be done synchronously otherwise the document
916  // might already become invalid during the process
917 
918  const sal_Int32 nOffset = 1;
919  rOutPrintOptions.realloc( nOffset );
920  rOutPrintOptions[ 0 ].Name = "Wait";
921  rOutPrintOptions[ 0 ].Value <<= true;
922 
923  // copy print options
924  sal_Int32 nIndex = nOffset;
925  for( const beans::PropertyValue& rOption : rInPrintOptions)
926  {
927  if( rOption.Name == "CopyCount" || rOption.Name == "FileName"
928  || rOption.Name == "Collate" || rOption.Name == "Pages"
929  || rOption.Name == "Wait" || rOption.Name == "PrinterName" )
930  {
931  // add an option
932  rOutPrintOptions.realloc( nIndex + 1 );
933  rOutPrintOptions[ nIndex ].Name = rOption.Name;
934  rOutPrintOptions[ nIndex++ ].Value = rOption.Value ;
935  }
936  }
937 }
938 
940  // input
941  const WorkingDocType aType, const SwWrtShell &rSourceWrtShell,
942  // optional input
943  const vcl::Window *pSourceWindow,
944  // optional in and output to swap the DB manager
945  SwDBManager** const ppDBManager,
946  // optional output
947  SwView** const pView, SwWrtShell** const pWrtShell, SwDoc** const pDoc )
948 {
949  const SwDoc *pSourceDoc = rSourceWrtShell.GetDoc();
950  SfxObjectShellRef xWorkObjectShell = pSourceDoc->CreateCopy( true, (aType == WorkingDocType::TARGET) );
951  SfxViewFrame* pWorkFrame = SfxViewFrame::LoadHiddenDocument( *xWorkObjectShell, SFX_INTERFACE_NONE );
952 
953  if( pSourceWindow )
954  {
955  // the created window has to be located at the same position as the source window
956  vcl::Window& rTargetWindow = pWorkFrame->GetFrame().GetWindow();
957  rTargetWindow.SetPosPixel( pSourceWindow->GetPosPixel() );
958  }
959 
960  SwView* pWorkView = static_cast< SwView* >( pWorkFrame->GetViewShell() );
961  SwWrtShell* pWorkWrtShell = pWorkView->GetWrtShellPtr();
962  pWorkWrtShell->GetViewOptions()->SetIdle( false );
963  pWorkView->AttrChangedNotify(nullptr);// in order for SelectShell to be called
964  SwDoc* pWorkDoc = pWorkWrtShell->GetDoc();
965  pWorkDoc->GetIDocumentUndoRedo().DoUndo( false );
966  pWorkDoc->ReplaceDocumentProperties( *pSourceDoc );
967 
968  // import print settings
969  const SwPrintData &rPrintData = pSourceDoc->getIDocumentDeviceAccess().getPrintData();
970  pWorkDoc->getIDocumentDeviceAccess().setPrintData(rPrintData);
971  const JobSetup *pJobSetup = pSourceDoc->getIDocumentDeviceAccess().getJobsetup();
972  if (pJobSetup)
973  pWorkDoc->getIDocumentDeviceAccess().setJobsetup(*pJobSetup);
974 
975  if( aType == WorkingDocType::TARGET )
976  {
977  assert( !ppDBManager );
978  pWorkDoc->SetInMailMerge( true );
979  pWorkWrtShell->SetLabelDoc( false );
980  }
981  else
982  {
983  // We have to swap the DBmanager of the new doc, so we also need input
984  assert(ppDBManager && *ppDBManager);
985  SwDBManager *pWorkDBManager = pWorkDoc->GetDBManager();
986  pWorkDoc->SetDBManager( *ppDBManager );
987  *ppDBManager = pWorkDBManager;
988 
989  if( aType == WorkingDocType::SOURCE )
990  {
991  // the GetDBData call constructs the data, if it's missing - kind of const...
992  pWorkWrtShell->ChgDBData( const_cast<SwDoc*>(pSourceDoc)->GetDBData() );
993  // some DocumentSettings are currently not copied by SwDoc::CreateCopy
994  pWorkWrtShell->SetLabelDoc( rSourceWrtShell.IsLabelDoc() );
995  pWorkDoc->getIDocumentState().ResetModified();
996  }
997  else
999  }
1000 
1001  if( pView ) *pView = pWorkView;
1002  if( pWrtShell ) *pWrtShell = pWorkWrtShell;
1003  if( pDoc ) *pDoc = pWorkDoc;
1004 
1005  return xWorkObjectShell.get();
1006 }
1007 
1009  const SwMergeDescriptor &rMergeDescriptor,
1010  const OUString &sFileURL, const OUString &sMailRecipient,
1011  const OUString &sMailBodyMimeType, rtl_TextEncoding sMailEncoding,
1012  const OUString &sAttachmentMimeType )
1013 {
1014  SwMailMessage* pMessage = new SwMailMessage;
1015  if( rMergeDescriptor.pMailMergeConfigItem->IsMailReplyTo() )
1016  pMessage->setReplyToAddress(rMergeDescriptor.pMailMergeConfigItem->GetMailReplyTo());
1017  pMessage->addRecipient( sMailRecipient );
1018  pMessage->SetSenderAddress( rMergeDescriptor.pMailMergeConfigItem->GetMailAddress() );
1019 
1020  OUStringBuffer sBody;
1021  if( rMergeDescriptor.bSendAsAttachment )
1022  {
1023  sBody = rMergeDescriptor.sMailBody;
1024  mail::MailAttachment aAttach;
1025  aAttach.Data = new SwMailTransferable( sFileURL,
1026  rMergeDescriptor.sAttachmentName, sAttachmentMimeType );
1027  aAttach.ReadableName = rMergeDescriptor.sAttachmentName;
1028  pMessage->addAttachment( aAttach );
1029  }
1030  else
1031  {
1032  //read in the temporary file and use it as mail body
1033  SfxMedium aMedium( sFileURL, StreamMode::READ );
1034  SvStream* pInStream = aMedium.GetInStream();
1035  assert( pInStream && "no output file created?" );
1036  if( !pInStream )
1037  return pMessage;
1038 
1039  pInStream->SetStreamCharSet( sMailEncoding );
1040  OString sLine;
1041  while ( pInStream->ReadLine( sLine ) )
1042  {
1043  sBody.append(OStringToOUString( sLine, sMailEncoding ));
1044  sBody.append("\n");
1045  }
1046  }
1047  pMessage->setSubject( rMergeDescriptor.sSubject );
1048  uno::Reference< datatransfer::XTransferable> xBody =
1049  new SwMailTransferable( sBody.makeStringAndClear(), sMailBodyMimeType );
1050  pMessage->setBody( xBody );
1051 
1052  for( const OUString& sCcRecipient : rMergeDescriptor.aCopiesTo )
1053  pMessage->addCcRecipient( sCcRecipient );
1054  for( const OUString& sBccRecipient : rMergeDescriptor.aBlindCopiesTo )
1055  pMessage->addBccRecipient( sBccRecipient );
1056 
1057  return pMessage;
1058 }
1059 
1061 {
1063 
1064 public:
1066  : m_rDBManager( rDBManager ) {}
1067 
1068  virtual void idle() override {}
1069 
1070  virtual void mailDelivered( uno::Reference< mail::XMailMessage> xMessage ) override
1071  {
1072  osl::MutexGuard aGuard( m_rDBManager.m_pImpl->m_aAllEmailSendMutex );
1073  if ( m_rDBManager.m_pImpl->m_xLastMessage == xMessage )
1074  m_rDBManager.m_pImpl->m_xLastMessage.clear();
1075  }
1076 
1077  virtual void mailDeliveryError( ::rtl::Reference<MailDispatcher> xMailDispatcher,
1078  uno::Reference< mail::XMailMessage>, const OUString& ) override
1079  {
1080  osl::MutexGuard aGuard( m_rDBManager.m_pImpl->m_aAllEmailSendMutex );
1081  m_rDBManager.m_aMergeStatus = MergeStatus::Error;
1082  m_rDBManager.m_pImpl->m_xLastMessage.clear();
1083  xMailDispatcher->stop();
1084  }
1085 };
1086 
1092  const SwMergeDescriptor& rMergeDescriptor)
1093 {
1094  // deconstruct mail merge type for better readability.
1095  // uppercase naming is intentional!
1096  const bool bMT_EMAIL = rMergeDescriptor.nMergeType == DBMGR_MERGE_EMAIL;
1097  const bool bMT_SHELL = rMergeDescriptor.nMergeType == DBMGR_MERGE_SHELL;
1098  const bool bMT_PRINTER = rMergeDescriptor.nMergeType == DBMGR_MERGE_PRINTER;
1099  const bool bMT_FILE = rMergeDescriptor.nMergeType == DBMGR_MERGE_FILE;
1100 
1101  //check if the doc is synchronized and contains at least one linked section
1102  const bool bSynchronizedDoc = pSourceShell->IsLabelDoc() && pSourceShell->GetSectionFormatCount() > 1;
1103  const bool bNeedsTempFiles = ( bMT_EMAIL || bMT_FILE );
1104  const bool bIsMergeSilent = IsMergeSilent();
1105 
1106  bool bCheckSingleFile_ = rMergeDescriptor.bCreateSingleFile;
1107  OUString sPrefix_ = rMergeDescriptor.sPrefix;
1108  if( bMT_EMAIL )
1109  {
1110  assert( !rMergeDescriptor.bPrefixIsFilename );
1111  assert(!bCheckSingleFile_);
1112  bCheckSingleFile_ = false;
1113  }
1114  else if( bMT_SHELL || bMT_PRINTER )
1115  {
1116  assert(bCheckSingleFile_);
1117  bCheckSingleFile_ = true;
1118  assert(sPrefix_.isEmpty());
1119  sPrefix_.clear();
1120  }
1121  const bool bCreateSingleFile = bCheckSingleFile_;
1122  const OUString sDescriptorPrefix = sPrefix_;
1123 
1124  // Setup for dumping debugging documents
1125  static const sal_Int32 nMaxDumpDocs = []() {
1126  if (const char* sEnv = getenv("SW_DEBUG_MAILMERGE_DOCS"))
1127  return OUString(sEnv, strlen(sEnv), osl_getThreadTextEncoding()).toInt32();
1128  else
1129  return sal_Int32(0);
1130  }();
1131 
1132  ::rtl::Reference< MailDispatcher > xMailDispatcher;
1134  OUString sMailBodyMimeType;
1135  rtl_TextEncoding sMailEncoding = ::osl_getThreadTextEncoding();
1136 
1137  uno::Reference< beans::XPropertySet > xColumnProp;
1138 
1139  // Check for (mandatory) email or (optional) filename column
1140  SwDBFormatData aColumnDBFormat;
1141  bool bColumnName = !rMergeDescriptor.sDBcolumn.isEmpty();
1142  if( ! bColumnName )
1143  {
1144  if( bMT_EMAIL )
1145  return false;
1146  }
1147  else
1148  {
1149  uno::Reference< sdbcx::XColumnsSupplier > xColsSupp( m_pImpl->pMergeData->xResultSet, uno::UNO_QUERY );
1150  uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
1151  if( !xCols->hasByName( rMergeDescriptor.sDBcolumn ) )
1152  return false;
1153  uno::Any aCol = xCols->getByName( rMergeDescriptor.sDBcolumn );
1154  aCol >>= xColumnProp;
1155 
1156  aColumnDBFormat.xFormatter = m_pImpl->pMergeData->xFormatter;
1157  aColumnDBFormat.aNullDate = m_pImpl->pMergeData->aNullDate;
1158 
1159  if( bMT_EMAIL )
1160  {
1161  // Reset internal mail accounting data
1162  m_pImpl->m_xLastMessage.clear();
1163 
1164  xMailDispatcher.set( new MailDispatcher(rMergeDescriptor.xSmtpServer) );
1165  xMailListener = new MailDispatcherListener_Impl( *this );
1166  xMailDispatcher->addListener( xMailListener );
1167  if(!rMergeDescriptor.bSendAsAttachment && rMergeDescriptor.bSendAsHTML)
1168  {
1169  sMailBodyMimeType = "text/html; charset=" + OUString::createFromAscii(
1170  rtl_getBestMimeCharsetFromTextEncoding( sMailEncoding ));
1171  SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
1172  sMailEncoding = rHtmlOptions.GetTextEncoding();
1173  }
1174  else
1175  sMailBodyMimeType = "text/plain; charset=UTF-8; format=flowed";
1176  }
1177  }
1178 
1179  SwDocShell *pSourceDocSh = pSourceShell->GetView().GetDocShell();
1180 
1181  // setup the output format
1182  std::shared_ptr<const SfxFilter> pStoreToFilter = SwIoSystem::GetFileFilter(
1184  SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
1185  const OUString* pStoreToFilterOptions = nullptr;
1186 
1187  // if a save_to filter is set then use it - otherwise use the default
1188  if( bMT_EMAIL && !rMergeDescriptor.bSendAsAttachment )
1189  {
1190  OUString sExtension = rMergeDescriptor.bSendAsHTML ? OUString("html") : OUString("txt");
1191  pStoreToFilter = pFilterContainer->GetFilter4Extension(sExtension, SfxFilterFlags::EXPORT);
1192  }
1193  else if( !rMergeDescriptor.sSaveToFilter.isEmpty())
1194  {
1195  std::shared_ptr<const SfxFilter> pFilter =
1196  pFilterContainer->GetFilter4FilterName( rMergeDescriptor.sSaveToFilter );
1197  if(pFilter)
1198  {
1199  pStoreToFilter = pFilter;
1200  if(!rMergeDescriptor.sSaveToFilterOptions.isEmpty())
1201  pStoreToFilterOptions = &rMergeDescriptor.sSaveToFilterOptions;
1202  }
1203  }
1204  const bool bIsPDFexport = pStoreToFilter && pStoreToFilter->GetFilterName() == "writer_pdf_Export";
1205 
1207 
1208  // in case of creating a single resulting file this has to be created here
1209  SwView* pTargetView = rMergeDescriptor.pMailMergeConfigItem ?
1210  rMergeDescriptor.pMailMergeConfigItem->GetTargetView() : nullptr;
1211  SwWrtShell* pTargetShell = nullptr;
1212  SwDoc* pTargetDoc = nullptr;
1213  SfxObjectShellRef xTargetDocShell;
1214 
1215  std::unique_ptr< utl::TempFile > aTempFile;
1216  sal_uInt16 nStartingPageNo = 0;
1217 
1218  vcl::Window *pSourceWindow = nullptr;
1219  std::shared_ptr<weld::GenericDialogController> xProgressDlg;
1220 
1221  try
1222  {
1223  if( !bIsMergeSilent )
1224  {
1225  // construct the process dialog
1226  pSourceWindow = &pSourceShell->GetView().GetEditWin();
1227  if (!bMT_PRINTER)
1228  xProgressDlg.reset(new CreateMonitor(pSourceWindow->GetFrameWeld()));
1229  else
1230  {
1231  xProgressDlg.reset(new PrintMonitor(pSourceWindow->GetFrameWeld()));
1232  static_cast<PrintMonitor*>(xProgressDlg.get())->set_title(
1233  pSourceDocSh->GetTitle(22));
1234  }
1235  weld::DialogController::runAsync(xProgressDlg, [this, &xProgressDlg](sal_Int32 nResult){
1236  if (nResult == RET_CANCEL)
1237  MergeCancel();
1238  xProgressDlg.reset();
1239  });
1240 
1241  Application::Reschedule( true );
1242  }
1243 
1244  if( bCreateSingleFile && !pTargetView )
1245  {
1246  // create a target docshell to put the merged document into
1247  xTargetDocShell = lcl_CreateWorkingDocument( WorkingDocType::TARGET,
1248  *pSourceShell, bMT_SHELL ? pSourceWindow : nullptr,
1249  nullptr, &pTargetView, &pTargetShell, &pTargetDoc );
1250 
1251  if (nMaxDumpDocs)
1252  lcl_SaveDebugDoc( xTargetDocShell.get(), "MergeDoc" );
1253  }
1254  else if( pTargetView )
1255  {
1256  pTargetShell = pTargetView->GetWrtShellPtr();
1257  pTargetDoc = pTargetShell->GetDoc();
1258  xTargetDocShell = pTargetView->GetDocShell();
1259  }
1260 
1261  if( bCreateSingleFile )
1262  {
1263  // determine the page style and number used at the start of the source document
1264  pSourceShell->SttEndDoc(true);
1265  nStartingPageNo = pSourceShell->GetVirtPageNum();
1266  }
1267 
1268  // Progress, to prohibit KeyInputs
1269  SfxProgress aProgress(pSourceDocSh, OUString(), 1);
1270 
1271  // lock all dispatchers
1272  SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst(pSourceDocSh);
1273  while (pViewFrame)
1274  {
1275  pViewFrame->GetDispatcher()->Lock(true);
1276  pViewFrame = SfxViewFrame::GetNext(*pViewFrame, pSourceDocSh);
1277  }
1278 
1279  sal_Int32 nDocNo = 1;
1280 
1281  // For single file mode, the number of pages in the target document so far, which is used
1282  // by AppendDoc() to adjust position of page-bound objects. Getting this information directly
1283  // from the target doc would require repeated layouts of the doc, which is expensive, but
1284  // it can be manually computed from the source documents (for which we do layouts, so the page
1285  // count is known, and there is a blank page between each of them in the target document).
1286  int targetDocPageCount = 0;
1287 
1288  if( !bIsMergeSilent && !bMT_PRINTER )
1289  {
1290  sal_Int32 nRecordCount = 1;
1291  lcl_getCountFromResultSet( nRecordCount, m_pImpl->pMergeData.get() );
1292 
1293  // Synchronized docs don't auto-advance the record set, but there is a
1294  // "security" check, which will always advance the record set, if there
1295  // is no "next record" field in a synchronized doc => nRecordPerDoc > 0
1296  sal_Int32 nRecordPerDoc = pSourceShell->GetDoc()
1298  if ( bSynchronizedDoc && (nRecordPerDoc > 1) )
1299  --nRecordPerDoc;
1300  assert( nRecordPerDoc > 0 );
1301 
1302  sal_Int32 nMaxDocs = nRecordCount / nRecordPerDoc;
1303  if ( 0 != nRecordCount % nRecordPerDoc )
1304  nMaxDocs += 1;
1305  static_cast<CreateMonitor*>(xProgressDlg.get())->SetTotalCount(nMaxDocs);
1306  }
1307 
1308  long nStartRow, nEndRow;
1309  bool bFreezedLayouts = false;
1310  // to collect temporary email files
1311  std::vector< OUString> aFilesToRemove;
1312 
1313  // The SfxObjectShell will be closed explicitly later but
1314  // it is more safe to use SfxObjectShellLock here
1315  SfxObjectShellLock xWorkDocSh;
1316  SwView* pWorkView = nullptr;
1317  SwDoc* pWorkDoc = nullptr;
1318  SwDBManager* pWorkDocOrigDBManager = nullptr;
1319  SwWrtShell* pWorkShell = nullptr;
1320  bool bWorkDocInitialized = false;
1321 
1322  do
1323  {
1324  nStartRow = m_pImpl->pMergeData ? m_pImpl->pMergeData->xResultSet->getRow() : 0;
1325 
1326  OUString sColumnData;
1327 
1328  // Read the indicated data column, which should contain a valid mail
1329  // address or an optional file name
1330  if( bMT_EMAIL || bColumnName )
1331  {
1332  sColumnData = GetDBField( xColumnProp, aColumnDBFormat );
1333  }
1334 
1335  // create a new temporary file name - only done once in case of bCreateSingleFile
1336  if( bNeedsTempFiles && ( !bWorkDocInitialized || !bCreateSingleFile ))
1337  {
1338  OUString sPrefix = sDescriptorPrefix;
1339  OUString sLeading;
1340 
1341  //#i97667# if the name is from a database field then it will be used _as is_
1342  if( bColumnName && !bMT_EMAIL )
1343  {
1344  if (!sColumnData.isEmpty())
1345  sLeading = sColumnData;
1346  else
1347  sLeading = "_";
1348  }
1349  else
1350  {
1351  INetURLObject aEntry( sPrefix );
1352  sLeading = aEntry.GetBase();
1353  aEntry.removeSegment();
1355  }
1356 
1357  OUString sExt(comphelper::string::stripStart(pStoreToFilter->GetDefaultExtension(), '*'));
1358  aTempFile.reset( new utl::TempFile(sLeading, sColumnData.isEmpty(), &sExt, &sPrefix, true) );
1359  if( !aTempFile->IsValid() )
1360  {
1363  }
1364  }
1365 
1366  if( IsMergeOk() )
1367  {
1368  std::unique_ptr< INetURLObject > aTempFileURL;
1369  if( bNeedsTempFiles )
1370  aTempFileURL.reset( new INetURLObject(aTempFile->GetURL()));
1371  if( !bIsMergeSilent ) {
1372  if( !bMT_PRINTER )
1373  static_cast<CreateMonitor*>(xProgressDlg.get())->SetCurrentPosition(nDocNo);
1374  else {
1375  PrintMonitor *pPrintMonDlg = static_cast<PrintMonitor*>(xProgressDlg.get());
1376  pPrintMonDlg->m_xPrinter->set_label(bNeedsTempFiles
1377  ? aTempFileURL->GetBase() : pSourceDocSh->GetTitle( 2));
1378  OUString sStat = SwResId(STR_STATSTR_LETTER) + " " + OUString::number( nDocNo );
1379  pPrintMonDlg->m_xPrintInfo->set_label(sStat);
1380  }
1381  //TODO xProgressDlg->queue_draw();
1382  }
1383 
1384  Application::Reschedule( true );
1385 
1386  // Create a copy of the source document and work with that one instead of the source.
1387  // If we're not in the single file mode (which requires modifying the document for the merging),
1388  // it is enough to do this just once. Currently PDF also has to be treated special.
1389  if( !bWorkDocInitialized || bCreateSingleFile || bIsPDFexport )
1390  {
1391  assert( !xWorkDocSh.Is());
1392  pWorkDocOrigDBManager = this;
1393  xWorkDocSh = lcl_CreateWorkingDocument( WorkingDocType::COPY,
1394  *pSourceShell, nullptr, &pWorkDocOrigDBManager,
1395  &pWorkView, &pWorkShell, &pWorkDoc );
1396  if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) )
1397  lcl_SaveDebugDoc( xWorkDocSh, "WorkDoc", nDocNo );
1398 
1399  // #i69458# lock fields to prevent access to the result set while calculating layout
1400  // tdf#92324: and do not unlock: keep document locked during printing to avoid
1401  // ExpFields update during printing, generation of preview, etc.
1402  pWorkShell->LockExpFields();
1403  pWorkShell->CalcLayout();
1404  // tdf#121168: Now force correct page descriptions applied to page frames. Without
1405  // this, e.g., page frames starting with sections could have page descriptions set
1406  // wrong. This would lead to wrong page styles applied in SwDoc::AppendDoc below.
1407  pWorkShell->GetViewOptions()->SetIdle(true);
1408  for (auto aLayout : pWorkShell->GetDoc()->GetAllLayouts())
1409  {
1410  aLayout->FreezeLayout(false);
1411  aLayout->AllCheckPageDescs();
1412  }
1413  }
1414 
1415  lcl_emitEvent(SfxEventHintId::SwEventFieldMerge, STR_SW_EVENT_FIELD_MERGE, xWorkDocSh);
1416 
1417  // tdf#92324: Allow ExpFields update only by explicit instruction to avoid
1418  // database cursor movement on any other fields update, for example during
1419  // print preview and other operations
1420  if ( pWorkShell->IsExpFieldsLocked() )
1421  pWorkShell->UnlockExpFields();
1422  pWorkShell->SwViewShell::UpdateFields();
1423  pWorkShell->LockExpFields();
1424 
1425  lcl_emitEvent(SfxEventHintId::SwEventFieldMergeFinished, STR_SW_EVENT_FIELD_MERGE_FINISHED, xWorkDocSh);
1426 
1427  // also emit MailMergeEvent on XInterface if possible
1428  const SwXMailMerge *pEvtSrc = GetMailMergeEvtSrc();
1429  if(pEvtSrc)
1430  {
1431  uno::Reference< uno::XInterface > xRef(
1432  static_cast<text::XMailMergeBroadcaster*>(const_cast<SwXMailMerge*>(pEvtSrc)) );
1433  text::MailMergeEvent aEvt( xRef, xWorkDocSh->GetModel() );
1434  pEvtSrc->LaunchMailMergeEvent( aEvt );
1435  }
1436 
1437  // working copy is merged - prepare final steps depending on merge options
1438 
1439  if( bCreateSingleFile )
1440  {
1441  assert( pTargetShell && "no target shell available!" );
1442 
1443  // prepare working copy and target to append
1444 
1445  pWorkDoc->RemoveInvisibleContent();
1446  // remove of invisible content has influence on page count and so on fields for page count,
1447  // therefore layout has to be updated before fields are converted to text
1448  pWorkShell->CalcLayout();
1449  pWorkShell->ConvertFieldsToText();
1450  pWorkShell->SetNumberingRestart();
1451  if( bSynchronizedDoc )
1452  {
1453  lcl_RemoveSectionLinks( *pWorkShell );
1454  }
1455 
1456  if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) )
1457  lcl_SaveDebugDoc( xWorkDocSh, "WorkDoc", nDocNo );
1458 
1459  // append the working document to the target document
1460  if( targetDocPageCount % 2 == 1 )
1461  ++targetDocPageCount; // Docs always start on odd pages (so offset must be even).
1462  SwNodeIndex appendedDocStart = pTargetDoc->AppendDoc( *pWorkDoc,
1463  nStartingPageNo, !bWorkDocInitialized, targetDocPageCount, nDocNo);
1464  targetDocPageCount += pWorkShell->GetPageCnt();
1465 
1466  if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) )
1467  lcl_SaveDebugDoc( xTargetDocShell.get(), "MergeDoc" );
1468 
1469  if (bMT_SHELL)
1470  {
1471  SwDocMergeInfo aMergeInfo;
1472  // Name of the mark is actually irrelevant, UNO bookmarks have internals names.
1473  aMergeInfo.startPageInTarget = pTargetDoc->getIDocumentMarkAccess()->makeMark(
1474  appendedDocStart, "", IDocumentMarkAccess::MarkType::UNO_BOOKMARK,
1476  aMergeInfo.nDBRow = nStartRow;
1477  rMergeDescriptor.pMailMergeConfigItem->AddMergedDocument( aMergeInfo );
1478  }
1479  }
1480  else
1481  {
1482  assert( bNeedsTempFiles );
1483  assert( pWorkShell->IsExpFieldsLocked() );
1484 
1485  // fields are locked, so it's fine to
1486  // restore the old / empty DB manager for save
1487  pWorkDoc->SetDBManager( pWorkDocOrigDBManager );
1488 
1489  // save merged document
1490  OUString sFileURL;
1491  if( !lcl_SaveDoc( aTempFileURL.get(), pStoreToFilter, pStoreToFilterOptions,
1492  &rMergeDescriptor.aSaveToFilterData, bIsPDFexport,
1493  xWorkDocSh, *pWorkShell, &sFileURL ) )
1494  {
1496  }
1497 
1498  // back to the MM DB manager
1499  pWorkDoc->SetDBManager( this );
1500 
1501  if( bMT_EMAIL && !IsMergeError() )
1502  {
1503  // schedule file for later removal
1504  aFilesToRemove.push_back( sFileURL );
1505 
1506  if( !SwMailMergeHelper::CheckMailAddress( sColumnData ) )
1507  {
1508  OSL_FAIL("invalid e-Mail address in database column");
1509  }
1510  else
1511  {
1512  uno::Reference< mail::XMailMessage > xMessage = lcl_CreateMailFromDoc(
1513  rMergeDescriptor, sFileURL, sColumnData, sMailBodyMimeType,
1514  sMailEncoding, pStoreToFilter->GetMimeType() );
1515  if( xMessage.is() )
1516  {
1517  osl::MutexGuard aGuard( m_pImpl->m_aAllEmailSendMutex );
1518  m_pImpl->m_xLastMessage.set( xMessage );
1519  xMailDispatcher->enqueueMailMessage( xMessage );
1520  if( !xMailDispatcher->isStarted() )
1521  xMailDispatcher->start();
1522  }
1523  }
1524  }
1525  }
1526  if( bCreateSingleFile || bIsPDFexport )
1527  {
1528  pWorkDoc->SetDBManager( pWorkDocOrigDBManager );
1529  xWorkDocSh->DoClose();
1530  xWorkDocSh = nullptr;
1531  }
1532  }
1533 
1534  bWorkDocInitialized = true;
1535  nDocNo++;
1536  nEndRow = m_pImpl->pMergeData ? m_pImpl->pMergeData->xResultSet->getRow() : 0;
1537 
1538  // Freeze the layouts of the target document after the first inserted
1539  // sub-document, to get the correct PageDesc.
1540  if(!bFreezedLayouts && bCreateSingleFile)
1541  {
1542  for ( auto aLayout : pTargetShell->GetDoc()->GetAllLayouts() )
1543  aLayout->FreezeLayout(true);
1544  bFreezedLayouts = true;
1545  }
1546  } while( IsMergeOk() &&
1547  ((bSynchronizedDoc && (nStartRow != nEndRow)) ? IsValidMergeRecord() : ToNextMergeRecord()));
1548 
1549  if ( xWorkDocSh.Is() && pWorkView->GetWrtShell().IsExpFieldsLocked() )
1550  {
1551  // Unlock document fields after merge complete
1552  pWorkView->GetWrtShell().UnlockExpFields();
1553  }
1554 
1555  if( !bCreateSingleFile )
1556  {
1557  if( bMT_PRINTER )
1559  if( !bIsPDFexport )
1560  {
1561  pWorkDoc->SetDBManager( pWorkDocOrigDBManager );
1562  xWorkDocSh->DoClose();
1563  }
1564  }
1565  else if( IsMergeOk() ) // && bCreateSingleFile
1566  {
1567  Application::Reschedule( true );
1568 
1569  // sw::DocumentLayoutManager::CopyLayoutFormat() did not generate
1570  // unique fly names, do it here once.
1571  pTargetDoc->SetInMailMerge(false);
1572  pTargetDoc->SetAllUniqueFlyNames();
1573 
1574  // Unfreeze target document layouts and correct all PageDescs.
1575  SAL_INFO( "sw.pageframe", "(MergeMailFiles pTargetShell->CalcLayout in" );
1576  pTargetShell->CalcLayout();
1577  SAL_INFO( "sw.pageframe", "MergeMailFiles pTargetShell->CalcLayout out)" );
1578  pTargetShell->GetViewOptions()->SetIdle( true );
1579  pTargetDoc->GetIDocumentUndoRedo().DoUndo( true );
1580  for ( auto aLayout : pTargetShell->GetDoc()->GetAllLayouts() )
1581  {
1582  aLayout->FreezeLayout(false);
1583  aLayout->AllCheckPageDescs();
1584  }
1585 
1586  Application::Reschedule( true );
1587 
1588  if( IsMergeOk() && bMT_FILE )
1589  {
1590  // save merged document
1591  assert( aTempFile.get() );
1592  INetURLObject aTempFileURL;
1593  if (sDescriptorPrefix.isEmpty() || !rMergeDescriptor.bPrefixIsFilename)
1594  aTempFileURL.SetURL( aTempFile->GetURL() );
1595  else
1596  {
1597  aTempFileURL.SetURL(sDescriptorPrefix);
1598  // remove the unneeded temporary file
1599  aTempFile->EnableKillingFile();
1600  }
1601  if( !lcl_SaveDoc( &aTempFileURL, pStoreToFilter,
1602  pStoreToFilterOptions, &rMergeDescriptor.aSaveToFilterData,
1603  bIsPDFexport, xTargetDocShell.get(), *pTargetShell ) )
1604  {
1606  }
1607  }
1608  else if( IsMergeOk() && bMT_PRINTER )
1609  {
1610  // print the target document
1611  uno::Sequence< beans::PropertyValue > aOptions( rMergeDescriptor.aPrintOptions );
1612  lcl_PreparePrinterOptions( rMergeDescriptor.aPrintOptions, aOptions );
1613  pTargetView->ExecPrint( aOptions, bIsMergeSilent, false/*bPrintAsync*/ );
1614  }
1615  }
1616 
1617  // we also show canceled documents, as long as there was no error
1618  if( !IsMergeError() && bMT_SHELL )
1619  // leave docshell available for caller (e.g. MM wizard)
1620  rMergeDescriptor.pMailMergeConfigItem->SetTargetView( pTargetView );
1621  else if( xTargetDocShell.is() )
1622  xTargetDocShell->DoClose();
1623 
1624  Application::Reschedule( true );
1625 
1626  if (xProgressDlg)
1627  {
1628  xProgressDlg->response(RET_OK);
1629  }
1630 
1631  // unlock all dispatchers
1632  pViewFrame = SfxViewFrame::GetFirst(pSourceDocSh);
1633  while (pViewFrame)
1634  {
1635  pViewFrame->GetDispatcher()->Lock(false);
1636  pViewFrame = SfxViewFrame::GetNext(*pViewFrame, pSourceDocSh);
1637  }
1638 
1639  SW_MOD()->SetView(&pSourceShell->GetView());
1640 
1641  if( xMailDispatcher.is() )
1642  {
1643  if( IsMergeOk() )
1644  {
1645  // TODO: Instead of polling via an AutoTimer, post an Idle event,
1646  // if the main loop has been made thread-safe.
1647  AutoTimer aEmailDispatcherPollTimer;
1648  aEmailDispatcherPollTimer.SetDebugName(
1649  "sw::SwDBManager aEmailDispatcherPollTimer" );
1650  aEmailDispatcherPollTimer.SetTimeout( 500 );
1651  aEmailDispatcherPollTimer.Start();
1652  while( IsMergeOk() && m_pImpl->m_xLastMessage.is() )
1654  aEmailDispatcherPollTimer.Stop();
1655  }
1656  xMailDispatcher->stop();
1657  xMailDispatcher->shutdown();
1658  }
1659 
1660  // remove the temporary files
1661  // has to be done after xMailDispatcher is finished, as mails may be
1662  // delivered as message attachments!
1663  for( const OUString &sFileURL : aFilesToRemove )
1664  SWUnoHelper::UCB_DeleteFile( sFileURL );
1665  }
1666  catch (const uno::Exception&)
1667  {
1668  if (xProgressDlg)
1669  {
1670  xProgressDlg->response(RET_CANCEL);
1671  }
1672  }
1673 
1674  return !IsMergeError();
1675 }
1676 
1678 {
1681 }
1682 
1683 // determine the column's Numberformat and transfer to the forwarded Formatter,
1684 // if applicable.
1685 sal_uLong SwDBManager::GetColumnFormat( const OUString& rDBName,
1686  const OUString& rTableName,
1687  const OUString& rColNm,
1688  SvNumberFormatter* pNFormatr,
1689  LanguageType nLanguage )
1690 {
1691  sal_uLong nRet = 0;
1692  if(pNFormatr)
1693  {
1694  uno::Reference< sdbc::XDataSource> xSource;
1695  uno::Reference< sdbc::XConnection> xConnection;
1696  bool bUseMergeData = false;
1697  uno::Reference< sdbcx::XColumnsSupplier> xColsSupp;
1698  bool bDisposeConnection = false;
1699  if(m_pImpl->pMergeData &&
1700  ((m_pImpl->pMergeData->sDataSource == rDBName && m_pImpl->pMergeData->sCommand == rTableName) ||
1701  (rDBName.isEmpty() && rTableName.isEmpty())))
1702  {
1703  xConnection = m_pImpl->pMergeData->xConnection;
1704  xSource = SwDBManager::getDataSourceAsParent(xConnection,rDBName);
1705  bUseMergeData = true;
1706  xColsSupp.set(m_pImpl->pMergeData->xResultSet, css::uno::UNO_QUERY);
1707  }
1708  if(!xConnection.is())
1709  {
1710  SwDBData aData;
1711  aData.sDataSource = rDBName;
1712  aData.sCommand = rTableName;
1713  aData.nCommandType = -1;
1714  SwDSParam* pParam = FindDSData(aData, false);
1715  if(pParam && pParam->xConnection.is())
1716  {
1717  xConnection = pParam->xConnection;
1718  xColsSupp.set(pParam->xResultSet, css::uno::UNO_QUERY);
1719  }
1720  else
1721  {
1722  xConnection = RegisterConnection( rDBName );
1723  bDisposeConnection = true;
1724  }
1725  if(bUseMergeData)
1726  m_pImpl->pMergeData->xConnection = xConnection;
1727  }
1728  bool bDispose = !xColsSupp.is();
1729  if(bDispose)
1730  {
1731  xColsSupp = SwDBManager::GetColumnSupplier(xConnection, rTableName);
1732  }
1733  if(xColsSupp.is())
1734  {
1735  uno::Reference<container::XNameAccess> xCols;
1736  try
1737  {
1738  xCols = xColsSupp->getColumns();
1739  }
1740  catch (const uno::Exception&)
1741  {
1742  TOOLS_WARN_EXCEPTION("sw.mailmerge", "Exception in getColumns()");
1743  }
1744  if(!xCols.is() || !xCols->hasByName(rColNm))
1745  return nRet;
1746  uno::Any aCol = xCols->getByName(rColNm);
1747  uno::Reference< beans::XPropertySet > xColumn;
1748  aCol >>= xColumn;
1749  nRet = GetColumnFormat(xSource, xConnection, xColumn, pNFormatr, nLanguage);
1750  if(bDispose)
1751  {
1752  ::comphelper::disposeComponent( xColsSupp );
1753  }
1754  if(bDisposeConnection)
1755  {
1756  ::comphelper::disposeComponent( xConnection );
1757  }
1758  }
1759  else
1760  nRet = pNFormatr->GetFormatIndex( NF_NUMBER_STANDARD, LANGUAGE_SYSTEM );
1761  }
1762  return nRet;
1763 }
1764 
1765 sal_uLong SwDBManager::GetColumnFormat( uno::Reference< sdbc::XDataSource> const & xSource_in,
1766  uno::Reference< sdbc::XConnection> const & xConnection,
1767  uno::Reference< beans::XPropertySet> const & xColumn,
1768  SvNumberFormatter* pNFormatr,
1769  LanguageType nLanguage )
1770 {
1771  auto xSource = xSource_in;
1772 
1773  // set the NumberFormat in the doc if applicable
1774  sal_uLong nRet = 0;
1775 
1776  if(!xSource.is())
1777  {
1778  uno::Reference<container::XChild> xChild(xConnection, uno::UNO_QUERY);
1779  if ( xChild.is() )
1780  xSource.set(xChild->getParent(), uno::UNO_QUERY);
1781  }
1782  if(xSource.is() && xConnection.is() && xColumn.is() && pNFormatr)
1783  {
1784  SvNumberFormatsSupplierObj* pNumFormat = new SvNumberFormatsSupplierObj( pNFormatr );
1785  uno::Reference< util::XNumberFormatsSupplier > xDocNumFormatsSupplier = pNumFormat;
1786  uno::Reference< util::XNumberFormats > xDocNumberFormats = xDocNumFormatsSupplier->getNumberFormats();
1787  uno::Reference< util::XNumberFormatTypes > xDocNumberFormatTypes(xDocNumberFormats, uno::UNO_QUERY);
1788 
1789  css::lang::Locale aLocale( LanguageTag( nLanguage ).getLocale());
1790 
1791  //get the number formatter of the data source
1792  uno::Reference<beans::XPropertySet> xSourceProps(xSource, uno::UNO_QUERY);
1793  uno::Reference< util::XNumberFormats > xNumberFormats;
1794  if(xSourceProps.is())
1795  {
1796  uno::Any aFormats = xSourceProps->getPropertyValue("NumberFormatsSupplier");
1797  if(aFormats.hasValue())
1798  {
1799  uno::Reference<util::XNumberFormatsSupplier> xSuppl;
1800  aFormats >>= xSuppl;
1801  if(xSuppl.is())
1802  {
1803  xNumberFormats = xSuppl->getNumberFormats();
1804  }
1805  }
1806  }
1807  bool bUseDefault = true;
1808  try
1809  {
1810  uno::Any aFormatKey = xColumn->getPropertyValue("FormatKey");
1811  if(aFormatKey.hasValue())
1812  {
1813  sal_Int32 nFormat = 0;
1814  aFormatKey >>= nFormat;
1815  if(xNumberFormats.is())
1816  {
1817  try
1818  {
1819  uno::Reference<beans::XPropertySet> xNumProps = xNumberFormats->getByKey( nFormat );
1820  uno::Any aFormatString = xNumProps->getPropertyValue("FormatString");
1821  uno::Any aLocaleVal = xNumProps->getPropertyValue("Locale");
1822  OUString sFormat;
1823  aFormatString >>= sFormat;
1824  lang::Locale aLoc;
1825  aLocaleVal >>= aLoc;
1826  nFormat = xDocNumberFormats->queryKey( sFormat, aLoc, false );
1827  if(NUMBERFORMAT_ENTRY_NOT_FOUND == sal::static_int_cast< sal_uInt32, sal_Int32>(nFormat))
1828  nFormat = xDocNumberFormats->addNew( sFormat, aLoc );
1829  nRet = nFormat;
1830  bUseDefault = false;
1831  }
1832  catch (const uno::Exception&)
1833  {
1834  TOOLS_WARN_EXCEPTION("sw.mailmerge", "illegal number format key");
1835  }
1836  }
1837  }
1838  }
1839  catch(const uno::Exception&)
1840  {
1841  SAL_WARN("sw.mailmerge", "no FormatKey property found");
1842  }
1843  if(bUseDefault)
1844  nRet = dbtools::getDefaultNumberFormat(xColumn, xDocNumberFormatTypes, aLocale);
1845  }
1846  return nRet;
1847 }
1848 
1849 sal_Int32 SwDBManager::GetColumnType( const OUString& rDBName,
1850  const OUString& rTableName,
1851  const OUString& rColNm )
1852 {
1853  sal_Int32 nRet = sdbc::DataType::SQLNULL;
1854  SwDBData aData;
1855  aData.sDataSource = rDBName;
1856  aData.sCommand = rTableName;
1857  aData.nCommandType = -1;
1858  SwDSParam* pParam = FindDSData(aData, false);
1859  uno::Reference< sdbc::XConnection> xConnection;
1860  uno::Reference< sdbcx::XColumnsSupplier > xColsSupp;
1861  bool bDispose = false;
1862  if(pParam && pParam->xConnection.is())
1863  {
1864  xConnection = pParam->xConnection;
1865  xColsSupp.set( pParam->xResultSet, uno::UNO_QUERY );
1866  }
1867  else
1868  {
1869  xConnection = RegisterConnection( rDBName );
1870  }
1871  if( !xColsSupp.is() )
1872  {
1873  xColsSupp = SwDBManager::GetColumnSupplier(xConnection, rTableName);
1874  bDispose = true;
1875  }
1876  if(xColsSupp.is())
1877  {
1878  uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
1879  if(xCols->hasByName(rColNm))
1880  {
1881  uno::Any aCol = xCols->getByName(rColNm);
1882  uno::Reference<beans::XPropertySet> xCol;
1883  aCol >>= xCol;
1884  uno::Any aType = xCol->getPropertyValue("Type");
1885  aType >>= nRet;
1886  }
1887  if(bDispose)
1888  ::comphelper::disposeComponent( xColsSupp );
1889  }
1890  return nRet;
1891 }
1892 
1893 uno::Reference< sdbc::XConnection> SwDBManager::GetConnection(const OUString& rDataSource,
1894  uno::Reference<sdbc::XDataSource>& rxSource, const SwView *pView)
1895 {
1896  uno::Reference< sdbc::XConnection> xConnection;
1897  uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
1898  try
1899  {
1900  uno::Reference<sdb::XCompletedConnection> xComplConnection(dbtools::getDataSource(rDataSource, xContext), uno::UNO_QUERY);
1901  if ( xComplConnection.is() )
1902  {
1903  rxSource.set(xComplConnection, uno::UNO_QUERY);
1904  weld::Window* pWindow = pView ? pView->GetFrameWeld() : nullptr;
1905  uno::Reference< task::XInteractionHandler > xHandler( task::InteractionHandler::createWithParent(xContext, pWindow ? pWindow->GetXWindow() : nullptr), uno::UNO_QUERY_THROW );
1906  xConnection = xComplConnection->connectWithCompletion( xHandler );
1907  }
1908  }
1909  catch(const uno::Exception&)
1910  {
1911  }
1912 
1913  return xConnection;
1914 }
1915 
1916 uno::Reference< sdbcx::XColumnsSupplier> SwDBManager::GetColumnSupplier(uno::Reference<sdbc::XConnection> const & xConnection,
1917  const OUString& rTableOrQuery,
1918  SwDBSelect eTableOrQuery)
1919 {
1920  uno::Reference< sdbcx::XColumnsSupplier> xRet;
1921  try
1922  {
1923  if(eTableOrQuery == SwDBSelect::UNKNOWN)
1924  {
1925  //search for a table with the given command name
1926  uno::Reference<sdbcx::XTablesSupplier> xTSupplier(xConnection, uno::UNO_QUERY);
1927  if(xTSupplier.is())
1928  {
1929  uno::Reference<container::XNameAccess> xTables = xTSupplier->getTables();
1930  eTableOrQuery = xTables->hasByName(rTableOrQuery) ?
1932  }
1933  }
1934  sal_Int32 nCommandType = SwDBSelect::TABLE == eTableOrQuery ?
1935  sdb::CommandType::TABLE : sdb::CommandType::QUERY;
1936  uno::Reference< lang::XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
1937  uno::Reference<sdbc::XRowSet> xRowSet(xMgr->createInstance("com.sun.star.sdb.RowSet"), uno::UNO_QUERY);
1938 
1939  OUString sDataSource;
1940  uno::Reference<sdbc::XDataSource> xSource = SwDBManager::getDataSourceAsParent(xConnection, sDataSource);
1941  uno::Reference<beans::XPropertySet> xSourceProperties(xSource, uno::UNO_QUERY);
1942  if(xSourceProperties.is())
1943  {
1944  xSourceProperties->getPropertyValue("Name") >>= sDataSource;
1945  }
1946 
1947  uno::Reference<beans::XPropertySet> xRowProperties(xRowSet, uno::UNO_QUERY);
1948  xRowProperties->setPropertyValue("DataSourceName", uno::makeAny(sDataSource));
1949  xRowProperties->setPropertyValue("Command", uno::makeAny(rTableOrQuery));
1950  xRowProperties->setPropertyValue("CommandType", uno::makeAny(nCommandType));
1951  xRowProperties->setPropertyValue("FetchSize", uno::makeAny(sal_Int32(10)));
1952  xRowProperties->setPropertyValue("ActiveConnection", uno::makeAny(xConnection));
1953  xRowSet->execute();
1954  xRet.set( xRowSet, uno::UNO_QUERY );
1955  }
1956  catch (const uno::Exception&)
1957  {
1958  TOOLS_WARN_EXCEPTION("sw.mailmerge", "Exception in SwDBManager::GetColumnSupplier");
1959  }
1960 
1961  return xRet;
1962 }
1963 
1964 OUString SwDBManager::GetDBField(uno::Reference<beans::XPropertySet> const & xColumnProps,
1965  const SwDBFormatData& rDBFormatData,
1966  double* pNumber)
1967 {
1968  uno::Reference< sdb::XColumn > xColumn(xColumnProps, uno::UNO_QUERY);
1969  OUString sRet;
1970  assert( xColumn.is() && "SwDBManager::::ImportDBField: illegal arguments" );
1971  if(!xColumn.is())
1972  return sRet;
1973 
1974  uno::Any aType = xColumnProps->getPropertyValue("Type");
1975  sal_Int32 eDataType = sdbc::DataType::SQLNULL;
1976  aType >>= eDataType;
1977  switch(eDataType)
1978  {
1979  case sdbc::DataType::CHAR:
1980  case sdbc::DataType::VARCHAR:
1981  case sdbc::DataType::LONGVARCHAR:
1982  try
1983  {
1984  sRet = xColumn->getString();
1985  sRet = sRet.replace( '\xb', '\n' ); // MSWord uses \xb as a newline
1986  }
1987  catch(const sdbc::SQLException&)
1988  {
1989  }
1990  break;
1991  case sdbc::DataType::BIT:
1992  case sdbc::DataType::BOOLEAN:
1993  case sdbc::DataType::TINYINT:
1994  case sdbc::DataType::SMALLINT:
1995  case sdbc::DataType::INTEGER:
1996  case sdbc::DataType::BIGINT:
1997  case sdbc::DataType::FLOAT:
1998  case sdbc::DataType::REAL:
1999  case sdbc::DataType::DOUBLE:
2000  case sdbc::DataType::NUMERIC:
2001  case sdbc::DataType::DECIMAL:
2002  case sdbc::DataType::DATE:
2003  case sdbc::DataType::TIME:
2004  case sdbc::DataType::TIMESTAMP:
2005  {
2006 
2007  try
2008  {
2010  xColumnProps,
2011  rDBFormatData.xFormatter,
2012  rDBFormatData.aLocale,
2013  rDBFormatData.aNullDate);
2014  if (pNumber)
2015  {
2016  double fVal = xColumn->getDouble();
2017  if(!xColumn->wasNull())
2018  {
2019  *pNumber = fVal;
2020  }
2021  }
2022  }
2023  catch (const uno::Exception&)
2024  {
2025  TOOLS_WARN_EXCEPTION("sw.mailmerge", "");
2026  }
2027 
2028  }
2029  break;
2030  }
2031 
2032  return sRet;
2033 }
2034 
2035 // checks if a desired data source table or query is open
2036 bool SwDBManager::IsDataSourceOpen(const OUString& rDataSource,
2037  const OUString& rTableOrQuery, bool bMergeShell)
2038 {
2039  if(m_pImpl->pMergeData)
2040  {
2041  return ((rDataSource == m_pImpl->pMergeData->sDataSource
2042  && rTableOrQuery == m_pImpl->pMergeData->sCommand)
2043  || (rDataSource.isEmpty() && rTableOrQuery.isEmpty()))
2044  && m_pImpl->pMergeData->xResultSet.is();
2045  }
2046  else if(!bMergeShell)
2047  {
2048  SwDBData aData;
2049  aData.sDataSource = rDataSource;
2050  aData.sCommand = rTableOrQuery;
2051  aData.nCommandType = -1;
2052  SwDSParam* pFound = FindDSData(aData, false);
2053  return (pFound && pFound->xResultSet.is());
2054  }
2055  return false;
2056 }
2057 
2058 // read column data at a specified position
2059 bool SwDBManager::GetColumnCnt(const OUString& rSourceName, const OUString& rTableName,
2060  const OUString& rColumnName, sal_uInt32 nAbsRecordId,
2061  LanguageType nLanguage,
2062  OUString& rResult, double* pNumber)
2063 {
2064  bool bRet = false;
2065  SwDSParam* pFound = nullptr;
2066  //check if it's the merge data source
2067  if(m_pImpl->pMergeData &&
2068  rSourceName == m_pImpl->pMergeData->sDataSource &&
2069  rTableName == m_pImpl->pMergeData->sCommand)
2070  {
2071  pFound = m_pImpl->pMergeData.get();
2072  }
2073  else
2074  {
2075  SwDBData aData;
2076  aData.sDataSource = rSourceName;
2077  aData.sCommand = rTableName;
2078  aData.nCommandType = -1;
2079  pFound = FindDSData(aData, false);
2080  }
2081  if (!pFound)
2082  return false;
2083  //check validity of supplied record Id
2084  if(pFound->aSelection.hasElements())
2085  {
2086  //the destination has to be an element of the selection
2087  bool bFound = std::any_of(pFound->aSelection.begin(), pFound->aSelection.end(),
2088  [nAbsRecordId](const uno::Any& rSelection) {
2089  sal_Int32 nSelection = 0;
2090  rSelection >>= nSelection;
2091  return nSelection == static_cast<sal_Int32>(nAbsRecordId);
2092  });
2093  if(!bFound)
2094  return false;
2095  }
2096  if( pFound->HasValidRecord() )
2097  {
2098  sal_Int32 nOldRow = 0;
2099  try
2100  {
2101  nOldRow = pFound->xResultSet->getRow();
2102  }
2103  catch(const uno::Exception&)
2104  {
2105  return false;
2106  }
2107  //position to the desired index
2108  bool bMove = true;
2109  if ( nOldRow != static_cast<sal_Int32>(nAbsRecordId) )
2110  bMove = lcl_MoveAbsolute(pFound, nAbsRecordId);
2111  if(bMove)
2112  bRet = lcl_GetColumnCnt(pFound, rColumnName, nLanguage, rResult, pNumber);
2113  if ( nOldRow != static_cast<sal_Int32>(nAbsRecordId) )
2114  lcl_MoveAbsolute(pFound, nOldRow);
2115  }
2116  return bRet;
2117 }
2118 
2119 // reads the column data at the current position
2120 bool SwDBManager::GetMergeColumnCnt(const OUString& rColumnName, LanguageType nLanguage,
2121  OUString &rResult, double *pNumber)
2122 {
2123  if( !IsValidMergeRecord() )
2124  {
2125  rResult.clear();
2126  return false;
2127  }
2128 
2129  bool bRet = lcl_GetColumnCnt(m_pImpl->pMergeData.get(), rColumnName, nLanguage, rResult, pNumber);
2130  return bRet;
2131 }
2132 
2134 {
2135  assert( m_pImpl->pMergeData && m_pImpl->pMergeData->xResultSet.is() && "no data source in merge" );
2136  return lcl_ToNextRecord( m_pImpl->pMergeData.get() );
2137 }
2138 
2140  LanguageType nLanguage, SwCalc &rCalc )
2141 {
2142  if( !IsValidMergeRecord() )
2143  return false;
2144 
2145  uno::Reference< sdbcx::XColumnsSupplier > xColsSupp( m_pImpl->pMergeData->xResultSet, uno::UNO_QUERY );
2146  if( !xColsSupp.is() )
2147  return false;
2148 
2149  {
2150  uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
2151  const uno::Sequence<OUString> aColNames = xCols->getElementNames();
2152  OUString aString;
2153 
2154  // add the "record number" variable, as SwCalc::VarLook would.
2155  rCalc.VarChange( GetAppCharClass().lowercase(
2157 
2158  for( const OUString& rColName : aColNames )
2159  {
2160  // get the column type
2161  sal_Int32 nColumnType = sdbc::DataType::SQLNULL;
2162  uno::Any aCol = xCols->getByName( rColName );
2163  uno::Reference<beans::XPropertySet> xColumnProps;
2164  aCol >>= xColumnProps;
2165  uno::Any aType = xColumnProps->getPropertyValue( "Type" );
2166  aType >>= nColumnType;
2167  double aNumber = DBL_MAX;
2168 
2169  lcl_GetColumnCnt( m_pImpl->pMergeData.get(), xColumnProps, nLanguage, aString, &aNumber );
2170 
2171  sal_uInt32 nFormat = GetColumnFormat( m_pImpl->pMergeData->sDataSource,
2172  m_pImpl->pMergeData->sCommand,
2173  rColName, pDocFormatter, nLanguage );
2174  // aNumber is overwritten by SwDBField::FormatValue, so store initial status
2175  bool colIsNumber = aNumber != DBL_MAX;
2176  bool bValidValue = SwDBField::FormatValue( pDocFormatter, aString, nFormat,
2177  aNumber, nColumnType );
2178  if( colIsNumber )
2179  {
2180  if( bValidValue )
2181  {
2182  SwSbxValue aValue;
2183  aValue.PutDouble( aNumber );
2184  aValue.SetDBvalue( true );
2185  SAL_INFO( "sw.ui", "'" << rColName << "': " << aNumber << " / " << aString );
2186  rCalc.VarChange( rColName, aValue );
2187  }
2188  }
2189  else
2190  {
2191  SwSbxValue aValue;
2192  aValue.PutString( aString );
2193  aValue.SetDBvalue( true );
2194  SAL_INFO( "sw.ui", "'" << rColName << "': " << aString );
2195  rCalc.VarChange( rColName, aValue );
2196  }
2197  }
2198  }
2199 
2200  return true;
2201 }
2202 
2204  const OUString& rDataSource, const OUString& rCommand)
2205 {
2206  SwDSParam* pFound = nullptr;
2207  if(m_pImpl->pMergeData &&
2208  rDataSource == m_pImpl->pMergeData->sDataSource &&
2209  rCommand == m_pImpl->pMergeData->sCommand)
2210  {
2211  pFound = m_pImpl->pMergeData.get();
2212  }
2213  else
2214  {
2215  SwDBData aData;
2216  aData.sDataSource = rDataSource;
2217  aData.sCommand = rCommand;
2218  aData.nCommandType = -1;
2219  pFound = FindDSData(aData, false);
2220  }
2221  lcl_ToNextRecord( pFound );
2222 }
2223 
2224 static bool lcl_ToNextRecord( SwDSParam* pParam, const SwDBNextRecord action )
2225 {
2226  bool bRet = true;
2227 
2228  assert( SwDBNextRecord::NEXT == action ||
2229  (SwDBNextRecord::FIRST == action && pParam) );
2230  if( nullptr == pParam )
2231  return false;
2232 
2233  if( action == SwDBNextRecord::FIRST )
2234  {
2235  pParam->nSelectionIndex = 0;
2236  pParam->bEndOfDB = false;
2237  }
2238 
2239  if( !pParam->HasValidRecord() )
2240  return false;
2241 
2242  try
2243  {
2244  if( pParam->aSelection.hasElements() )
2245  {
2246  if( pParam->nSelectionIndex >= pParam->aSelection.getLength() )
2247  pParam->bEndOfDB = true;
2248  else
2249  {
2250  sal_Int32 nPos = 0;
2251  pParam->aSelection.getConstArray()[ pParam->nSelectionIndex ] >>= nPos;
2252  pParam->bEndOfDB = !pParam->xResultSet->absolute( nPos );
2253  }
2254  }
2255  else if( action == SwDBNextRecord::FIRST )
2256  {
2257  pParam->bEndOfDB = !pParam->xResultSet->first();
2258  }
2259  else
2260  {
2261  sal_Int32 nBefore = pParam->xResultSet->getRow();
2262  pParam->bEndOfDB = !pParam->xResultSet->next();
2263  if( !pParam->bEndOfDB && nBefore == pParam->xResultSet->getRow() )
2264  {
2265  // next returned true but it didn't move
2266  ::dbtools::throwFunctionSequenceException( pParam->xResultSet );
2267  }
2268  }
2269 
2270  ++pParam->nSelectionIndex;
2271  bRet = !pParam->bEndOfDB;
2272  }
2273  catch( const uno::Exception & )
2274  {
2275  // we allow merging with empty databases, so don't warn on init
2276  TOOLS_WARN_EXCEPTION_IF(action == SwDBNextRecord::NEXT,
2277  "sw.mailmerge", "exception in ToNextRecord()");
2278  pParam->bEndOfDB = true;
2279  bRet = false;
2280  }
2281  return bRet;
2282 }
2283 
2284 // synchronized labels contain a next record field at their end
2285 // to assure that the next page can be created in mail merge
2286 // the cursor position must be validated
2288 {
2289  return( m_pImpl->pMergeData && m_pImpl->pMergeData->HasValidRecord() );
2290 }
2291 
2293 {
2294  sal_uInt32 nRet = 0;
2295  assert( m_pImpl->pMergeData &&
2296  m_pImpl->pMergeData->xResultSet.is() && "no data source in merge" );
2297  if(!m_pImpl->pMergeData || !m_pImpl->pMergeData->xResultSet.is())
2298  return 0;
2299  try
2300  {
2301  nRet = m_pImpl->pMergeData->xResultSet->getRow();
2302  }
2303  catch(const uno::Exception&)
2304  {
2305  }
2306  return nRet;
2307 }
2308 
2309 bool SwDBManager::ToRecordId(sal_Int32 nSet)
2310 {
2311  assert( m_pImpl->pMergeData &&
2312  m_pImpl->pMergeData->xResultSet.is() && "no data source in merge" );
2313  if(!m_pImpl->pMergeData || !m_pImpl->pMergeData->xResultSet.is()|| nSet < 0)
2314  return false;
2315  bool bRet = false;
2316  sal_Int32 nAbsPos = nSet;
2317  assert(nAbsPos >= 0);
2318  bRet = lcl_MoveAbsolute(m_pImpl->pMergeData.get(), nAbsPos);
2319  m_pImpl->pMergeData->bEndOfDB = !bRet;
2320  return bRet;
2321 }
2322 
2323 bool SwDBManager::OpenDataSource(const OUString& rDataSource, const OUString& rTableOrQuery)
2324 {
2325  SwDBData aData;
2326  aData.sDataSource = rDataSource;
2327  aData.sCommand = rTableOrQuery;
2328  aData.nCommandType = -1;
2329 
2330  SwDSParam* pFound = FindDSData(aData, true);
2331  if(pFound->xResultSet.is())
2332  return true;
2333  SwDSParam* pParam = FindDSConnection(rDataSource, false);
2334  if(pParam && pParam->xConnection.is())
2335  pFound->xConnection = pParam->xConnection;
2336  if(pFound->xConnection.is())
2337  {
2338  try
2339  {
2340  uno::Reference< sdbc::XDatabaseMetaData > xMetaData = pFound->xConnection->getMetaData();
2341  try
2342  {
2343  pFound->bScrollable = xMetaData
2344  ->supportsResultSetType(sal_Int32(sdbc::ResultSetType::SCROLL_INSENSITIVE));
2345  }
2346  catch(const uno::Exception&)
2347  {
2348  // DB driver may not be ODBC 3.0 compliant
2349  pFound->bScrollable = true;
2350  }
2351  pFound->xStatement = pFound->xConnection->createStatement();
2352  OUString aQuoteChar = xMetaData->getIdentifierQuoteString();
2353  OUString sStatement = "SELECT * FROM " + aQuoteChar + rTableOrQuery + aQuoteChar;
2354  pFound->xResultSet = pFound->xStatement->executeQuery( sStatement );
2355 
2356  //after executeQuery the cursor must be positioned
2357  pFound->bEndOfDB = !pFound->xResultSet->next();
2358  ++pFound->nSelectionIndex;
2359  }
2360  catch (const uno::Exception&)
2361  {
2362  pFound->xResultSet = nullptr;
2363  pFound->xStatement = nullptr;
2364  pFound->xConnection = nullptr;
2365  }
2366  }
2367  return pFound->xResultSet.is();
2368 }
2369 
2370 uno::Reference< sdbc::XConnection> const & SwDBManager::RegisterConnection(OUString const& rDataSource)
2371 {
2372  SwDSParam* pFound = SwDBManager::FindDSConnection(rDataSource, true);
2373  uno::Reference< sdbc::XDataSource> xSource;
2374  if(!pFound->xConnection.is())
2375  {
2376  SwView* pView = (m_pDoc && m_pDoc->GetDocShell()) ? m_pDoc->GetDocShell()->GetView() : nullptr;
2377  pFound->xConnection = SwDBManager::GetConnection(rDataSource, xSource, pView);
2378  try
2379  {
2380  uno::Reference<lang::XComponent> xComponent(pFound->xConnection, uno::UNO_QUERY);
2381  if(xComponent.is())
2382  xComponent->addEventListener(m_pImpl->m_xDisposeListener.get());
2383  }
2384  catch(const uno::Exception&)
2385  {
2386  }
2387  }
2388  return pFound->xConnection;
2389 }
2390 
2392  const OUString& rDataSource, const OUString& rTableOrQuery, sal_Int32 nCommandType)
2393 {
2394  sal_uInt32 nRet = 0xffffffff;
2395  //check for merge data source first
2396  if(m_pImpl->pMergeData &&
2397  ((rDataSource == m_pImpl->pMergeData->sDataSource &&
2398  rTableOrQuery == m_pImpl->pMergeData->sCommand) ||
2399  (rDataSource.isEmpty() && rTableOrQuery.isEmpty())) &&
2400  (nCommandType == -1 || nCommandType == m_pImpl->pMergeData->nCommandType) &&
2401  m_pImpl->pMergeData->xResultSet.is())
2402  {
2403  nRet = GetSelectedRecordId();
2404  }
2405  else
2406  {
2407  SwDBData aData;
2408  aData.sDataSource = rDataSource;
2409  aData.sCommand = rTableOrQuery;
2410  aData.nCommandType = nCommandType;
2411  SwDSParam* pFound = FindDSData(aData, false);
2412  if(pFound && pFound->xResultSet.is())
2413  {
2414  try
2415  { //if a selection array is set the current row at the result set may not be set yet
2416  if(pFound->aSelection.hasElements())
2417  {
2418  sal_Int32 nSelIndex = pFound->nSelectionIndex;
2419  if(nSelIndex >= pFound->aSelection.getLength())
2420  nSelIndex = pFound->aSelection.getLength() -1;
2421  pFound->aSelection.getConstArray()[nSelIndex] >>= nRet;
2422 
2423  }
2424  else
2425  nRet = pFound->xResultSet->getRow();
2426  }
2427  catch(const uno::Exception&)
2428  {
2429  }
2430  }
2431  }
2432  return nRet;
2433 }
2434 
2435 // close all data sources - after fields were updated
2436 void SwDBManager::CloseAll(bool bIncludingMerge)
2437 {
2438  //the only thing done here is to reset the selection index
2439  //all connections stay open
2440  for (auto & pParam : m_DataSourceParams)
2441  {
2442  if (bIncludingMerge || pParam.get() != m_pImpl->pMergeData.get())
2443  {
2444  pParam->nSelectionIndex = 0;
2445  pParam->bEndOfDB = false;
2446  try
2447  {
2448  if(!m_bInMerge && pParam->xResultSet.is())
2449  pParam->xResultSet->first();
2450  }
2451  catch(const uno::Exception&)
2452  {}
2453  }
2454  }
2455 }
2456 
2457 SwDSParam* SwDBManager::FindDSData(const SwDBData& rData, bool bCreate)
2458 {
2459  //prefer merge data if available
2460  if(m_pImpl->pMergeData &&
2461  ((rData.sDataSource == m_pImpl->pMergeData->sDataSource &&
2462  rData.sCommand == m_pImpl->pMergeData->sCommand) ||
2463  (rData.sDataSource.isEmpty() && rData.sCommand.isEmpty())) &&
2464  (rData.nCommandType == -1 || rData.nCommandType == m_pImpl->pMergeData->nCommandType ||
2465  (bCreate && m_pImpl->pMergeData->nCommandType == -1)))
2466  {
2467  return m_pImpl->pMergeData.get();
2468  }
2469 
2470  SwDSParam* pFound = nullptr;
2471  for (size_t nPos = m_DataSourceParams.size(); nPos; nPos--)
2472  {
2473  SwDSParam* pParam = m_DataSourceParams[nPos - 1].get();
2474  if(rData.sDataSource == pParam->sDataSource &&
2475  rData.sCommand == pParam->sCommand &&
2476  (rData.nCommandType == -1 || rData.nCommandType == pParam->nCommandType ||
2477  (bCreate && pParam->nCommandType == -1)))
2478  {
2479  // calls from the calculator may add a connection with an invalid commandtype
2480  //later added "real" data base connections have to re-use the already available
2481  //DSData and set the correct CommandType
2482  if(bCreate && pParam->nCommandType == -1)
2483  pParam->nCommandType = rData.nCommandType;
2484  pFound = pParam;
2485  break;
2486  }
2487  }
2488  if(bCreate && !pFound)
2489  {
2490  pFound = new SwDSParam(rData);
2491  m_DataSourceParams.push_back(std::unique_ptr<SwDSParam>(pFound));
2492  try
2493  {
2494  uno::Reference<lang::XComponent> xComponent(pFound->xConnection, uno::UNO_QUERY);
2495  if(xComponent.is())
2496  xComponent->addEventListener(m_pImpl->m_xDisposeListener.get());
2497  }
2498  catch(const uno::Exception&)
2499  {
2500  }
2501  }
2502  return pFound;
2503 }
2504 
2505 SwDSParam* SwDBManager::FindDSConnection(const OUString& rDataSource, bool bCreate)
2506 {
2507  //prefer merge data if available
2508  if(m_pImpl->pMergeData && rDataSource == m_pImpl->pMergeData->sDataSource )
2509  {
2510  SetAsUsed(rDataSource);
2511  return m_pImpl->pMergeData.get();
2512  }
2513  SwDSParam* pFound = nullptr;
2514  for (const auto & pParam : m_DataSourceParams)
2515  {
2516  if(rDataSource == pParam->sDataSource)
2517  {
2518  SetAsUsed(rDataSource);
2519  pFound = pParam.get();
2520  break;
2521  }
2522  }
2523  if(bCreate && !pFound)
2524  {
2525  SwDBData aData;
2526  aData.sDataSource = rDataSource;
2527  pFound = new SwDSParam(aData);
2528  SetAsUsed(rDataSource);
2529  m_DataSourceParams.push_back(std::unique_ptr<SwDSParam>(pFound));
2530  try
2531  {
2532  uno::Reference<lang::XComponent> xComponent(pFound->xConnection, uno::UNO_QUERY);
2533  if(xComponent.is())
2534  xComponent->addEventListener(m_pImpl->m_xDisposeListener.get());
2535  }
2536  catch(const uno::Exception&)
2537  {
2538  }
2539  }
2540  return pFound;
2541 }
2542 
2544 {
2545  return SW_MOD()->GetDBConfig()->GetAddressSource();
2546 }
2547 
2548 uno::Sequence<OUString> SwDBManager::GetExistingDatabaseNames()
2549 {
2550  uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
2551  uno::Reference<sdb::XDatabaseContext> xDBContext = sdb::DatabaseContext::create(xContext);
2552  return xDBContext->getElementNames();
2553 }
2554 
2555 namespace sw
2556 {
2558 {
2559  OUString sExt(rURL.GetFileExtension());
2561 
2562  if (sExt == "odb")
2563  {
2564  type = DBConnURIType::ODB;
2565  }
2566  else if (sExt.equalsIgnoreAsciiCase("sxc")
2567  || sExt.equalsIgnoreAsciiCase("ods")
2568  || sExt.equalsIgnoreAsciiCase("xls")
2569  || sExt.equalsIgnoreAsciiCase("xlsx"))
2570  {
2571  type = DBConnURIType::CALC;
2572  }
2573  else if (sExt.equalsIgnoreAsciiCase("sxw") || sExt.equalsIgnoreAsciiCase("odt") || sExt.equalsIgnoreAsciiCase("doc") || sExt.equalsIgnoreAsciiCase("docx"))
2574  {
2575  type = DBConnURIType::WRITER;
2576  }
2577  else if (sExt.equalsIgnoreAsciiCase("dbf"))
2578  {
2579  type = DBConnURIType::DBASE;
2580  }
2581  else if (sExt.equalsIgnoreAsciiCase("csv") || sExt.equalsIgnoreAsciiCase("txt"))
2582  {
2583  type = DBConnURIType::FLAT;
2584  }
2585 #ifdef _WIN32
2586  else if (sExt.equalsIgnoreAsciiCase("mdb") || sExt.equalsIgnoreAsciiCase("mde"))
2587  {
2588  type = DBConnURIType::MSJET;
2589  }
2590  else if (sExt.equalsIgnoreAsciiCase("accdb") || sExt.equalsIgnoreAsciiCase("accde"))
2591  {
2592  type = DBConnURIType::MSACE;
2593  }
2594 #endif
2595  return type;
2596 }
2597 }
2598 
2599 namespace
2600 {
2601 uno::Any GetDBunoURI(const INetURLObject &rURL, DBConnURIType& rType)
2602 {
2603  uno::Any aURLAny;
2604 
2605  if (rType == DBConnURIType::UNKNOWN)
2606  rType = GetDBunoType(rURL);
2607 
2608  switch (rType) {
2609  case DBConnURIType::UNKNOWN:
2610  case DBConnURIType::ODB:
2611  break;
2612  case DBConnURIType::CALC:
2613  {
2614  OUString sDBURL = "sdbc:calc:" +
2616  aURLAny <<= sDBURL;
2617  }
2618  break;
2619  case DBConnURIType::WRITER:
2620  {
2621  OUString sDBURL = "sdbc:writer:" +
2623  aURLAny <<= sDBURL;
2624  }
2625  break;
2626  case DBConnURIType::DBASE:
2627  {
2628  INetURLObject aUrlTmp(rURL);
2629  aUrlTmp.removeSegment();
2630  aUrlTmp.removeFinalSlash();
2631  OUString sDBURL = "sdbc:dbase:" +
2632  aUrlTmp.GetMainURL(INetURLObject::DecodeMechanism::NONE);
2633  aURLAny <<= sDBURL;
2634  }
2635  break;
2636  case DBConnURIType::FLAT:
2637  {
2638  INetURLObject aUrlTmp(rURL);
2639  aUrlTmp.removeSegment();
2640  aUrlTmp.removeFinalSlash();
2641  OUString sDBURL = "sdbc:flat:" +
2642  //only the 'path' has to be added
2643  aUrlTmp.GetMainURL(INetURLObject::DecodeMechanism::NONE);
2644  aURLAny <<= sDBURL;
2645  }
2646  break;
2647  case DBConnURIType::MSJET:
2648 #ifdef _WIN32
2649  {
2650  OUString sDBURL("sdbc:ado:access:PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + rURL.PathToFileName());
2651  aURLAny <<= sDBURL;
2652  }
2653 #endif
2654  break;
2655  case DBConnURIType::MSACE:
2656 #ifdef _WIN32
2657  {
2658  OUString sDBURL("sdbc:ado:PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=" + rURL.PathToFileName());
2659  aURLAny <<= sDBURL;
2660  }
2661 #endif
2662  break;
2663  }
2664  return aURLAny;
2665 }
2666 
2668 OUString getOwnURL(SfxObjectShell const * pDocShell)
2669 {
2670  OUString aRet;
2671 
2672  if (!pDocShell)
2673  return aRet;
2674 
2675  const INetURLObject& rURLObject = pDocShell->GetMedium()->GetURLObject();
2677  return aRet;
2678 }
2679 
2686 OUString LoadAndRegisterDataSource_Impl(DBConnURIType type, const uno::Reference< beans::XPropertySet > *pSettings,
2687  const INetURLObject &rURL, const OUString *pDestDir, SfxObjectShell* pDocShell)
2688 {
2689  OUString sExt(rURL.GetFileExtension());
2690  uno::Any aTableFilterAny;
2691  uno::Any aSuppressVersionsAny;
2692  uno::Any aInfoAny;
2693  bool bStore = true;
2694  OUString sFind;
2695  uno::Sequence<OUString> aFilters(1);
2696 
2697  uno::Any aURLAny = GetDBunoURI(rURL, type);
2698  switch (type) {
2699  case DBConnURIType::UNKNOWN:
2700  case DBConnURIType::CALC:
2701  case DBConnURIType::WRITER:
2702  break;
2703  case DBConnURIType::ODB:
2704  bStore = false;
2705  break;
2706  case DBConnURIType::FLAT:
2707  case DBConnURIType::DBASE:
2708  //set the filter to the file name without extension
2710  aTableFilterAny <<= aFilters;
2711  break;
2712  case DBConnURIType::MSJET:
2713  case DBConnURIType::MSACE:
2714  aSuppressVersionsAny <<= true;
2715  break;
2716  }
2717 
2718  try
2719  {
2720  uno::Reference<uno::XComponentContext> xContext(::comphelper::getProcessComponentContext());
2721  uno::Reference<sdb::XDatabaseContext> xDBContext = sdb::DatabaseContext::create(xContext);
2722 
2723  OUString sNewName = rURL.getName(
2725  sal_Int32 nExtLen = sExt.getLength();
2726  sNewName = sNewName.replaceAt(sNewName.getLength() - nExtLen - 1, nExtLen + 1, "");
2727 
2728  //find a unique name if sNewName already exists
2729  sFind = sNewName;
2730  sal_Int32 nIndex = 0;
2731  while (xDBContext->hasByName(sFind))
2732  sFind = sNewName + OUString::number(++nIndex);
2733 
2734  uno::Reference<uno::XInterface> xNewInstance;
2735  if (!bStore)
2736  {
2737  //odb-file
2738  uno::Any aDataSource = xDBContext->getByName(rURL.GetMainURL(INetURLObject::DecodeMechanism::NONE));
2739  aDataSource >>= xNewInstance;
2740  }
2741  else
2742  {
2743  xNewInstance = xDBContext->createInstance();
2744  uno::Reference<beans::XPropertySet> xDataProperties(xNewInstance, uno::UNO_QUERY);
2745 
2746  if (aURLAny.hasValue())
2747  xDataProperties->setPropertyValue("URL", aURLAny);
2748  if (aTableFilterAny.hasValue())
2749  xDataProperties->setPropertyValue("TableFilter", aTableFilterAny);
2750  if (aSuppressVersionsAny.hasValue())
2751  xDataProperties->setPropertyValue("SuppressVersionColumns", aSuppressVersionsAny);
2752  if (aInfoAny.hasValue())
2753  xDataProperties->setPropertyValue("Info", aInfoAny);
2754 
2755  if (DBConnURIType::FLAT == type && pSettings)
2756  {
2757  uno::Any aSettings = xDataProperties->getPropertyValue("Settings");
2758  uno::Reference < beans::XPropertySet > xDSSettings;
2759  aSettings >>= xDSSettings;
2760  ::comphelper::copyProperties(*pSettings, xDSSettings);
2761  xDSSettings->setPropertyValue("Extension", uno::makeAny(sExt));
2762  }
2763 
2764  uno::Reference<sdb::XDocumentDataSource> xDS(xNewInstance, uno::UNO_QUERY_THROW);
2765  uno::Reference<frame::XStorable> xStore(xDS->getDatabaseDocument(), uno::UNO_QUERY_THROW);
2766  OUString aOwnURL = getOwnURL(pDocShell);
2767  if (aOwnURL.isEmpty())
2768  {
2769  // Cannot embed, as embedded data source would need the URL of the parent document.
2770  OUString const sOutputExt = ".odb";
2771  OUString sHomePath(SvtPathOptions().GetWorkPath());
2772  utl::TempFile aTempFile(sNewName, true, &sOutputExt, pDestDir ? pDestDir : &sHomePath);
2773  const OUString& sTmpName = aTempFile.GetURL();
2774  xStore->storeAsURL(sTmpName, uno::Sequence<beans::PropertyValue>());
2775  }
2776  else
2777  {
2778  // Embed.
2779  OUString aStreamRelPath = "EmbeddedDatabase";
2780  uno::Reference<embed::XStorage> xStorage = pDocShell->GetStorage();
2781 
2782  // Refer to the sub-storage name in the document settings, so
2783  // we can load it again next time the file is imported.
2784  uno::Reference<lang::XMultiServiceFactory> xFactory(pDocShell->GetModel(), uno::UNO_QUERY);
2785  uno::Reference<beans::XPropertySet> xPropertySet(xFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
2786  xPropertySet->setPropertyValue("EmbeddedDatabaseName", uno::makeAny(aStreamRelPath));
2787 
2788  // Store it only after setting the above property, so that only one data source gets registered.
2789  SwDBManager::StoreEmbeddedDataSource(xStore, xStorage, aStreamRelPath, aOwnURL);
2790  }
2791  }
2792  xDBContext->registerObject(sFind, xNewInstance);
2793  }
2794  catch (const uno::Exception&)
2795  {
2796  sFind.clear();
2797  }
2798  return sFind;
2799 }
2800 
2801 // Construct vnd.sun.star.pkg:// URL
2802 OUString ConstructVndSunStarPkgUrl(const OUString& rMainURL, const OUString& rStreamRelPath)
2803 {
2804  auto xContext(comphelper::getProcessComponentContext());
2805  auto xUri = css::uri::UriReferenceFactory::create(xContext)->parse(rMainURL);
2806  assert(xUri.is());
2807  xUri = css::uri::VndSunStarPkgUrlReferenceFactory::create(xContext)
2808  ->createVndSunStarPkgUrlReference(xUri);
2809  assert(xUri.is());
2810  return xUri->getUriReference() + "/"
2812  rStreamRelPath, INetURLObject::PART_FPATH,
2814 }
2815 }
2816 
2818 {
2819  sfx2::FileDialogHelper aDlgHelper(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, pParent);
2820  uno::Reference < ui::dialogs::XFilePicker3 > xFP = aDlgHelper.GetFilePicker();
2821 
2822  OUString sHomePath(SvtPathOptions().GetWorkPath());
2823  aDlgHelper.SetDisplayDirectory( sHomePath );
2824 
2825  OUString sFilterAll(SwResId(STR_FILTER_ALL));
2826  OUString sFilterAllData(SwResId(STR_FILTER_ALL_DATA));
2827  OUString sFilterSXB(SwResId(STR_FILTER_SXB));
2828  OUString sFilterSXC(SwResId(STR_FILTER_SXC));
2829  OUString sFilterSXW(SwResId(STR_FILTER_SXW));
2830  OUString sFilterDBF(SwResId(STR_FILTER_DBF));
2831  OUString sFilterXLS(SwResId(STR_FILTER_XLS));
2832  OUString sFilterDOC(SwResId(STR_FILTER_DOC));
2833  OUString sFilterTXT(SwResId(STR_FILTER_TXT));
2834  OUString sFilterCSV(SwResId(STR_FILTER_CSV));
2835 #ifdef _WIN32
2836  OUString sFilterMDB(SwResId(STR_FILTER_MDB));
2837  OUString sFilterACCDB(SwResId(STR_FILTER_ACCDB));
2838 #endif
2839  xFP->appendFilter( sFilterAll, "*" );
2840  xFP->appendFilter( sFilterAllData, "*.ods;*.sxc;*.odt;*.sxw;*.dbf;*.xls;*.xlsx;*.doc;*.docx;*.txt;*.csv");
2841 
2842  xFP->appendFilter( sFilterSXB, "*.odb" );
2843  xFP->appendFilter( sFilterSXC, "*.ods;*.sxc" );
2844  xFP->appendFilter( sFilterSXW, "*.odt;*.sxw" );
2845  xFP->appendFilter( sFilterDBF, "*.dbf" );
2846  xFP->appendFilter( sFilterXLS, "*.xls;*.xlsx" );
2847  xFP->appendFilter( sFilterDOC, "*.doc;*.docx" );
2848  xFP->appendFilter( sFilterTXT, "*.txt" );
2849  xFP->appendFilter( sFilterCSV, "*.csv" );
2850 #ifdef _WIN32
2851  xFP->appendFilter(sFilterMDB, "*.mdb;*.mde");
2852  xFP->appendFilter(sFilterACCDB, "*.accdb;*.accde");
2853 #endif
2854 
2855  xFP->setCurrentFilter( sFilterAll ) ;
2856  OUString sFind;
2857  if( ERRCODE_NONE == aDlgHelper.Execute() )
2858  {
2859  uno::Reference< beans::XPropertySet > aSettings;
2860  const INetURLObject aURL( xFP->getSelectedFiles().getConstArray()[0] );
2861  const DBConnURIType type = GetDBunoType( aURL );
2862 
2863  if( DBConnURIType::FLAT == type )
2864  {
2865  uno::Reference<uno::XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
2866  uno::Reference < sdb::XTextConnectionSettings > xSettingsDlg = sdb::TextConnectionSettings::create(xContext);
2867  if( xSettingsDlg->execute() )
2868  aSettings.set( uno::Reference < beans::XPropertySet >( xSettingsDlg, uno::UNO_QUERY_THROW ) );
2869  }
2870  sFind = LoadAndRegisterDataSource_Impl( type, DBConnURIType::FLAT == type ? &aSettings : nullptr, aURL, nullptr, pDocShell );
2871 
2872  m_aUncommittedRegistrations.push_back(std::pair<SwDocShell*, OUString>(pDocShell, sFind));
2873  }
2874  return sFind;
2875 }
2876 
2877 void SwDBManager::StoreEmbeddedDataSource(const uno::Reference<frame::XStorable>& xStorable,
2878  const uno::Reference<embed::XStorage>& xStorage,
2879  const OUString& rStreamRelPath,
2880  const OUString& rOwnURL, bool bCopyTo)
2881 {
2882  // Construct vnd.sun.star.pkg:// URL for later loading, and TargetStorage/StreamRelPath for storing.
2883  OUString const sTmpName = ConstructVndSunStarPkgUrl(rOwnURL, rStreamRelPath);
2884 
2885  uno::Sequence<beans::PropertyValue> aSequence = comphelper::InitPropertySequence(
2886  {
2887  {"TargetStorage", uno::makeAny(xStorage)},
2888  {"StreamRelPath", uno::makeAny(rStreamRelPath)},
2889  {"BaseURI", uno::makeAny(rOwnURL)}
2890  });
2891  if (bCopyTo)
2892  xStorable->storeToURL(sTmpName, aSequence);
2893  else
2894  xStorable->storeAsURL(sTmpName, aSequence);
2895 }
2896 
2897 OUString SwDBManager::LoadAndRegisterDataSource(const OUString &rURI, const OUString *pDestDir)
2898 {
2899  return LoadAndRegisterDataSource_Impl( DBConnURIType::UNKNOWN, nullptr, INetURLObject(rURI), pDestDir, nullptr );
2900 }
2901 
2902 namespace
2903 {
2904  // tdf#117824 switch the embedded database away from using its current storage and point it to temporary storage
2905  // which allows the original storage to be deleted
2906  void switchEmbeddedDatabaseStorage(const uno::Reference<sdb::XDatabaseContext>& rDatabaseContext, const OUString& rName)
2907  {
2908  uno::Reference<sdb::XDocumentDataSource> xDS(rDatabaseContext->getByName(rName), uno::UNO_QUERY);
2909  if (!xDS)
2910  return;
2911  uno::Reference<document::XStorageBasedDocument> xStorageDoc(xDS->getDatabaseDocument(), uno::UNO_QUERY);
2912  if (!xStorageDoc)
2913  return;
2914  xStorageDoc->switchToStorage(comphelper::OStorageHelper::GetTemporaryStorage());
2915  }
2916 }
2917 
2918 void SwDBManager::RevokeDataSource(const OUString& rName)
2919 {
2920  uno::Reference<sdb::XDatabaseContext> xDatabaseContext = sdb::DatabaseContext::create(comphelper::getProcessComponentContext());
2921  if (xDatabaseContext->hasByName(rName))
2922  {
2923  switchEmbeddedDatabaseStorage(xDatabaseContext, rName);
2924  xDatabaseContext->revokeObject(rName);
2925  }
2926 }
2927 
2929 {
2930  uno::Reference<sdb::XDatabaseContext> xDatabaseContext = sdb::DatabaseContext::create(comphelper::getProcessComponentContext());
2931 
2932  OUString sDataSource = rData.sDataSource;
2933 
2934  // Fallback, just in case the document would contain an embedded data source, but no DB fields.
2935  if (sDataSource.isEmpty())
2936  sDataSource = "EmbeddedDatabase";
2937 
2938  SwDBManager::RevokeDataSource( sDataSource );
2939 
2940  // Encode the stream name and the real path into a single URL.
2941  const INetURLObject& rURLObject = rDocShell.GetMedium()->GetURLObject();
2942  OUString const aURL = ConstructVndSunStarPkgUrl(
2944  m_sEmbeddedName);
2945 
2946  uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY);
2947  xDatabaseContext->registerObject( sDataSource, xDataSource );
2948 
2949  // temp file - don't remember connection
2950  if (rData.sDataSource.isEmpty())
2951  m_aUncommittedRegistrations.push_back(std::pair<SwDocShell*, OUString>(nullptr, sDataSource));
2952 }
2953 
2955  const uno::Sequence<beans::PropertyValue>& rProperties)
2956 {
2957  //prevent second call
2958  if(m_pImpl->pMergeDialog)
2959  return ;
2960  OUString sDataSource, sDataTableOrQuery;
2961  uno::Sequence<uno::Any> aSelection;
2962 
2963  sal_Int32 nCmdType = sdb::CommandType::TABLE;
2964  uno::Reference< sdbc::XConnection> xConnection;
2965 
2966  svx::ODataAccessDescriptor aDescriptor(rProperties);
2967  sDataSource = aDescriptor.getDataSource();
2968  OSL_VERIFY(aDescriptor[svx::DataAccessDescriptorProperty::Command] >>= sDataTableOrQuery);
2969  OSL_VERIFY(aDescriptor[svx::DataAccessDescriptorProperty::CommandType] >>= nCmdType);
2970 
2972  aDescriptor[svx::DataAccessDescriptorProperty::Selection] >>= aSelection;
2974  aDescriptor[svx::DataAccessDescriptorProperty::Connection] >>= xConnection;
2975 
2976  if(sDataSource.isEmpty() || sDataTableOrQuery.isEmpty())
2977  {
2978  OSL_FAIL("PropertyValues missing or unset");
2979  return;
2980  }
2981 
2982  //always create a connection for the dialog and dispose it after the dialog has been closed
2983  SwDSParam* pFound = nullptr;
2984  if(!xConnection.is())
2985  {
2986  xConnection = SwDBManager::RegisterConnection(sDataSource);
2987  pFound = FindDSConnection(sDataSource, true);
2988  }
2990  m_pImpl->pMergeDialog = pFact->CreateMailMergeDlg(rSh.GetView().GetViewFrame()->GetWindow().GetFrameWeld(), rSh,
2991  sDataSource,
2992  sDataTableOrQuery,
2993  nCmdType,
2994  xConnection);
2995  if(m_pImpl->pMergeDialog->Execute() == RET_OK)
2996  {
2997  aDescriptor[svx::DataAccessDescriptorProperty::Selection] <<= m_pImpl->pMergeDialog->GetSelection();
2998 
2999  uno::Reference<sdbc::XResultSet> xResSet = m_pImpl->pMergeDialog->GetResultSet();
3000  if(xResSet.is())
3001  aDescriptor[svx::DataAccessDescriptorProperty::Cursor] <<= xResSet;
3002 
3003  // SfxObjectShellRef is ok, since there should be no control over the document lifetime here
3004  SfxObjectShellRef xDocShell = rSh.GetView().GetViewFrame()->GetObjectShell();
3005 
3006  lcl_emitEvent(SfxEventHintId::SwMailMerge, STR_SW_EVENT_MAIL_MERGE, xDocShell.get());
3007 
3008  // prepare mail merge descriptor
3009  SwMergeDescriptor aMergeDesc( m_pImpl->pMergeDialog->GetMergeType(), rSh, aDescriptor );
3010  aMergeDesc.sSaveToFilter = m_pImpl->pMergeDialog->GetSaveFilter();
3011  aMergeDesc.bCreateSingleFile = m_pImpl->pMergeDialog->IsSaveSingleDoc();
3012  aMergeDesc.bPrefixIsFilename = aMergeDesc.bCreateSingleFile;
3013  aMergeDesc.sPrefix = m_pImpl->pMergeDialog->GetTargetURL();
3014  if( !aMergeDesc.bCreateSingleFile && m_pImpl->pMergeDialog->IsGenerateFromDataBase() )
3015  {
3016  aMergeDesc.sDBcolumn = m_pImpl->pMergeDialog->GetColumnName();
3017  }
3018 
3019  Merge( aMergeDesc );
3020 
3021  lcl_emitEvent(SfxEventHintId::SwMailMergeEnd, STR_SW_EVENT_MAIL_MERGE_END, xDocShell.get());
3022 
3023  // reset the cursor inside
3024  xResSet = nullptr;
3025  aDescriptor[svx::DataAccessDescriptorProperty::Cursor] <<= xResSet;
3026  }
3027  if(pFound)
3028  {
3029  for (const auto & pParam : m_DataSourceParams)
3030  {
3031  if (pParam.get() == pFound)
3032  {
3033  try
3034  {
3035  uno::Reference<lang::XComponent> xComp(pParam->xConnection, uno::UNO_QUERY);
3036  if(xComp.is())
3037  xComp->dispose();
3038  }
3039  catch(const uno::RuntimeException&)
3040  {
3041  //may be disposed already since multiple entries may have used the same connection
3042  }
3043  break;
3044  }
3045  //pFound doesn't need to be removed/deleted -
3046  //this has been done by the SwConnectionDisposedListener_Impl already
3047  }
3048  }
3049  m_pImpl->pMergeDialog.disposeAndClear();
3050 }
3051 
3053  const uno::Sequence< beans::PropertyValue>& rProperties)
3054 {
3055  OUString sDataSource, sDataTableOrQuery;
3056  uno::Reference<sdbc::XResultSet> xResSet;
3057  uno::Sequence<uno::Any> aSelection;
3058  sal_Int16 nCmdType = sdb::CommandType::TABLE;
3059  uno::Reference< sdbc::XConnection> xConnection;
3060  for(const beans::PropertyValue& rValue : rProperties)
3061  {
3062  if ( rValue.Name == "DataSourceName" )
3063  rValue.Value >>= sDataSource;
3064  else if ( rValue.Name == "Command" )
3065  rValue.Value >>= sDataTableOrQuery;
3066  else if ( rValue.Name == "Cursor" )
3067  rValue.Value >>= xResSet;
3068  else if ( rValue.Name == "Selection" )
3069  rValue.Value >>= aSelection;
3070  else if ( rValue.Name == "CommandType" )
3071  rValue.Value >>= nCmdType;
3072  else if ( rValue.Name == "ActiveConnection" )
3073  rValue.Value >>= xConnection;
3074  }
3075  if(sDataSource.isEmpty() || sDataTableOrQuery.isEmpty() || !xResSet.is())
3076  {
3077  OSL_FAIL("PropertyValues missing or unset");
3078  return;
3079  }
3080  uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
3081  uno::Reference<sdbc::XDataSource> xSource;
3082  uno::Reference<container::XChild> xChild(xConnection, uno::UNO_QUERY);
3083  if(xChild.is())
3084  xSource.set(xChild->getParent(), uno::UNO_QUERY);
3085  if(!xSource.is())
3086  xSource = dbtools::getDataSource(sDataSource, xContext);
3087  uno::Reference< sdbcx::XColumnsSupplier > xColSupp( xResSet, uno::UNO_QUERY );
3088  SwDBData aDBData;
3089  aDBData.sDataSource = sDataSource;
3090  aDBData.sCommand = sDataTableOrQuery;
3091  aDBData.nCommandType = nCmdType;
3092 
3095  xSource,
3096  xColSupp,
3097  aDBData ));
3098  if( RET_OK == pDlg->Execute() )
3099  {
3100  OUString sDummy;
3101  if(!xConnection.is())
3102  xConnection = xSource->getConnection(sDummy, sDummy);
3103  try
3104  {
3105  pDlg->DataToDoc( aSelection , xSource, xConnection, xResSet);
3106  }
3107  catch (const uno::Exception&)
3108  {
3109  TOOLS_WARN_EXCEPTION("sw.mailmerge", "");
3110  }
3111  }
3112 }
3113 
3114 uno::Reference<sdbc::XDataSource> SwDBManager::getDataSourceAsParent(const uno::Reference< sdbc::XConnection>& _xConnection,const OUString& _sDataSourceName)
3115 {
3116  uno::Reference<sdbc::XDataSource> xSource;
3117  try
3118  {
3119  uno::Reference<container::XChild> xChild(_xConnection, uno::UNO_QUERY);
3120  if ( xChild.is() )
3121  xSource.set(xChild->getParent(), uno::UNO_QUERY);
3122  if ( !xSource.is() )
3123  xSource = dbtools::getDataSource(_sDataSourceName, ::comphelper::getProcessComponentContext());
3124  }
3125  catch (const uno::Exception&)
3126  {
3127  TOOLS_WARN_EXCEPTION("sw.mailmerge", "getDataSourceAsParent()");
3128  }
3129  return xSource;
3130 }
3131 
3132 uno::Reference<sdbc::XResultSet> SwDBManager::createCursor(const OUString& _sDataSourceName,
3133  const OUString& _sCommand,
3134  sal_Int32 _nCommandType,
3135  const uno::Reference<sdbc::XConnection>& _xConnection,
3136  const SwView* pView)
3137 {
3138  uno::Reference<sdbc::XResultSet> xResultSet;
3139  try
3140  {
3141  uno::Reference< lang::XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
3142  if( xMgr.is() )
3143  {
3144  uno::Reference<uno::XInterface> xInstance = xMgr->createInstance("com.sun.star.sdb.RowSet");
3145  uno::Reference<beans::XPropertySet> xRowSetPropSet(xInstance, uno::UNO_QUERY);
3146  if(xRowSetPropSet.is())
3147  {
3148  xRowSetPropSet->setPropertyValue("DataSourceName", uno::makeAny(_sDataSourceName));
3149  xRowSetPropSet->setPropertyValue("ActiveConnection", uno::makeAny(_xConnection));
3150  xRowSetPropSet->setPropertyValue("Command", uno::makeAny(_sCommand));
3151  xRowSetPropSet->setPropertyValue("CommandType", uno::makeAny(_nCommandType));
3152 
3153  uno::Reference< sdb::XCompletedExecution > xRowSet(xInstance, uno::UNO_QUERY);
3154 
3155  if ( xRowSet.is() )
3156  {
3157  weld::Window* pWindow = pView ? pView->GetFrameWeld() : nullptr;
3158  uno::Reference< task::XInteractionHandler > xHandler( task::InteractionHandler::createWithParent(comphelper::getComponentContext(xMgr), pWindow ? pWindow->GetXWindow() : nullptr), uno::UNO_QUERY_THROW );
3159  xRowSet->executeWithCompletion(xHandler);
3160  }
3161  xResultSet.set(xRowSet, uno::UNO_QUERY);
3162  }
3163  }
3164  }
3165  catch (const uno::Exception&)
3166  {
3167  TOOLS_WARN_EXCEPTION("sw.mailmerge", "Caught exception while creating a new RowSet");
3168  }
3169  return xResultSet;
3170 }
3171 
3172 void SwDBManager::setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell)
3173 {
3174  bool bLoad = m_sEmbeddedName != rEmbeddedName && !rEmbeddedName.isEmpty();
3175  bool bRegisterListener = m_sEmbeddedName.isEmpty() && !rEmbeddedName.isEmpty();
3176 
3177  m_sEmbeddedName = rEmbeddedName;
3178 
3179  if (bLoad)
3180  {
3181  uno::Reference<embed::XStorage> xStorage = rDocShell.GetStorage();
3182  // It's OK that we don't have the named sub-storage yet, in case
3183  // we're in the process of creating it.
3184  if (xStorage->hasByName(rEmbeddedName))
3185  LoadAndRegisterEmbeddedDataSource(rDocShell.GetDoc()->GetDBData(), rDocShell);
3186  }
3187 
3188  if (bRegisterListener)
3189  // Register a remove listener, so we know when the embedded data source is removed.
3190  m_pImpl->m_xDataSourceRemovedListener = new SwDataSourceRemovedListener(*this);
3191 }
3192 
3193 const OUString& SwDBManager::getEmbeddedName() const
3194 {
3195  return m_sEmbeddedName;
3196 }
3197 
3199 {
3200  return m_pDoc;
3201 }
3202 
3204 {
3205  if (m_pImpl->m_xDataSourceRemovedListener.is())
3206  {
3207  m_pImpl->m_xDataSourceRemovedListener->Dispose();
3208  m_pImpl->m_xDataSourceRemovedListener.clear();
3209  }
3210 }
3211 
3213  : m_pDBManager(&rManager)
3214 {
3215 }
3216 
3217 void SwDBManager::ConnectionDisposedListener_Impl::disposing( const lang::EventObject& rSource )
3218 {
3219  ::SolarMutexGuard aGuard;
3220 
3221  if (!m_pDBManager) return; // we're disposed too!
3222 
3223  uno::Reference<sdbc::XConnection> xSource(rSource.Source, uno::UNO_QUERY);
3224  for (size_t nPos = m_pDBManager->m_DataSourceParams.size(); nPos; nPos--)
3225  {
3226  SwDSParam* pParam = m_pDBManager->m_DataSourceParams[nPos - 1].get();
3227  if(pParam->xConnection.is() &&
3228  (xSource == pParam->xConnection))
3229  {
3230  m_pDBManager->m_DataSourceParams.erase(
3231  m_pDBManager->m_DataSourceParams.begin() + nPos - 1);
3232  }
3233  }
3234 }
3235 
3236 std::shared_ptr<SwMailMergeConfigItem> SwDBManager::PerformMailMerge(SwView const * pView)
3237 {
3238  std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
3239  if (!xConfigItem)
3240  return xConfigItem;
3241 
3242  svx::ODataAccessDescriptor aDescriptor;
3243  aDescriptor.setDataSource(xConfigItem->GetCurrentDBData().sDataSource);
3244  aDescriptor[ svx::DataAccessDescriptorProperty::Connection ] <<= xConfigItem->GetConnection().getTyped();
3245  aDescriptor[ svx::DataAccessDescriptorProperty::Cursor ] <<= xConfigItem->GetResultSet();
3246  aDescriptor[ svx::DataAccessDescriptorProperty::Command ] <<= xConfigItem->GetCurrentDBData().sCommand;
3247  aDescriptor[ svx::DataAccessDescriptorProperty::CommandType ] <<= xConfigItem->GetCurrentDBData().nCommandType;
3248  aDescriptor[ svx::DataAccessDescriptorProperty::Selection ] <<= xConfigItem->GetSelection();
3249 
3250  SwWrtShell& rSh = pView->GetWrtShell();
3251  xConfigItem->SetTargetView(nullptr);
3252 
3253  SwMergeDescriptor aMergeDesc(DBMGR_MERGE_SHELL, rSh, aDescriptor);
3254  aMergeDesc.pMailMergeConfigItem = xConfigItem.get();
3255  aMergeDesc.bCreateSingleFile = true;
3256  rSh.GetDBManager()->Merge(aMergeDesc);
3257 
3258  return xConfigItem;
3259 }
3260 
3262 {
3263  if (!m_aUncommittedRegistrations.empty())
3264  {
3265  SwView* pView = ( m_pDoc && m_pDoc->GetDocShell() ) ? m_pDoc->GetDocShell()->GetView() : nullptr;
3266  if (pView)
3267  {
3268  const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = pView->GetMailMergeConfigItem();
3269  if (xConfigItem)
3270  {
3271  xConfigItem->DisposeResultSet();
3272  xConfigItem->DocumentReloaded();
3273  }
3274  }
3275 
3276  for (auto it = m_aUncommittedRegistrations.begin(); it != m_aUncommittedRegistrations.end();)
3277  {
3278  if ((m_pDoc && it->first == m_pDoc->GetDocShell()) || it->first == nullptr)
3279  {
3280  RevokeDataSource(it->second);
3281  it = m_aUncommittedRegistrations.erase(it);
3282  }
3283  else
3284  ++it;
3285  }
3286  }
3287 }
3288 
3290 {
3291  for (auto aIt = m_aUncommittedRegistrations.begin(); aIt != m_aUncommittedRegistrations.end();)
3292  {
3293  if (aIt->first == m_pDoc->GetDocShell() || aIt->first == nullptr)
3294  {
3295  m_aNotUsedConnections.push_back(aIt->second);
3296  aIt = m_aUncommittedRegistrations.erase(aIt);
3297  }
3298  else
3299  aIt++;
3300  }
3301 }
3302 
3303 void SwDBManager::SetAsUsed(const OUString& rName)
3304 {
3305  auto aFound = std::find(m_aNotUsedConnections.begin(), m_aNotUsedConnections.end(), rName);
3306  if (aFound != m_aNotUsedConnections.end())
3307  m_aNotUsedConnections.erase(aFound);
3308 }
3309 
3311 {
3312  for (auto aIt = m_aNotUsedConnections.begin(); aIt != m_aNotUsedConnections.end();)
3313  {
3314  RevokeDataSource(*aIt);
3315  aIt = m_aNotUsedConnections.erase(aIt);
3316  }
3317 }
3318 
3319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void InsertLineBreak()
Definition: wrtsh1.cxx:905
virtual Point GetPosPixel() const
static bool lcl_ToNextRecord(SwDSParam *pParam, const SwDBNextRecord action=SwDBNextRecord::NEXT)
Definition: dbmgr.cxx:2224
SfxViewFrame * GetViewFrame() const
css::uno::Reference< css::sdbc::XResultSet > xResultSet
Definition: dbmgr.hxx:107
bool is() const
SwNodeIndex AppendDoc(const SwDoc &rSource, sal_uInt16 nStartPageNumber, bool bDeletePrevious, int physicalPageOffset, const sal_uLong nDocNo)
Definition: docnew.cxx:981
bool bCreateSingleFile
Create a single or multiple results.
Definition: dbmgr.hxx:149
Definition: calc.hxx:184
SAL_DLLPRIVATE void ImportDBEntry(SwWrtShell *pSh)
Insert a single data record as text into document.
Definition: dbmgr.cxx:629
void RevokeLastRegistrations()
Revoke not committed registrations in case of mail merge cancel.
Definition: dbmgr.cxx:3261
URL aURL
virtual void SAL_CALL setBody(const css::uno::Reference< css::datatransfer::XTransferable > &_body) override
const SwXMailMerge * GetMailMergeEvtSrc() const
MailMergeEvent source.
Definition: dbmgr.hxx:292
osl::Mutex m_aAllEmailSendMutex
Definition: dbmgr.cxx:298
bool hasValue()
sal_Int32 nIndex
sal_Int32 nCommandType
Definition: swdbdata.hxx:32
void MergeCancel()
Definition: dbmgr.cxx:1677
void SplitNode(bool bAutoFormat=false)
Definition: wrtsh1.cxx:981
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
const OUString & GetTempPath() const
void SetType(SectionType const eNew)
Definition: section.hxx:96
virtual bool DoSaveCompleted(SfxMedium *pNewStor=nullptr, bool bRegisterRecent=true)
css::util::Date aNullDate
Definition: dbmgr.hxx:65
static bool FormatValue(SvNumberFormatter const *pDocFormatter, OUString const &aString, sal_uInt32 nFormat, double &aNumber, sal_Int32 nColumnType, SwDBField *pField=nullptr)
Definition: dbfld.cxx:263
OUString GetTitle(sal_uInt16 nMaxLen=0) const
SwDSParams_t m_DataSourceParams
Definition: dbmgr.hxx:250
SwMailMergeConfigItem * pMailMergeConfigItem
Definition: dbmgr.hxx:214
const char aData[]
Definition: ww8scan.hxx:47
css::uno::Reference< css::sdbc::XConnection > const & RegisterConnection(OUString const &rSource)
create and store or find an already stored connection to a data source for use in SwFieldMgr and SwDB...
Definition: dbmgr.cxx:2370
void setDataSource(const OUString &_sDataSourceNameOrLocation)
static css::uno::Reference< css::sdbcx::XColumnsSupplier > GetColumnSupplier(css::uno::Reference< css::sdbc::XConnection > const &xConnection, const OUString &rTableOrQuery, SwDBSelect eTableOrQuery=SwDBSelect::UNKNOWN)
Definition: dbmgr.cxx:1916
bool SttEndDoc(bool bStt)
Definition: crsrsh.cxx:566
OUString const & GetMailAddress() const
bool bEndOfDB
Definition: dbmgr.hxx:110
SwDocShell * GetDocShell()
Definition: doc.hxx:1346
std::shared_ptr< SwMailMergeConfigItem > const & GetMailMergeConfigItem() const
Definition: view0.cxx:128
bool GetTableNames(weld::ComboBox &rBox, const OUString &rDBName)
Fill listbox with all table names of a database.
Definition: dbmgr.cxx:697
IDocumentDeviceAccess const & getIDocumentDeviceAccess() const
Definition: doc.cxx:237
sal_uInt32 GetFormatIndex(NfIndexTableOffset, LanguageType eLnge=LANGUAGE_DONTKNOW)
SAL_DLLPRIVATE bool ToNextMergeRecord()
Definition: dbmgr.cxx:2133
static const SwDBData & GetAddressDBName()
Definition: dbmgr.cxx:2543
bool Is() const
OUString getBase(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
static bool lcl_SaveDoc(const INetURLObject *pFileURL, const std::shared_ptr< const SfxFilter > &pStoreToFilter, const OUString *pStoreToFilterOptions, const uno::Sequence< beans::PropertyValue > *pSaveToFilterData, const bool bIsPDFexport, SfxObjectShell *xObjectShell, SwWrtShell &rWorkShell, OUString *const decodedURL=nullptr)
Definition: dbmgr.cxx:866
SfxDispatcher * GetDispatcher()
bool OpenDataSource(const OUString &rDataSource, const OUString &rTableOrQuery)
open the source while fields are updated - for the calculator only!
Definition: dbmgr.cxx:2323
sal_uIntPtr sal_uLong
#define DB_SEP_NEWLINE
Definition: dbmgr.cxx:130
OUString sDataSource
Definition: swdbdata.hxx:30
sal_Int32 toInt32(OUString const &rStr)
css::uno::Reference< css::mail::XSmtpService > xSmtpServer
Definition: dbmgr.hxx:192
MailDispatcher listener interface.
Definition: doc.hxx:185
SAL_DLLPRIVATE bool IsValidMergeRecord() const
Definition: dbmgr.cxx:2287
bool HasValidRecord() const
Definition: dbmgr.hxx:131
IDocumentLinksAdministration const & getIDocumentLinksAdministration() const
Definition: doc.cxx:259
sal_uInt32 GetSelectedRecordId()
Definition: dbmgr.cxx:2292
css::util::Date aNullDate
Definition: dbmgr.hxx:102
bool bSendAsAttachment
Definition: dbmgr.hxx:194
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:233
void SetTargetView(SwView *pView)
uno::Reference< mail::XMailMessage > m_xLastMessage
Definition: dbmgr.cxx:299
SwEditWin & GetEditWin()
Definition: view.hxx:403
static void StoreEmbeddedDataSource(const css::uno::Reference< css::frame::XStorable > &xStorable, const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &rStreamRelPath, const OUString &rOwnURL, bool bCopyTo=false)
Definition: dbmgr.cxx:2877
Data records in fields.
Definition: dbmgr.hxx:87
static std::vector< std::pair< SwDocShell *, OUString > > m_aUncommittedRegistrations
Store last registrations to revoke or commit.
Definition: dbmgr.hxx:257
IDocumentMarkAccess * getIDocumentMarkAccess()
Definition: docbm.cxx:1625
Dialog to specify the properties of date form field.
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:143
css::uno::Reference< css::frame::XModel > GetModel() const
rtl::Reference< SwDataSourceRemovedListener > m_xDataSourceRemovedListener
Definition: dbmgr.cxx:297
void SetModified()
Definition: edws.cxx:69
bool UCB_DeleteFile(const OUString &rURL)
Definition: swunohelper.cxx:58
bool m_bInMerge
merge process active
Definition: dbmgr.hxx:248
css::uno::Reference< css::sdbc::XConnection > xConnection
Definition: dbmgr.hxx:105
void SetLabelDoc(bool bFlag)
Labels: Synchronize ranges.
Definition: edfld.cxx:376
void SetDisplayDirectory(const OUString &rPath)
virtual void mailDelivered(uno::Reference< mail::XMailMessage > xMessage) override
Definition: dbmgr.cxx:1070
virtual short Execute()=0
virtual SfxObjectShell * GetObjectShell() override
void EndAllAction()
Definition: edws.cxx:96
static void FinishPrintJob(const std::shared_ptr< vcl::PrinterController > &i_pController)
RET_CANCEL
css::uno::Sequence< css::beans::PropertyValue > aSaveToFilterData
Definition: dbmgr.hxx:157
bool IsMergeError() const
Definition: dbmgr.hxx:303
virtual void SAL_CALL disposing(const lang::EventObject &Source) override
Definition: dbmgr.cxx:3217
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
SwDBSelect
Definition: dbmgr.hxx:95
bool DelRight()
Definition: delete.cxx:285
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
OUString m_sEmbeddedName
Name of the embedded database that's included in the current document.
Definition: dbmgr.hxx:254
SfxApplication * SfxGetpApp()
OOO_DLLPUBLIC_DBTOOLS OUString getFormattedValue(const css::uno::Reference< css::beans::XPropertySet > &_xColumn, const css::uno::Reference< css::util::XNumberFormatter > &xFormatter, const css::lang::Locale &_rLocale, const css::util::Date &rNullDate)
OUString PathToFileName() const
void UpdateSection(size_t const nSect, SwSectionData &, SfxItemSet const *const =nullptr)
Definition: edsect.cxx:155
css::uno::Reference< css::embed::XStorage > const & GetStorage()
SwDoc * m_pDoc
Definition: docbm.cxx:1134
OUString GetBase() const
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
static css::uno::Sequence< OUString > GetExistingDatabaseNames()
Definition: dbmgr.cxx:2548
std::unique_ptr< SwDSParam > pMergeData
Definition: dbmgr.cxx:294
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:356
virtual void mailDeliveryError(::rtl::Reference< MailDispatcher > xMailDispatcher, uno::Reference< mail::XMailMessage >, const OUString &) override
Definition: dbmgr.cxx:1077
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
weld::Window * GetFrameWeld() const
virtual void idle() override
Called when there are no more mail messages to deliver.
Definition: dbmgr.cxx:1068
NF_NUMBER_STANDARD
sal_uInt16 sal_Unicode
sw::mark::IMark * startPageInTarget
vcl::Window & GetWindow() const
constexpr auto SFX_INTERFACE_NONE
const SwView & GetView() const
Definition: wrtsh.hxx:428
bool ConvertFieldsToText()
Replace fields by text - mailmerge support.
Definition: editsh.cxx:749
bool IsInitDBFields() const
Initialize data fields that lack name of database.
Definition: dbmgr.hxx:308
void VarChange(const OUString &rStr, const SwSbxValue &rValue)
Definition: calc.cxx:575
static void Yield()
#define STR_SW_EVENT_FIELD_MERGE
Definition: swevent.hxx:30
Print mail merge.
Definition: dbmgr.hxx:88
bool ReadLine(OString &rStr, sal_Int32 nMaxBytesToRead=0xFFFE)
SfxFrame & GetFrame() const
virtual ::sw::mark::IMark * makeMark(const SwPaM &rPaM, const OUString &rProposedName, MarkType eMark,::sw::mark::InsertMode eMode, SwPosition const *pSepPos=nullptr)=0
Generates a new mark in the document for a certain selection.
SAL_DLLPRIVATE SwDSParam * FindDSConnection(const OUString &rSource, bool bCreate)
Definition: dbmgr.cxx:2505
void setEmbeddedName(const OUString &rEmbeddedName, SwDocShell &rDocShell)
Definition: dbmgr.cxx:3172
virtual void DoUndo(bool const bDoUndo)=0
Enable/Disable Undo.
Send mail merge as email.
Definition: dbmgr.hxx:89
static void lcl_SaveDebugDoc(SfxObjectShell *xTargetDocShell, const char *name, int no=0)
Definition: dbmgr.cxx:829
OUString sSaveToFilter
Definition: dbmgr.hxx:155
void CommitLastRegistrations()
Accept not committed registrations.
Definition: dbmgr.cxx:3289
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
bool IsLabelDoc() const
Definition: edfld.cxx:381
ConnectionDisposedListener_Impl(SwDBManager &rMgr)
Definition: dbmgr.cxx:3212
void DoGroupUndo(bool bUn)
Definition: edws.cxx:205
sal_Int32 GetColumnType(const OUString &rDBName, const OUString &rTableName, const OUString &rColNm)
Definition: dbmgr.cxx:1849
css::lang::Locale aLocale
Definition: dbmgr.hxx:67
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
Create merge doc and keep the doc shell.
Definition: dbmgr.hxx:91
SAL_DLLPRIVATE SwDSParam * FindDSData(const SwDBData &rData, bool bCreate)
Definition: dbmgr.cxx:2457
void Insert(SwField const &, SwPaM *pAnnotationRange=nullptr)
Definition: wrtsh2.cxx:60
const SwSectionFormat & GetSectionFormat(size_t nFormat) const
Definition: edsect.cxx:141
if(nullptr==pCandidateA||nullptr==pCandidateB)
OUString sMailBody
Definition: dbmgr.hxx:188
static css::uno::Reference< css::sdbc::XResultSet > createCursor(const OUString &_sDataSourceName, const OUString &_sCommand, sal_Int32 _nCommandType, const css::uno::Reference< css::sdbc::XConnection > &_xConnection, const SwView *pView)
creates a RowSet, which must be disposed after use.
Definition: dbmgr.cxx:3132
void AddMergedDocument(SwDocMergeInfo const &rInfo)
css::uno::Reference< css::lang::XComponent > xComponent
SwWrtShell & rSh
Definition: dbmgr.hxx:140
static OUString lcl_FindColumn(const OUString &sFormatStr, sal_uInt16 &nUsedPos, sal_uInt8 &nSeparator)
Definition: dbmgr.cxx:598
static css::uno::Reference< css::sdbc::XDataSource > getDataSourceAsParent(const css::uno::Reference< css::sdbc::XConnection > &_xConnection, const OUString &_sDataSourceName)
try to get the data source from the given connection through the XChild interface.
Definition: dbmgr.cxx:3114
static void RevokeDataSource(const OUString &rName)
Unregister a data source.
Definition: dbmgr.cxx:2918
#define ERRCODE_IO_NOTSUPPORTED
const std::shared_ptr< vcl::PrinterController > & GetPrinterController() const
void SetDebugName(const char *pDebugName)
static SvxHtmlOptions & Get()
void SetDBvalue(bool bSet)
Definition: calc.hxx:120
bool Merge(const SwMergeDescriptor &rMergeDesc)
Merging of data records into fields.
Definition: dbmgr.cxx:419
SwDoc * m_pDoc
The document that owns this manager.
Definition: dbmgr.hxx:266
bool bPrefixIsFilename
Use the sPrefix as the target filename also overwriting an existing target file.
Definition: dbmgr.hxx:180
bool IsModified() const
SwDBManager * GetDBManager() const
For evaluation of DB fields (new DB-manager).
Definition: edfld.cxx:336
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:203
OUString sPrefix
Basename incl.
Definition: dbmgr.hxx:172
OUString sSaveToFilterOptions
Definition: dbmgr.hxx:156
T * get() const
static OUString GetTypeStr(SwFieldTypesEnum nTypeId)
Definition: fldbas.cxx:120
static css::uno::Reference< css::embed::XStorage > GetTemporaryStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
#define STR_SW_EVENT_MAIL_MERGE_END
Definition: swevent.hxx:29
#define TOOLS_WARN_EXCEPTION(area, stream)
void LoadAndRegisterEmbeddedDataSource(const SwDBData &rData, const SwDocShell &rDocShell)
Load the embedded data source of the document and also register it.
Definition: dbmgr.cxx:2928
vcl::Window & GetWindow() const
bool HasSelection() const
Definition: wrtsh.hxx:141
#define SW_MOD()
Definition: swmodule.hxx:256
static bool Reschedule(bool bHandleAllCurrentEvents=false)
SwDBData const & GetDBData()
Definition: docfld.cxx:342
OUString sSubject
Definition: dbmgr.hxx:187
void SetDBManager(SwDBManager *pNewMgr)
Definition: doc.hxx:663
sal_uInt16 GetPageCnt()
Definition: crsrsh.cxx:1282
bool bScrollable
Definition: dbmgr.hxx:109
virtual const SwPrintData & getPrintData() const =0
Returns the PrintData.
OUString const & GetURL() const
void SetAsUsed(const OUString &rName)
Set connection as used.
Definition: dbmgr.cxx:3303
#define LANGUAGE_SYSTEM
bool GetMergeColumnCnt(const OUString &rColumnName, LanguageType nLanguage, OUString &rResult, double *pNumber)
Definition: dbmgr.cxx:2120
#define DB_SEP_SPACE
Definition: dbmgr.cxx:127
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
bool GetColumnCnt(const OUString &rSourceName, const OUString &rTableName, const OUString &rColumnName, sal_uInt32 nAbsRecordId, LanguageType nLanguage, OUString &rResult, double *pNumber)
Definition: dbmgr.cxx:2059
SwDBManager_Impl(SwDBManager &rDBManager)
Definition: dbmgr.cxx:301
SfxObjectShell * CreateCopy(bool bCallInitNew, bool bEmpty) const
Definition: docnew.cxx:859
int i
void ExecPrint(const css::uno::Sequence< css::beans::PropertyValue > &, bool, bool)
OUString sAttachmentName
Definition: dbmgr.hxx:189
static void lcl_GetColumnCnt(SwDSParam *pParam, const uno::Reference< beans::XPropertySet > &rColumnProps, LanguageType nLanguage, OUString &rResult, double *pNumber)
Definition: dbmgr.cxx:378
static css::uno::Reference< css::sdbc::XConnection > GetConnection(const OUString &rDataSource, css::uno::Reference< css::sdbc::XDataSource > &rxSource, const SwView *pView)
Definition: dbmgr.cxx:1893
bool DoesGroupUndo() const
Definition: edws.cxx:208
static SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:222
virtual void SAL_CALL addCcRecipient(const OUString &sRecipientAddress) override
static void InsertText(SwWrtShell &rSh, const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
Definition: dbmgr.cxx:3052
void NotifyEvent(const SfxEventHint &rEvent, bool bSynchron=true)
std::unique_ptr< SwDBManager_Impl > m_pImpl
Definition: dbmgr.hxx:251
void CloseAll(bool bIncludingMerge=true)
close all data sources - after fields were updated
Definition: dbmgr.cxx:2436
SwDBData const & GetDBData() const
Database information.
Definition: edfld.cxx:294
virtual sal_Int32 GetRecordsPerDocument() const =0
virtual void Start() override
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:393
void LaunchMailMergeEvent(const css::text::MailMergeEvent &rData) const
std::set< SwRootFrame * > GetAllLayouts()
Definition: doclay.cxx:1660
void RevokeNotUsedConnections()
Remove not used connections.
Definition: dbmgr.cxx:3310
VclPtr< AbstractMailMergeDlg > pMergeDialog
Definition: dbmgr.cxx:295
SfxItemSet * GetItemSet() const
static SwAbstractDialogFactory * Create()
Definition: swabstdlg.cxx:36
OUString const & GetMailReplyTo() const
Marks a node in the document model.
Definition: ndindex.hxx:31
virtual void setJobsetup(const JobSetup &rJobSetup)=0
Sets the Jobsetup.
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 Lock(bool bLock)
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
OUString sPrefix
virtual void clear()=0
SAL_DLLPRIVATE void ImportFromConnection(SwWrtShell *pSh)
Insert data record as text into document.
Definition: dbmgr.cxx:567
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
void UnlockExpFields()
Definition: edfld.cxx:356
void SetTimeout(sal_uInt64 nTimeoutMs)
sal_uInt16 GetVirtPageNum() const
Definition: fews.cxx:342
static void lcl_RemoveSectionLinks(SwWrtShell &rWorkShell)
Definition: dbmgr.cxx:812
#define DB_DELIM
Definition: swtypes.hxx:141
SfxViewShell * GetViewShell() const
virtual const JobSetup * getJobsetup() const =0
Returns the Jobsetup.
SwDocShell * GetDocShell()
Definition: view.cxx:1107
virtual void SAL_CALL addRecipient(const OUString &sRecipientAddress) override
static void lcl_PreparePrinterOptions(const uno::Sequence< beans::PropertyValue > &rInPrintOptions, uno::Sequence< beans::PropertyValue > &rOutPrintOptions)
Definition: dbmgr.cxx:911
bool ToRecordId(sal_Int32 nSet)
Definition: dbmgr.cxx:2309
WorkingDocType
Definition: dbmgr.cxx:155
std::vector< OUString > m_aNotUsedConnections
Not used connections.
Definition: dbmgr.hxx:260
OUString getDataSource() const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
sal_Int32 getDefaultNumberFormat(const Reference< XPropertySet > &_xColumn, const Reference< XNumberFormatTypes > &_xTypes, const Locale &_rLocale)
bool FillCalcWithMergeData(SvNumberFormatter *pDocFormatter, LanguageType nLanguage, SwCalc &aCalc)
Definition: dbmgr.cxx:2139
static std::shared_ptr< SwMailMergeConfigItem > PerformMailMerge(SwView const *pView)
Definition: dbmgr.cxx:3236
NEXT
std::unique_ptr< weld::Label > m_xPrinter
Definition: dbui.hxx:30
size_t GetSectionFormatCount() const
Definition: edsect.cxx:113
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const DBManagerOptions nMergeType
Definition: dbmgr.hxx:139
SvStream * GetInStream()
Reference< XMultiServiceFactory > getProcessServiceFactory()
css::uno::Sequence< OUString > aCopiesTo
Definition: dbmgr.hxx:190
SwWrtShell * GetWrtShellPtr() const
Definition: view.hxx:401
void releaseRevokeListener()
Stop reacting to removed database registrations.
Definition: dbmgr.cxx:3203
css::uno::Sequence< css::beans::PropertyValue > aPrintOptions
Definition: dbmgr.hxx:211
bool DoSaveAs(SfxMedium &rNewStor)
css::uno::Reference< css::util::XNumberFormatter > xFormatter
Definition: dbmgr.hxx:104
virtual bool EmbedAllLinks()=0
Embed all local links (ranges/graphics).
bool has(DataAccessDescriptorProperty _eWhich) const
void Stop()
weld::Window * GetFrameWeld() const
Save mail merge as files.
Definition: dbmgr.hxx:90
virtual void DataToDoc(const css::uno::Sequence< css::uno::Any > &rSelection, css::uno::Reference< css::sdbc::XDataSource > rxSource, css::uno::Reference< css::sdbc::XConnection > xConnection, css::uno::Reference< css::sdbc::XResultSet > xResultSet)=0
#define ERRCODE_NONE
static SfxViewFrame * LoadHiddenDocument(SfxObjectShell const &i_rDoc, SfxInterfaceId i_nViewId)
unsigned char sal_uInt8
const svx::ODataAccessDescriptor & rDescriptor
Definition: dbmgr.hxx:141
DBConnURIType GetDBunoType(const INetURLObject &rURL)
Definition: dbmgr.cxx:2557
#define STR_SW_EVENT_FIELD_MERGE_FINISHED
Definition: swevent.hxx:31
std::unique_ptr< weld::Label > m_xPrintInfo
Definition: dbui.hxx:31
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:426
#define STR_SW_EVENT_MAIL_MERGE
Definition: swevent.hxx:28
static bool lcl_getCountFromResultSet(sal_Int32 &rCount, const SwDSParam *pParam)
Definition: dbmgr.cxx:165
~SwDBManager() COVERITY_NOEXCEPT_FALSE
Definition: dbmgr.cxx:784
rtl::Reference< SwDBManager::ConnectionDisposedListener_Impl > m_xDisposeListener
Definition: dbmgr.cxx:296
void SetIdle(bool b) const
Definition: viewopt.hxx:209
#define SAL_INFO(area, stream)
bool PutString(const OUString &)
SfxEventHintId
SwDoc * getDoc() const
Definition: dbmgr.cxx:3198
void SetInitDBFields(bool b)
Definition: dbmgr.hxx:309
virtual void SAL_CALL addBccRecipient(const OUString &sRecipientAddress) override
RET_OK
bool IsMergeSilent() const
Definition: dbmgr.hxx:295
static SfxObjectShell * lcl_CreateWorkingDocument(const WorkingDocType aType, const SwWrtShell &rSourceWrtShell, const vcl::Window *pSourceWindow, SwDBManager **const ppDBManager, SwView **const pView, SwWrtShell **const pWrtShell, SwDoc **const pDoc)
Definition: dbmgr.cxx:939
virtual void SAL_CALL setReplyToAddress(const OUString &_replytoaddress) override
bool PutDouble(double)
virtual VclPtr< AbstractMailMergeDlg > CreateMailMergeDlg(weld::Window *pParent, SwWrtShell &rSh, const OUString &rSourceName, const OUString &rTableName, sal_Int32 nCommandType, const css::uno::Reference< css::sdbc::XConnection > &xConnection)=0
void SetStreamCharSet(rtl_TextEncoding eCharSet)
OUString GetFileExtension() const
virtual void setPrintData(const SwPrintData &rPrtData)=0
Sets the PrintData.
SAL_DLLPRIVATE bool MergeMailFiles(SwWrtShell *pSh, const SwMergeDescriptor &rMergeDescriptor)
Run the mail merge for defined modes, except DBMGR_MERGE.
Definition: dbmgr.cxx:1091
const INetURLObject & GetURLObject() const
#define DB_SEP_RETURN
Definition: dbmgr.cxx:129
css::uno::Sequence< OUString > aBlindCopiesTo
Definition: dbmgr.hxx:191
Reference< XComponentContext > getProcessComponentContext()
static OUString GetDBField(css::uno::Reference< css::beans::XPropertySet > const &xColumnProp, const SwDBFormatData &rDBFormatData, double *pNumber=nullptr)
Definition: dbmgr.cxx:1964
css::uno::Reference< css::util::XNumberFormatter > xFormatter
Definition: dbmgr.hxx:66
MailDispatcherListener_Impl(SwDBManager &rDBManager)
Definition: dbmgr.cxx:1065
OString stripStart(const OString &rIn, char c)
bool RemoveInvisibleContent()
Remove the invisible content from the document e.g. hidden areas, hidden paragraphs.
Definition: doc.cxx:1388
OUString sDBcolumn
DB column to fetch EMail of Filename from.
Definition: dbmgr.hxx:203
virtual VclPtr< AbstractSwInsertDBColAutoPilot > CreateSwInsertDBColAutoPilot(SwView &rView, css::uno::Reference< css::sdbc::XDataSource > rxSource, css::uno::Reference< css::sdbcx::XColumnsSupplier > xColSupp, const SwDBData &rData)=0
static bool lcl_MoveAbsolute(SwDSParam *pParam, long nAbsPos)
Definition: dbmgr.cxx:342
SwDBNextRecord
Definition: dbmgr.cxx:147
DBConnURIType
Definition: dbmgr.hxx:474
static void lcl_InitNumberFormatter(SwDSParam &rParam, uno::Reference< sdbc::XDataSource > const &xSource)
Definition: dbmgr.cxx:313
static OUString GetEventName(sal_Int32 nId)
Definition: docsh.cxx:1325
Reference< XDataSource > getDataSource(const OUString &_rsTitleOrPath, const Reference< XComponentContext > &_rxContext)
virtual void CalcLayout() override
To enable set up of StartActions and EndActions.
Definition: edws.cxx:107
Reference< XColumn > xColumn
css::uno::Sequence< css::uno::Any > aSelection
Definition: dbmgr.hxx:108
ErrCode GetError() const
const short COPY
bool IsDataSourceOpen(const OUString &rDataSource, const OUString &rTableOrQuery, bool bMergeShell)
check if a data source is open
Definition: dbmgr.cxx:2036
virtual void SAL_CALL addAttachment(const css::mail::MailAttachment &aMailAttachment) override
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
static std::shared_ptr< const SfxFilter > GetFileFilter(const OUString &rFileName)
Detect for the given file which filter should be used.
Definition: iodetect.cxx:148
ResultType type
#define SAL_WARN(area, stream)
void ReplaceDocumentProperties(const SwDoc &rSource, bool mailMerge=false)
Replace document properties with those from rSource.
Definition: docglos.cxx:83
Reference< XSingleServiceFactory > xFactory
SwDBManager(SwDBManager const &)=delete
bool SetURL(OUString const &rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
bool CheckMailAddress(const OUString &rMailAddress)
void append_text(const OUString &rStr)
static OUString LoadAndRegisterDataSource(weld::Window *pParent, SwDocShell *pDocShell=nullptr)
Loads a data source from file and registers it.
Definition: dbmgr.cxx:2817
rtl_TextEncoding GetTextEncoding() const
#define TOOLS_WARN_EXCEPTION_IF(cond, area, stream)
const SwView * GetView() const
Definition: docsh.hxx:220
void Dispose(const T &xInterface)
void GetColumnNames(weld::ComboBox &rBox, const OUString &rDBName, const OUString &rTableName)
Fill listbox with all column names of a database table.
Definition: dbmgr.cxx:737
css::uno::Reference< css::sdbc::XStatement > xStatement
Definition: dbmgr.hxx:106
void ChgDBData(const SwDBData &SwDBData)
Definition: wrtsh1.cxx:1744
A MailDispatcher should be used for sending a bunch a mail messages asynchronously.
static SwMailMessage * lcl_CreateMailFromDoc(const SwMergeDescriptor &rMergeDescriptor, const OUString &sFileURL, const OUString &sMailRecipient, const OUString &sMailBodyMimeType, rtl_TextEncoding sMailEncoding, const OUString &sAttachmentMimeType)
Definition: dbmgr.cxx:1008
MergeStatus m_aMergeStatus
current / last merge status
Definition: dbmgr.hxx:246
virtual void SAL_CALL setSubject(const OUString &_subject) override
void SetInMailMerge(bool bNew)
Definition: doc.hxx:958
sal_Int32 const nLength
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
SwSection * GetSection() const
Definition: section.cxx:671
void SetNumberingRestart()
Set all numbering start points to a fixed value - mailmerge support.
Definition: editsh.cxx:757
virtual css::uno::Reference< css::util::XNumberFormats > SAL_CALL getNumberFormats() override
void ChangeDBFields(const std::vector< OUString > &rOldNames, const OUString &rNewName)
Definition: edfld.cxx:315
void StartAllAction()
For all views of this document.
Definition: edws.cxx:85
const css::uno::Reference< css::ui::dialogs::XFilePicker3 > & GetFilePicker() const
bool IsExpFieldsLocked() const
Definition: edfld.cxx:361
bool IsMailReplyTo() const
#define DB_SEP_TAB
Definition: dbmgr.cxx:128
void ExecuteFormLetter(SwWrtShell &rSh, const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
Definition: dbmgr.cxx:2954
CharClass & GetAppCharClass()
Definition: init.cxx:709
OUString sCommand
Definition: swdbdata.hxx:31
virtual void SetPosPixel(const Point &rNewPos)
bool IsMergeOk() const
Definition: dbmgr.hxx:302
void SetFilter(const std::shared_ptr< const SfxFilter > &pFilter)
void SetAllUniqueFlyNames()
Definition: doclay.cxx:1437
SwDBManager * GetDBManager() const
Definition: doc.hxx:664
void LockExpFields()
Definition: edfld.cxx:351
Definition: view.hxx:146
void SetSenderAddress(const OUString &rSenderAddress)
sal_uInt16 nPos
static OUString encode(OUString const &rText, Part ePart, EncodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
long nSelectionIndex
Definition: dbmgr.hxx:111
virtual OUString get_active_text() const =0
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
virtual void ResetModified()=0
const OUString & getEmbeddedName() const
Definition: dbmgr.cxx:3193
void ToNextRecord(const OUString &rDataSource, const OUString &rTableOrQuery)
Definition: dbmgr.cxx:2203
SfxMedium * GetMedium() const