More hacking on --disable-database-connectivity

Work in progress, still lots of undefineds when attempting to link
TiledLibreOffice.

Change-Id: I80fa330768d9f9fa9ef65e3693f1d777c0713210
diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk
index 2f0e9a4..3f9ded6 100644
--- a/svx/Library_svx.mk
+++ b/svx/Library_svx.mk
@@ -247,12 +247,11 @@ $(eval $(call gb_Library_add_exception_objects,svx,\
    svx/source/unogallery/unogalthemeprovider \
))

ifneq (,$(filter DBCONNECTIVITY,$(BUILD_TYPE)))
$(eval $(call gb_Library_add_exception_objects,svx,\
    svx/source/fmcomp/dbaobjectex \
    svx/source/form/databaselocationinput \
    svx/source/form/dbcharsethelper \
    svx/source/form/filtnav \
    $(call gb_Helper_optional,DBCONNECTIVITY,svx/source/form/filtnav) \
    svx/source/form/fmobjfac \
    svx/source/form/fmPropBrw \
    svx/source/form/fmsrccfg \
@@ -260,7 +259,6 @@ $(eval $(call gb_Library_add_exception_objects,svx,\
    svx/source/form/tabwin \
    svx/source/form/tbxform \
))
endif

ifeq ($(OS),WNT)
$(eval $(call gb_Library_use_system_win32_libs,svx,\
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 2b2d194..ccb48ed 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -390,8 +390,6 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
    svx/source/xoutdev/xtablend \
))

ifneq (,$(filter DBCONNECTIVITY,$(BUILD_TYPE)))

$(eval $(call gb_Library_add_exception_objects,svxcore,\
    svx/source/fmcomp/dbaexchange \
    svx/source/fmcomp/fmgridcl \
@@ -445,7 +443,6 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
    svx/source/form/typemap \
    svx/source/form/xfm_addcondition \
))
endif

$(eval $(call gb_SdiTarget_SdiTarget,svx/sdi/svxslots,svx/sdi/svx))

diff --git a/svx/source/form/fmobjfac.cxx b/svx/source/form/fmobjfac.cxx
index 8c00e5e..f1bad87 100644
--- a/svx/source/form/fmobjfac.cxx
+++ b/svx/source/form/fmobjfac.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <tools/diagnose_ex.h>
#include <svx/svdobj.hxx>
#include "svx/fmtools.hxx"
@@ -79,8 +81,9 @@ FmFormObjFactory::FmFormObjFactory()
        FmPropBrwMgr::RegisterChildWindow();
        NavigatorFrameManager::RegisterChildWindow();
        DataNavigatorManager::RegisterChildWindow();
#if HAVE_FEATURE_DBCONNECTIVITY
        FmFilterNavigatorWinMgr::RegisterChildWindow();

#endif

        // Interface fuer die Formshell registrieren
        FmFormShell::RegisterInterface(0);
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index 1f7d55a..6bb809d 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -256,7 +256,6 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
    sw/source/core/fields/authfld \
    sw/source/core/fields/cellfml \
    sw/source/core/fields/chpfld \
    sw/source/core/fields/dbfld \
    sw/source/core/fields/ddefld \
    sw/source/core/fields/ddetbl \
    sw/source/core/fields/docufld \
@@ -744,6 +743,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\

ifneq (,$(filter DBCONNECTIVITY,$(BUILD_TYPE)))
$(eval $(call gb_Library_add_exception_objects,sw,\
    sw/source/core/fields/dbfld \
    sw/source/core/uibase/dbui/dbmgr \
    sw/source/core/uibase/dbui/dbtree \
    sw/source/core/uibase/dbui/dbui \
diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx
index 837d87e..4c3a68e 100644
--- a/sw/source/core/bastyp/calc.cxx
+++ b/sw/source/core/bastyp/calc.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <calc.hxx>
#include <cctype>
#include <cfloat>
@@ -513,6 +515,7 @@ SwCalcExp* SwCalc::VarLook( const OUString& rStr, sal_uInt16 ins )

    if( !ins )
    {
#if HAVE_FEATURE_DBCONNECTIVITY
        SwDBMgr *pMgr = rDoc.GetNewDBMgr();

        OUString sDBName(GetDBName( sTmpName ));
@@ -558,6 +561,7 @@ SwCalcExp* SwCalc::VarLook( const OUString& rStr, sal_uInt16 ins )
            }
        }
        else
#endif
        {
            //data source was not available - set return to "NoValue"
            aErrExpr.nValue.SetVoidValue(true);
@@ -575,6 +579,7 @@ SwCalcExp* SwCalc::VarLook( const OUString& rStr, sal_uInt16 ins )
    if( sColumnName.equalsIgnoreAsciiCase(
                            SwFieldType::GetTypeStr( TYP_DBSETNUMBERFLD ) ))
    {
#if HAVE_FEATURE_DBCONNECTIVITY
        SwDBMgr *pMgr = rDoc.GetNewDBMgr();
        OUString sDBName(GetDBName( sTmpName ));
        OUString sSourceName(sDBName.getToken(0, DB_DELIM));
@@ -586,6 +591,7 @@ SwCalcExp* SwCalc::VarLook( const OUString& rStr, sal_uInt16 ins )
            pNewExp->nValue.PutULong( pMgr->GetSelectedRecordId(sSourceName, sTableName));
        }
        else
#endif
        {
            pNewExp->nValue.SetVoidValue(true);
        }
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx
index a609091..21b5652 100644
--- a/sw/source/core/doc/docfld.cxx
+++ b/sw/source/core/doc/docfld.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <hintids.hxx>

#include <string.h>
@@ -347,10 +349,12 @@ void SwDoc::UpdateFlds( SfxPoolItem *pNewHt, bool bCloseDB )

    // References
    UpdateRefFlds(pNewHt);

    if( bCloseDB )
    {
#if HAVE_FEATURE_DBCONNECTIVITY
        GetNewDBMgr()->CloseAll();

#endif
    }
    // Only evaluate on full update
    SetModified();
}
@@ -997,6 +1001,8 @@ OUString LookString( SwHash** ppTbl, sal_uInt16 nSize, const OUString& rName,
    return OUString();
}

#if HAVE_FEATURE_DBCONNECTIVITY

static OUString lcl_GetDBVarName( SwDoc& rDoc, SwDBNameInfField& rDBFld )
{
    SwDBData aDBData( rDBFld.GetDBData( &rDoc ));
@@ -1015,6 +1021,8 @@ static OUString lcl_GetDBVarName( SwDoc& rDoc, SwDBNameInfField& rDBFld )
    return sDBNumNm;
}

#endif

static void lcl_CalcFld( SwDoc& rDoc, SwCalc& rCalc, const _SetGetExpFld& rSGEFld,
                        SwDBMgr* pMgr )
{
@@ -1039,6 +1047,9 @@ static void lcl_CalcFld( SwDoc& rDoc, SwCalc& rCalc, const _SetGetExpFld& rSGEFl
    }
    else if( pMgr )
    {
#if !HAVE_FEATURE_DBCONNECTIVITY
        (void) rDoc;
#else
        switch( nFldWhich )
        {
        case RES_DBNUMSETFLD:
@@ -1069,6 +1080,7 @@ static void lcl_CalcFld( SwDoc& rDoc, SwCalc& rCalc, const _SetGetExpFld& rSGEFl
            break;

        }
#endif
    }
}

@@ -1078,8 +1090,12 @@ void SwDoc::FldsToCalc( SwCalc& rCalc, const _SetGetExpFld& rToThisFld )
    mpUpdtFlds->MakeFldList( *this, mbNewFldLst, GETFLD_CALC );
    mbNewFldLst = false;

#if !HAVE_FEATURE_DBCONNECTIVITY
    SwDBMgr* pMgr = NULL;
#else
    SwDBMgr* pMgr = GetNewDBMgr();
    pMgr->CloseAll(sal_False);
#endif

    if( !mpUpdtFlds->GetSortLst()->empty() )
    {
@@ -1089,8 +1105,9 @@ void SwDoc::FldsToCalc( SwCalc& rCalc, const _SetGetExpFld& rToThisFld )
        for( _SetGetExpFlds::const_iterator it = mpUpdtFlds->GetSortLst()->begin(); it != itLast; ++it )
            lcl_CalcFld( *this, rCalc, **it, pMgr );
    }

#if HAVE_FEATURE_DBCONNECTIVITY
    pMgr->CloseAll(sal_False);
#endif
}

void SwDoc::FldsToCalc( SwCalc& rCalc, sal_uLong nLastNd, sal_uInt16 nLastCnt )
@@ -1099,8 +1116,12 @@ void SwDoc::FldsToCalc( SwCalc& rCalc, sal_uLong nLastNd, sal_uInt16 nLastCnt )
    mpUpdtFlds->MakeFldList( *this, mbNewFldLst, GETFLD_CALC );
    mbNewFldLst = false;

#if !HAVE_FEATURE_DBCONNECTIVITY
    SwDBMgr* pMgr = NULL;
#else
    SwDBMgr* pMgr = GetNewDBMgr();
    pMgr->CloseAll(sal_False);
#endif

    for( _SetGetExpFlds::const_iterator it = mpUpdtFlds->GetSortLst()->begin();
        it != mpUpdtFlds->GetSortLst()->end() &&
@@ -1112,7 +1133,9 @@ void SwDoc::FldsToCalc( SwCalc& rCalc, sal_uLong nLastNd, sal_uInt16 nLastCnt )
        lcl_CalcFld( *this, rCalc, **it, pMgr );
    }

#if HAVE_FEATURE_DBCONNECTIVITY
    pMgr->CloseAll(sal_False);
#endif
}

void SwDoc::FldsToExpand( SwHash**& ppHashTbl, sal_uInt16& rTblSize,
@@ -1256,11 +1279,13 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )
    // The array is filled with all fields; start calculation.
    SwCalc aCalc( *this );

#if HAVE_FEATURE_DBCONNECTIVITY
    OUString sDBNumNm( SwFieldType::GetTypeStr( TYP_DBSETNUMBERFLD ) );

    // already set the current record number
    SwDBMgr* pMgr = GetNewDBMgr();
    pMgr->CloseAll(sal_False);
#endif

    // Make sure we don't hide all sections, which would lead to a crash. First, count how many of them do we have.
    int nShownSections = 0;
@@ -1342,17 +1367,24 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )
        }
        break;
        case RES_DBSETNUMBERFLD:
#if HAVE_FEATURE_DBCONNECTIVITY
        {
            ((SwDBSetNumberField*)pFld)->Evaluate(this);
            aCalc.VarChange( sDBNumNm, ((SwDBSetNumberField*)pFld)->GetSetNumber());
        }
#endif
        break;
        case RES_DBNEXTSETFLD:
        case RES_DBNUMSETFLD:
#if HAVE_FEATURE_DBCONNECTIVITY
        {
            UpdateDBNumFlds( *(SwDBNameInfField*)pFld, aCalc );
        }
#endif
        break;
        case RES_DBFLD:
        {
#if HAVE_FEATURE_DBCONNECTIVITY
            // evaluate field
            ((SwDBField*)pFld)->Evaluate();

@@ -1379,6 +1411,7 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )
                *(pHashStrTbl + nPos ) = new _HashStr( rName,
                    value, static_cast<_HashStr *>(*(pHashStrTbl + nPos)));
            }
#endif
        }
        break;
        case RES_GETEXPFLD:
@@ -1503,7 +1536,9 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )
        }
    }

#if HAVE_FEATURE_DBCONNECTIVITY
    pMgr->CloseAll(sal_False);
#endif
    // delete hash table
    ::DeleteHashTable( pHashStrTbl, nStrFmtCnt );

@@ -1517,6 +1552,10 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )

void SwDoc::UpdateDBNumFlds( SwDBNameInfField& rDBFld, SwCalc& rCalc )
{
#if !HAVE_FEATURE_DBCONNECTIVITY
    (void) rDBFld;
    (void) rCalc;
#else
    SwDBMgr* pMgr = GetNewDBMgr();

    sal_uInt16 nFldType = rDBFld.Which();
@@ -1546,6 +1585,7 @@ void SwDoc::UpdateDBNumFlds( SwDBNameInfField& rDBFld, SwCalc& rCalc )
    {
        OSL_FAIL("TODO: what should happen with unnamed DBFields?");
    }
#endif
}

void SwDoc::_InitFieldTypes()       // is being called by the CTOR
@@ -1567,9 +1607,11 @@ void SwDoc::_InitFieldTypes()       // is being called by the CTOR
    mpFldTypes->push_back( new SwTblFieldType( this ) );
    mpFldTypes->push_back( new SwMacroFieldType(this) );
    mpFldTypes->push_back( new SwHiddenParaFieldType );
#if HAVE_FEATURE_DBCONNECTIVITY
    mpFldTypes->push_back( new SwDBNextSetFieldType );
    mpFldTypes->push_back( new SwDBNumSetFieldType );
    mpFldTypes->push_back( new SwDBSetNumberFieldType );
#endif
    mpFldTypes->push_back( new SwTemplNameFieldType(this) );
    mpFldTypes->push_back( new SwTemplNameFieldType(this) );
    mpFldTypes->push_back( new SwExtUserFieldType );
@@ -1609,6 +1651,7 @@ SwDBData SwDoc::GetDBData()

const SwDBData& SwDoc::GetDBDesc()
{
#if HAVE_FEATURE_DBCONNECTIVITY
    if(maDBData.sDataSource.isEmpty())
    {
        const sal_uInt16 nSize = mpFldTypes->size();
@@ -1645,14 +1688,21 @@ const SwDBData& SwDoc::GetDBDesc()
    }
    if(maDBData.sDataSource.isEmpty())
        maDBData = GetNewDBMgr()->GetAddressDBName();
#endif
    return maDBData;
}

void SwDoc::SetInitDBFields( sal_Bool b )
{
#if !HAVE_FEATURE_DBCONNECTIVITY
    (void) b;
#else
    GetNewDBMgr()->SetInitDBFields( b );
#endif
}

#if HAVE_FEATURE_DBCONNECTIVITY

/// Get all databases that are used by fields
static OUString lcl_DBDataToString(const SwDBData& rData)
{
@@ -1664,9 +1714,15 @@ static OUString lcl_DBDataToString(const SwDBData& rData)
    return sRet;
}

#endif

void SwDoc::GetAllUsedDB( std::vector<OUString>& rDBNameList,
                          const std::vector<OUString>* pAllDBNames )
{
#if !HAVE_FEATURE_DBCONNECTIVITY
    (void) rDBNameList;
    (void) pAllDBNames;
#else
    std::vector<OUString> aUsedDBNames;
    std::vector<OUString> aAllDBNames;

@@ -1738,10 +1794,14 @@ void SwDoc::GetAllUsedDB( std::vector<OUString>& rDBNameList,
                break;
        }
    }
#endif
}

void SwDoc::GetAllDBNames( std::vector<OUString>& rAllDBNames )
{
#if !HAVE_FEATURE_DBCONNECTIVITY
    (void) rAllDBNames;
#else
    SwDBMgr* pMgr = GetNewDBMgr();

    const SwDSParamArr& rArr = pMgr->GetDSParamArray();
@@ -1750,6 +1810,7 @@ void SwDoc::GetAllDBNames( std::vector<OUString>& rAllDBNames )
        const SwDSParam* pParam = &rArr[i];
        rAllDBNames.push_back(pParam->sDataSource + OUString(DB_DELIM) + pParam->sCommand);
    }
#endif
}

std::vector<OUString>& SwDoc::FindUsedDBs( const std::vector<OUString>& rAllDBNames,
@@ -1794,6 +1855,10 @@ void SwDoc::AddUsedDBToList( std::vector<OUString>& rDBNameList,

void SwDoc::AddUsedDBToList( std::vector<OUString>& rDBNameList, const OUString& rDBName)
{
#if !HAVE_FEATURE_DBCONNECTIVITY
    (void) rDBNameList;
    (void) rDBName;
#else
    if( rDBName.isEmpty() )
        return;

@@ -1814,11 +1879,16 @@ void SwDoc::AddUsedDBToList( std::vector<OUString>& rDBNameList, const OUString&
    aData.nCommandType = -1;
    GetNewDBMgr()->CreateDSData(aData);
    rDBNameList.push_back(rDBName);
#endif
}

void SwDoc::ChangeDBFields( const std::vector<OUString>& rOldNames,
                            const OUString& rNewName )
{
#if !HAVE_FEATURE_DBCONNECTIVITY
    (void) rOldNames;
    (void) rNewName;
#else
    SwDBData aNewDBData;
    aNewDBData.sDataSource = rNewName.getToken(0, DB_DELIM);
    aNewDBData.sCommand = rNewName.getToken(1, DB_DELIM);
@@ -1908,6 +1978,7 @@ void SwDoc::ChangeDBFields( const std::vector<OUString>& rOldNames,
            pTxtFld->ExpandAlways();
    }
    SetModified();
#endif
}

namespace
@@ -2259,7 +2330,9 @@ void SwDocUpdtFld::_MakeFldList( SwDoc& rDoc, int eGetMode )
    const OUString sTrue("TRUE");
    const OUString sFalse("FALSE");

#if HAVE_FEATURE_DBCONNECTIVITY
    bool bIsDBMgr = 0 != rDoc.GetNewDBMgr();
#endif
    sal_uInt16 nWhich, n;
    const SfxPoolItem* pItem;
    sal_uInt32 nMaxItems = rDoc.GetAttrPool().GetItemCount2( RES_TXTATR_FIELD );
@@ -2333,6 +2406,7 @@ void SwDocUpdtFld::_MakeFldList( SwDoc& rDoc, int eGetMode )
                }
                break;

#if HAVE_FEATURE_DBCONNECTIVITY
            case RES_DBNUMSETFLD:
            {
                SwDBData aDBData(((SwDBNumSetField*)pFld)->GetDBData(&rDoc));
@@ -2359,6 +2433,7 @@ void SwDocUpdtFld::_MakeFldList( SwDoc& rDoc, int eGetMode )
                }
            }
            break;
#endif
        }

        if (!sFormula.isEmpty())
diff --git a/sw/source/core/edit/edfld.cxx b/sw/source/core/edit/edfld.cxx
index 2d2b2c3..a765fbb 100644
--- a/sw/source/core/edit/edfld.cxx
+++ b/sw/source/core/edit/edfld.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <unotools/charclass.hxx>
#include <editsh.hxx>
#include <fldbas.hxx>
@@ -365,13 +367,21 @@ void SwEditShell::UpdateExpFlds(sal_Bool bCloseDB)
    StartAllAction();
    GetDoc()->UpdateExpFlds(NULL, true);
    if (bCloseDB)
    {
#if HAVE_FEATURE_DBCONNECTIVITY
        GetDoc()->GetNewDBMgr()->CloseAll(); // close all database connections
#endif
    }
    EndAllAction();
}

SwDBMgr* SwEditShell::GetNewDBMgr() const
{
#if HAVE_FEATURE_DBCONNECTIVITY
    return GetDoc()->GetNewDBMgr();
#else
    return NULL;
#endif
}

/// insert field type
diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx
index 65d9960..c91bf64 100644
--- a/sw/source/core/fields/docufld.cxx
+++ b/sw/source/core/fields/docufld.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <textapi.hxx>

#include <hintids.hxx>
@@ -1366,8 +1368,11 @@ void SwHiddenTxtField::Evaluate(SwDoc* pDoc)

    if( TYP_CONDTXTFLD == nSubType )
    {
#if !HAVE_FEATURE_DBCONNECTIVITY
        (void) pDoc;
#else
        SwDBMgr* pMgr = pDoc->GetNewDBMgr();

#endif
        bValid = sal_False;
        OUString sTmpName = (bCanToggle && !bIsHidden) ? aTRUETxt : aFALSETxt;

@@ -1389,7 +1394,7 @@ void SwHiddenTxtField::Evaluate(SwDoc* pDoc)
            {   // remove brackets
                sTmpName = sTmpName.copy(1, sTmpName.getLength() - 2);
            }

#if HAVE_FEATURE_DBCONNECTIVITY
            if( pMgr)
            {
                OUString sDBName( GetDBName( sTmpName, pDoc ));
@@ -1409,6 +1414,7 @@ void SwHiddenTxtField::Evaluate(SwDoc* pDoc)
                         !sDataTableOrQuery.isEmpty() )
                    bValid = sal_True;
            }
#endif
        }
    }
}
diff --git a/sw/source/core/uibase/app/apphdl.cxx b/sw/source/core/uibase/app/apphdl.cxx
index 7fbdc2d7..b1149ca 100644
--- a/sw/source/core/uibase/app/apphdl.cxx
+++ b/sw/source/core/uibase/app/apphdl.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <hintids.hxx>

#include <osl/diagnose.h>
@@ -181,7 +183,15 @@ void SwModule::StateOther(SfxItemSet &rSet)
    }
}

static SwView* lcl_LoadDoc(SwView* pView, const OUString& rURL)
// start field dialog
void NewXForms( SfxRequest& rReq ); // implementation: below

#if HAVE_FEATURE_DBCONNECTIVITY

namespace
{

SwView* lcl_LoadDoc(SwView* pView, const OUString& rURL)
{
    SwView* pNewView = 0;
    if(!rURL.isEmpty())
@@ -226,12 +236,6 @@ static SwView* lcl_LoadDoc(SwView* pView, const OUString& rURL)
    return pNewView;
}

// start field dialog
void NewXForms( SfxRequest& rReq ); // implementation: below

namespace
{

class SwMailMergeWizardExecutor : public salhelper::SimpleReferenceObject
{
    SwView*                  m_pView;       // never owner
@@ -573,6 +577,8 @@ IMPL_LINK_NOARG(SwMailMergeWizardExecutor, CloseFrameHdl)

} // namespace

#endif // HAVE_FEATURE_DBCONNECTIVITY

void SwModule::ExecOther(SfxRequest& rReq)
{
    const SfxItemSet *pArgs = rReq.GetArgs();
@@ -630,11 +636,13 @@ void SwModule::ExecOther(SfxRequest& rReq)
                pModuleConfig->SetInsTblFormatNum( bWebView, bSet );
            }
            break;
#if HAVE_FEATURE_DBCONNECTIVITY
        case FN_MAILMERGE_WIZARD:
        {
            rtl::Reference< SwMailMergeWizardExecutor > xEx( new SwMailMergeWizardExecutor );
            xEx->ExecuteMailMergeWizard( pArgs );
        }
#endif
        break;
    }
}
diff --git a/sw/source/core/uibase/fldui/fldmgr.cxx b/sw/source/core/uibase/fldui/fldmgr.cxx
index d4a0b5c..7f0f587 100644
--- a/sw/source/core/uibase/fldui/fldmgr.cxx
+++ b/sw/source/core/uibase/fldui/fldmgr.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <cmdid.h>
#include <hintids.hxx>
#include <svl/stritem.hxx>
@@ -1068,6 +1070,7 @@ sal_Bool SwFldMgr::InsertFld(

    case TYP_DBFLD:
        {
#if HAVE_FEATURE_DBCONNECTIVITY
            SwDBData aDBData;
            OUString sPar1;

@@ -1113,6 +1116,7 @@ sal_Bool SwFldMgr::InsertFld(
            pFld->ChangeFormat( nFormatId );

            bExp = true;
#endif
            break;
        }

@@ -1121,6 +1125,7 @@ sal_Bool SwFldMgr::InsertFld(
    case TYP_DBNEXTSETFLD:
    case TYP_DBNAMEFLD:
        {
#if HAVE_FEATURE_DBCONNECTIVITY
            SwDBData aDBData;

            // excract DBName from rData.sPar1. Format: DBName.TableName.CommandType.ExpStrg
@@ -1189,6 +1194,7 @@ sal_Bool SwFldMgr::InsertFld(
                    break;
                }
            }
#endif
            break;
        }

diff --git a/sw/source/core/uibase/uiview/view2.cxx b/sw/source/core/uibase/uiview/view2.cxx
index 20aa0034..4f45362 100644
--- a/sw/source/core/uibase/uiview/view2.cxx
+++ b/sw/source/core/uibase/uiview/view2.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <com/sun/star/util/SearchOptions.hpp>
#include <com/sun/star/util/SearchFlags.hpp>
#include <com/sun/star/i18n/TransliterationModules.hpp>
@@ -1088,6 +1090,7 @@ void SwView::Execute(SfxRequest &rReq)
                GetViewFrame()->ToggleChildWindow(nSlot);
            //if fields have been successfully inserted call the "real"
            //mail merge dialog
#if HAVE_FEATURE_DBCONNECTIVITY
            SwWrtShell &rSh = GetWrtShell();
            if(m_bInMailMerge && rSh.IsAnyDatabaseFieldInDoc())
            {
@@ -1110,6 +1113,7 @@ void SwView::Execute(SfxRequest &rReq)
                    pNewDBMgr->ExecuteFormLetter(rSh, aProperties, sal_True);
                }
            }
#endif
            m_bInMailMerge &= bShow;
            GetViewFrame()->GetBindings().Invalidate(FN_INSERT_FIELD);
        }
@@ -2269,6 +2273,8 @@ void SwView::EnableMailMerge(sal_Bool bEnable )
    rBind.Update(FN_INSERT_FIELD_DATA_ONLY);
}

#if HAVE_FEATURE_DBCONNECTIVITY

namespace
{
    sal_Bool lcl_NeedAdditionalDataSource( const uno::Reference< XDatabaseContext >& _rDatasourceContext )
@@ -2283,8 +2289,13 @@ namespace
    }
}

#endif

void SwView::GenerateFormLetter(sal_Bool bUseCurrentDocument)
{
#if !HAVE_FEATURE_DBCONNECTIVITY
    (void) bUseCurrentDocument;
#else
    if(bUseCurrentDocument)
    {
        if(!GetWrtShell().IsAnyDatabaseFieldInDoc())
@@ -2419,6 +2430,7 @@ void SwView::GenerateFormLetter(sal_Bool bUseCurrentDocument)
            // but we want that the new document is on top
            pTopWin->ToTop();
    }
#endif
}

IMPL_LINK( SwView, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
diff --git a/sw/source/core/uibase/uno/unodispatch.cxx b/sw/source/core/uibase/uno/unodispatch.cxx
index 9c7ba21..b061c01 100644
--- a/sw/source/core/uibase/uno/unodispatch.cxx
+++ b/sw/source/core/uibase/uno/unodispatch.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <vcl/svapp.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/dispatch.hxx>
@@ -205,6 +207,12 @@ void SwXDispatch::dispatch(const util::URL& aURL,
{
    if(!m_pView)
        throw uno::RuntimeException();
#if !HAVE_FEATURE_DBCONNECTIVITY
    (void) aArgs;
    if (false)
    {
    }
#else
    SwWrtShell& rSh = m_pView->GetWrtShell();
    SwDBMgr* pNewDBMgr = rSh.GetNewDBMgr();
    if(aURL.Complete.equalsAscii(cURLInsertContent))
@@ -225,6 +233,7 @@ void SwXDispatch::dispatch(const util::URL& aURL,
            SFX_CALLMODE_ASYNCHRON,
            &aDBProperties, 0L);
    }
#endif
    else if(aURL.Complete.equalsAscii(cURLDocumentDataSource))
    {
        OSL_FAIL("SwXDispatch::dispatch: this URL is not to be dispatched!");
diff --git a/sw/source/core/uibase/utlui/initui.cxx b/sw/source/core/uibase/utlui/initui.cxx
index eea83f0..e998945 100644
--- a/sw/source/core/uibase/utlui/initui.cxx
+++ b/sw/source/core/uibase/utlui/initui.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <unotools/localedatawrapper.hxx>
#include <viewsh.hxx>
#include <initui.hxx>
@@ -146,7 +148,9 @@ std::vector<OUString>* pAuthFieldTypeList = 0;

void _FinitUI()
{
#if HAVE_FEATURE_DBCONNECTIVITY
    SwDBMgr::RemoveDbtoolsClient();
#endif
    delete SwViewShell::GetShellRes();
    SwViewShell::SetShellRes( 0 );

diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx
index 9bcf759..c777729 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <sal/config.h>

#include <algorithm>
@@ -760,6 +762,9 @@ throw (beans::UnknownPropertyException, beans::PropertyVetoException,

SwFieldType* SwXFieldMaster::GetFldType(bool const bDontCreate) const
{
#if !HAVE_FEATURE_DBCONNECTIVITY
    (void) bDontCreate;
#else
    if (!bDontCreate && RES_DBFLD == m_pImpl->m_nResTypeId
        && m_pImpl->m_bIsDescriptor && m_pImpl->m_pDoc)
    {
@@ -780,6 +785,7 @@ SwFieldType* SwXFieldMaster::GetFldType(bool const bDontCreate) const
        pType->Add(m_pImpl.get());
        const_cast<SwXFieldMaster*>(this)->m_pImpl->m_bIsDescriptor = false;
    }
#endif
    if (m_pImpl->m_bIsDescriptor)
        return 0;
    else
@@ -1618,6 +1624,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
        }
        break;
        case SW_SERVICE_FIELDTYPE_DATABASE_NAME:
#if HAVE_FEATURE_DBCONNECTIVITY
        {
            SwFieldType* pFldType = pDoc->GetSysFldType(RES_DBNAMEFLD);
            SwDBData aData;
@@ -1632,8 +1639,10 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
                nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
            pFld->SetSubType(nSubType);
        }
#endif
        break;
        case SW_SERVICE_FIELDTYPE_DATABASE_NEXT_SET:
#if HAVE_FEATURE_DBCONNECTIVITY
        {
            SwDBData aData;
            aData.sDataSource = m_pImpl->m_pProps->sPar1;
@@ -1643,8 +1652,10 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
            pFld = new SwDBNextSetField((SwDBNextSetFieldType*)pFldType,
                    m_pImpl->m_pProps->sPar3, OUString(), aData);
        }
#endif
        break;
        case SW_SERVICE_FIELDTYPE_DATABASE_NUM_SET:
#if HAVE_FEATURE_DBCONNECTIVITY
        {
            SwDBData aData;
            aData.sDataSource = m_pImpl->m_pProps->sPar1;
@@ -1656,8 +1667,10 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
                OUString::number(m_pImpl->m_pProps->nFormat),
                aData );
        }
#endif
        break;
        case SW_SERVICE_FIELDTYPE_DATABASE_SET_NUM:
#if HAVE_FEATURE_DBCONNECTIVITY
        {
            SwDBData aData;
            aData.sDataSource = m_pImpl->m_pProps->sPar1;
@@ -1676,8 +1689,10 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
                nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
            pFld->SetSubType(nSubType);
        }
#endif
        break;
        case SW_SERVICE_FIELDTYPE_DATABASE:
#if HAVE_FEATURE_DBCONNECTIVITY
        {
            SwFieldType* pFldType =
                pDoc->GetFldType(RES_DBFLD, m_pImpl->m_sTypeName, false);
@@ -1693,6 +1708,7 @@ throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception)
                nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
            pFld->SetSubType(nSubType);
        }
#endif
        break;
        case SW_SERVICE_FIELDTYPE_SET_EXP:
        {
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index 95b4b3b..a5ecce5 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -17,6 +17,8 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>

#include <sal/types.h>
#include <tools/solar.h>
#include <comphelper/processfactory.hxx>
@@ -2383,6 +2385,10 @@ eF_ResT SwWW8ImplReader::Read_F_IncludeText( WW8FieldDesc* /*pF*/, OUString& rSt
// "SERIENDRUCKFELD"
eF_ResT SwWW8ImplReader::Read_F_DBField( WW8FieldDesc* pF, OUString& rStr )
{
#if !HAVE_FEATURE_DBCONNECTIVITY
    (void) pF;
    (void) rStr;
#else
    OUString aName;
    WW8ReadFieldParams aReadParam( rStr );
    for (;;)
@@ -2411,29 +2417,33 @@ eF_ResT SwWW8ImplReader::Read_F_DBField( WW8FieldDesc* pF, OUString& rStr )
    aFld.InitContent(aResult);

    rDoc.InsertPoolItem(*pPaM, SwFmtFld( aFld ), 0);

#endif
    return FLD_OK;
}

// "N"ACHSTER"
eF_ResT SwWW8ImplReader::Read_F_DBNext( WW8FieldDesc*, OUString& )
{
#if HAVE_FEATURE_DBCONNECTIVITY
    SwDBNextSetFieldType aN;
    SwFieldType* pFT = rDoc.InsertFldType( aN );
    SwDBNextSetField aFld( (SwDBNextSetFieldType*)pFT, OUString(), OUString(),
                            SwDBData() );       // Datenbank: Nichts
    rDoc.InsertPoolItem( *pPaM, SwFmtFld( aFld ), 0 );
#endif
    return FLD_OK;
}

// "DATENSATZ"
eF_ResT SwWW8ImplReader::Read_F_DBNum( WW8FieldDesc*, OUString& )
{
#if HAVE_FEATURE_DBCONNECTIVITY
    SwDBSetNumberFieldType aN;
    SwFieldType* pFT = rDoc.InsertFldType( aN );
    SwDBSetNumberField aFld( (SwDBSetNumberFieldType*)pFT,
                           SwDBData() );            // Datenbank: Nichts
    rDoc.InsertPoolItem( *pPaM, SwFmtFld( aFld ), 0 );
#endif
    return FLD_OK;
}