diff options
Diffstat (limited to 'connectivity/source/drivers/dbase')
-rw-r--r-- | connectivity/source/drivers/dbase/DCatalog.cxx | 3 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DColumns.cxx | 12 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DConnection.cxx | 19 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DDatabaseMetaData.cxx | 258 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DDriver.cxx | 37 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DIndex.cxx | 37 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DIndexColumns.cxx | 10 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DIndexIter.cxx | 5 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DIndexes.cxx | 51 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DPreparedStatement.cxx | 8 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DResultSet.cxx | 15 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DStatement.cxx | 5 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DTable.cxx | 289 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/DTables.cxx | 23 | ||||
-rw-r--r-- | connectivity/source/drivers/dbase/dindexnode.cxx | 56 |
15 files changed, 386 insertions, 442 deletions
diff --git a/connectivity/source/drivers/dbase/DCatalog.cxx b/connectivity/source/drivers/dbase/DCatalog.cxx index a8aaf89c529a..6af3440b6071 100644 --- a/connectivity/source/drivers/dbase/DCatalog.cxx +++ b/connectivity/source/drivers/dbase/DCatalog.cxx @@ -24,7 +24,6 @@ #include <com/sun/star/sdbc/XResultSet.hpp> using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; @@ -40,7 +39,7 @@ void ODbaseCatalog::refreshTables() { ::std::vector<OUString> aVector; Sequence<OUString> aTypes; - Reference<XResultSet> xResult = m_xMetaData->getTables(Any(), "%", "%", aTypes); + Reference<XResultSet> xResult = m_xMetaData->getTables(Any(), u"%"_ustr, u"%"_ustr, aTypes); if (xResult.is()) { diff --git a/connectivity/source/drivers/dbase/DColumns.cxx b/connectivity/source/drivers/dbase/DColumns.cxx index b997ec8d9087..4025fcc5a800 100644 --- a/connectivity/source/drivers/dbase/DColumns.cxx +++ b/connectivity/source/drivers/dbase/DColumns.cxx @@ -25,21 +25,17 @@ using namespace connectivity::dbase; using namespace connectivity; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -sdbcx::ObjectType ODbaseColumns::createObject(const OUString& _rName) +css::uno::Reference< css::beans::XPropertySet > ODbaseColumns::createObject(const OUString& _rName) { ODbaseTable* pTable = static_cast<ODbaseTable*>(m_pTable); const ::rtl::Reference<OSQLColumns>& aCols = pTable->getTableColumns(); OSQLColumns::const_iterator aIter = find(aCols->begin(),aCols->end(),_rName,::comphelper::UStringMixEqual(isCaseSensitive())); - sdbcx::ObjectType xRet; + css::uno::Reference< css::beans::XPropertySet > xRet; if(aIter != aCols->end()) - xRet = sdbcx::ObjectType(*aIter,UNO_QUERY); + xRet = *aIter; return xRet; } @@ -56,7 +52,7 @@ Reference< XPropertySet > ODbaseColumns::createDescriptor() // XAppend -sdbcx::ObjectType ODbaseColumns::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) +css::uno::Reference< css::beans::XPropertySet > ODbaseColumns::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) { if ( m_pTable->isNew() ) return cloneDescriptor( descriptor ); diff --git a/connectivity/source/drivers/dbase/DConnection.cxx b/connectivity/source/drivers/dbase/DConnection.cxx index 7c577b7c9541..ab97a3aeeaa0 100644 --- a/connectivity/source/drivers/dbase/DConnection.cxx +++ b/connectivity/source/drivers/dbase/DConnection.cxx @@ -33,10 +33,8 @@ typedef connectivity::file::OConnection OConnection_BASE; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::lang; ODbaseConnection::ODbaseConnection(ODriver* _pDriver) : OConnection(_pDriver) { @@ -49,7 +47,7 @@ ODbaseConnection::~ODbaseConnection() // XServiceInfo -IMPLEMENT_SERVICE_INFO(ODbaseConnection, "com.sun.star.sdbc.drivers.dbase.Connection", "com.sun.star.sdbc.Connection") +IMPLEMENT_SERVICE_INFO(ODbaseConnection, u"com.sun.star.sdbc.drivers.dbase.Connection"_ustr, u"com.sun.star.sdbc.Connection"_ustr) Reference< XDatabaseMetaData > SAL_CALL ODbaseConnection::getMetaData( ) @@ -71,12 +69,11 @@ Reference< XDatabaseMetaData > SAL_CALL ODbaseConnection::getMetaData( ) css::uno::Reference< XTablesSupplier > ODbaseConnection::createCatalog() { ::osl::MutexGuard aGuard( m_aMutex ); - Reference< XTablesSupplier > xTab = m_xCatalog; + rtl::Reference< connectivity::sdbcx::OCatalog > xTab = m_xCatalog; if(!xTab.is()) { - ODbaseCatalog *pCat = new ODbaseCatalog(this); - xTab = pCat; - m_xCatalog = xTab; + xTab = new ODbaseCatalog(this); + m_xCatalog = xTab.get(); } return xTab; } @@ -97,9 +94,7 @@ Reference< XPreparedStatement > SAL_CALL ODbaseConnection::prepareStatement( con ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OConnection_BASE::rBHelper.bDisposed); - - ODbasePreparedStatement* pStmt = new ODbasePreparedStatement(this); - Reference< XPreparedStatement > xHoldAlive = pStmt; + rtl::Reference<ODbasePreparedStatement> pStmt = new ODbasePreparedStatement(this); pStmt->construct(sql); m_aStatements.push_back(WeakReferenceHelper(*pStmt)); return pStmt; @@ -107,9 +102,7 @@ Reference< XPreparedStatement > SAL_CALL ODbaseConnection::prepareStatement( con Reference< XPreparedStatement > SAL_CALL ODbaseConnection::prepareCall( const OUString& /*sql*/ ) { - ::dbtools::throwFeatureNotImplementedSQLException( "XConnection::prepareCall", *this ); - return nullptr; + ::dbtools::throwFeatureNotImplementedSQLException( u"XConnection::prepareCall"_ustr, *this ); } - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx index b896e942cb01..7e17e1fc0d79 100644 --- a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx +++ b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx @@ -54,101 +54,96 @@ ODbaseDatabaseMetaData::~ODbaseDatabaseMetaData() Reference< XResultSet > ODbaseDatabaseMetaData::impl_getTypeInfo_throw( ) { - ::osl::MutexGuard aGuard( m_aMutex ); - - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); - Reference< XResultSet > xRef = pResult; + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); - static ODatabaseMetaDataResultSet::ORows aRows; - if(aRows.empty()) + ODatabaseMetaDataResultSet::ORows aRows; + aRows.reserve(10); + ODatabaseMetaDataResultSet::ORow aRow { - ODatabaseMetaDataResultSet::ORow aRow; - aRow.reserve(19); - - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(OUString("VARCHAR"))); - aRow.push_back(new ORowSetValueDecorator(DataType::VARCHAR)); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(254))); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(new ORowSetValueDecorator(OUString("length"))); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(ColumnValue::NULLABLE))); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(ColumnSearch::FULL))); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(new ORowSetValueDecorator(OUString("C"))); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(10))); - - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("LONGVARCHAR")); - aRow[2] = new ORowSetValueDecorator(DataType::LONGVARCHAR); - aRow[3] = new ORowSetValueDecorator(sal_Int32(2147483647)); - aRow[6] = new ORowSetValueDecorator(); - aRow[13] = new ORowSetValueDecorator(OUString("M")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("DATE")); - aRow[2] = new ORowSetValueDecorator(DataType::DATE); - aRow[3] = new ORowSetValueDecorator(sal_Int32(10)); - aRow[13] = new ORowSetValueDecorator(OUString("D")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("BOOLEAN")); - aRow[2] = new ORowSetValueDecorator(DataType::BIT); - aRow[3] = ODatabaseMetaDataResultSet::get1Value(); - aRow[4] = ODatabaseMetaDataResultSet::getEmptyValue(); - aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue(); - aRow[6] = new ORowSetValueDecorator(OUString()); - aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); - aRow[13] = new ORowSetValueDecorator(OUString("L")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("DOUBLE")); - aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE); - aRow[3] = new ORowSetValueDecorator(sal_Int32(8)); - aRow[13] = new ORowSetValueDecorator(OUString("B")); - aRows.push_back(aRow); - - aRow[11] = new ORowSetValueDecorator(true); - aRow[13] = new ORowSetValueDecorator(OUString("Y")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP")); - aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP); - aRow[11] = new ORowSetValueDecorator(false); - aRow[13] = new ORowSetValueDecorator(OUString("T")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("INTEGER")); - aRow[2] = new ORowSetValueDecorator(DataType::INTEGER); - aRow[3] = new ORowSetValueDecorator(sal_Int32(10)); - aRow[13] = new ORowSetValueDecorator(OUString("I")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL")); - aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); - aRow[3] = new ORowSetValueDecorator(sal_Int32(20)); - aRow[6] = new ORowSetValueDecorator(OUString("length,scale")); - aRow[13] = new ORowSetValueDecorator(OUString("F")); - aRows.push_back(aRow); - - aRow[1] = new ORowSetValueDecorator(OUString("NUMERIC")); - aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); - aRow[3] = new ORowSetValueDecorator(sal_Int32(16)); - aRow[13] = new ORowSetValueDecorator(OUString("N")); - aRow[15] = new ORowSetValueDecorator(sal_Int32(16)); - aRows.push_back(aRow); - } - - pResult->setRows(aRows); - return xRef; + ODatabaseMetaDataResultSet::getEmptyValue(), + new ORowSetValueDecorator(u"VARCHAR"_ustr), + new ORowSetValueDecorator(DataType::VARCHAR), + new ORowSetValueDecorator(sal_Int32(254)), + ODatabaseMetaDataResultSet::getQuoteValue(), + ODatabaseMetaDataResultSet::getQuoteValue(), + new ORowSetValueDecorator(u"length"_ustr), + new ORowSetValueDecorator(sal_Int32(ColumnValue::NULLABLE)), + ODatabaseMetaDataResultSet::get1Value(), + new ORowSetValueDecorator(sal_Int32(ColumnSearch::FULL)), + ODatabaseMetaDataResultSet::get1Value(), + ODatabaseMetaDataResultSet::get0Value(), + ODatabaseMetaDataResultSet::get0Value(), + new ORowSetValueDecorator(u"C"_ustr), + ODatabaseMetaDataResultSet::get0Value(), + ODatabaseMetaDataResultSet::get0Value(), + ODatabaseMetaDataResultSet::getEmptyValue(), + ODatabaseMetaDataResultSet::getEmptyValue(), + new ORowSetValueDecorator(sal_Int32(10)) + }; + + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(u"LONGVARCHAR"_ustr); + aRow[2] = new ORowSetValueDecorator(DataType::LONGVARCHAR); + aRow[3] = new ORowSetValueDecorator(sal_Int32(2147483647)); + aRow[6] = new ORowSetValueDecorator(); + aRow[13] = new ORowSetValueDecorator(u"M"_ustr); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(u"DATE"_ustr); + aRow[2] = new ORowSetValueDecorator(DataType::DATE); + aRow[3] = new ORowSetValueDecorator(sal_Int32(10)); + aRow[13] = new ORowSetValueDecorator(u"D"_ustr); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(u"BOOLEAN"_ustr); + aRow[2] = new ORowSetValueDecorator(DataType::BIT); + aRow[3] = ODatabaseMetaDataResultSet::get1Value(); + aRow[4] = ODatabaseMetaDataResultSet::getEmptyValue(); + aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue(); + aRow[6] = new ORowSetValueDecorator(OUString()); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRow[13] = new ORowSetValueDecorator(u"L"_ustr); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(u"DOUBLE"_ustr); + aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE); + aRow[3] = new ORowSetValueDecorator(sal_Int32(8)); + aRow[13] = new ORowSetValueDecorator(u"B"_ustr); + aRows.push_back(aRow); + + aRow[11] = new ORowSetValueDecorator(ORowSetValue(true)); + aRow[13] = new ORowSetValueDecorator(u"Y"_ustr); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(u"TIMESTAMP"_ustr); + aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP); + aRow[11] = new ORowSetValueDecorator(ORowSetValue(false)); + aRow[13] = new ORowSetValueDecorator(u"T"_ustr); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(u"INTEGER"_ustr); + aRow[2] = new ORowSetValueDecorator(DataType::INTEGER); + aRow[3] = new ORowSetValueDecorator(sal_Int32(10)); + aRow[13] = new ORowSetValueDecorator(u"I"_ustr); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(u"DECIMAL"_ustr); + aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); + aRow[3] = new ORowSetValueDecorator(sal_Int32(20)); + aRow[6] = new ORowSetValueDecorator(u"length,scale"_ustr); + aRow[13] = new ORowSetValueDecorator(u"F"_ustr); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(u"NUMERIC"_ustr); + aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); + aRow[3] = new ORowSetValueDecorator(sal_Int32(16)); + aRow[13] = new ORowSetValueDecorator(u"N"_ustr); + aRow[15] = new ORowSetValueDecorator(sal_Int32(16)); + aRows.push_back(aRow); + + pResult->setRows(std::move(aRows)); + return pResult; } Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( @@ -171,35 +166,28 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( try { aRow[10] = new ORowSetValueDecorator(sal_Int32(10)); - Sequence< OUString> aTabNames(xNames->getElementNames()); - const OUString* pTabBegin = aTabNames.getConstArray(); - const OUString* pTabEnd = pTabBegin + aTabNames.getLength(); - for(;pTabBegin != pTabEnd;++pTabBegin) + for (auto& tabName : xNames->getElementNames()) { - if(match(tableNamePattern,*pTabBegin,'\0')) + if (match(tableNamePattern, tabName, '\0')) { - Reference< XColumnsSupplier> xTable( - xNames->getByName(*pTabBegin), css::uno::UNO_QUERY); + Reference<XColumnsSupplier> xTable(xNames->getByName(tabName), css::uno::UNO_QUERY); OSL_ENSURE(xTable.is(),"Table not found! Normally an exception had to be thrown here!"); - aRow[3] = new ORowSetValueDecorator(*pTabBegin); + aRow[3] = new ORowSetValueDecorator(tabName); Reference< XNameAccess> xColumns = xTable->getColumns(); if(!xColumns.is()) throw SQLException(); - Sequence< OUString> aColNames(xColumns->getElementNames()); - - const OUString* pBegin = aColNames.getConstArray(); - const OUString* pEnd = pBegin + aColNames.getLength(); Reference< XPropertySet> xColumn; - for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i) + sal_Int32 i = 0; + for (auto& colName : xColumns->getElementNames()) { - if(match(columnNamePattern,*pBegin,'\0')) + ++i; + if (match(columnNamePattern, colName, '\0')) { - aRow[4] = new ORowSetValueDecorator(*pBegin); + aRow[4] = new ORowSetValueDecorator(colName); - xColumn.set( - xColumns->getByName(*pBegin), css::uno::UNO_QUERY); + xColumn.set(xColumns->getByName(colName), css::uno::UNO_QUERY); OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!"); aRow[5] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))); aRow[6] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))); @@ -207,7 +195,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( aRow[9] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))); aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))); aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))); - switch(static_cast<sal_Int32>(aRow[5]->getValue())) + switch(aRow[5]->getValue().getInt32()) { case DataType::CHAR: case DataType::VARCHAR: @@ -220,13 +208,13 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( aRow[16] = new ORowSetValueDecorator(sal_Int32(0)); } aRow[17] = new ORowSetValueDecorator(i); - switch(sal_Int32(aRow[11]->getValue())) + switch(aRow[11]->getValue().getInt32()) { case ColumnValue::NO_NULLS: - aRow[18] = new ORowSetValueDecorator(OUString("NO")); + aRow[18] = new ORowSetValueDecorator(u"NO"_ustr); break; case ColumnValue::NULLABLE: - aRow[18] = new ORowSetValueDecorator(OUString("YES")); + aRow[18] = new ORowSetValueDecorator(u"YES"_ustr); break; default: aRow[18] = new ORowSetValueDecorator(OUString()); @@ -244,11 +232,10 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( throw aSql; throw WrappedTargetRuntimeException(e.Message, e.Context, e.TargetException); } - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); - Reference< XResultSet > xRef = pResult; - pResult->setRows(aRows); + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); + pResult->setRows(std::move(aRows)); - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo( @@ -269,7 +256,7 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo( ODatabaseMetaDataResultSet::ORow aRow(14); aRow[5] = new ORowSetValueDecorator(OUString()); - aRow[10] = new ORowSetValueDecorator(OUString("A")); + aRow[10] = new ORowSetValueDecorator(u"A"_ustr); Reference< XIndexesSupplier> xTable( xNames->getByName(table), css::uno::UNO_QUERY); @@ -280,22 +267,18 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo( if(!xIndexes.is()) throw SQLException(); - Sequence< OUString> aIdxNames(xIndexes->getElementNames()); - - const OUString* pBegin = aIdxNames.getConstArray(); - const OUString* pEnd = pBegin + aIdxNames.getLength(); Reference< XPropertySet> xIndex; - for(;pBegin != pEnd;++pBegin) + for (auto& idxName : xIndexes->getElementNames()) { - xIndex.set(xIndexes->getByName(*pBegin), css::uno::UNO_QUERY); + xIndex.set(xIndexes->getByName(idxName), css::uno::UNO_QUERY); OSL_ENSURE(xIndex.is(),"Indexes contains a column who isn't a fastpropertyset!"); if(unique && !getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE)))) continue; - aRow[4] = new ORowSetValueDecorator(getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE)))); - aRow[6] = new ORowSetValueDecorator(*pBegin); + aRow[4] = new ORowSetValueDecorator(ORowSetValue(getBOOL(xIndex->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISUNIQUE))))); + aRow[6] = new ORowSetValueDecorator(idxName); - auto pIndex = comphelper::getUnoTunnelImplementation<ODbaseIndex>(xIndex); + auto pIndex = dynamic_cast<ODbaseIndex*>(xIndex.get()); if(pIndex) { aRow[11] = new ORowSetValueDecorator(static_cast<sal_Int32>(pIndex->getHeader().db_maxkeys)); @@ -304,22 +287,19 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getIndexInfo( Reference<XColumnsSupplier> xColumnsSup(xIndex,UNO_QUERY); Reference< XNameAccess> xColumns = xColumnsSup->getColumns(); - Sequence< OUString> aColNames(xColumns->getElementNames()); - const OUString* pColBegin = aColNames.getConstArray(); - const OUString* pColEnd = pColBegin + aColNames.getLength(); - for(sal_Int32 j=1;pColBegin != pColEnd;++pColBegin,++j) + sal_Int32 j = 0; + for (auto& colName : xColumns->getElementNames()) { - aRow[8] = new ORowSetValueDecorator(j); - aRow[9] = new ORowSetValueDecorator(*pColBegin); + aRow[8] = new ORowSetValueDecorator(++j); + aRow[9] = new ORowSetValueDecorator(colName); aRows.push_back(aRow); } } - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eIndexInfo); - Reference< XResultSet > xRef = pResult; - pResult->setRows(aRows); - return xRef; + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eIndexInfo); + pResult->setRows(std::move(aRows)); + return pResult; } OUString SAL_CALL ODbaseDatabaseMetaData::getURL( ) @@ -369,7 +349,7 @@ sal_Bool SAL_CALL ODbaseDatabaseMetaData::isReadOnly( ) bool bReadOnly = false; ::ucbhelper::Content aFile(m_pConnection->getContent(),Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext()); - aFile.getPropertyValue("IsReadOnly") >>= bReadOnly; + aFile.getPropertyValue(u"IsReadOnly"_ustr) >>= bReadOnly; return bReadOnly; } diff --git a/connectivity/source/drivers/dbase/DDriver.cxx b/connectivity/source/drivers/dbase/DDriver.cxx index 5d9d56dcd5cf..36d44951f0f2 100644 --- a/connectivity/source/drivers/dbase/DDriver.cxx +++ b/connectivity/source/drivers/dbase/DDriver.cxx @@ -36,7 +36,7 @@ using namespace ::com::sun::star::lang; OUString SAL_CALL ODriver::getImplementationName( ) { - return "com.sun.star.comp.sdbc.dbase.ODriver"; + return u"com.sun.star.comp.sdbc.dbase.ODriver"_ustr; } @@ -51,7 +51,7 @@ connectivity_dbase_ODriver( } if (ret) ret->acquire(); - return static_cast<cppu::OWeakObject*>(ret.get()); + return getXWeak(ret.get()); } @@ -64,12 +64,11 @@ Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const S if ( ! acceptsURL(url) ) return nullptr; - ODbaseConnection* pCon = new ODbaseConnection(this); + rtl::Reference<ODbaseConnection> pCon = new ODbaseConnection(this); pCon->construct(url,info); - Reference< XConnection > xCon = pCon; - m_xConnections.push_back(WeakReferenceHelper(*pCon)); + m_xConnections.push_back(pCon.get()); - return xCon; + return pCon; } sal_Bool SAL_CALL ODriver::acceptsURL( const OUString& url ) @@ -81,41 +80,37 @@ Sequence< DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo( const OUString { if ( acceptsURL(url) ) { - Sequence< OUString > aBoolean(2); - aBoolean[0] = "0"; - aBoolean[1] = "1"; + Sequence< OUString > aBoolean { u"0"_ustr, u"1"_ustr }; - DriverPropertyInfo aDriverInfo[] = { + return + { { - "CharSet" - ,"CharSet of the database." + u"CharSet"_ustr + ,u"CharSet of the database."_ustr ,false ,OUString() ,Sequence< OUString >() }, { - "ShowDeleted" - ,"Display inactive records." + u"ShowDeleted"_ustr + ,u"Display inactive records."_ustr ,false - ,"0" + ,u"0"_ustr ,aBoolean }, { - "EnableSQL92Check" - ,"Use SQL92 naming constraints." + u"EnableSQL92Check"_ustr + ,u"Use SQL92 naming constraints."_ustr ,false - ,"0" + ,u"0"_ustr ,aBoolean } }; - - return Sequence< DriverPropertyInfo >(aDriverInfo, std::size(aDriverInfo)); } SharedResources aResources; const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); ::dbtools::throwGenericSQLException(sMessage ,*this); - return Sequence< DriverPropertyInfo >(); } diff --git a/connectivity/source/drivers/dbase/DIndex.cxx b/connectivity/source/drivers/dbase/DIndex.cxx index d168de39eb77..1c32440e6b89 100644 --- a/connectivity/source/drivers/dbase/DIndex.cxx +++ b/connectivity/source/drivers/dbase/DIndex.cxx @@ -30,7 +30,6 @@ #include <unotools/ucbhelper.hxx> #include <comphelper/servicehelper.hxx> #include <comphelper/types.hxx> -#include <cppuhelper/typeprovider.hxx> #include <connectivity/dbexception.hxx> #include <dbase/DResultSet.hxx> #include <strings.hrc> @@ -42,15 +41,12 @@ using namespace connectivity; using namespace utl; using namespace ::cppu; using namespace connectivity::file; -using namespace connectivity::sdbcx; using namespace connectivity::dbase; using namespace com::sun::star::sdbc; -using namespace com::sun::star::sdbcx; using namespace com::sun::star::uno; using namespace com::sun::star::beans; -using namespace com::sun::star::lang; -IMPLEMENT_SERVICE_INFO(ODbaseIndex,"com.sun.star.sdbcx.driver.dbase.Index","com.sun.star.sdbcx.Index"); +IMPLEMENT_SERVICE_INFO(ODbaseIndex,u"com.sun.star.sdbcx.driver.dbase.Index"_ustr,u"com.sun.star.sdbcx.Index"_ustr); ODbaseIndex::ODbaseIndex(ODbaseTable* _pTable) : OIndex(true/*_pTable->getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers()*/) @@ -100,22 +96,6 @@ void ODbaseIndex::refreshColumns() m_pColumns.reset(new ODbaseIndexColumns(this,m_aMutex,aVector)); } -Sequence< sal_Int8 > ODbaseIndex::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// XUnoTunnel - -sal_Int64 ODbaseIndex::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return (isUnoTunnelId<ODbaseIndex>(rId)) - ? reinterpret_cast< sal_Int64 >( this ) - : ODbaseIndex_BASE::getSomething(rId); -} - ONDXPagePtr const & ODbaseIndex::getRoot() { openIndexFile(); @@ -357,7 +337,7 @@ SvStream& connectivity::dbase::operator >> (SvStream &rStream, ODbaseIndex& rInd return rStream; } -SvStream& connectivity::dbase::WriteODbaseIndex(SvStream &rStream, ODbaseIndex& rIndex) +SvStream& connectivity::dbase::WriteODbaseIndex(SvStream &rStream, const ODbaseIndex& rIndex) { rStream.Seek(0); rStream.WriteUInt32(rIndex.m_aHeader.db_rootpage); @@ -404,8 +384,7 @@ void ODbaseIndex::createINFEntry() bool bCase = isCaseSensitive(); while (aNewEntry.isEmpty()) { - aNewEntry = OString("NDX"); - aNewEntry += OString::number(++nSuffix); + aNewEntry = "NDX" + OString::number(++nSuffix); for (sal_uInt16 i = 0; i < aInfFile.GetKeyCount(); i++) { aKeyName = aInfFile.GetKeyName(i); @@ -461,7 +440,7 @@ void ODbaseIndex::DropImpl() } } -void ODbaseIndex::impl_killFileAndthrowError_throw(const char* pErrorId, const OUString& _sFile) +void ODbaseIndex::impl_killFileAndthrowError_throw(TranslateId pErrorId, const OUString& _sFile) { closeImpl(); if(UCBContentHelper::Exists(_sFile)) @@ -568,15 +547,13 @@ void ODbaseIndex::CreateImpl() if(xSet->last()) { - Reference< XUnoTunnel> xTunnel(xSet, UNO_QUERY_THROW); - ODbaseResultSet* pDbaseRes = reinterpret_cast< ODbaseResultSet* >( xTunnel->getSomething(ODbaseResultSet::getUnoTunnelId()) ); + ODbaseResultSet* pDbaseRes = dynamic_cast<ODbaseResultSet*>(xSet.getTyped().get()); assert(pDbaseRes); //"No dbase resultset found? What's going on here! nRowsLeft = xSet->getRow(); xSet->beforeFirst(); - ORowSetValue atmpValue; - ONDXKey aKey(atmpValue, nType, 0); - ONDXKey aInsertKey(atmpValue, nType, 0); + ONDXKey aKey(ORowSetValue(), nType, 0); + ONDXKey aInsertKey(ORowSetValue(), nType, 0); // Create the index structure while (xSet->next()) { diff --git a/connectivity/source/drivers/dbase/DIndexColumns.cxx b/connectivity/source/drivers/dbase/DIndexColumns.cxx index 886c7273db31..dbf8f59a43c9 100644 --- a/connectivity/source/drivers/dbase/DIndexColumns.cxx +++ b/connectivity/source/drivers/dbase/DIndexColumns.cxx @@ -28,12 +28,10 @@ using namespace connectivity::dbase; using namespace connectivity; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -sdbcx::ObjectType ODbaseIndexColumns::createObject(const OUString& _rName) +css::uno::Reference< css::beans::XPropertySet > ODbaseIndexColumns::createObject(const OUString& _rName) { const ODbaseTable* pTable = m_pIndex->getTable(); @@ -45,9 +43,9 @@ sdbcx::ObjectType ODbaseIndexColumns::createObject(const OUString& _rName) xCol = *aIter; if(!xCol.is()) - return sdbcx::ObjectType(); + return css::uno::Reference< css::beans::XPropertySet >(); - sdbcx::ObjectType xRet = new sdbcx::OIndexColumn(true,_rName + css::uno::Reference< css::beans::XPropertySet > xRet = new sdbcx::OIndexColumn(true,_rName ,getString(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))) ,OUString() ,getINT32(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))) @@ -73,7 +71,7 @@ Reference< XPropertySet > ODbaseIndexColumns::createDescriptor() return new sdbcx::OIndexColumn(m_pIndex->getTable()->getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers()); } -sdbcx::ObjectType ODbaseIndexColumns::appendObject( const OUString& /*_rForName*/, const Reference< XPropertySet >& descriptor ) +css::uno::Reference< css::beans::XPropertySet > ODbaseIndexColumns::appendObject( const OUString& /*_rForName*/, const Reference< XPropertySet >& descriptor ) { return cloneDescriptor( descriptor ); } diff --git a/connectivity/source/drivers/dbase/DIndexIter.cxx b/connectivity/source/drivers/dbase/DIndexIter.cxx index 37e28a073f4c..35f5862b1bc2 100644 --- a/connectivity/source/drivers/dbase/DIndexIter.cxx +++ b/connectivity/source/drivers/dbase/DIndexIter.cxx @@ -109,7 +109,7 @@ ONDXKey* OIndexIterator::GetFirstKey(ONDXPage* pPage, const OOperand& rKey) pFoundKey = nullptr; m_aCurLeaf = pPage; - m_nCurNode = pFoundKey ? i : i - 1; + m_nCurNode = pFoundKey ? i : sal_uInt16(i - 1); } return pFoundKey; } @@ -262,7 +262,8 @@ ONDXKey* OIndexIterator::GetNextKey() sal_uInt16 nPos = pParentPage->Search(pPage); if (nPos != pParentPage->Count() - 1) { // page found - pPage = (*pParentPage)[nPos + 1].GetChild(m_xIndex.get(), pParentPage); + pPage = (*pParentPage)[o3tl::sanitizing_inc(nPos)].GetChild(m_xIndex.get(), + pParentPage); break; } } diff --git a/connectivity/source/drivers/dbase/DIndexes.cxx b/connectivity/source/drivers/dbase/DIndexes.cxx index 1ebce2612098..1ade0679216c 100644 --- a/connectivity/source/drivers/dbase/DIndexes.cxx +++ b/connectivity/source/drivers/dbase/DIndexes.cxx @@ -24,20 +24,14 @@ #include <unotools/ucbhelper.hxx> #include <strings.hrc> -using namespace ::comphelper; - using namespace utl; using namespace ::connectivity; using namespace ::dbtools; using namespace ::connectivity::dbase; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; -sdbcx::ObjectType ODbaseIndexes::createObject(const OUString& _rName) +css::uno::Reference< css::beans::XPropertySet > ODbaseIndexes::createObject(const OUString& _rName) { OUString sFile = m_pTable->getConnection()->getURL() + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELIMITER) + @@ -51,23 +45,8 @@ sdbcx::ObjectType ODbaseIndexes::createObject(const OUString& _rName) ::dbtools::throwGenericSQLException( sError, *m_pTable ); } - sdbcx::ObjectType xRet; std::unique_ptr<SvStream> pFileStream = ::connectivity::file::OFileTable::createStream_simpleError(sFile, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE); - if(pFileStream) - { - pFileStream->SetEndian(SvStreamEndian::LITTLE); - pFileStream->SetBufferSize(DINDEX_PAGE_SIZE); - ODbaseIndex::NDXHeader aHeader; - - pFileStream->Seek(0); - ReadHeader(*pFileStream, aHeader); - pFileStream.reset(); - - ODbaseIndex* pIndex = new ODbaseIndex(m_pTable,aHeader,_rName); - xRet = pIndex; - pIndex->openIndexFile(); - } - else + if(!pFileStream) { const OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution( STR_COULD_NOT_LOAD_FILE, @@ -75,7 +54,18 @@ sdbcx::ObjectType ODbaseIndexes::createObject(const OUString& _rName) ) ); ::dbtools::throwGenericSQLException( sError, *m_pTable ); } - return xRet; + + pFileStream->SetEndian(SvStreamEndian::LITTLE); + pFileStream->SetBufferSize(DINDEX_PAGE_SIZE); + ODbaseIndex::NDXHeader aHeader; + + pFileStream->Seek(0); + ReadHeader(*pFileStream, aHeader); + pFileStream.reset(); + + rtl::Reference<ODbaseIndex> pIndex = new ODbaseIndex(m_pTable,aHeader,_rName); + pIndex->openIndexFile(); + return pIndex; } void ODbaseIndexes::impl_refresh( ) @@ -90,16 +80,11 @@ Reference< XPropertySet > ODbaseIndexes::createDescriptor() } // XAppend -sdbcx::ObjectType ODbaseIndexes::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) +css::uno::Reference< css::beans::XPropertySet > ODbaseIndexes::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) { - Reference<XUnoTunnel> xTunnel(descriptor,UNO_QUERY); - if(xTunnel.is()) - { - ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) ); - if(!pIndex) - throw SQLException(); + ODbaseIndex* pIndex = dynamic_cast<ODbaseIndex*>(descriptor.get()); + if(pIndex) pIndex->CreateImpl(); - } return createObject( _rForName ); } @@ -107,7 +92,7 @@ sdbcx::ObjectType ODbaseIndexes::appendObject( const OUString& _rForName, const // XDrop void ODbaseIndexes::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/) { - auto pIndex = comphelper::getUnoTunnelImplementation<ODbaseIndex>(getObject(_nPos)); + rtl::Reference<ODbaseIndex> pIndex = dynamic_cast<ODbaseIndex*>(getObject(_nPos).get()); if ( pIndex ) pIndex->DropImpl(); } diff --git a/connectivity/source/drivers/dbase/DPreparedStatement.cxx b/connectivity/source/drivers/dbase/DPreparedStatement.cxx index 852c98acf509..3dc39e68857a 100644 --- a/connectivity/source/drivers/dbase/DPreparedStatement.cxx +++ b/connectivity/source/drivers/dbase/DPreparedStatement.cxx @@ -22,14 +22,14 @@ using namespace connectivity::dbase; using namespace connectivity::file; -using namespace com::sun::star::uno; -OResultSet* ODbasePreparedStatement::createResultSet() +rtl::Reference<OResultSet> ODbasePreparedStatement::createResultSet() { return new ODbaseResultSet(this, m_aSQLIterator); } -IMPLEMENT_SERVICE_INFO(ODbasePreparedStatement, "com.sun.star.sdbc.driver.dbase.PreparedStatement", - "com.sun.star.sdbc.PreparedStatement"); +IMPLEMENT_SERVICE_INFO(ODbasePreparedStatement, + u"com.sun.star.sdbc.driver.dbase.PreparedStatement"_ustr, + u"com.sun.star.sdbc.PreparedStatement"_ustr); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/dbase/DResultSet.cxx b/connectivity/source/drivers/dbase/DResultSet.cxx index f9395a359465..99357a01fcc8 100644 --- a/connectivity/source/drivers/dbase/DResultSet.cxx +++ b/connectivity/source/drivers/dbase/DResultSet.cxx @@ -49,12 +49,12 @@ ODbaseResultSet::ODbaseResultSet( OStatement_Base* pStmt,connectivity::OSQLParse OUString SAL_CALL ODbaseResultSet::getImplementationName( ) { - return "com.sun.star.sdbcx.dbase.ResultSet"; + return u"com.sun.star.sdbcx.dbase.ResultSet"_ustr; } Sequence< OUString > SAL_CALL ODbaseResultSet::getSupportedServiceNames( ) { - return { "com.sun.star.sdbc.ResultSet", "com.sun.star.sdbcx.ResultSet" }; + return { u"com.sun.star.sdbc.ResultSet"_ustr, u"com.sun.star.sdbcx.ResultSet"_ustr }; } sal_Bool SAL_CALL ODbaseResultSet::supportsService( const OUString& _rServiceName ) @@ -81,7 +81,7 @@ Any SAL_CALL ODbaseResultSet::getBookmark( ) checkDisposed(OResultSet_BASE::rBHelper.bDisposed); OSL_ENSURE((m_bShowDeleted || !m_aRow->isDeleted()),"getBookmark called for deleted row"); - return makeAny(static_cast<sal_Int32>((*m_aRow)[0]->getValue())); + return Any((*m_aRow)[0]->getValue().getInt32()); } sal_Bool SAL_CALL ODbaseResultSet::moveToBookmark( const Any& bookmark ) @@ -149,13 +149,12 @@ Sequence< sal_Int32 > SAL_CALL ODbaseResultSet::deleteRows( const Sequence< An ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - ::dbtools::throwFeatureNotImplementedSQLException( "XDeleteRows::deleteRows", *this ); - return Sequence< sal_Int32 >(); + ::dbtools::throwFeatureNotImplementedSQLException( u"XDeleteRows::deleteRows"_ustr, *this ); } bool ODbaseResultSet::fillIndexValues(const Reference< XColumnsSupplier> &_xIndex) { - auto pIndex = comphelper::getUnoTunnelImplementation<dbase::ODbaseIndex>(_xIndex); + auto pIndex = dynamic_cast<dbase::ODbaseIndex*>(_xIndex.get()); if(pIndex) { std::unique_ptr<dbase::OIndexIterator> pIter = pIndex->createIterator(); @@ -187,12 +186,12 @@ bool ODbaseResultSet::fillIndexValues(const Reference< XColumnsSupplier> &_xInde return new ::cppu::OPropertyArrayHelper(aProps); } -void SAL_CALL ODbaseResultSet::acquire() throw() +void SAL_CALL ODbaseResultSet::acquire() noexcept { ODbaseResultSet_BASE2::acquire(); } -void SAL_CALL ODbaseResultSet::release() throw() +void SAL_CALL ODbaseResultSet::release() noexcept { ODbaseResultSet_BASE2::release(); } diff --git a/connectivity/source/drivers/dbase/DStatement.cxx b/connectivity/source/drivers/dbase/DStatement.cxx index 096878e3e245..c6245e852d31 100644 --- a/connectivity/source/drivers/dbase/DStatement.cxx +++ b/connectivity/source/drivers/dbase/DStatement.cxx @@ -22,14 +22,13 @@ using namespace connectivity::dbase; using namespace connectivity::file; -using namespace com::sun::star::uno; -OResultSet* ODbaseStatement::createResultSet() +rtl::Reference<OResultSet> ODbaseStatement::createResultSet() { return new ODbaseResultSet(this,m_aSQLIterator); } -IMPLEMENT_SERVICE_INFO(ODbaseStatement,"com.sun.star.sdbc.driver.dbase.Statement","com.sun.star.sdbc.Statement"); +IMPLEMENT_SERVICE_INFO(ODbaseStatement,u"com.sun.star.sdbc.driver.dbase.Statement"_ustr,u"com.sun.star.sdbc.Statement"_ustr); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx index fece1bf7fb21..c7b6802209fd 100644 --- a/connectivity/source/drivers/dbase/DTable.cxx +++ b/connectivity/source/drivers/dbase/DTable.cxx @@ -28,7 +28,7 @@ #include <dbase/DConnection.hxx> #include <dbase/DColumns.hxx> #include <tools/config.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <dbase/DIndex.hxx> #include <dbase/DIndexes.hxx> #include <comphelper/processfactory.hxx> @@ -39,11 +39,12 @@ #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> #include <comphelper/property.hxx> #include <comphelper/servicehelper.hxx> +#include <o3tl/string_view.hxx> #include <comphelper/string.hxx> +#include <comphelper/configuration.hxx> #include <unotools/tempfile.hxx> #include <unotools/ucbhelper.hxx> #include <comphelper/types.hxx> -#include <cppuhelper/typeprovider.hxx> #include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/queryinterface.hxx> #include <connectivity/dbtools.hxx> @@ -54,6 +55,7 @@ #include <rtl/strbuf.hxx> #include <sal/log.hxx> #include <tools/date.hxx> +#include <i18nutil/calendar.hxx> #include <algorithm> #include <cassert> @@ -132,13 +134,13 @@ void lcl_CalcJulDate(sal_Int32& _nJulianDate,sal_Int32& _nJulianTime, const css: if ( aDateTime.Year <= 0 ) { _nJulianDate = static_cast<sal_Int32>((365.25 * iy0) - 0.75) - + static_cast<sal_Int32>(30.6001 * (im0 + 1) ) + + static_cast<sal_Int32>(i18nutil::monthDaysWithoutJanFeb * (im0 + 1) ) + aDateTime.Day + 1720994; } // if ( rDateTime.Year <= 0 ) else { _nJulianDate = static_cast<sal_Int32>(365.25 * iy0) - + static_cast<sal_Int32>(30.6001 * (im0 + 1)) + + static_cast<sal_Int32>(i18nutil::monthDaysWithoutJanFeb * (im0 + 1)) + aDateTime.Day + 1720994; } double JD = _nJulianDate + 0.5; @@ -155,17 +157,17 @@ void lcl_CalDate(sal_Int32 _nJulianDate,sal_Int32 _nJulianTime,css::util::DateTi { if ( _nJulianDate ) { - sal_Int32 ka = _nJulianDate; + sal_Int64 ka = _nJulianDate; if ( _nJulianDate >= 2299161 ) { - sal_Int32 ialp = static_cast<sal_Int32>( (static_cast<double>(_nJulianDate) - 1867216.25 ) / 36524.25 ); - ka = _nJulianDate + 1 + ialp - ( ialp >> 2 ); + sal_Int64 ialp = static_cast<sal_Int64>( (static_cast<double>(_nJulianDate) - 1867216.25 ) / 36524.25 ); + ka = ka + 1 + ialp - ( ialp >> 2 ); } - sal_Int32 kb = ka + 1524; - sal_Int32 kc = static_cast<sal_Int32>( (static_cast<double>(kb) - 122.1 ) / 365.25 ); - sal_Int32 kd = static_cast<sal_Int32>(static_cast<double>(kc) * 365.25); - sal_Int32 ke = static_cast<sal_Int32>(static_cast<double>( kb - kd ) / 30.6001 ); - _rDateTime.Day = static_cast<sal_uInt16>(kb - kd - static_cast<sal_Int32>( static_cast<double>(ke) * 30.6001 )); + sal_Int64 kb = ka + 1524; + sal_Int64 kc = static_cast<sal_Int64>((static_cast<double>(kb) - 122.1) / 365.25); + sal_Int64 kd = static_cast<sal_Int64>(static_cast<double>(kc) * 365.25); + sal_Int64 ke = static_cast<sal_Int64>(static_cast<double>(kb - kd) / i18nutil::monthDaysWithoutJanFeb); + _rDateTime.Day = static_cast<sal_uInt16>(kb - kd - static_cast<sal_Int64>( static_cast<double>(ke) * i18nutil::monthDaysWithoutJanFeb )); if ( ke > 13 ) _rDateTime.Month = static_cast<sal_uInt16>(ke - 13); else @@ -273,7 +275,11 @@ void ODbaseTable::readHeader() void ODbaseTable::fillColumns() { m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); - m_pFileStream->Seek(32); + if (!checkSeek(*m_pFileStream, 32)) + { + SAL_WARN("connectivity.drivers", "ODbaseTable::fillColumns: bad offset!"); + return; + } if(!m_aColumns.is()) m_aColumns = new OSQLColumns(); @@ -285,8 +291,21 @@ void ODbaseTable::fillColumns() m_aScales.clear(); // Number of fields: - const sal_Int32 nFieldCount = (m_aHeader.headerLength - 1) / 32 - 1; - OSL_ENSURE(nFieldCount,"No columns in table!"); + sal_Int32 nFieldCount = (m_aHeader.headerLength - 1) / 32 - 1; + if (nFieldCount <= 0) + { + SAL_WARN("connectivity.drivers", "No columns in table!"); + return; + } + + auto nRemainingsize = m_pFileStream->remainingSize(); + auto nMaxPossibleRecords = nRemainingsize / 32; + if (o3tl::make_unsigned(nFieldCount) > nMaxPossibleRecords) + { + SAL_WARN("connectivity.drivers", "Parsing error: " << nMaxPossibleRecords << + " max possible entries, but " << nFieldCount << " claimed, truncating"); + nFieldCount = nMaxPossibleRecords; + } m_aColumns->reserve(nFieldCount); m_aTypes.reserve(nFieldCount); @@ -301,17 +320,13 @@ void ODbaseTable::fillColumns() for (; i < nFieldCount; i++) { DBFColumn aDBFColumn; -#if !defined(NDEBUG) - sal_uInt64 const nOldPos(m_pFileStream->Tell()); -#endif m_pFileStream->ReadBytes(aDBFColumn.db_fnm, 11); m_pFileStream->ReadUChar(aDBFColumn.db_typ); m_pFileStream->ReadUInt32(aDBFColumn.db_adr); m_pFileStream->ReadUChar(aDBFColumn.db_flng); m_pFileStream->ReadUChar(aDBFColumn.db_dez); m_pFileStream->ReadBytes(aDBFColumn.db_free2, 14); - assert(m_pFileStream->GetError() || m_pFileStream->Tell() == nOldPos + sizeof(aDBFColumn)); - if (m_pFileStream->GetError()) + if (!m_pFileStream->good()) { SAL_WARN("connectivity.drivers", "ODbaseTable::fillColumns: short read!"); break; @@ -455,7 +470,6 @@ ODbaseTable::ODbaseTable(sdbcx::OCollection* _pTables, ODbaseConnection* _pConne m_eEncoding = getConnection()->getTextEncoding(); } - void ODbaseTable::construct() { // initialize the header @@ -483,19 +497,47 @@ void ODbaseTable::construct() m_pFileStream = createStream_simpleError( sFileName, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); } - if(!m_pFileStream) + if (!m_pFileStream) return; readHeader(); + + std::size_t nFileSize = lcl_getFileSize(*m_pFileStream); + + if (m_aHeader.headerLength > nFileSize) + { + SAL_WARN("connectivity.drivers", "Parsing error: " << nFileSize << + " max possible size, but " << m_aHeader.headerLength << " claimed, abandoning"); + return; + } + + if (m_aHeader.recordLength) + { + std::size_t nMaxPossibleRecords = (nFileSize - m_aHeader.headerLength) / m_aHeader.recordLength; + // #i83401# seems to be empty or someone wrote nonsense into the dbase + // file try and recover if m_aHeader.db_slng is sane + if (m_aHeader.nbRecords == 0) + { + SAL_WARN("connectivity.drivers", "Parsing warning: 0 records claimed, recovering"); + m_aHeader.nbRecords = nMaxPossibleRecords; + } + else if (m_aHeader.nbRecords > nMaxPossibleRecords) + { + SAL_WARN("connectivity.drivers", "Parsing error: " << nMaxPossibleRecords << + " max possible records, but " << m_aHeader.nbRecords << " claimed, truncating"); + m_aHeader.nbRecords = std::max(nMaxPossibleRecords, static_cast<size_t>(1)); + } + } + if (HasMemoFields()) { // Create Memo-Filename (.DBT): // nyi: Ugly for Unix and Mac! if ( m_aHeader.type == FoxProMemo || m_aHeader.type == VisualFoxPro || m_aHeader.type == VisualFoxProAuto) // foxpro uses another extension - aURL.SetExtension("fpt"); + aURL.SetExtension(u"fpt"); else - aURL.SetExtension("dbt"); + aURL.SetExtension(u"dbt"); // If the memo file isn't found, the data will be displayed anyhow. // However, updates can't be done @@ -508,18 +550,10 @@ void ODbaseTable::construct() if (m_pMemoStream) ReadMemoHeader(); } - fillColumns(); - std::size_t nFileSize = lcl_getFileSize(*m_pFileStream); + fillColumns(); m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN); - // seems to be empty or someone wrote bullshit into the dbase file - // try and recover if m_aHeader.db_slng is sane - if (m_aHeader.nbRecords == 0 && m_aHeader.recordLength) - { - std::size_t nRecords = (nFileSize-m_aHeader.headerLength)/m_aHeader.recordLength; - if (nRecords > 0) - m_aHeader.nbRecords = nRecords; - } + // Buffersize dependent on the file size m_pFileStream->SetBufferSize(nFileSize > 1000000 ? 32768 : @@ -614,7 +648,7 @@ OUString ODbaseTable::getEntry(file::OConnection const * _pConnection, std::u16s // name and extension have to coincide if ( _pConnection->matchesExtension( sExt ) ) { - sName = sName.replaceAt(sName.getLength() - (sExt.getLength() + 1), sExt.getLength() + 1, OUString()); + sName = sName.replaceAt(sName.getLength() - (sExt.getLength() + 1), sExt.getLength() + 1, u""); if ( sName == _sName ) { Reference< XContentAccess > xContentAccess( xDir, UNO_QUERY ); @@ -645,7 +679,7 @@ void ODbaseTable::refreshColumns() if(m_xColumns) m_xColumns->reFill(aVector); else - m_xColumns = new ODbaseColumns(this,m_aMutex,aVector); + m_xColumns.reset(new ODbaseColumns(this,m_aMutex,aVector)); } void ODbaseTable::refreshIndexes() @@ -656,7 +690,7 @@ void ODbaseTable::refreshIndexes() INetURLObject aURL; aURL.SetURL(getEntry(m_pConnection,m_Name)); - aURL.setExtension("inf"); + aURL.setExtension(u"inf"); Config aInfFile(aURL.getFSysPath(FSysStyle::Detect)); aInfFile.SetGroup(dBASE_III_GROUP); sal_uInt16 nKeyCnt = aInfFile.GetKeyCount(); @@ -688,7 +722,7 @@ void ODbaseTable::refreshIndexes() if(m_xIndexes) m_xIndexes->reFill(aVector); else - m_xIndexes = new ODbaseIndexes(this,m_aMutex,aVector); + m_xIndexes.reset(new ODbaseIndexes(this,m_aMutex,aVector)); } @@ -705,14 +739,12 @@ Sequence< Type > SAL_CALL ODbaseTable::getTypes( ) std::vector<Type> aOwnTypes; aOwnTypes.reserve(aTypes.getLength()); - const Type* pBegin = aTypes.getConstArray(); - const Type* pEnd = pBegin + aTypes.getLength(); - for(;pBegin != pEnd;++pBegin) + for (auto& type : aTypes) { - if(*pBegin != cppu::UnoType<XKeysSupplier>::get() && - *pBegin != cppu::UnoType<XDataDescriptorFactory>::get()) + if(type != cppu::UnoType<XKeysSupplier>::get() && + type != cppu::UnoType<XDataDescriptorFactory>::get()) { - aOwnTypes.push_back(*pBegin); + aOwnTypes.push_back(type); } } aOwnTypes.push_back(cppu::UnoType<css::lang::XUnoTunnel>::get()); @@ -727,25 +759,9 @@ Any SAL_CALL ODbaseTable::queryInterface( const Type & rType ) return Any(); Any aRet = OTable_TYPEDEF::queryInterface(rType); - return aRet.hasValue() ? aRet : ::cppu::queryInterface(rType,static_cast< css::lang::XUnoTunnel*> (this)); -} - - -Sequence< sal_Int8 > ODbaseTable::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); + return aRet; } -// css::lang::XUnoTunnel - -sal_Int64 ODbaseTable::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return (isUnoTunnelId<ODbaseTable>(rId)) - ? reinterpret_cast< sal_Int64 >( this ) - : ODbaseTable_BASE::getSomething(rId); -} bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool bRetrieveData) { @@ -753,7 +769,7 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool return false; // Read the data - bool bIsCurRecordDeleted = static_cast<char>(m_pBuffer[0]) == '*'; + bool bIsCurRecordDeleted = m_pBuffer[0] == '*'; // only read the bookmark @@ -772,10 +788,8 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool for (std::size_t i = 1; aIter != aEnd && nByteOffset <= m_nBufferSize && i < nCount;++aIter, i++) { // Lengths depending on data type: - sal_Int32 nLen = 0; - sal_Int32 nType = 0; - nLen = m_aPrecisions[i-1]; - nType = m_aTypes[i-1]; + sal_Int32 nLen = m_aPrecisions[i-1]; + sal_Int32 nType = m_aTypes[i-1]; switch(nType) { @@ -827,15 +841,20 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool } else { - // Commit the string. Use intern() to ref-count it. - *(*_rRow)[i] = OUString::intern(pData, static_cast<sal_Int32>(nLastPos+1), m_eEncoding); + // Commit the string + *(*_rRow)[i] = OUString(pData, static_cast<sal_Int32>(nLastPos+1), m_eEncoding); } } // if (nType == DataType::CHAR || nType == DataType::VARCHAR) else if ( DataType::TIMESTAMP == nType ) { sal_Int32 nDate = 0,nTime = 0; + if (o3tl::make_unsigned(nLen) < 8) + { + SAL_WARN("connectivity.drivers", "short TIMESTAMP"); + return false; + } memcpy(&nDate, pData, 4); - memcpy(&nTime, pData+ 4, 4); + memcpy(&nTime, pData + 4, 4); if ( !nDate && !nTime ) { (*_rRow)[i]->setNull(); @@ -907,20 +926,20 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool continue; } - OUString aStr = OUString::intern(pData+nPos1, nPos2-nPos1+1, m_eEncoding); + OUString aStr(pData+nPos1, nPos2-nPos1+1, m_eEncoding); switch (nType) { case DataType::DATE: { - if (aStr.getLength() != nLen) + if (nLen < 8 || aStr.getLength() != nLen) { (*_rRow)[i]->setNull(); break; } - const sal_uInt16 nYear = static_cast<sal_uInt16>(aStr.copy( 0, 4 ).toInt32()); - const sal_uInt16 nMonth = static_cast<sal_uInt16>(aStr.copy( 4, 2 ).toInt32()); - const sal_uInt16 nDay = static_cast<sal_uInt16>(aStr.copy( 6, 2 ).toInt32()); + const sal_uInt16 nYear = static_cast<sal_uInt16>(o3tl::toInt32(aStr.subView( 0, 4 ))); + const sal_uInt16 nMonth = static_cast<sal_uInt16>(o3tl::toInt32(aStr.subView( 4, 2 ))); + const sal_uInt16 nDay = static_cast<sal_uInt16>(o3tl::toInt32(aStr.subView( 6, 2 ))); const css::util::Date aDate(nDay,nMonth,nYear); *(*_rRow)[i] = aDate; @@ -971,9 +990,6 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool void ODbaseTable::FileClose() { ::osl::MutexGuard aGuard(m_aMutex); - // if not everything has been written yet - if (m_pMemoStream && m_pMemoStream->IsWritable()) - m_pMemoStream->Flush(); m_pMemoStream.reset(); @@ -984,7 +1000,7 @@ bool ODbaseTable::CreateImpl() { OSL_ENSURE(!m_pFileStream, "SequenceError"); - if ( m_pConnection->isCheckEnabled() && ::dbtools::convertName2SQLName(m_Name,OUString()) != m_Name ) + if ( m_pConnection->isCheckEnabled() && ::dbtools::convertName2SQLName(m_Name, u"") != m_Name ) { const OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( STR_SQL_NAME_ERROR, @@ -1036,7 +1052,7 @@ bool ODbaseTable::CreateImpl() try { Content aContent(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),Reference<XCommandEnvironment>(), comphelper::getProcessComponentContext()); - aContent.executeCommand( "delete", css::uno::Any( true ) ); + aContent.executeCommand( u"delete"_ustr, css::uno::Any( true ) ); } catch(const Exception&) // an exception is thrown when no file exists { @@ -1047,7 +1063,7 @@ bool ODbaseTable::CreateImpl() if (bMemoFile) { OUString aExt = aURL.getExtension(); - aURL.setExtension("dbt"); // extension for memo file + aURL.setExtension(u"dbt"); // extension for memo file bool bMemoAlreadyExists = false; try @@ -1064,7 +1080,7 @@ bool ODbaseTable::CreateImpl() try { Content aMemoContent(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),Reference<XCommandEnvironment>(), comphelper::getProcessComponentContext()); - aMemoContent.executeCommand( "delete", css::uno::Any( true ) ); + aMemoContent.executeCommand( u"delete"_ustr, css::uno::Any( true ) ); } catch(const Exception&) { @@ -1082,7 +1098,7 @@ bool ODbaseTable::CreateImpl() try { Content aMemoContent(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),Reference<XCommandEnvironment>(), comphelper::getProcessComponentContext()); - aMemoContent.executeCommand( "delete", css::uno::Any( true ) ); + aMemoContent.executeCommand( u"delete"_ustr, css::uno::Any( true ) ); } catch(const ContentCreationException&) { @@ -1103,7 +1119,7 @@ bool ODbaseTable::CreateImpl() return true; } -void ODbaseTable::throwInvalidColumnType(const char* pErrorId, const OUString& _sColumnName) +void ODbaseTable::throwInvalidColumnType(TranslateId pErrorId, const OUString& _sColumnName) { try { @@ -1363,6 +1379,10 @@ bool ODbaseTable::CreateFile(const INetURLObject& aFile, bool& bCreateMemo) return true; } +bool ODbaseTable::HasMemoFields() const +{ + return m_aHeader.type > dBaseIV && !comphelper::IsFuzzing(); +} // creates in principle dBase III file format bool ODbaseTable::CreateMemoFile(const INetURLObject& aFile) @@ -1378,12 +1398,11 @@ bool ODbaseTable::CreateMemoFile(const INetURLObject& aFile) m_pMemoStream->Seek(0); (*m_pMemoStream).WriteUInt32( 1 ); // pointer to the first free block - m_pMemoStream->Flush(); m_pMemoStream.reset(); return true; } -bool ODbaseTable::Drop_Static(const OUString& _sUrl, bool _bHasMemoFields, OCollection* _pIndexes ) +bool ODbaseTable::Drop_Static(std::u16string_view _sUrl, bool _bHasMemoFields, OCollection* _pIndexes ) { INetURLObject aURL; aURL.SetURL(_sUrl); @@ -1394,7 +1413,7 @@ bool ODbaseTable::Drop_Static(const OUString& _sUrl, bool _bHasMemoFields, OColl { if (_bHasMemoFields) { // delete the memo fields - aURL.setExtension("dbt"); + aURL.setExtension(u"dbt"); bDropped = ::utl::UCBContentHelper::Kill(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)); } @@ -1414,13 +1433,13 @@ bool ODbaseTable::Drop_Static(const OUString& _sUrl, bool _bHasMemoFields, OColl { } } - aURL.setExtension("inf"); + aURL.setExtension(u"inf"); // as the inf file does not necessarily exist, we aren't allowed to use UCBContentHelper::Kill try { ::ucbhelper::Content aDeleteContent( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext() ); - aDeleteContent.executeCommand( "delete", makeAny( true ) ); + aDeleteContent.executeCommand( u"delete"_ustr, Any( true ) ); } catch(const Exception&) { @@ -1562,10 +1581,8 @@ bool ODbaseTable::DeleteRow(const OSQLColumns& _rCols) { xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName; - Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY); - OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!"); - ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) ); - OSL_ENSURE(pIndex,"ODbaseTable::DeleteRow: No Index returned!"); + ODbaseIndex* pIndex = dynamic_cast<ODbaseIndex*>(xIndex.get()); + assert(pIndex && "ODbaseTable::DeleteRow: No Index returned!"); OSQLColumns::const_iterator aIter = std::find_if(_rCols.begin(), _rCols.end(), [&aCase, &aColName](const OSQLColumns::value_type& rxCol) { @@ -1613,7 +1630,7 @@ Reference<XPropertySet> ODbaseTable::isUniqueByColumnName(sal_Int32 _nColumnPos) return Reference<XPropertySet>(); } -static double toDouble(const OString& rString) +static double toDouble(std::string_view rString) { return ::rtl::math::stringToDouble( rString, '.', ',' ); } @@ -1635,7 +1652,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo ::comphelper::UStringMixEqual aCase(isCaseSensitive()); - Reference<XIndexAccess> xColumns = m_xColumns.get(); + Reference<XIndexAccess> xColumns(m_xColumns.get()); // first search a key that exist already in the table for (sal_Int32 i = 0; i < nColumnCount; ++i) { @@ -1668,10 +1685,8 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo continue; else { - Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY); - OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!"); - ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) ); - OSL_ENSURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!"); + ODbaseIndex* pIndex = dynamic_cast<ODbaseIndex*>(xIndex.get()); + assert(pIndex && "ODbaseTable::UpdateBuffer: No Index returned!"); if (pIndex->Find(0,*rRow[nPos])) { @@ -1776,10 +1791,8 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo } if (aIndexedCols[i].is()) { - Reference<XUnoTunnel> xTunnel(aIndexedCols[i],UNO_QUERY); - OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!"); - ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) ); - OSL_ENSURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!"); + ODbaseIndex* pIndex = dynamic_cast<ODbaseIndex*>(aIndexedCols[i].get()); + assert(pIndex && "ODbaseTable::UpdateBuffer: No Index returned!"); // Update !! if (pOrgRow.is() && !thisColIsNull) pIndex->Update(m_nFilePos, *(*pOrgRow)[nPos], thisColVal); @@ -1806,7 +1819,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo case DataType::TIMESTAMP: { sal_Int32 nJulianDate = 0, nJulianTime = 0; - lcl_CalcJulDate(nJulianDate,nJulianTime, thisColVal); + lcl_CalcJulDate(nJulianDate,nJulianTime, thisColVal.getDateTime()); // Exactly 8 bytes to copy: memcpy(pData,&nJulianDate,4); memcpy(pData+4,&nJulianTime,4); @@ -1818,7 +1831,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo if(thisColVal.getTypeKind() == DataType::DOUBLE) aDate = ::dbtools::DBTypeConversion::toDate(thisColVal.getDouble()); else - aDate = thisColVal; + aDate = thisColVal.getDate(); char s[sizeof("-327686553565535")]; // reserve enough space for hypothetical max length snprintf(s, @@ -1833,7 +1846,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo } break; case DataType::INTEGER: { - sal_Int32 nValue = thisColVal; + sal_Int32 nValue = thisColVal.getInt32(); if (o3tl::make_unsigned(nLen) > sizeof(nValue)) return false; memcpy(pData,&nValue,nLen); @@ -1841,7 +1854,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo break; case DataType::DOUBLE: { - const double d = thisColVal; + const double d = thisColVal.getDouble(); m_xColumns->getByIndex(i) >>= xCol; if (getBOOL(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency is treated separately @@ -1867,7 +1880,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo { memset(pData,' ',nLen); // Clear to NULL - const double n = thisColVal; + const double n = thisColVal.getDouble(); // one, because const_cast GetFormatPrecision on SvNumberFormat is not constant, // even though it really could and should be @@ -1885,11 +1898,13 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo m_xColumns->getByIndex(i) >>= xCol; OSL_ENSURE(xCol.is(),"ODbaseTable::UpdateBuffer column is null!"); xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)) >>= aColName; - std::vector< std::pair<const char* , OUString > > aStringToSubstitutes; - aStringToSubstitutes.push_back(std::pair<const char* , OUString >("$columnname$", aColName)); - aStringToSubstitutes.push_back(std::pair<const char* , OUString >("$precision$", OUString::number(nLen))); - aStringToSubstitutes.push_back(std::pair<const char* , OUString >("$scale$", OUString::number(nScale))); - aStringToSubstitutes.push_back(std::pair<const char* , OUString >("$value$", OStringToOUString(aDefaultValue,RTL_TEXTENCODING_UTF8))); + std::vector< std::pair<const char* , OUString > > aStringToSubstitutes + { + { "$columnname$", aColName }, + { "$precision$", OUString::number(nLen) }, + { "$scale$", OUString::number(nScale) }, + { "$value$", OStringToOUString(aDefaultValue,RTL_TEXTENCODING_UTF8) } + }; const OUString sError( getConnection()->getResources().getResourceStringWithSubstitution( STR_INVALID_COLUMN_DECIMAL_VALUE @@ -2154,9 +2169,8 @@ void ODbaseTable::alterColumn(sal_Int32 index, OUString sTempName = createTempFile(); - ODbaseTable* pNewTable = new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection)); - Reference<XPropertySet> xHoldTable = pNewTable; - pNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(sTempName)); + rtl::Reference<ODbaseTable> pNewTable = new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection)); + pNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),Any(sTempName)); Reference<XAppend> xAppend(pNewTable->getColumns(),UNO_QUERY); OSL_ENSURE(xAppend.is(),"ODbaseTable::alterColumn: No XAppend interface!"); @@ -2205,7 +2219,7 @@ void ODbaseTable::alterColumn(sal_Int32 index, pNewTable->construct(); // copy the data - copyData(pNewTable,0); + copyData(pNewTable.get(),0); // now drop the old one if( DropImpl() ) // we don't want to delete the memo columns too @@ -2224,8 +2238,8 @@ void ODbaseTable::alterColumn(sal_Int32 index, ::dbtools::throwGenericSQLException( sError, *this ); } // release the temp file + ::comphelper::disposeComponent(pNewTable); pNewTable = nullptr; - ::comphelper::disposeComponent(xHoldTable); } else { @@ -2272,7 +2286,7 @@ void SAL_CALL ODbaseTable::rename( const OUString& newName ) namespace { void renameFile(file::OConnection const * _pConnection,std::u16string_view oldName, - const OUString& newName,const OUString& _sExtension) + const OUString& newName, std::u16string_view _sExtension) { OUString aName = ODbaseTable::getEntry(_pConnection,oldName); if(aName.isEmpty()) @@ -2293,14 +2307,14 @@ namespace { Content aContent(aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE),Reference<XCommandEnvironment>(), comphelper::getProcessComponentContext()); - Sequence< PropertyValue > aProps( 1 ); - aProps[0].Name = "Title"; - aProps[0].Handle = -1; // n/a - aProps[0].Value <<= sNewName; + Sequence< PropertyValue > aProps{ { u"Title"_ustr, + -1, // n/a + Any(sNewName), + css::beans::PropertyState_DIRECT_VALUE } }; Sequence< Any > aValues; - aContent.executeCommand( "setPropertyValues",makeAny(aProps) ) >>= aValues; + aContent.executeCommand( u"setPropertyValues"_ustr,Any(aProps) ) >>= aValues; if(aValues.hasElements() && aValues[0].hasValue()) - throw Exception("setPropertyValues returned non-zero", nullptr); + throw Exception(u"setPropertyValues returned non-zero"_ustr, nullptr); } catch(const Exception&) { @@ -2319,7 +2333,7 @@ void ODbaseTable::renameImpl( const OUString& newName ) renameFile(m_pConnection,m_Name,newName,m_pConnection->getExtension()); if ( HasMemoFields() ) { // delete the memo fields - renameFile(m_pConnection,m_Name,newName,"dbt"); + renameFile(m_pConnection,m_Name,newName,u"dbt"); } } @@ -2328,7 +2342,7 @@ void ODbaseTable::addColumn(const Reference< XPropertySet >& _xNewColumn) OUString sTempName = createTempFile(); rtl::Reference xNewTable(new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection))); - xNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(sTempName)); + xNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),Any(sTempName)); { Reference<XAppend> xAppend(xNewTable->getColumns(),UNO_QUERY); bool bCase = getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(); @@ -2386,7 +2400,7 @@ void ODbaseTable::dropColumn(sal_Int32 _nPos) OUString sTempName = createTempFile(); rtl::Reference xNewTable(new ODbaseTable(m_pTables,static_cast<ODbaseConnection*>(m_pConnection))); - xNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(sTempName)); + xNewTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),Any(sTempName)); { Reference<XAppend> xAppend(xNewTable->getColumns(),UNO_QUERY); bool bCase = getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(); @@ -2440,16 +2454,14 @@ OUString ODbaseTable::createTempFile() if ( aIdent.lastIndexOf('/') != (aIdent.getLength()-1) ) aIdent += "/"; - OUString sTempName(aIdent); OUString sExt("." + m_pConnection->getExtension()); - OUString sName(m_Name); - TempFile aTempFile(sName, true, &sExt, &sTempName); - if(!aTempFile.IsValid()) + OUString aTempFileURL = utl::CreateTempURL(m_Name, true, sExt, &aIdent); + if(aTempFileURL.isEmpty()) getConnection()->throwGenericSQLException(STR_COULD_NOT_ALTER_TABLE, *this); INetURLObject aURL; aURL.SetSmartProtocol(INetProtocol::File); - aURL.SetURL(aTempFile.GetURL()); + aURL.SetURL(aTempFileURL); OUString sNewName(aURL.getName().copy(0, aURL.getName().getLength() - sExt.getLength())); @@ -2499,7 +2511,7 @@ void ODbaseTable::copyData(ODbaseTable* _pNewTable,sal_Int32 _nPos) } } } - bOk = _pNewTable->InsertRow(*aInsertRow,_pNewTable->m_xColumns.get()); + bOk = _pNewTable->InsertRow(*aInsertRow, _pNewTable->m_xColumns.get()); SAL_WARN_IF(!bOk, "connectivity.drivers", "Row could not be inserted!"); } else @@ -2646,7 +2658,7 @@ bool ODbaseTable::ReadMemo(std::size_t nBlockNo, ORowSetValue& aVariable) } while (!bReady && !m_pMemoStream->eof()); - aVariable = OStringToOUString(aBStr.makeStringAndClear(), + aVariable = OStringToOUString(aBStr, m_eEncoding); } break; @@ -2670,7 +2682,14 @@ bool ODbaseTable::ReadMemo(std::size_t nBlockNo, ORowSetValue& aVariable) (*m_pMemoStream).ReadUInt32( nLength ); if (m_aMemoHeader.db_typ == MemodBaseIV) + { + if (nLength < 8) + { + SAL_WARN("connectivity.drivers", "Size too small"); + return false; + } nLength -= 8; + } if ( nLength ) { @@ -2680,7 +2699,7 @@ bool ODbaseTable::ReadMemo(std::size_t nBlockNo, ORowSetValue& aVariable) //pad it out with ' ' to expected length on short read sal_Int32 nRequested = sal::static_int_cast<sal_Int32>(nLength); comphelper::string::padToLength(aBuffer, nRequested, ' '); - aVariable = OStringToOUString(aBuffer.makeStringAndClear(), m_eEncoding); + aVariable = OStringToOUString(aBuffer, m_eEncoding); } // if ( bIsText ) else { diff --git a/connectivity/source/drivers/dbase/DTables.cxx b/connectivity/source/drivers/dbase/DTables.cxx index 1d922969493f..d43bfb31356a 100644 --- a/connectivity/source/drivers/dbase/DTables.cxx +++ b/connectivity/source/drivers/dbase/DTables.cxx @@ -32,7 +32,6 @@ #include <strings.hrc> #include <connectivity/dbexception.hxx> -using namespace ::comphelper; using namespace connectivity; using namespace connectivity::dbase; using namespace connectivity::file; @@ -40,17 +39,15 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::lang; using namespace ::com::sun::star::container; -sdbcx::ObjectType ODbaseTables::createObject(const OUString& _rName) +css::uno::Reference< css::beans::XPropertySet > ODbaseTables::createObject(const OUString& _rName) { - ODbaseTable* pRet = new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()), - _rName,"TABLE"); + rtl::Reference<ODbaseTable> pRet = new ODbaseTable(this, static_cast<ODbaseConnection*>(static_cast<OFileCatalog&>(m_rParent).getConnection()), + _rName,u"TABLE"_ustr); - sdbcx::ObjectType xRet = pRet; pRet->construct(); - return xRet; + return pRet; } void ODbaseTables::impl_refresh( ) @@ -64,12 +61,12 @@ Reference< XPropertySet > ODbaseTables::createDescriptor() } // XAppend -sdbcx::ObjectType ODbaseTables::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) +css::uno::Reference< css::beans::XPropertySet > ODbaseTables::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) { - auto pTable = comphelper::getUnoTunnelImplementation<ODbaseTable>(descriptor); + auto pTable = dynamic_cast<ODbaseTable*>(descriptor.get()); if(pTable) { - pTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(_rForName)); + pTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),Any(_rForName)); try { if(!pTable->CreateImpl()) @@ -82,7 +79,7 @@ sdbcx::ObjectType ODbaseTables::appendObject( const OUString& _rForName, const R catch(Exception& ex) { css::uno::Any anyEx = cppu::getCaughtException(); - throw SQLException( ex.Message, nullptr, "", 0, anyEx ); + throw SQLException( ex.Message, nullptr, u""_ustr, 0, anyEx ); } } return createObject( _rForName ); @@ -91,7 +88,7 @@ sdbcx::ObjectType ODbaseTables::appendObject( const OUString& _rForName, const R // XDrop void ODbaseTables::dropObject(sal_Int32 _nPos, const OUString& _sElementName) { - Reference< XUnoTunnel> xTunnel; + Reference< XInterface > xTunnel; try { xTunnel.set(getObject(_nPos),UNO_QUERY); @@ -104,7 +101,7 @@ void ODbaseTables::dropObject(sal_Int32 _nPos, const OUString& _sElementName) if ( xTunnel.is() ) { - ODbaseTable* pTable = reinterpret_cast< ODbaseTable* >( xTunnel->getSomething(ODbaseTable::getUnoTunnelId()) ); + ODbaseTable* pTable = dynamic_cast<ODbaseTable*>(xTunnel.get()); if(pTable) pTable->DropImpl(); } diff --git a/connectivity/source/drivers/dbase/dindexnode.cxx b/connectivity/source/drivers/dbase/dindexnode.cxx index 69648c480e79..0e4746a0b9a6 100644 --- a/connectivity/source/drivers/dbase/dindexnode.cxx +++ b/connectivity/source/drivers/dbase/dindexnode.cxx @@ -26,6 +26,7 @@ #include <algorithm> #include <memory> +#include <utility> using namespace connectivity; @@ -38,10 +39,10 @@ ONDXKey::ONDXKey() { } -ONDXKey::ONDXKey(const ORowSetValue& rVal, sal_Int32 eType, sal_uInt32 nRec) +ONDXKey::ONDXKey(ORowSetValue aVal, sal_Int32 eType, sal_uInt32 nRec) : ONDXKey_BASE(eType) , nRecord(nRec) - , xValue(rVal) + , xValue(std::move(aVal)) { } @@ -167,7 +168,7 @@ bool ONDXPage::Find(const ONDXKey& rKey) else if (i == nCount) { rIndex.m_aCurLeaf = this; - rIndex.m_nCurNode = i - 1; + rIndex.m_nCurNode = sal_uInt16(i - 1); bResult = false; } else @@ -206,8 +207,13 @@ bool ONDXPage::Insert(ONDXNode& rNode, sal_uInt32 nRowsLeft) } else // position unknown { - sal_uInt16 nPos = NODE_NOTFOUND; - while (++nPos < nCount && rNode.GetKey() > ((*this)[nPos]).GetKey()) ; + sal_uInt16 nPos = 0; + while (nPos < nCount) + { + if (rNode.GetKey() <= ((*this)[nPos]).GetKey()) + break; + ++nPos; + } --nCount; // (otherwise we might get Assertions and GPFs - 60593) bResult = Insert(nPos, rNode); @@ -234,7 +240,7 @@ bool ONDXPage::Insert(ONDXNode& rNode, sal_uInt32 nRowsLeft) ONDXPagePtr aNewRoot = rIndex.CreatePage(nNewPagePos + 1); aNewRoot->SetChild(this); - rIndex.m_aRoot = aNewRoot; + rIndex.m_aRoot = std::move(aNewRoot); rIndex.SetRootPos(nNewPagePos + 1); rIndex.SetPageCount(++nNewPageCount); } @@ -268,7 +274,7 @@ bool ONDXPage::Insert(ONDXNode& rNode, sal_uInt32 nRowsLeft) ONDXPagePtr aTempParent = aParent; if (IsLeaf()) { - rIndex.m_aCurLeaf = aNewPage; + rIndex.m_aCurLeaf = std::move(aNewPage); rIndex.m_nCurNode = rIndex.m_aCurLeaf->Count() - 1; // free not needed pages, there are no references to those on the page @@ -410,8 +416,8 @@ void ONDXPage::Delete(sal_uInt16 nNodePos) else { // merge with right neighbour - Merge(nParentNodePos + 1,((*aParent)[nParentNodePos + 1].GetChild(&rIndex,aParent))); - nParentNodePos++; + nParentNodePos = o3tl::sanitizing_inc(nParentNodePos); + Merge(nParentNodePos,((*aParent)[nParentNodePos].GetChild(&rIndex,aParent))); } if (HasParent() && !(*aParent)[nParentNodePos].HasChild()) aParent->Delete(nParentNodePos); @@ -482,7 +488,7 @@ void ONDXPage::Merge(sal_uInt16 nParentNodePos, const ONDXPagePtr& xPage) nMaxNodes_2 = nMaxNodes / 2; // Determine if page is right or left neighbour - bool bRight = ((*xPage)[0].GetKey() > (*this)[0].GetKey()); // sal_True, whenn xPage the right side is + bool bRight = ((*xPage)[0].GetKey() > (*this)[0].GetKey()); // true when xPage is at the right side sal_uInt16 nNewCount = (*xPage).Count() + Count(); if (IsLeaf()) @@ -701,7 +707,7 @@ void ONDXNode::Write(SvStream &rStream, const ONDXPage& rPage) const rStream.WriteBytes(&buf[0], sizeof(double)); } else - rStream.WriteDouble( static_cast<double>(aKey.getValue()) ); + rStream.WriteDouble( aKey.getValue().getDouble() ); } else { @@ -710,7 +716,7 @@ void ONDXNode::Write(SvStream &rStream, const ONDXPage& rPage) const memset(&pBuf[0], 0x20, nLen); if (!aKey.getValue().isNull()) { - OUString sValue = aKey.getValue(); + OUString sValue = aKey.getValue().getString(); OString aText(OUStringToOString(sValue, rIndex.m_pTable->getConnection()->getTextEncoding())); strncpy(reinterpret_cast<char *>(&pBuf[0]), aText.getStr(), std::min<size_t>(nLen, aText.getLength())); @@ -764,8 +770,8 @@ int ONDXKey::Compare(const ONDXKey& rKey) const } else { - double m = getValue(); - double n = rKey.getValue(); + double m = getValue().getDouble(); + double n = rKey.getValue().getDouble(); nRes = (m > n) ? 1 : ( m < n) ? -1 : 0; } @@ -968,28 +974,28 @@ bool ONDXPage::IsFull() const return Count() == rIndex.getHeader().db_maxkeys; } - sal_uInt16 ONDXPage::Search(const ONDXKey& rSearch) { // binary search later - sal_uInt16 i = NODE_NOTFOUND; - while (++i < Count()) - if ((*this)[i].GetKey() == rSearch) - break; + for (sal_uInt16 i = 0, nSize = Count(); i < nSize; ++i) + { + if (((*this)[i]).GetKey() == rSearch) + return i; + } - return (i < Count()) ? i : NODE_NOTFOUND; + return NODE_NOTFOUND; } - sal_uInt16 ONDXPage::Search(const ONDXPage* pPage) { - sal_uInt16 i = NODE_NOTFOUND; - while (++i < Count()) + for (sal_uInt16 i = 0, nSize = Count(); i < nSize; ++i) + { if (((*this)[i]).GetChild() == pPage) - break; + return i; + } // if not found, then we assume, that the page itself points to the page - return (i < Count()) ? i : NODE_NOTFOUND; + return NODE_NOTFOUND; } // runs recursively |