diff -urN libreoffice-5.4.2.2-orig/Repository.mk libreoffice-5.4.2.2/Repository.mk
--- libreoffice-5.4.2.2-orig/Repository.mk	2017-09-28 03:03:26 +0900
+++ libreoffice-5.4.2.2/Repository.mk	2019-05-23 05:43:05 +0900
@@ -231,8 +231,8 @@
 
 $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,base, \
 	abp \
-	dbp \
-	dbu \
+	$(call gb_Helper_optional,DBCONNECTIVITY,dbp) \
+	$(call gb_Helper_optional,DBCONNECTIVITY,dbu) \
 ))
 
 $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,calc, \
@@ -320,7 +320,7 @@
 		basprov \
 	) \
 	basegfx \
-	bib \
+	$(call gb_Helper_optional,DBCONNECTIVITY,bib) \
 	$(if $(ENABLE_CAIRO_CANVAS),cairocanvas) \
 	canvasfactory \
 	canvastools \
@@ -359,7 +359,7 @@
 	fps_office \
 	for \
 	forui \
-	frm \
+	$(call gb_Helper_optional,DBCONNECTIVITY,frm) \
 	fsstorage \
 	fwe \
 	fwi \
@@ -388,13 +388,13 @@
 	$(call gb_Helper_optional,SCRIPTING,msforms) \
 	mtfrenderer \
 	$(call gb_Helper_optional,DBCONNECTIVITY,mysql) \
-	odbc \
+	$(call gb_Helper_optional,DBCONNECTIVITY,odbc) \
 	odfflatxml \
 	offacc \
 	oox \
 	$(call gb_Helper_optional,OPENCL,opencl) \
 	passwordcontainer \
-	pcr \
+	$(call gb_Helper_optional,DBCONNECTIVITY,pcr) \
 	pdffilter \
 	$(call gb_Helper_optional,SCRIPTING,protocolhandler) \
 	res \
@@ -454,8 +454,8 @@
 	xof \
 	xsltdlg \
 	xsltfilter \
-	mork \
-	mozbootstrap \
+	$(call gb_Helper_optional,DBCONNECTIVITY,mork) \
+	$(call gb_Helper_optional,DBCONNECTIVITY,mozbootstrap) \
 	$(if $(filter $(OS),WNT), \
 		ado \
 		oleautobridge \
@@ -607,7 +607,7 @@
 	package2 \
 	$(if $(USING_X11),recentfile) \
 	$(call gb_Helper_optional,SCRIPTING,scriptframe) \
-	sdbc2 \
+	$(call gb_Helper_optional,DBCONNECTIVITY,sdbc2) \
 	sofficeapp \
 	srtrs1 \
 	$(if $(filter $(OS),WNT),sysdtrans) \
@@ -1121,9 +1121,7 @@
 		modules/dbbrowser \
 		modules/dbquery \
 		modules/dbrelation \
-	) \
-	modules/dbreport \
-	$(call gb_Helper_optional,DBCONNECTIVITY,\
+		modules/dbreport \
 		modules/dbtable \
 		modules/dbtdata \
 	) \
diff -urN libreoffice-5.4.2.2-orig/configure.ac libreoffice-5.4.2.2/configure.ac
--- libreoffice-5.4.2.2-orig/configure.ac	2017-09-28 03:03:26 +0900
+++ libreoffice-5.4.2.2/configure.ac	2019-05-23 05:43:05 +0900
@@ -8870,7 +8870,9 @@
 dnl Check for system odbc
 dnl ===================================================================
 AC_MSG_CHECKING([which odbc headers to use])
-if test "$with_system_odbc" = "yes" -o '(' "$with_system_headers" = "yes" -a "$with_system_odbc" = "auto" ')' -o '(' "$_os" = "WINNT" -a  "$with_system_odbc" != "no" ')'; then
+if test "$enable_database_connectivity" != yes; then
+    AC_MSG_RESULT([none])
+elif test "$with_system_odbc" = "yes" -o '(' "$with_system_headers" = "yes" -a "$with_system_odbc" = "auto" ')' -o '(' "$_os" = "WINNT" -a  "$with_system_odbc" != "no" ')'; then
     AC_MSG_RESULT([external])
     SYSTEM_ODBC_HEADERS=TRUE
 
@@ -8887,8 +8889,6 @@
         AC_CHECK_HEADER(sqlext.h, [],
             [AC_MSG_ERROR(odbc not found. install odbc)],[])
     fi
-elif test "$enable_database_connectivity" != yes; then
-    AC_MSG_RESULT([none])
 else
     AC_MSG_RESULT([internal])
     SYSTEM_ODBC_HEADERS=
diff -urN libreoffice-5.4.2.2-orig/scp2/source/base/file_base.scp libreoffice-5.4.2.2/scp2/source/base/file_base.scp
--- libreoffice-5.4.2.2-orig/scp2/source/base/file_base.scp	2017-09-28 03:03:26 +0900
+++ libreoffice-5.4.2.2/scp2/source/base/file_base.scp	2019-05-23 05:43:05 +0900
@@ -20,6 +20,8 @@
 
 STD_RES_FILE( gid_File_Res_Abp, abp)
 
+#ifdef DBCONNECTIVITY
+
 STD_RES_FILE( gid_File_Res_Dbp, dbp)
 
 STD_RES_FILE( gid_File_Res_Dbu, dbu)
@@ -31,6 +33,8 @@
 
 STD_RES_FILE( gid_File_Res_Rptui, rptui)
 
+#endif
+
 #if defined WITH_HELP
 File gid_File_Help_Sdatabase_Zip
     Dir = FILELIST_DIR;
diff -urN libreoffice-5.4.2.2-orig/scp2/source/ooo/file_resource_ooo.scp libreoffice-5.4.2.2/scp2/source/ooo/file_resource_ooo.scp
--- libreoffice-5.4.2.2-orig/scp2/source/ooo/file_resource_ooo.scp	2017-09-28 03:03:26 +0900
+++ libreoffice-5.4.2.2/scp2/source/ooo/file_resource_ooo.scp	2019-05-23 05:43:05 +0900
@@ -24,24 +24,36 @@
 
 #endif
 
+#ifdef DBCONNECTIVITY
+
 STD_RES_FILE( gid_File_Res_Bib, bib )
 
+#endif
+
 STD_RES_FILE( gid_File_Res_Chartcontroller, chartcontroller )
 
+#ifdef DBCONNECTIVITY
+
 STD_RES_FILE( gid_File_Res_Dba, dba)
 
 STD_RES_FILE( gid_File_Res_Sdbt, sdbt)
 
 STD_RES_FILE( gid_File_Res_Dbmm, dbmm)
 
+#endif
+
 STD_RES_FILE( gid_File_Res_Dbw, dbw )
 
 STD_RES_FILE( gid_File_Res_Dkt, dkt)
 
 STD_RES_FILE( gid_File_Res_Eur, eur )
 
+#ifdef DBCONNECTIVITY
+
 STD_RES_FILE( gid_File_Res_Frm, frm)
 
+#endif
+
 STD_RES_FILE( gid_File_Res_Fwe, fwe)
 
 STD_RES_FILE( gid_File_Res_Fps_Office, fps_office)
@@ -55,8 +67,12 @@
 
 STD_RES_FILE( gid_File_Res_Ofa, ofa )
 
+#ifdef DBCONNECTIVITY
+
 STD_RES_FILE( gid_File_Res_Pcr, pcr)
 
+#endif
+
 STD_RES_FILE( gid_File_Res_Pdffilter, pdffilter)
 
 #ifdef UNX
diff -urN libreoffice-5.4.2.2-orig/sw/Library_sw.mk libreoffice-5.4.2.2/sw/Library_sw.mk
--- libreoffice-5.4.2.2-orig/sw/Library_sw.mk	2017-09-28 03:03:26 +0900
+++ libreoffice-5.4.2.2/sw/Library_sw.mk	2019-05-23 05:43:05 +0900
@@ -571,6 +571,7 @@
     sw/source/uibase/app/swmodule \
     sw/source/uibase/app/swwait \
     sw/source/uibase/dbui/dbmgr \
+    sw/source/uibase/dbui/dbtree \
     sw/source/uibase/dbui/dbui \
     sw/source/uibase/dbui/maildispatcher \
     sw/source/uibase/dbui/mailmergehelper \
@@ -774,7 +775,6 @@
 
 ifneq (,$(filter DBCONNECTIVITY,$(BUILD_TYPE)))
 $(eval $(call gb_Library_add_exception_objects,sw,\
-    sw/source/uibase/dbui/dbtree \
     sw/source/uibase/dbui/mailmergetoolbarcontrols \
 ))
 endif
diff -urN libreoffice-5.4.2.2-orig/sw/source/core/fields/dbfld.cxx libreoffice-5.4.2.2/sw/source/core/fields/dbfld.cxx
--- libreoffice-5.4.2.2-orig/sw/source/core/fields/dbfld.cxx	2017-09-28 03:03:26 +0900
+++ libreoffice-5.4.2.2/sw/source/core/fields/dbfld.cxx	2019-05-23 07:40:39 +0900
@@ -313,6 +313,10 @@
 /// get current field value and cache it
 void SwDBField::Evaluate()
 {
+#if !HAVE_FEATURE_DBCONNECTIVITY
+    return;
+#endif
+
     SwDBManager* pMgr = GetDoc()->GetDBManager();
 
     // first delete
@@ -584,6 +588,10 @@
 
 void SwDBNextSetField::Evaluate(SwDoc* pDoc)
 {
+#if !HAVE_FEATURE_DBCONNECTIVITY
+    return;
+#endif
+
     SwDBManager* pMgr = pDoc->GetDBManager();
     const SwDBData& rData = GetDBData();
     if( !bCondValid ||
diff -urN libreoffice-5.4.2.2-orig/sw/source/ui/dialog/swdlgfact.cxx libreoffice-5.4.2.2/sw/source/ui/dialog/swdlgfact.cxx
--- libreoffice-5.4.2.2-orig/sw/source/ui/dialog/swdlgfact.cxx	2017-09-28 03:03:26 +0900
+++ libreoffice-5.4.2.2/sw/source/ui/dialog/swdlgfact.cxx	2019-05-23 05:43:05 +0900
@@ -235,7 +235,14 @@
         uno::Reference< sdbc::XConnection> xConnection,
         uno::Reference< sdbc::XResultSet > xResultSet)
 {
+#if HAVE_FEATURE_DBCONNECTIVITY
     pDlg->DataToDoc(rSelection, rxSource, xConnection, xResultSet);
+#else
+    (void) rSelection;
+    (void) rxSource;
+    (void) xConnection;
+    (void) xResultSet;
+#endif
 }
 
 OString AbstractDropDownFieldDialog_Impl::GetWindowState() const
@@ -695,8 +702,13 @@
 
 VclPtr<VclAbstractDialog> SwAbstractDialogFactory_Impl::CreateSwChangeDBDlg(SwView& rVw)
 {
+#if HAVE_FEATURE_DBCONNECTIVITY
     VclPtr<Dialog> pDlg = VclPtr<SwChangeDBDlg>::Create(rVw);
     return VclPtr<VclAbstractDialog_Impl>::Create(pDlg);
+#else
+    (void) rVw;
+    return nullptr;
+#endif
 }
 
 VclPtr<SfxAbstractTabDialog>  SwAbstractDialogFactory_Impl::CreateSwCharDlg(vcl::Window* pParent, SwView& pVw,
@@ -723,8 +735,16 @@
         uno::Reference<sdbcx::XColumnsSupplier> xColSupp,
         const SwDBData& rData)
 {
+#if HAVE_FEATURE_DBCONNECTIVITY
     VclPtr<SwInsertDBColAutoPilot> pDlg = VclPtr<SwInsertDBColAutoPilot>::Create( rView, rxSource, xColSupp, rData );
     return VclPtr<AbstractSwInsertDBColAutoPilot_Impl>::Create( pDlg );
+#else
+    (void) rView;
+    (void) rxSource;
+    (void) xColSupp;
+    (void) rData;
+    return nullptr;
+#endif
 }
 
 VclPtr<SfxAbstractTabDialog> SwAbstractDialogFactory_Impl::CreateSwFootNoteOptionDlg(vcl::Window *pParent, SwWrtShell &rSh)
@@ -1054,7 +1074,13 @@
 VclPtr<AbstractMailMergeWizard> SwAbstractDialogFactory_Impl::CreateMailMergeWizard(
                                     SwView& rView, std::shared_ptr<SwMailMergeConfigItem>& rConfigItem)
 {
+#if HAVE_FEATURE_DBCONNECTIVITY
     return VclPtr<AbstractMailMergeWizard_Impl>::Create( VclPtr<SwMailMergeWizard>::Create(rView, rConfigItem));
+#else
+    (void) rView;
+    (void) rConfigItem;
+    return nullptr;
+#endif
 }
 
 GlossaryGetCurrGroup    SwAbstractDialogFactory_Impl::GetGlossaryCurrGroupFunc()
@@ -1127,20 +1153,26 @@
 
 void SwAbstractDialogFactory_Impl::ExecuteMMResultSaveDialog()
 {
+#if HAVE_FEATURE_DBCONNECTIVITY
     ScopedVclPtrInstance<SwMMResultSaveDialog> pDialog;
     pDialog->Execute();
+#endif
 }
 
 void SwAbstractDialogFactory_Impl::ExecuteMMResultPrintDialog()
 {
+#if HAVE_FEATURE_DBCONNECTIVITY
     ScopedVclPtrInstance<SwMMResultPrintDialog> pDialog;
     pDialog->Execute();
+#endif
 }
 
 void SwAbstractDialogFactory_Impl::ExecuteMMResultEmailDialog()
 {
+#if HAVE_FEATURE_DBCONNECTIVITY
     ScopedVclPtrInstance<SwMMResultEmailDialog> pDialog;
     pDialog->Execute();
+#endif
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff -urN libreoffice-5.4.2.2-orig/sw/source/uibase/app/docsh.cxx libreoffice-5.4.2.2/sw/source/uibase/app/docsh.cxx
--- libreoffice-5.4.2.2-orig/sw/source/uibase/app/docsh.cxx	2017-09-28 03:03:26 +0900
+++ libreoffice-5.4.2.2/sw/source/uibase/app/docsh.cxx	2019-05-23 07:38:11 +0900
@@ -419,6 +419,7 @@
 
     CalcLayoutForOLEObjects();  // format for OLE objects
 
+#if HAVE_FEATURE_DBCONNECTIVITY
     bool bURLChanged = !GetMedium() || GetMedium()->GetURLObject() != rMedium.GetURLObject();
     if (!m_pDoc->GetDBManager()->getEmbeddedName().isEmpty() && bURLChanged)
     {
@@ -436,6 +437,7 @@
         uno::Reference<frame::XStorable> xStorable(xDataSource->getDatabaseDocument(), uno::UNO_QUERY);
         SwDBManager::StoreEmbeddedDataSource(xStorable, rMedium.GetOutputStorage(), m_pDoc->GetDBManager()->getEmbeddedName(), rMedium.GetName());
     }
+#endif
 
     // #i62875#
     // reset compatibility flag <DoNotCaptureDrawObjsOnPage>, if possible
diff -urN libreoffice-5.4.2.2-orig/sw/source/uibase/dbui/dbmgr.cxx libreoffice-5.4.2.2/sw/source/uibase/dbui/dbmgr.cxx
--- libreoffice-5.4.2.2-orig/sw/source/uibase/dbui/dbmgr.cxx	2017-09-28 03:03:26 +0900
+++ libreoffice-5.4.2.2/sw/source/uibase/dbui/dbmgr.cxx	2019-05-23 05:43:05 +0900
@@ -3085,8 +3085,8 @@
 
 void SwDBManager::setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell)
 {
-    bool bLoad = m_sEmbeddedName != rEmbeddedName && !rEmbeddedName.isEmpty();
-    bool bRegisterListener = m_sEmbeddedName.isEmpty() && !rEmbeddedName.isEmpty();
+    bool bLoad = !rEmbeddedName.isEmpty() && m_sEmbeddedName != rEmbeddedName;
+    bool bRegisterListener = !rEmbeddedName.isEmpty() && m_sEmbeddedName.isEmpty();
 
     m_sEmbeddedName = rEmbeddedName;
 
diff -urN libreoffice-5.4.2.2-orig/sw/source/uibase/dbui/dbtree.cxx libreoffice-5.4.2.2/sw/source/uibase/dbui/dbtree.cxx
--- libreoffice-5.4.2.2-orig/sw/source/uibase/dbui/dbtree.cxx	2017-09-28 03:03:26 +0900
+++ libreoffice-5.4.2.2/sw/source/uibase/dbui/dbtree.cxx	2019-05-23 05:43:05 +0900
@@ -119,12 +119,14 @@
 
 bool SwDBTreeList_Impl::HasContext()
 {
+#if HAVE_FEATURE_DBCONNECTIVITY
     if(!m_xDatabaseContext.is())
     {
         Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
         m_xDatabaseContext = DatabaseContext::create(xContext);
         m_xDatabaseContext->addContainerListener( this );
     }
+#endif
     return m_xDatabaseContext.is();
 }
 
@@ -168,6 +170,9 @@
 
 void SwDBTreeList::InitTreeList()
 {
+#if HAVE_FEATURE_DBCONNECTIVITY
+    return;
+#endif
     if(!pImpl->HasContext() && pImpl->GetWrtShell())
         return;
     SetSelectionMode(SelectionMode::Single);
diff -urN libreoffice-5.4.2.2-orig/sw/source/uibase/uno/SwXDocumentSettings.cxx libreoffice-5.4.2.2/sw/source/uibase/uno/SwXDocumentSettings.cxx
--- libreoffice-5.4.2.2-orig/sw/source/uibase/uno/SwXDocumentSettings.cxx	2017-09-28 03:03:26 +0900
+++ libreoffice-5.4.2.2/sw/source/uibase/uno/SwXDocumentSettings.cxx	2019-05-23 05:43:38 +0900
@@ -504,9 +504,11 @@
         break;
         case HANDLE_EMBEDDED_DATABASE_NAME:
         {
+#if HAVE_FEATURE_DBCONNECTIVITY
             OUString sEmbeddedName;
             if (rValue >>= sEmbeddedName)
                 mpDoc->GetDBManager()->setEmbeddedName(sEmbeddedName, *mpDocSh);
+#endif
         }
         break;
         case HANDLE_SAVE_VERSION_ON_CLOSE:
@@ -996,7 +998,11 @@
         break;
         case HANDLE_EMBEDDED_DATABASE_NAME:
         {
+#if HAVE_FEATURE_DBCONNECTIVITY
             rValue <<= mpDoc->GetDBManager()->getEmbeddedName();
+#else
+            rValue <<= OUString();
+#endif
         }
         break;
         case HANDLE_SAVE_VERSION_ON_CLOSE:
