tdf#156174 sc DBData: fix regression of database ranges

Regression from commit 0c0444c44107f1a18f23dd0833d462d8dbf56569
"tdf#126926 sc DBData: delete the database range".

Change-Id: If6cccc41af42a44cadbb8485bfa5b9a8eca5a757
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154582
Tested-by: Jenkins
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit 94ca402cd1fe2fd9776d08448f7216b7f638e69a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155041
diff --git a/sc/qa/unit/uicalc/uicalc2.cxx b/sc/qa/unit/uicalc/uicalc2.cxx
index 3be123d..1ec77ad 100644
--- a/sc/qa/unit/uicalc/uicalc2.cxx
+++ b/sc/qa/unit/uicalc/uicalc2.cxx
@@ -1419,6 +1419,32 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testTdf152577)
    CPPUNIT_ASSERT(!pDBs->empty());
}

CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testTdf156174)
{
    createScDoc();
    ScDocument* pDoc = getScDoc();

    insertNewSheet(*pDoc);

    insertStringToCell("A1", u"1");
    insertStringToCell("A2", u"2");
    insertStringToCell("B1", u"3");
    insertStringToCell("B2", u"4");

    ScDBData* pDBData = new ScDBData("testDB", 1, 0, 0, 1, 1);
    bool bInserted
        = pDoc->GetDBCollection()->getNamedDBs().insert(std::unique_ptr<ScDBData>(pDBData));
    CPPUNIT_ASSERT(bInserted);

    insertNewSheet(*pDoc);
    uno::Sequence<beans::PropertyValue> aArgs(
        comphelper::InitPropertySequence({ { "Index", uno::Any(sal_uInt16(3)) } }));
    dispatchCommand(mxComponent, ".uno:Remove", aArgs);

    ScDBCollection* pDBs = pDoc->GetDBCollection();
    CPPUNIT_ASSERT(!pDBs->empty());
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/tool/refupdat.cxx b/sc/source/core/tool/refupdat.cxx
index ef0902a..e05a14d0 100644
--- a/sc/source/core/tool/refupdat.cxx
+++ b/sc/source/core/tool/refupdat.cxx
@@ -286,12 +286,7 @@ ScRefUpdateRes ScRefUpdate::Update( const ScDocument* pDoc, UpdateRefMode eUpdat
            bool bExp = (bExpand && IsExpand( theTab1, theTab2, nTab1, nDz ));
            bCut1 = lcl_MoveStart( theTab1, nTab1, nDz, nMaxTab );
            bCut2 = lcl_MoveEnd( theTab2, nTab1, nDz, nMaxTab );
            if ( theTab2 < theTab1 )
            {
                eRet = UR_INVALID;
                theTab2 = theTab1;
            }
            else if ( bCut1 || bCut2 )
            if ( bCut1 || bCut2 )
                eRet = UR_UPDATED;
            if ( bExp )
            {