diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-18 10:51:27 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-18 20:35:49 +0200 |
commit | 2d0bdcc586af71dae665646b37177fa104c50906 (patch) | |
tree | a4c0fafefd366b2840365a3e0ee83ed0ad314bbd /connectivity/source/drivers | |
parent | 02f7d20f14dffcb3832264eeab5bb97acc4977f3 (diff) |
loplugin:flatten connectivity
Change-Id: Ic1d9eb84b64ebde99e15704a10b27f21447df4d5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92469
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'connectivity/source/drivers')
34 files changed, 1155 insertions, 1156 deletions
diff --git a/connectivity/source/drivers/calc/CTable.cxx b/connectivity/source/drivers/calc/CTable.cxx index 1d905aa73ea8..045ea54190ac 100644 --- a/connectivity/source/drivers/calc/CTable.cxx +++ b/connectivity/source/drivers/calc/CTable.cxx @@ -65,21 +65,21 @@ static void lcl_UpdateArea( const Reference<XCellRange>& xUsedRange, sal_Int32& // update rEndCol, rEndRow if any non-empty cell in xUsedRange is right/below const Reference<XCellRangesQuery> xUsedQuery( xUsedRange, UNO_QUERY ); - if ( xUsedQuery.is() ) - { - const sal_Int16 nContentFlags = - CellFlags::STRING | CellFlags::VALUE | CellFlags::DATETIME | CellFlags::FORMULA | CellFlags::ANNOTATION; + if ( !xUsedQuery.is() ) + return; - const Reference<XSheetCellRanges> xUsedRanges = xUsedQuery->queryContentCells( nContentFlags ); - const Sequence<CellRangeAddress> aAddresses = xUsedRanges->getRangeAddresses(); + const sal_Int16 nContentFlags = + CellFlags::STRING | CellFlags::VALUE | CellFlags::DATETIME | CellFlags::FORMULA | CellFlags::ANNOTATION; - const sal_Int32 nCount = aAddresses.getLength(); - const CellRangeAddress* pData = aAddresses.getConstArray(); - for ( sal_Int32 i=0; i<nCount; i++ ) - { - rEndCol = std::max(pData[i].EndColumn, rEndCol); - rEndRow = std::max(pData[i].EndRow, rEndRow); - } + const Reference<XSheetCellRanges> xUsedRanges = xUsedQuery->queryContentCells( nContentFlags ); + const Sequence<CellRangeAddress> aAddresses = xUsedRanges->getRangeAddresses(); + + const sal_Int32 nCount = aAddresses.getLength(); + const CellRangeAddress* pData = aAddresses.getConstArray(); + for ( sal_Int32 i=0; i<nCount; i++ ) + { + rEndCol = std::max(pData[i].EndColumn, rEndCol); + rEndRow = std::max(pData[i].EndRow, rEndRow); } } @@ -237,64 +237,64 @@ static void lcl_GetColumnInfo( const Reference<XSpreadsheet>& xSheet, const Refe Reference<XCell> xDataCell = lcl_GetUsedCell( xSheet, nDocColumn, nDataRow ); Reference<XPropertySet> xProp( xDataCell, UNO_QUERY ); - if ( xProp.is() ) + if ( !xProp.is() ) + return; + + rCurrency = false; // set to true for currency below + + const CellContentType eCellType = lcl_GetContentOrResultType( xDataCell ); + // #i35178# use "text" type if there is any text cell in the column + if ( eCellType == CellContentType_TEXT || lcl_HasTextInColumn( xSheet, nDocColumn, nDataRow ) ) + rDataType = DataType::VARCHAR; + else if ( eCellType == CellContentType_VALUE ) { - rCurrency = false; // set to true for currency below + // get number format to distinguish between different types - const CellContentType eCellType = lcl_GetContentOrResultType( xDataCell ); - // #i35178# use "text" type if there is any text cell in the column - if ( eCellType == CellContentType_TEXT || lcl_HasTextInColumn( xSheet, nDocColumn, nDataRow ) ) - rDataType = DataType::VARCHAR; - else if ( eCellType == CellContentType_VALUE ) + sal_Int16 nNumType = NumberFormat::NUMBER; + try { - // get number format to distinguish between different types + sal_Int32 nKey = 0; - sal_Int16 nNumType = NumberFormat::NUMBER; - try + if ( xProp->getPropertyValue( "NumberFormat" ) >>= nKey ) { - sal_Int32 nKey = 0; - - if ( xProp->getPropertyValue( "NumberFormat" ) >>= nKey ) + const Reference<XPropertySet> xFormat = xFormats->getByKey( nKey ); + if ( xFormat.is() ) { - const Reference<XPropertySet> xFormat = xFormats->getByKey( nKey ); - if ( xFormat.is() ) - { - xFormat->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE) ) >>= nNumType; - } + xFormat->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE) ) >>= nNumType; } } - catch ( Exception& ) - { - } - - if ( nNumType & NumberFormat::TEXT ) - rDataType = DataType::VARCHAR; - else if ( nNumType & NumberFormat::NUMBER ) - rDataType = DataType::DECIMAL; - else if ( nNumType & NumberFormat::CURRENCY ) - { - rCurrency = true; - rDataType = DataType::DECIMAL; - } - else if ( ( nNumType & NumberFormat::DATETIME ) == NumberFormat::DATETIME ) - { - // NumberFormat::DATETIME is DATE | TIME - rDataType = DataType::TIMESTAMP; - } - else if ( nNumType & NumberFormat::DATE ) - rDataType = DataType::DATE; - else if ( nNumType & NumberFormat::TIME ) - rDataType = DataType::TIME; - else if ( nNumType & NumberFormat::LOGICAL ) - rDataType = DataType::BIT; - else - rDataType = DataType::DECIMAL; } - else + catch ( Exception& ) { - // whole column empty + } + + if ( nNumType & NumberFormat::TEXT ) rDataType = DataType::VARCHAR; + else if ( nNumType & NumberFormat::NUMBER ) + rDataType = DataType::DECIMAL; + else if ( nNumType & NumberFormat::CURRENCY ) + { + rCurrency = true; + rDataType = DataType::DECIMAL; } + else if ( ( nNumType & NumberFormat::DATETIME ) == NumberFormat::DATETIME ) + { + // NumberFormat::DATETIME is DATE | TIME + rDataType = DataType::TIMESTAMP; + } + else if ( nNumType & NumberFormat::DATE ) + rDataType = DataType::DATE; + else if ( nNumType & NumberFormat::TIME ) + rDataType = DataType::TIME; + else if ( nNumType & NumberFormat::LOGICAL ) + rDataType = DataType::BIT; + else + rDataType = DataType::DECIMAL; + } + else + { + // whole column empty + rDataType = DataType::VARCHAR; } } @@ -310,104 +310,104 @@ static void lcl_SetValue( ORowSetValue& rValue, const Reference<XSpreadsheet>& x ++nDocRow; const Reference<XCell> xCell = xSheet->getCellByPosition( nDocColumn, nDocRow ); - if ( xCell.is() ) + if ( !xCell.is() ) + return; + + CellContentType eCellType = lcl_GetContentOrResultType( xCell ); + switch (nType) { - CellContentType eCellType = lcl_GetContentOrResultType( xCell ); - switch (nType) - { - case DataType::VARCHAR: - if ( eCellType == CellContentType_EMPTY ) - rValue.setNull(); - else - { - // #i25840# still let Calc convert numbers to text - const Reference<XText> xText( xCell, UNO_QUERY ); - if ( xText.is() ) - rValue = xText->getString(); - } - break; - case DataType::DECIMAL: - if ( eCellType == CellContentType_VALUE ) - rValue = xCell->getValue(); // double - else - rValue.setNull(); - break; - case DataType::BIT: - if ( eCellType == CellContentType_VALUE ) - rValue = xCell->getValue() != 0.0; - else - rValue.setNull(); - break; - case DataType::DATE: - if ( eCellType == CellContentType_VALUE ) - { - ::Date aDate( rNullDate ); - aDate.AddDays(::rtl::math::approxFloor( xCell->getValue() )); - rValue = aDate.GetUNODate(); - } - else - rValue.setNull(); - break; - case DataType::TIME: - if ( eCellType == CellContentType_VALUE ) + case DataType::VARCHAR: + if ( eCellType == CellContentType_EMPTY ) + rValue.setNull(); + else + { + // #i25840# still let Calc convert numbers to text + const Reference<XText> xText( xCell, UNO_QUERY ); + if ( xText.is() ) + rValue = xText->getString(); + } + break; + case DataType::DECIMAL: + if ( eCellType == CellContentType_VALUE ) + rValue = xCell->getValue(); // double + else + rValue.setNull(); + break; + case DataType::BIT: + if ( eCellType == CellContentType_VALUE ) + rValue = xCell->getValue() != 0.0; + else + rValue.setNull(); + break; + case DataType::DATE: + if ( eCellType == CellContentType_VALUE ) + { + ::Date aDate( rNullDate ); + aDate.AddDays(::rtl::math::approxFloor( xCell->getValue() )); + rValue = aDate.GetUNODate(); + } + else + rValue.setNull(); + break; + case DataType::TIME: + if ( eCellType == CellContentType_VALUE ) + { + double fCellVal = xCell->getValue(); + double fTime = fCellVal - rtl::math::approxFloor( fCellVal ); + sal_Int64 nIntTime = static_cast<sal_Int64>(rtl::math::round( fTime * static_cast<double>(::tools::Time::nanoSecPerDay) )); + if ( nIntTime == ::tools::Time::nanoSecPerDay) + nIntTime = 0; // 23:59:59.9999999995 and above is 00:00:00.00 + css::util::Time aTime; + aTime.NanoSeconds = static_cast<sal_uInt32>( nIntTime % ::tools::Time::nanoSecPerSec ); + nIntTime /= ::tools::Time::nanoSecPerSec; + aTime.Seconds = static_cast<sal_uInt16>( nIntTime % 60 ); + nIntTime /= 60; + aTime.Minutes = static_cast<sal_uInt16>( nIntTime % 60 ); + nIntTime /= 60; + OSL_ENSURE( nIntTime < 24, "error in time calculation" ); + aTime.Hours = static_cast<sal_uInt16>(nIntTime); + rValue = aTime; + } + else + rValue.setNull(); + break; + case DataType::TIMESTAMP: + if ( eCellType == CellContentType_VALUE ) + { + double fCellVal = xCell->getValue(); + double fDays = ::rtl::math::approxFloor( fCellVal ); + double fTime = fCellVal - fDays; + long nIntDays = static_cast<long>(fDays); + sal_Int64 nIntTime = ::rtl::math::round( fTime * static_cast<double>(::tools::Time::nanoSecPerDay) ); + if ( nIntTime == ::tools::Time::nanoSecPerDay ) { - double fCellVal = xCell->getValue(); - double fTime = fCellVal - rtl::math::approxFloor( fCellVal ); - sal_Int64 nIntTime = static_cast<sal_Int64>(rtl::math::round( fTime * static_cast<double>(::tools::Time::nanoSecPerDay) )); - if ( nIntTime == ::tools::Time::nanoSecPerDay) - nIntTime = 0; // 23:59:59.9999999995 and above is 00:00:00.00 - css::util::Time aTime; - aTime.NanoSeconds = static_cast<sal_uInt32>( nIntTime % ::tools::Time::nanoSecPerSec ); - nIntTime /= ::tools::Time::nanoSecPerSec; - aTime.Seconds = static_cast<sal_uInt16>( nIntTime % 60 ); - nIntTime /= 60; - aTime.Minutes = static_cast<sal_uInt16>( nIntTime % 60 ); - nIntTime /= 60; - OSL_ENSURE( nIntTime < 24, "error in time calculation" ); - aTime.Hours = static_cast<sal_uInt16>(nIntTime); - rValue = aTime; + nIntTime = 0; // 23:59:59.9999999995 and above is 00:00:00.00 + ++nIntDays; // (next day) } - else - rValue.setNull(); - break; - case DataType::TIMESTAMP: - if ( eCellType == CellContentType_VALUE ) - { - double fCellVal = xCell->getValue(); - double fDays = ::rtl::math::approxFloor( fCellVal ); - double fTime = fCellVal - fDays; - long nIntDays = static_cast<long>(fDays); - sal_Int64 nIntTime = ::rtl::math::round( fTime * static_cast<double>(::tools::Time::nanoSecPerDay) ); - if ( nIntTime == ::tools::Time::nanoSecPerDay ) - { - nIntTime = 0; // 23:59:59.9999999995 and above is 00:00:00.00 - ++nIntDays; // (next day) - } - css::util::DateTime aDateTime; + css::util::DateTime aDateTime; - aDateTime.NanoSeconds = static_cast<sal_uInt16>( nIntTime % ::tools::Time::nanoSecPerSec ); - nIntTime /= ::tools::Time::nanoSecPerSec; - aDateTime.Seconds = static_cast<sal_uInt16>( nIntTime % 60 ); - nIntTime /= 60; - aDateTime.Minutes = static_cast<sal_uInt16>( nIntTime % 60 ); - nIntTime /= 60; - OSL_ENSURE( nIntTime < 24, "error in time calculation" ); - aDateTime.Hours = static_cast<sal_uInt16>(nIntTime); + aDateTime.NanoSeconds = static_cast<sal_uInt16>( nIntTime % ::tools::Time::nanoSecPerSec ); + nIntTime /= ::tools::Time::nanoSecPerSec; + aDateTime.Seconds = static_cast<sal_uInt16>( nIntTime % 60 ); + nIntTime /= 60; + aDateTime.Minutes = static_cast<sal_uInt16>( nIntTime % 60 ); + nIntTime /= 60; + OSL_ENSURE( nIntTime < 24, "error in time calculation" ); + aDateTime.Hours = static_cast<sal_uInt16>(nIntTime); - ::Date aDate( rNullDate ); - aDate.AddDays( nIntDays ); - aDateTime.Day = aDate.GetDay(); - aDateTime.Month = aDate.GetMonth(); - aDateTime.Year = aDate.GetYear(); + ::Date aDate( rNullDate ); + aDate.AddDays( nIntDays ); + aDateTime.Day = aDate.GetDay(); + aDateTime.Month = aDate.GetMonth(); + aDateTime.Year = aDate.GetYear(); - rValue = aDateTime; - } - else - rValue.setNull(); - break; - } // switch (nType) - } + rValue = aDateTime; + } + else + rValue.setNull(); + break; + } // switch (nType) // rValue.setTypeKind(nType); } diff --git a/connectivity/source/drivers/dbase/DIndex.cxx b/connectivity/source/drivers/dbase/DIndex.cxx index fdb782174412..d168de39eb77 100644 --- a/connectivity/source/drivers/dbase/DIndex.cxx +++ b/connectivity/source/drivers/dbase/DIndex.cxx @@ -130,30 +130,30 @@ ONDXPagePtr const & ODbaseIndex::getRoot() void ODbaseIndex::openIndexFile() { - if(!m_pFileStream) + if(m_pFileStream) + return; + + OUString sFile = getCompletePath(); + if(UCBContentHelper::Exists(sFile)) { - OUString sFile = getCompletePath(); - if(UCBContentHelper::Exists(sFile)) - { - m_pFileStream = OFileTable::createStream_simpleError(sFile, StreamMode::READWRITE | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE); - if (!m_pFileStream) - m_pFileStream = OFileTable::createStream_simpleError(sFile, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); - if(m_pFileStream) - { - m_pFileStream->SetEndian(SvStreamEndian::LITTLE); - m_pFileStream->SetBufferSize(DINDEX_PAGE_SIZE); - (*m_pFileStream) >> *this; - } - } - if(!m_pFileStream) + m_pFileStream = OFileTable::createStream_simpleError(sFile, StreamMode::READWRITE | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE); + if (!m_pFileStream) + m_pFileStream = OFileTable::createStream_simpleError(sFile, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); + if(m_pFileStream) { - const OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution( - STR_COULD_NOT_LOAD_FILE, - "$filename$", sFile - ) ); - ::dbtools::throwGenericSQLException( sError, *this ); + m_pFileStream->SetEndian(SvStreamEndian::LITTLE); + m_pFileStream->SetBufferSize(DINDEX_PAGE_SIZE); + (*m_pFileStream) >> *this; } } + if(!m_pFileStream) + { + const OUString sError( m_pTable->getConnection()->getResources().getResourceStringWithSubstitution( + STR_COULD_NOT_LOAD_FILE, + "$filename$", sFile + ) ); + ::dbtools::throwGenericSQLException( sError, *this ); + } } std::unique_ptr<OIndexIterator> ODbaseIndex::createIterator() diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx index bf2036b2ca19..ff01f3b6ba37 100644 --- a/connectivity/source/drivers/dbase/DTable.cxx +++ b/connectivity/source/drivers/dbase/DTable.cxx @@ -482,63 +482,63 @@ void ODbaseTable::construct() m_pFileStream = createStream_simpleError( sFileName, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); } - if(m_pFileStream) - { - readHeader(); - if (HasMemoFields()) - { - // Create Memo-Filename (.DBT): - // nyi: Ugly for Unix and Mac! + if(!m_pFileStream) + return; - if ( m_aHeader.type == FoxProMemo || m_aHeader.type == VisualFoxPro || m_aHeader.type == VisualFoxProAuto) // foxpro uses another extension - aURL.SetExtension("fpt"); - else - aURL.SetExtension("dbt"); + readHeader(); + if (HasMemoFields()) + { + // Create Memo-Filename (.DBT): + // nyi: Ugly for Unix and Mac! - // If the memo file isn't found, the data will be displayed anyhow. - // However, updates can't be done - // but the operation is executed - m_pMemoStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READWRITE | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE); - if ( !m_pMemoStream ) - { - m_pMemoStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); - } - if (m_pMemoStream) - ReadMemoHeader(); - } - fillColumns(); + if ( m_aHeader.type == FoxProMemo || m_aHeader.type == VisualFoxPro || m_aHeader.type == VisualFoxProAuto) // foxpro uses another extension + aURL.SetExtension("fpt"); + else + aURL.SetExtension("dbt"); - std::size_t nFileSize = lcl_getFileSize(*m_pFileStream); - 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) + // If the memo file isn't found, the data will be displayed anyhow. + // However, updates can't be done + // but the operation is executed + m_pMemoStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READWRITE | StreamMode::NOCREATE | StreamMode::SHARE_DENYWRITE); + if ( !m_pMemoStream ) { - std::size_t nRecords = (nFileSize-m_aHeader.headerLength)/m_aHeader.recordLength; - if (nRecords > 0) - m_aHeader.nbRecords = nRecords; + m_pMemoStream = createStream_simpleError( aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE), StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); } + if (m_pMemoStream) + ReadMemoHeader(); + } + fillColumns(); - // Buffersize dependent on the file size - m_pFileStream->SetBufferSize(nFileSize > 1000000 ? 32768 : - nFileSize > 100000 ? 16384 : - nFileSize > 10000 ? 4096 : 1024); + std::size_t nFileSize = lcl_getFileSize(*m_pFileStream); + 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; + } - if (m_pMemoStream) - { - // set the buffer exactly to the length of a record - nFileSize = m_pMemoStream->TellEnd(); - m_pMemoStream->Seek(STREAM_SEEK_TO_BEGIN); - - // Buffersize dependent on the file size - m_pMemoStream->SetBufferSize(nFileSize > 1000000 ? 32768 : - nFileSize > 100000 ? 16384 : - nFileSize > 10000 ? 4096 : - m_aMemoHeader.db_size); - } + // Buffersize dependent on the file size + m_pFileStream->SetBufferSize(nFileSize > 1000000 ? 32768 : + nFileSize > 100000 ? 16384 : + nFileSize > 10000 ? 4096 : 1024); + + if (m_pMemoStream) + { + // set the buffer exactly to the length of a record + nFileSize = m_pMemoStream->TellEnd(); + m_pMemoStream->Seek(STREAM_SEEK_TO_BEGIN); - AllocBuffer(); + // Buffersize dependent on the file size + m_pMemoStream->SetBufferSize(nFileSize > 1000000 ? 32768 : + nFileSize > 100000 ? 16384 : + nFileSize > 10000 ? 4096 : + m_aMemoHeader.db_size); } + + AllocBuffer(); } void ODbaseTable::ReadMemoHeader() diff --git a/connectivity/source/drivers/dbase/dindexnode.cxx b/connectivity/source/drivers/dbase/dindexnode.cxx index ae105b8be512..1ac10800f0a9 100644 --- a/connectivity/source/drivers/dbase/dindexnode.cxx +++ b/connectivity/source/drivers/dbase/dindexnode.cxx @@ -997,24 +997,24 @@ void ONDXPage::SearchAndReplace(const ONDXKey& rSearch, ONDXKey const & rReplace) { OSL_ENSURE(rSearch != rReplace,"Invalid here:rSearch == rReplace"); - if (rSearch != rReplace) - { - sal_uInt16 nPos = NODE_NOTFOUND; - ONDXPage* pPage = this; + if (rSearch == rReplace) + return; - while (pPage) - { - nPos = pPage->Search(rSearch); - if (nPos != NODE_NOTFOUND) - break; - pPage = pPage->aParent; - } + sal_uInt16 nPos = NODE_NOTFOUND; + ONDXPage* pPage = this; - if (pPage) - { - (*pPage)[nPos].GetKey() = rReplace; - pPage->SetModified(true); - } + while (pPage) + { + nPos = pPage->Search(rSearch); + if (nPos != NODE_NOTFOUND) + break; + pPage = pPage->aParent; + } + + if (pPage) + { + (*pPage)[nPos].GetKey() = rReplace; + pPage->SetModified(true); } } diff --git a/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx b/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx index a5efdd2a0e6a..9eb6f1d34862 100644 --- a/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx +++ b/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx @@ -90,53 +90,53 @@ namespace connectivity::evoab static void initFields() { - if( !pFields ) + if( pFields ) + return; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( pFields ) + return; + + guint nProps; + ColumnProperty **pToBeFields; + GParamSpec **pProps; + nFields = 0; + pProps = g_object_class_list_properties + ( static_cast<GObjectClass *>(g_type_class_ref( E_TYPE_CONTACT )), + &nProps ); + pToBeFields = g_new0(ColumnProperty *, (nProps + OTHER_ZIP)/* new column(s)*/ ); + for ( guint i = 0; i < nProps; i++ ) { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if( !pFields ) + switch (pProps[i]->value_type) { - guint nProps; - ColumnProperty **pToBeFields; - GParamSpec **pProps; - nFields = 0; - pProps = g_object_class_list_properties - ( static_cast<GObjectClass *>(g_type_class_ref( E_TYPE_CONTACT )), - &nProps ); - pToBeFields = g_new0(ColumnProperty *, (nProps + OTHER_ZIP)/* new column(s)*/ ); - for ( guint i = 0; i < nProps; i++ ) + case G_TYPE_STRING: + case G_TYPE_BOOLEAN: { - switch (pProps[i]->value_type) + bool bAdd = true; + const char *pName = g_param_spec_get_name( pProps[i] ); + for (unsigned int j = 0; j < G_N_ELEMENTS( pBlackList ); j++ ) { - case G_TYPE_STRING: - case G_TYPE_BOOLEAN: + if( !strcmp( pBlackList[j], pName ) ) { - bool bAdd = true; - const char *pName = g_param_spec_get_name( pProps[i] ); - for (unsigned int j = 0; j < G_N_ELEMENTS( pBlackList ); j++ ) - { - if( !strcmp( pBlackList[j], pName ) ) - { - bAdd = false; - break; - } - } - if( bAdd ) - { - pToBeFields[nFields]= g_new0(ColumnProperty,1); - pToBeFields[nFields]->bIsSplittedValue=false; - pToBeFields[ nFields++ ]->pField = g_param_spec_ref( pProps[i] ); - } + bAdd = false; break; } - default: - break; } + if( bAdd ) + { + pToBeFields[nFields]= g_new0(ColumnProperty,1); + pToBeFields[nFields]->bIsSplittedValue=false; + pToBeFields[ nFields++ ]->pField = g_param_spec_ref( pProps[i] ); + } + break; } - - splitColumn(pToBeFields); - pFields = pToBeFields; + default: + break; } } + + splitColumn(pToBeFields); + pFields = pToBeFields; } diff --git a/connectivity/source/drivers/file/FPreparedStatement.cxx b/connectivity/source/drivers/file/FPreparedStatement.cxx index 6d74583935ca..fc5b81923cb4 100644 --- a/connectivity/source/drivers/file/FPreparedStatement.cxx +++ b/connectivity/source/drivers/file/FPreparedStatement.cxx @@ -482,17 +482,17 @@ void OPreparedStatement::describeParameter() { std::vector< OSQLParseNode*> aParseNodes; scanParameter(m_pParseTree,aParseNodes); - if ( !aParseNodes.empty() ) + if ( aParseNodes.empty() ) + return; + + // m_xParamColumns = new OSQLColumns(); + const OSQLTables& rTabs = m_aSQLIterator.getTables(); + if( !rTabs.empty() ) { - // m_xParamColumns = new OSQLColumns(); - const OSQLTables& rTabs = m_aSQLIterator.getTables(); - if( !rTabs.empty() ) + OSQLTable xTable = rTabs.begin()->second; + for (auto const& parseNode : aParseNodes) { - OSQLTable xTable = rTabs.begin()->second; - for (auto const& parseNode : aParseNodes) - { - describeColumn(parseNode,parseNode->getParent()->getChild(0),xTable); - } + describeColumn(parseNode,parseNode->getParent()->getChild(0),xTable); } } } @@ -501,36 +501,36 @@ void OPreparedStatement::initializeResultSet(OResultSet* pRS) OStatement_Base::initializeResultSet(pRS); // Substitute parameter (AssignValues and criteria): - if (!m_xParamColumns->empty()) - { - // begin with AssignValues - sal_uInt16 nParaCount=0; // gives the current number of previously set Parameters + if (m_xParamColumns->empty()) + return; - // search for parameters to be substituted: - size_t nCount = m_aAssignValues.is() ? m_aAssignValues->size() : 1; // 1 is important for the Criteria - for (size_t j = 1; j < nCount; j++) - { - sal_uInt32 nParameter = (*m_aAssignValues).getParameterIndex(j); - if (nParameter == SQL_NO_PARAMETER) - continue; // this AssignValue is no Parameter + // begin with AssignValues + sal_uInt16 nParaCount=0; // gives the current number of previously set Parameters - ++nParaCount; // now the Parameter is valid - } + // search for parameters to be substituted: + size_t nCount = m_aAssignValues.is() ? m_aAssignValues->size() : 1; // 1 is important for the Criteria + for (size_t j = 1; j < nCount; j++) + { + sal_uInt32 nParameter = (*m_aAssignValues).getParameterIndex(j); + if (nParameter == SQL_NO_PARAMETER) + continue; // this AssignValue is no Parameter - if (m_aParameterRow.is() && (m_xParamColumns->size()+1) != m_aParameterRow->size() ) + ++nParaCount; // now the Parameter is valid + } + + if (m_aParameterRow.is() && (m_xParamColumns->size()+1) != m_aParameterRow->size() ) + { + sal_Int32 i = m_aParameterRow->size(); + sal_Int32 nParamColumns = m_xParamColumns->size()+1; + m_aParameterRow->resize(nParamColumns); + for ( ;i < nParamColumns; ++i ) { - sal_Int32 i = m_aParameterRow->size(); - sal_Int32 nParamColumns = m_xParamColumns->size()+1; - m_aParameterRow->resize(nParamColumns); - for ( ;i < nParamColumns; ++i ) - { - if ( !(*m_aParameterRow)[i].is() ) - (*m_aParameterRow)[i] = new ORowSetValueDecorator; - } + if ( !(*m_aParameterRow)[i].is() ) + (*m_aParameterRow)[i] = new ORowSetValueDecorator; } - if (m_aParameterRow.is() && nParaCount < m_aParameterRow->size() ) - m_pSQLAnalyzer->bindParameterRow(m_aParameterRow); } + if (m_aParameterRow.is() && nParaCount < m_aParameterRow->size() ) + m_pSQLAnalyzer->bindParameterRow(m_aParameterRow); } void OPreparedStatement::parseParamterElem(const OUString& _sColumnName, OSQLParseNode* pRow_Value_Constructor_Elem) diff --git a/connectivity/source/drivers/file/FResultSet.cxx b/connectivity/source/drivers/file/FResultSet.cxx index 3b8f69d6ab6e..d7f3d6bd2090 100644 --- a/connectivity/source/drivers/file/FResultSet.cxx +++ b/connectivity/source/drivers/file/FResultSet.cxx @@ -1472,40 +1472,40 @@ void OResultSet::setBoundedColumns(const OValueRefRow& _rRow, } } // in this case we got more select columns as columns exist in the table - if ( _bSetColumnMapping && aSelectIters.size() != _rColMapping.size() ) - { - Reference<XNameAccess> xNameAccess(_xNames,UNO_QUERY); - Sequence< OUString > aSelectColumns = xNameAccess->getElementNames(); + if ( !(_bSetColumnMapping && aSelectIters.size() != _rColMapping.size()) ) + return; - for ( OSQLColumns::iterator aIter = _rxColumns->begin(); - aIter != _rxColumns->end(); - ++aIter - ) + Reference<XNameAccess> xNameAccess(_xNames,UNO_QUERY); + Sequence< OUString > aSelectColumns = xNameAccess->getElementNames(); + + for ( OSQLColumns::iterator aIter = _rxColumns->begin(); + aIter != _rxColumns->end(); + ++aIter + ) + { + if ( aSelectIters.end() == aSelectIters.find(aIter) ) { - if ( aSelectIters.end() == aSelectIters.find(aIter) ) - { - if ( (*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName) ) - (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName; - else - (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName; + if ( (*aIter)->getPropertySetInfo()->hasPropertyByName(sRealName) ) + (*aIter)->getPropertyValue(sRealName) >>= sSelectColumnRealName; + else + (*aIter)->getPropertyValue(sName) >>= sSelectColumnRealName; - if ( xNameAccess->hasByName( sSelectColumnRealName ) ) + if ( xNameAccess->hasByName( sSelectColumnRealName ) ) + { + aSelectIters.emplace(aIter,true); + sal_Int32 nSelectColumnPos = aIter - _rxColumns->begin() + 1; + const OUString* pBegin = aSelectColumns.getConstArray(); + const OUString* pEnd = pBegin + aSelectColumns.getLength(); + for(sal_Int32 i=0;pBegin != pEnd;++pBegin,++i) { - aSelectIters.emplace(aIter,true); - sal_Int32 nSelectColumnPos = aIter - _rxColumns->begin() + 1; - const OUString* pBegin = aSelectColumns.getConstArray(); - const OUString* pEnd = pBegin + aSelectColumns.getLength(); - for(sal_Int32 i=0;pBegin != pEnd;++pBegin,++i) + if ( aCase(*pBegin, sSelectColumnRealName) ) { - if ( aCase(*pBegin, sSelectColumnRealName) ) - { - // the getXXX methods are 1-based ... - sal_Int32 nTableColumnPos = i + 1; - // get first table column is the bookmark column ... - _rColMapping[nSelectColumnPos] = nTableColumnPos; - (*_rSelectRow)[nSelectColumnPos] = (*_rRow)[nTableColumnPos]; - break; - } + // the getXXX methods are 1-based ... + sal_Int32 nTableColumnPos = i + 1; + // get first table column is the bookmark column ... + _rColMapping[nSelectColumnPos] = nTableColumnPos; + (*_rSelectRow)[nSelectColumnPos] = (*_rRow)[nTableColumnPos]; + break; } } } diff --git a/connectivity/source/drivers/file/FStatement.cxx b/connectivity/source/drivers/file/FStatement.cxx index 28eef44ff71e..08c4f7fdd844 100644 --- a/connectivity/source/drivers/file/FStatement.cxx +++ b/connectivity/source/drivers/file/FStatement.cxx @@ -310,25 +310,25 @@ void OStatement_Base::anylizeSQL() m_pSQLAnalyzer->start(m_pParseTree); const OSQLParseNode* pOrderbyClause = m_aSQLIterator.getOrderTree(); - if(pOrderbyClause) + if(!pOrderbyClause) + return; + + OSQLParseNode * pOrderingSpecCommalist = pOrderbyClause->getChild(2); + OSL_ENSURE(SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),"OResultSet: Error in Parse Tree"); + + for (size_t m = 0; m < pOrderingSpecCommalist->count(); m++) { - OSQLParseNode * pOrderingSpecCommalist = pOrderbyClause->getChild(2); - OSL_ENSURE(SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),"OResultSet: Error in Parse Tree"); + OSQLParseNode * pOrderingSpec = pOrderingSpecCommalist->getChild(m); + OSL_ENSURE(SQL_ISRULE(pOrderingSpec,ordering_spec),"OResultSet: Error in Parse Tree"); + OSL_ENSURE(pOrderingSpec->count() == 2,"OResultSet: Error in Parse Tree"); - for (size_t m = 0; m < pOrderingSpecCommalist->count(); m++) + OSQLParseNode * pColumnRef = pOrderingSpec->getChild(0); + if(!SQL_ISRULE(pColumnRef,column_ref)) { - OSQLParseNode * pOrderingSpec = pOrderingSpecCommalist->getChild(m); - OSL_ENSURE(SQL_ISRULE(pOrderingSpec,ordering_spec),"OResultSet: Error in Parse Tree"); - OSL_ENSURE(pOrderingSpec->count() == 2,"OResultSet: Error in Parse Tree"); - - OSQLParseNode * pColumnRef = pOrderingSpec->getChild(0); - if(!SQL_ISRULE(pColumnRef,column_ref)) - { - throw SQLException(); - } - OSQLParseNode * pAscendingDescending = pOrderingSpec->getChild(1); - setOrderbyColumn(pColumnRef,pAscendingDescending); + throw SQLException(); } + OSQLParseNode * pAscendingDescending = pOrderingSpec->getChild(1); + setOrderbyColumn(pColumnRef,pAscendingDescending); } } diff --git a/connectivity/source/drivers/firebird/Blob.cxx b/connectivity/source/drivers/firebird/Blob.cxx index 3468a50ce3f4..8ed9fc4a8ac7 100644 --- a/connectivity/source/drivers/firebird/Blob.cxx +++ b/connectivity/source/drivers/firebird/Blob.cxx @@ -153,21 +153,21 @@ void Blob::closeBlob() { MutexGuard aGuard(m_aMutex); - if (m_bBlobOpened) - { - ISC_STATUS aErr; - aErr = isc_close_blob(m_statusVector, - &m_blobHandle); - if (aErr) - evaluateStatusVector(m_statusVector, "isc_close_blob", *this); + if (!m_bBlobOpened) + return; - m_bBlobOpened = false; + ISC_STATUS aErr; + aErr = isc_close_blob(m_statusVector, + &m_blobHandle); + if (aErr) + evaluateStatusVector(m_statusVector, "isc_close_blob", *this); + + m_bBlobOpened = false; #if SAL_TYPES_SIZEOFPOINTER == 8 - m_blobHandle = 0; + m_blobHandle = 0; #else - m_blobHandle = nullptr; + m_blobHandle = nullptr; #endif - } } void SAL_CALL Blob::disposing() diff --git a/connectivity/source/drivers/firebird/Connection.cxx b/connectivity/source/drivers/firebird/Connection.cxx index 58aad4e1939e..b5a3c4ce748a 100644 --- a/connectivity/source/drivers/firebird/Connection.cxx +++ b/connectivity/source/drivers/firebird/Connection.cxx @@ -791,49 +791,48 @@ void SAL_CALL Connection::documentEventOccured( const DocumentEvent& Event ) if (!m_bIsEmbedded) return; - if (Event.EventName == "OnSave" || Event.EventName == "OnSaveAs") - { - commit(); // Commit and close transaction - if ( m_bIsEmbedded && m_xEmbeddedStorage.is() ) - { - SAL_INFO("connectivity.firebird", "Writing .fbk from running db"); - try - { - runBackupService(isc_action_svc_backup); - } - catch (const SQLException& e) - { - auto a = cppu::getCaughtException(); - throw WrappedTargetRuntimeException(e.Message, e.Context, a); - } + if (!(Event.EventName == "OnSave" || Event.EventName == "OnSaveAs")) + return; + commit(); // Commit and close transaction + if ( !(m_bIsEmbedded && m_xEmbeddedStorage.is()) ) + return; + + SAL_INFO("connectivity.firebird", "Writing .fbk from running db"); + try + { + runBackupService(isc_action_svc_backup); + } + catch (const SQLException& e) + { + auto a = cppu::getCaughtException(); + throw WrappedTargetRuntimeException(e.Message, e.Context, a); + } - Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(our_sFBKLocation, - ElementModes::WRITE)); - // TODO: verify the backup actually exists -- the backup service - // can fail without giving any sane error messages / telling us - // that it failed. - using namespace ::comphelper; - Reference< XComponentContext > xContext = comphelper::getProcessComponentContext(); - Reference< XInputStream > xInputStream; - if (xContext.is()) - { - xInputStream = - OStorageHelper::GetInputStreamFromURL(m_sFBKPath, xContext); - if (xInputStream.is()) - OStorageHelper::CopyInputToOutput( xInputStream, - xDBStream->getOutputStream()); + Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(our_sFBKLocation, + ElementModes::WRITE)); - // remove old fdb file if exists - uno::Reference< ucb::XSimpleFileAccess > xFileAccess = - ucb::SimpleFileAccess::create(xContext); - if (xFileAccess->exists(m_sFirebirdURL)) - xFileAccess->kill(m_sFirebirdURL); - } - } + // TODO: verify the backup actually exists -- the backup service + // can fail without giving any sane error messages / telling us + // that it failed. + using namespace ::comphelper; + Reference< XComponentContext > xContext = comphelper::getProcessComponentContext(); + Reference< XInputStream > xInputStream; + if (!xContext.is()) + return; - } + xInputStream = + OStorageHelper::GetInputStreamFromURL(m_sFBKPath, xContext); + if (xInputStream.is()) + OStorageHelper::CopyInputToOutput( xInputStream, + xDBStream->getOutputStream()); + + // remove old fdb file if exists + uno::Reference< ucb::XSimpleFileAccess > xFileAccess = + ucb::SimpleFileAccess::create(xContext); + if (xFileAccess->exists(m_sFirebirdURL)) + xFileAccess->kill(m_sFirebirdURL); } // XEventListener void SAL_CALL Connection::disposing(const EventObject& /*rSource*/) diff --git a/connectivity/source/drivers/firebird/Keys.cxx b/connectivity/source/drivers/firebird/Keys.cxx index 90f3966efad7..dd4cca47fb20 100644 --- a/connectivity/source/drivers/firebird/Keys.cxx +++ b/connectivity/source/drivers/firebird/Keys.cxx @@ -34,20 +34,20 @@ Keys::Keys(Table* pTable, Mutex& rMutex, const ::std::vector< OUString>& rNames) //----- XDrop ---------------------------------------------------------------- void Keys::dropObject(sal_Int32 nPosition, const OUString& sName) { - if (!m_pTable->isNew()) - { - uno::Reference<XPropertySet> xKey(getObject(nPosition), UNO_QUERY); + if (m_pTable->isNew()) + return; + + uno::Reference<XPropertySet> xKey(getObject(nPosition), UNO_QUERY); - if (xKey.is()) - { - const OUString sQuote = m_pTable->getConnection()->getMetaData() - ->getIdentifierQuoteString(); + if (xKey.is()) + { + const OUString sQuote = m_pTable->getConnection()->getMetaData() + ->getIdentifierQuoteString(); - OUString sSql("ALTER TABLE " + quoteName(sQuote, m_pTable->getName()) - + " DROP CONSTRAINT " + quoteName(sQuote, sName)); + OUString sSql("ALTER TABLE " + quoteName(sQuote, m_pTable->getName()) + + " DROP CONSTRAINT " + quoteName(sQuote, sName)); - m_pTable->getConnection()->createStatement()->execute(sSql); - } + m_pTable->getConnection()->createStatement()->execute(sSql); } } diff --git a/connectivity/source/drivers/firebird/Table.cxx b/connectivity/source/drivers/firebird/Table.cxx index 0220a8458264..e0eba9d7e264 100644 --- a/connectivity/source/drivers/firebird/Table.cxx +++ b/connectivity/source/drivers/firebird/Table.cxx @@ -70,24 +70,24 @@ Table::Table(Tables* pTables, void Table::construct() { OTableHelper::construct(); - if (!isNew()) - { - // TODO: get privileges when in non-embedded mode. - m_nPrivileges = Privilege::DROP | - Privilege::REFERENCE | - Privilege::ALTER | - Privilege::CREATE | - Privilege::READ | - Privilege::DELETE | - Privilege::UPDATE | - Privilege::INSERT | - Privilege::SELECT; - registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRIVILEGES), - PROPERTY_ID_PRIVILEGES, - PropertyAttribute::READONLY, - &m_nPrivileges, - cppu::UnoType<decltype(m_nPrivileges)>::get()); - } + if (isNew()) + return; + + // TODO: get privileges when in non-embedded mode. + m_nPrivileges = Privilege::DROP | + Privilege::REFERENCE | + Privilege::ALTER | + Privilege::CREATE | + Privilege::READ | + Privilege::DELETE | + Privilege::UPDATE | + Privilege::INSERT | + Privilege::SELECT; + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRIVILEGES), + PROPERTY_ID_PRIVILEGES, + PropertyAttribute::READONLY, + &m_nPrivileges, + cppu::UnoType<decltype(m_nPrivileges)>::get()); } //----- OTableHelper --------------------------------------------------------- OCollection* Table::createColumns(const ::std::vector< OUString>& rNames) diff --git a/connectivity/source/drivers/firebird/Tables.cxx b/connectivity/source/drivers/firebird/Tables.cxx index 7be79b5a2d4a..34907418abf8 100644 --- a/connectivity/source/drivers/firebird/Tables.cxx +++ b/connectivity/source/drivers/firebird/Tables.cxx @@ -207,19 +207,19 @@ void Tables::dropObject(sal_Int32 nPosition, const OUString& sName) { uno::Reference< XPropertySet > xTable(getObject(nPosition)); - if (!ODescriptor::isNew(xTable)) - { - OUStringBuffer sSql("DROP "); + if (ODescriptor::isNew(xTable)) + return; - OUString sType; - xTable->getPropertyValue("Type") >>= sType; - sSql.append(sType); + OUStringBuffer sSql("DROP "); - const OUString sQuoteString = m_xMetaData->getIdentifierQuoteString(); - sSql.append(::dbtools::quoteName(sQuoteString,sName)); + OUString sType; + xTable->getPropertyValue("Type") >>= sType; + sSql.append(sType); - m_xMetaData->getConnection()->createStatement()->execute(sSql.makeStringAndClear()); - } + const OUString sQuoteString = m_xMetaData->getIdentifierQuoteString(); + sSql.append(::dbtools::quoteName(sQuoteString,sName)); + + m_xMetaData->getConnection()->createStatement()->execute(sSql.makeStringAndClear()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/flat/ETable.cxx b/connectivity/source/drivers/flat/ETable.cxx index 670fe46dffb0..43bc75225b1d 100644 --- a/connectivity/source/drivers/flat/ETable.cxx +++ b/connectivity/source/drivers/flat/ETable.cxx @@ -430,19 +430,19 @@ void OFlatTable::construct() if(!m_pFileStream) m_pFileStream = createStream_simpleError( aFileName, StreamMode::READ | StreamMode::NOCREATE | StreamMode::SHARE_DENYNONE); - if(m_pFileStream) - { - sal_uInt64 const nSize = m_pFileStream->remainingSize(); + if(!m_pFileStream) + return; - // Buffersize is dependent on the file-size - m_pFileStream->SetBufferSize(nSize > 1000000 ? 32768 : - nSize > 100000 ? 16384 : - nSize > 10000 ? 4096 : 1024); + sal_uInt64 const nSize = m_pFileStream->remainingSize(); - fillColumns(aAppLocale); + // Buffersize is dependent on the file-size + m_pFileStream->SetBufferSize(nSize > 1000000 ? 32768 : + nSize > 100000 ? 16384 : + nSize > 10000 ? 4096 : 1024); - refreshColumns(); - } + fillColumns(aAppLocale); + + refreshColumns(); } OUString OFlatTable::getEntry() const diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx b/connectivity/source/drivers/hsqldb/HDriver.cxx index 7e006ecb61a2..05b9478a9f12 100644 --- a/connectivity/source/drivers/hsqldb/HDriver.cxx +++ b/connectivity/source/drivers/hsqldb/HDriver.cxx @@ -611,41 +611,41 @@ namespace connectivity Reference< XStorage> xStorage(aEvent.Source,UNO_QUERY); OUString sKey = StorageContainer::getRegisteredKey(xStorage); - if ( !sKey.isEmpty() ) - { - TWeakPairVector::const_iterator i = std::find_if(m_aConnections.begin(), m_aConnections.end(), - [&sKey] (const TWeakPairVector::value_type& conn) { - return conn.second.first == sKey; - }); + if ( sKey.isEmpty() ) + return; + + TWeakPairVector::const_iterator i = std::find_if(m_aConnections.begin(), m_aConnections.end(), + [&sKey] (const TWeakPairVector::value_type& conn) { + return conn.second.first == sKey; + }); + + OSL_ENSURE( i != m_aConnections.end(), "ODriverDelegator::preCommit: they're committing a storage which I do not know!" ); + if ( i == m_aConnections.end() ) + return; - OSL_ENSURE( i != m_aConnections.end(), "ODriverDelegator::preCommit: they're committing a storage which I do not know!" ); - if ( i != m_aConnections.end() ) + try + { + Reference<XConnection> xConnection(i->first,UNO_QUERY); + if ( xConnection.is() ) { - try - { - Reference<XConnection> xConnection(i->first,UNO_QUERY); - if ( xConnection.is() ) - { - Reference< XStatement> xStmt = xConnection->createStatement(); - OSL_ENSURE( xStmt.is(), "ODriverDelegator::preCommit: no statement!" ); - if ( xStmt.is() ) - xStmt->execute( "SET WRITE_DELAY 0" ); - - bool bPreviousAutoCommit = xConnection->getAutoCommit(); - xConnection->setAutoCommit( false ); - xConnection->commit(); - xConnection->setAutoCommit( bPreviousAutoCommit ); - - if ( xStmt.is() ) - xStmt->execute( "SET WRITE_DELAY 60" ); - } - } - catch(Exception&) - { - TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "ODriverDelegator::preCommit" ); - } + Reference< XStatement> xStmt = xConnection->createStatement(); + OSL_ENSURE( xStmt.is(), "ODriverDelegator::preCommit: no statement!" ); + if ( xStmt.is() ) + xStmt->execute( "SET WRITE_DELAY 0" ); + + bool bPreviousAutoCommit = xConnection->getAutoCommit(); + xConnection->setAutoCommit( false ); + xConnection->commit(); + xConnection->setAutoCommit( bPreviousAutoCommit ); + + if ( xStmt.is() ) + xStmt->execute( "SET WRITE_DELAY 60" ); } } + catch(Exception&) + { + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "ODriverDelegator::preCommit" ); + } } void SAL_CALL ODriverDelegator::commited( const css::lang::EventObject& /*aEvent*/ ) diff --git a/connectivity/source/drivers/hsqldb/HStorageAccess.cxx b/connectivity/source/drivers/hsqldb/HStorageAccess.cxx index f5d4110a36f0..5ea16e7e1c60 100644 --- a/connectivity/source/drivers/hsqldb/HStorageAccess.cxx +++ b/connectivity/source/drivers/hsqldb/HStorageAccess.cxx @@ -343,53 +343,53 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Nativ Reference< XSeekable> xSeek = pHelper.get() ? pHelper->getSeek() : Reference< XSeekable>(); OSL_ENSURE(xSeek.is(),"No Seekable stream!"); - if ( xSeek.is() ) + if ( !xSeek.is() ) + return; + +#ifdef HSQLDB_DBG + DataLogFile aDataLog( env, name, "data" ); +#endif + + ::sal_Int64 nLen = xSeek->getLength(); + if ( nLen < position) { + static const ::sal_Int64 BUFFER_SIZE = 9192; #ifdef HSQLDB_DBG - DataLogFile aDataLog( env, name, "data" ); + aDataLog.seek( nLen ); #endif + xSeek->seek(nLen); + Reference< XOutputStream> xOut = pHelper->getOutputStream(); + OSL_ENSURE(xOut.is(),"No output stream!"); - ::sal_Int64 nLen = xSeek->getLength(); - if ( nLen < position) + ::sal_Int64 diff = position - nLen; + sal_Int32 n; + while( diff != 0 ) { - static const ::sal_Int64 BUFFER_SIZE = 9192; - #ifdef HSQLDB_DBG - aDataLog.seek( nLen ); - #endif - xSeek->seek(nLen); - Reference< XOutputStream> xOut = pHelper->getOutputStream(); - OSL_ENSURE(xOut.is(),"No output stream!"); - - ::sal_Int64 diff = position - nLen; - sal_Int32 n; - while( diff != 0 ) + if ( BUFFER_SIZE < diff ) { - if ( BUFFER_SIZE < diff ) - { - n = static_cast<sal_Int32>(BUFFER_SIZE); - diff = diff - BUFFER_SIZE; - } - else - { - n = static_cast<sal_Int32>(diff); - diff = 0; - } - Sequence< ::sal_Int8 > aData(n); - memset(aData.getArray(),0,n); - xOut->writeBytes(aData); - #ifdef HSQLDB_DBG - aDataLog.write( aData.getConstArray(), n ); - #endif + n = static_cast<sal_Int32>(BUFFER_SIZE); + diff = diff - BUFFER_SIZE; } + else + { + n = static_cast<sal_Int32>(diff); + diff = 0; + } + Sequence< ::sal_Int8 > aData(n); + memset(aData.getArray(),0,n); + xOut->writeBytes(aData); + #ifdef HSQLDB_DBG + aDataLog.write( aData.getConstArray(), n ); + #endif } - xSeek->seek(position); - OSL_ENSURE(xSeek->getPosition() == position,"Wrong position after seeking the stream"); - - #ifdef HSQLDB_DBG - aDataLog.seek( position ); - OSL_ENSURE( xSeek->getPosition() == aDataLog.tell(), "Wrong position after seeking the stream" ); - #endif } + xSeek->seek(position); + OSL_ENSURE(xSeek->getPosition() == position,"Wrong position after seeking the stream"); + +#ifdef HSQLDB_DBG + aDataLog.seek( position ); + OSL_ENSURE( xSeek->getPosition() == aDataLog.tell(), "Wrong position after seeking the stream" ); +#endif } diff --git a/connectivity/source/drivers/hsqldb/HStorageMap.cxx b/connectivity/source/drivers/hsqldb/HStorageMap.cxx index 598ef060bc4c..d10ee29a69f6 100644 --- a/connectivity/source/drivers/hsqldb/HStorageMap.cxx +++ b/connectivity/source/drivers/hsqldb/HStorageMap.cxx @@ -233,25 +233,25 @@ namespace connectivity::hsqldb { TStorages& rMap = lcl_getStorageMap(); TStorages::iterator aFind = rMap.find(_sKey); - if ( aFind != rMap.end() ) + if ( aFind == rMap.end() ) + return; + + try { - try + if ( _xListener.is() ) { - if ( _xListener.is() ) - { - Reference<XTransactionBroadcaster> xBroad(aFind->second.mapStorage(),UNO_QUERY); - if ( xBroad.is() ) - xBroad->removeTransactionListener(_xListener); - Reference<XTransactedObject> xTrans(aFind->second.mapStorage(),UNO_QUERY); - if ( xTrans.is() ) - xTrans->commit(); - } + Reference<XTransactionBroadcaster> xBroad(aFind->second.mapStorage(),UNO_QUERY); + if ( xBroad.is() ) + xBroad->removeTransactionListener(_xListener); + Reference<XTransactedObject> xTrans(aFind->second.mapStorage(),UNO_QUERY); + if ( xTrans.is() ) + xTrans->commit(); } - catch(const Exception&) - { - } - rMap.erase(aFind); } + catch(const Exception&) + { + } + rMap.erase(aFind); } TStreamMap::mapped_type StorageContainer::registerStream(JNIEnv * env,jstring name, jstring key,sal_Int32 _nMode) diff --git a/connectivity/source/drivers/hsqldb/HTables.cxx b/connectivity/source/drivers/hsqldb/HTables.cxx index b98d57c774ab..787af894b992 100644 --- a/connectivity/source/drivers/hsqldb/HTables.cxx +++ b/connectivity/source/drivers/hsqldb/HTables.cxx @@ -110,39 +110,39 @@ void OTables::dropObject(sal_Int32 _nPos,const OUString& _sElementName) { Reference< XInterface > xObject( getObject( _nPos ) ); bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject ); - if (!bIsNew) - { - Reference< XConnection > xConnection = static_cast<OHCatalog&>(m_rParent).getConnection(); + if (bIsNew) + return; + Reference< XConnection > xConnection = static_cast<OHCatalog&>(m_rParent).getConnection(); - OUString sCatalog,sSchema,sTable; - ::dbtools::qualifiedNameComponents(m_xMetaData,_sElementName,sCatalog,sSchema,sTable,::dbtools::EComposeRule::InDataManipulation); - OUString aSql( "DROP " ); + OUString sCatalog,sSchema,sTable; + ::dbtools::qualifiedNameComponents(m_xMetaData,_sElementName,sCatalog,sSchema,sTable,::dbtools::EComposeRule::InDataManipulation); - Reference<XPropertySet> xProp(xObject,UNO_QUERY); - bool bIsView; - if((bIsView = (xProp.is() && ::comphelper::getString(xProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))) == "VIEW"))) // here we have a view - aSql += "VIEW "; - else - aSql += "TABLE "; + OUString aSql( "DROP " ); - OUString sComposedName( - ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, true, ::dbtools::EComposeRule::InDataManipulation ) ); - aSql += sComposedName; - Reference< XStatement > xStmt = xConnection->createStatement( ); - if ( xStmt.is() ) - { - xStmt->execute(aSql); - ::comphelper::disposeComponent(xStmt); - } - // if no exception was thrown we must delete it from the views - if ( bIsView ) - { - HViews* pViews = static_cast<HViews*>(static_cast<OHCatalog&>(m_rParent).getPrivateViews()); - if ( pViews && pViews->hasByName(_sElementName) ) - pViews->dropByNameImpl(_sElementName); - } + Reference<XPropertySet> xProp(xObject,UNO_QUERY); + bool bIsView; + if((bIsView = (xProp.is() && ::comphelper::getString(xProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))) == "VIEW"))) // here we have a view + aSql += "VIEW "; + else + aSql += "TABLE "; + + OUString sComposedName( + ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, true, ::dbtools::EComposeRule::InDataManipulation ) ); + aSql += sComposedName; + Reference< XStatement > xStmt = xConnection->createStatement( ); + if ( xStmt.is() ) + { + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + } + // if no exception was thrown we must delete it from the views + if ( bIsView ) + { + HViews* pViews = static_cast<HViews*>(static_cast<OHCatalog&>(m_rParent).getPrivateViews()); + if ( pViews && pViews->hasByName(_sElementName) ) + pViews->dropByNameImpl(_sElementName); } } diff --git a/connectivity/source/drivers/hsqldb/HUser.cxx b/connectivity/source/drivers/hsqldb/HUser.cxx index 0c413d117b0b..2ed0c06262ff 100644 --- a/connectivity/source/drivers/hsqldb/HUser.cxx +++ b/connectivity/source/drivers/hsqldb/HUser.cxx @@ -118,79 +118,79 @@ void OHSQLUser::findPrivilegesAndGrantPrivileges(const OUString& objName, sal_In break; } - if ( xRes.is() ) - { - static const char sYes [] = "YES"; + if ( !xRes.is() ) + return; - nRightsWithGrant = nRights = 0; + static const char sYes [] = "YES"; - Reference<XRow> xCurrentRow(xRes,UNO_QUERY); - while( xCurrentRow.is() && xRes->next() ) - { - OUString sGrantee = xCurrentRow->getString(5); - OUString sPrivilege = xCurrentRow->getString(6); - OUString sGrantable = xCurrentRow->getString(7); + nRightsWithGrant = nRights = 0; - if (!m_Name.equalsIgnoreAsciiCase(sGrantee)) - continue; + Reference<XRow> xCurrentRow(xRes,UNO_QUERY); + while( xCurrentRow.is() && xRes->next() ) + { + OUString sGrantee = xCurrentRow->getString(5); + OUString sPrivilege = xCurrentRow->getString(6); + OUString sGrantable = xCurrentRow->getString(7); - if (sPrivilege.equalsIgnoreAsciiCase("SELECT")) - { - nRights |= Privilege::SELECT; - if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) - nRightsWithGrant |= Privilege::SELECT; - } - else if (sPrivilege.equalsIgnoreAsciiCase("INSERT")) - { - nRights |= Privilege::INSERT; - if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) - nRightsWithGrant |= Privilege::INSERT; - } - else if (sPrivilege.equalsIgnoreAsciiCase("UPDATE")) - { - nRights |= Privilege::UPDATE; - if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) - nRightsWithGrant |= Privilege::UPDATE; - } - else if (sPrivilege.equalsIgnoreAsciiCase("DELETE")) - { - nRights |= Privilege::DELETE; - if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) - nRightsWithGrant |= Privilege::DELETE; - } - else if (sPrivilege.equalsIgnoreAsciiCase("READ")) - { - nRights |= Privilege::READ; - if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) - nRightsWithGrant |= Privilege::READ; - } - else if (sPrivilege.equalsIgnoreAsciiCase("CREATE")) - { - nRights |= Privilege::CREATE; - if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) - nRightsWithGrant |= Privilege::CREATE; - } - else if (sPrivilege.equalsIgnoreAsciiCase("ALTER")) - { - nRights |= Privilege::ALTER; - if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) - nRightsWithGrant |= Privilege::ALTER; - } - else if (sPrivilege.equalsIgnoreAsciiCase("REFERENCE")) - { - nRights |= Privilege::REFERENCE; - if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) - nRightsWithGrant |= Privilege::REFERENCE; - } - else if (sPrivilege.equalsIgnoreAsciiCase("DROP")) - { - nRights |= Privilege::DROP; - if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) - nRightsWithGrant |= Privilege::DROP; - } + if (!m_Name.equalsIgnoreAsciiCase(sGrantee)) + continue; + + if (sPrivilege.equalsIgnoreAsciiCase("SELECT")) + { + nRights |= Privilege::SELECT; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::SELECT; + } + else if (sPrivilege.equalsIgnoreAsciiCase("INSERT")) + { + nRights |= Privilege::INSERT; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::INSERT; + } + else if (sPrivilege.equalsIgnoreAsciiCase("UPDATE")) + { + nRights |= Privilege::UPDATE; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::UPDATE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("DELETE")) + { + nRights |= Privilege::DELETE; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::DELETE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("READ")) + { + nRights |= Privilege::READ; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::READ; + } + else if (sPrivilege.equalsIgnoreAsciiCase("CREATE")) + { + nRights |= Privilege::CREATE; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::CREATE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("ALTER")) + { + nRights |= Privilege::ALTER; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::ALTER; + } + else if (sPrivilege.equalsIgnoreAsciiCase("REFERENCE")) + { + nRights |= Privilege::REFERENCE; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::REFERENCE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("DROP")) + { + nRights |= Privilege::DROP; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::DROP; } - ::comphelper::disposeComponent(xRes); } + ::comphelper::disposeComponent(xRes); } sal_Int32 SAL_CALL OHSQLUser::getGrantablePrivileges( const OUString& objName, sal_Int32 objType ) diff --git a/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx b/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx index b8b698f50254..3e8461a95f8f 100644 --- a/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx +++ b/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx @@ -101,22 +101,22 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stora #endif TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); auto storage = aStoragePair.mapStorage(); - if ( storage.is() ) + if ( !storage.is() ) + return; + + try { - try - { - storage->removeElement(StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,name),aStoragePair.url)); - } - catch(const NoSuchElementException&) - { - if (env->ExceptionCheck()) - env->ExceptionClear(); - } - catch(const Exception& e) - { - TOOLS_WARN_EXCEPTION("connectivity.hsqldb", ""); - StorageContainer::throwJavaException(e,env); - } + storage->removeElement(StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,name),aStoragePair.url)); + } + catch(const NoSuchElementException&) + { + if (env->ExceptionCheck()) + env->ExceptionClear(); + } + catch(const Exception& e) + { + TOOLS_WARN_EXCEPTION("connectivity.hsqldb", ""); + StorageContainer::throwJavaException(e,env); } } @@ -138,29 +138,29 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stora #endif TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); auto storage = aStoragePair.mapStorage(); - if ( storage.is() ) + if ( !storage.is() ) + return; + + try { - try - { - storage->renameElement( - StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,oldname),aStoragePair.url), - StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.url) - ); + storage->renameElement( + StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,oldname),aStoragePair.url), + StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.url) + ); #ifdef HSQLDB_DBG - { - OUString sNewName = StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second); - OSL_ENSURE(aStoragePair.first.first->isStreamElement(sNewName),"Stream could not be renamed"); - } -#endif - } - catch(const NoSuchElementException&) - { - } - catch(const Exception& e) { - OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement"); - StorageContainer::throwJavaException(e,env); + OUString sNewName = StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second); + OSL_ENSURE(aStoragePair.first.first->isStreamElement(sNewName),"Stream could not be renamed"); } +#endif + } + catch(const NoSuchElementException&) + { + } + catch(const Exception& e) + { + OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement"); + StorageContainer::throwJavaException(e,env); } } diff --git a/connectivity/source/drivers/jdbc/CallableStatement.cxx b/connectivity/source/drivers/jdbc/CallableStatement.cxx index 720b9c9a8ff1..0994c827e29a 100644 --- a/connectivity/source/drivers/jdbc/CallableStatement.cxx +++ b/connectivity/source/drivers/jdbc/CallableStatement.cxx @@ -317,37 +317,37 @@ void java_sql_CallableStatement::createStatement(JNIEnv* /*_pEnv*/) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); - SDBThreadAttach t; OSL_ENSURE(t.pEnv,"Java environment has been deleted!"); - if( t.pEnv && !object ){ - // initialize temporary variable - static const char * const cMethodName = "prepareCall"; - // execute Java-Call - jobject out = nullptr; - // convert Parameter - jdbc::LocalRef< jstring > str( t.env(),convertwchar_tToJavaString(t.pEnv,m_sSqlStatement)); - - static jmethodID mID = [&]() - { - static const char * const cSignature = "(Ljava/lang/String;II)Ljava/sql/CallableStatement;"; - return t.pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature ); - }(); - if( mID ){ - out = t.pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID, str.get() ,m_nResultSetType,m_nResultSetConcurrency); + if( !(t.pEnv && !object) ) + return; + + // initialize temporary variable + static const char * const cMethodName = "prepareCall"; + // execute Java-Call + jobject out = nullptr; + // convert Parameter + jdbc::LocalRef< jstring > str( t.env(),convertwchar_tToJavaString(t.pEnv,m_sSqlStatement)); + + static jmethodID mID = [&]() + { + static const char * const cSignature = "(Ljava/lang/String;II)Ljava/sql/CallableStatement;"; + return t.pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature ); + }(); + if( mID ){ + out = t.pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID, str.get() ,m_nResultSetType,m_nResultSetConcurrency); + } //mID + else + { + static const char * const cSignature2 = "(Ljava/lang/String;)Ljava/sql/CallableStatement;"; + static jmethodID mID2 = t.pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );OSL_ENSURE(mID2,"Unknown method id!"); + if( mID2 ){ + out = t.pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2, str.get() ); } //mID - else - { - static const char * const cSignature2 = "(Ljava/lang/String;)Ljava/sql/CallableStatement;"; - static jmethodID mID2 = t.pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );OSL_ENSURE(mID2,"Unknown method id!"); - if( mID2 ){ - out = t.pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2, str.get() ); - } //mID - } - ThrowLoggedSQLException( m_aLogger, t.pEnv, *this ); + } + ThrowLoggedSQLException( m_aLogger, t.pEnv, *this ); - if ( out ) - object = t.pEnv->NewGlobalRef( out ); - } //t.pEnv + if ( out ) + object = t.pEnv->NewGlobalRef( out ); } diff --git a/connectivity/source/drivers/jdbc/JConnection.cxx b/connectivity/source/drivers/jdbc/JConnection.cxx index 6def8948abee..1d33f2941316 100644 --- a/connectivity/source/drivers/jdbc/JConnection.cxx +++ b/connectivity/source/drivers/jdbc/JConnection.cxx @@ -261,21 +261,21 @@ java_sql_Connection::java_sql_Connection( const java_sql_Driver& _rDriver ) java_sql_Connection::~java_sql_Connection() { ::rtl::Reference< jvmaccess::VirtualMachine > xTest = java_lang_Object::getVM(); - if ( xTest.is() ) - { - SDBThreadAttach t; - clearObject(*t.pEnv); + if ( !xTest.is() ) + return; - { - if ( m_pDriverobject ) - t.pEnv->DeleteGlobalRef( m_pDriverobject ); - m_pDriverobject = nullptr; - if ( m_Driver_theClass ) - t.pEnv->DeleteGlobalRef( m_Driver_theClass ); - m_Driver_theClass = nullptr; - } - SDBThreadAttach::releaseRef(); + SDBThreadAttach t; + clearObject(*t.pEnv); + + { + if ( m_pDriverobject ) + t.pEnv->DeleteGlobalRef( m_pDriverobject ); + m_pDriverobject = nullptr; + if ( m_Driver_theClass ) + t.pEnv->DeleteGlobalRef( m_Driver_theClass ); + m_Driver_theClass = nullptr; } + SDBThreadAttach::releaseRef(); } void java_sql_Connection::disposing() diff --git a/connectivity/source/drivers/jdbc/JStatement.cxx b/connectivity/source/drivers/jdbc/JStatement.cxx index 32ffe22a4897..9bfe11838b7f 100644 --- a/connectivity/source/drivers/jdbc/JStatement.cxx +++ b/connectivity/source/drivers/jdbc/JStatement.cxx @@ -761,33 +761,34 @@ void java_sql_Statement::createStatement(JNIEnv* _pEnv) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); - if( _pEnv && !object ){ - // initialize temporary variable - static const char * const cMethodName = "createStatement"; - // Java-Call - jobject out = nullptr; - static jmethodID mID(nullptr); - if ( !mID ) - { - static const char * const cSignature = "(II)Ljava/sql/Statement;"; - mID = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature ); - } - if( mID ){ - out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID,m_nResultSetType,m_nResultSetConcurrency ); + if( !(_pEnv && !object) ) + return; + + // initialize temporary variable + static const char * const cMethodName = "createStatement"; + // Java-Call + jobject out = nullptr; + static jmethodID mID(nullptr); + if ( !mID ) + { + static const char * const cSignature = "(II)Ljava/sql/Statement;"; + mID = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature ); + } + if( mID ){ + out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID,m_nResultSetType,m_nResultSetConcurrency ); + } //mID + else + { + static const char * const cSignature2 = "()Ljava/sql/Statement;"; + static jmethodID mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );OSL_ENSURE(mID2,"Unknown method id!"); + if( mID2 ){ + out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2); } //mID - else - { - static const char * const cSignature2 = "()Ljava/sql/Statement;"; - static jmethodID mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 );OSL_ENSURE(mID2,"Unknown method id!"); - if( mID2 ){ - out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2); - } //mID - } - ThrowLoggedSQLException( m_aLogger, _pEnv, *this ); + } + ThrowLoggedSQLException( m_aLogger, _pEnv, *this ); - if ( out ) - object = _pEnv->NewGlobalRef( out ); - } //_pEnv + if ( out ) + object = _pEnv->NewGlobalRef( out ); } diff --git a/connectivity/source/drivers/jdbc/PreparedStatement.cxx b/connectivity/source/drivers/jdbc/PreparedStatement.cxx index a01df751c4a0..34c28f084677 100644 --- a/connectivity/source/drivers/jdbc/PreparedStatement.cxx +++ b/connectivity/source/drivers/jdbc/PreparedStatement.cxx @@ -655,41 +655,42 @@ void java_sql_PreparedStatement::createStatement(JNIEnv* _pEnv) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(java_sql_Statement_BASE::rBHelper.bDisposed); - if( !object && _pEnv ){ - // initialize temporary variable - static const char * const cMethodName = "prepareStatement"; + if( !(!object && _pEnv) ) + return; - jvalue args[1]; - // convert Parameter - args[0].l = convertwchar_tToJavaString(_pEnv,m_sSqlStatement); - // Java-Call - jobject out = nullptr; - static jmethodID mID(nullptr); - if ( !mID ) - { - static const char * const cSignature = "(Ljava/lang/String;II)Ljava/sql/PreparedStatement;"; - mID = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature ); - } - if( mID ) - { - out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID, args[0].l ,m_nResultSetType,m_nResultSetConcurrency); - } - else + // initialize temporary variable + static const char * const cMethodName = "prepareStatement"; + + jvalue args[1]; + // convert Parameter + args[0].l = convertwchar_tToJavaString(_pEnv,m_sSqlStatement); + // Java-Call + jobject out = nullptr; + static jmethodID mID(nullptr); + if ( !mID ) + { + static const char * const cSignature = "(Ljava/lang/String;II)Ljava/sql/PreparedStatement;"; + mID = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature ); + } + if( mID ) + { + out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID, args[0].l ,m_nResultSetType,m_nResultSetConcurrency); + } + else + { + static jmethodID mID2 = nullptr; + if ( !mID2 ) { - static jmethodID mID2 = nullptr; - if ( !mID2 ) - { - static const char * const cSignature2 = "(Ljava/lang/String;)Ljava/sql/PreparedStatement;"; - mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 ); - } - if ( mID2 ) - out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2, args[0].l ); + static const char * const cSignature2 = "(Ljava/lang/String;)Ljava/sql/PreparedStatement;"; + mID2 = _pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature2 ); } - _pEnv->DeleteLocalRef(static_cast<jstring>(args[0].l)); - ThrowLoggedSQLException( m_aLogger, _pEnv, *this ); - if ( out ) - object = _pEnv->NewGlobalRef( out ); - } //t.pEnv + if ( mID2 ) + out = _pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID2, args[0].l ); + } + _pEnv->DeleteLocalRef(static_cast<jstring>(args[0].l)); + ThrowLoggedSQLException( m_aLogger, _pEnv, *this ); + if ( out ) + object = _pEnv->NewGlobalRef( out ); } diff --git a/connectivity/source/drivers/mork/MPreparedStatement.cxx b/connectivity/source/drivers/mork/MPreparedStatement.cxx index d61a0ec96a51..f2cd8fdc752e 100644 --- a/connectivity/source/drivers/mork/MPreparedStatement.cxx +++ b/connectivity/source/drivers/mork/MPreparedStatement.cxx @@ -431,17 +431,17 @@ void OPreparedStatement::describeParameter() { std::vector< OSQLParseNode*> aParseNodes; scanParameter(m_pParseTree.get(), aParseNodes); - if(!aParseNodes.empty()) + if(aParseNodes.empty()) + return; + + m_xParamColumns = new OSQLColumns(); + const OSQLTables& rTabs = m_pSQLIterator->getTables(); + if(!rTabs.empty()) { - m_xParamColumns = new OSQLColumns(); - const OSQLTables& rTabs = m_pSQLIterator->getTables(); - if(!rTabs.empty()) + OSQLTable xTable = rTabs.begin()->second; + for (auto const& parseNode : aParseNodes) { - OSQLTable xTable = rTabs.begin()->second; - for (auto const& parseNode : aParseNodes) - { - describeColumn(parseNode,parseNode->getParent()->getChild(0),xTable); - } + describeColumn(parseNode,parseNode->getParent()->getChild(0),xTable); } } } diff --git a/connectivity/source/drivers/mork/MStatement.cxx b/connectivity/source/drivers/mork/MStatement.cxx index fc97ab20b15d..bd153afa6438 100644 --- a/connectivity/source/drivers/mork/MStatement.cxx +++ b/connectivity/source/drivers/mork/MStatement.cxx @@ -420,25 +420,25 @@ void OCommonStatement::createColumnMapping() void OCommonStatement::analyseSQL() { const OSQLParseNode* pOrderbyClause = m_pSQLIterator->getOrderTree(); - if(pOrderbyClause) + if(!pOrderbyClause) + return; + + OSQLParseNode * pOrderingSpecCommalist = pOrderbyClause->getChild(2); + OSL_ENSURE(SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),"OResultSet: Error in Parse Tree"); + + for (size_t m = 0; m < pOrderingSpecCommalist->count(); m++) { - OSQLParseNode * pOrderingSpecCommalist = pOrderbyClause->getChild(2); - OSL_ENSURE(SQL_ISRULE(pOrderingSpecCommalist,ordering_spec_commalist),"OResultSet: Error in Parse Tree"); + OSQLParseNode * pOrderingSpec = pOrderingSpecCommalist->getChild(m); + OSL_ENSURE(SQL_ISRULE(pOrderingSpec,ordering_spec),"OResultSet: Error in Parse Tree"); + OSL_ENSURE(pOrderingSpec->count() == 2,"OResultSet: Error in Parse Tree"); - for (size_t m = 0; m < pOrderingSpecCommalist->count(); m++) + OSQLParseNode * pColumnRef = pOrderingSpec->getChild(0); + if(!SQL_ISRULE(pColumnRef,column_ref)) { - OSQLParseNode * pOrderingSpec = pOrderingSpecCommalist->getChild(m); - OSL_ENSURE(SQL_ISRULE(pOrderingSpec,ordering_spec),"OResultSet: Error in Parse Tree"); - OSL_ENSURE(pOrderingSpec->count() == 2,"OResultSet: Error in Parse Tree"); - - OSQLParseNode * pColumnRef = pOrderingSpec->getChild(0); - if(!SQL_ISRULE(pColumnRef,column_ref)) - { - throw SQLException(); - } - OSQLParseNode * pAscendingDescending = pOrderingSpec->getChild(1); - setOrderbyColumn(pColumnRef,pAscendingDescending); + throw SQLException(); } + OSQLParseNode * pAscendingDescending = pOrderingSpec->getChild(1); + setOrderbyColumn(pColumnRef,pAscendingDescending); } } diff --git a/connectivity/source/drivers/mysql_jdbc/YTables.cxx b/connectivity/source/drivers/mysql_jdbc/YTables.cxx index 83b60fff5f15..e21e05fb2914 100644 --- a/connectivity/source/drivers/mysql_jdbc/YTables.cxx +++ b/connectivity/source/drivers/mysql_jdbc/YTables.cxx @@ -104,44 +104,43 @@ void OTables::dropObject(sal_Int32 _nPos, const OUString& _sElementName) { Reference<XInterface> xObject(getObject(_nPos)); bool bIsNew = connectivity::sdbcx::ODescriptor::isNew(xObject); - if (!bIsNew) + if (bIsNew) + return; + + Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection(); + + OUString sCatalog, sSchema, sTable; + ::dbtools::qualifiedNameComponents(m_xMetaData, _sElementName, sCatalog, sSchema, sTable, + ::dbtools::EComposeRule::InDataManipulation); + + OUString aSql("DROP "); + + Reference<XPropertySet> xProp(xObject, UNO_QUERY); + bool bIsView = xProp.is() + && ::comphelper::getString(xProp->getPropertyValue( + OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))) + == "VIEW"; + if (bIsView) // here we have a view + aSql += "VIEW "; + else + aSql += "TABLE "; + + OUString sComposedName(::dbtools::composeTableName( + m_xMetaData, sCatalog, sSchema, sTable, true, ::dbtools::EComposeRule::InDataManipulation)); + aSql += sComposedName; + Reference<XStatement> xStmt = xConnection->createStatement(); + if (xStmt.is()) { - Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection(); - - OUString sCatalog, sSchema, sTable; - ::dbtools::qualifiedNameComponents(m_xMetaData, _sElementName, sCatalog, sSchema, sTable, - ::dbtools::EComposeRule::InDataManipulation); - - OUString aSql("DROP "); - - Reference<XPropertySet> xProp(xObject, UNO_QUERY); - bool bIsView = xProp.is() - && ::comphelper::getString(xProp->getPropertyValue( - OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))) - == "VIEW"; - if (bIsView) // here we have a view - aSql += "VIEW "; - else - aSql += "TABLE "; - - OUString sComposedName( - ::dbtools::composeTableName(m_xMetaData, sCatalog, sSchema, sTable, true, - ::dbtools::EComposeRule::InDataManipulation)); - aSql += sComposedName; - Reference<XStatement> xStmt = xConnection->createStatement(); - if (xStmt.is()) - { - xStmt->execute(aSql); - ::comphelper::disposeComponent(xStmt); - } - // if no exception was thrown we must delete it from the views - if (bIsView) - { - OViews* pViews - = static_cast<OViews*>(static_cast<OMySQLCatalog&>(m_rParent).getPrivateViews()); - if (pViews && pViews->hasByName(_sElementName)) - pViews->dropByNameImpl(_sElementName); - } + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + } + // if no exception was thrown we must delete it from the views + if (bIsView) + { + OViews* pViews + = static_cast<OViews*>(static_cast<OMySQLCatalog&>(m_rParent).getPrivateViews()); + if (pViews && pViews->hasByName(_sElementName)) + pViews->dropByNameImpl(_sElementName); } } diff --git a/connectivity/source/drivers/mysql_jdbc/YUser.cxx b/connectivity/source/drivers/mysql_jdbc/YUser.cxx index c5031f3c0205..b683fe2b2757 100644 --- a/connectivity/source/drivers/mysql_jdbc/YUser.cxx +++ b/connectivity/source/drivers/mysql_jdbc/YUser.cxx @@ -121,79 +121,79 @@ void OMySQLUser::findPrivilegesAndGrantPrivileges(const OUString& objName, sal_I break; } - if (xRes.is()) + if (!xRes.is()) + return; + + static const char sYes[] = "YES"; + + nRightsWithGrant = nRights = 0; + + Reference<XRow> xCurrentRow(xRes, UNO_QUERY); + while (xCurrentRow.is() && xRes->next()) { - static const char sYes[] = "YES"; + OUString sGrantee = xCurrentRow->getString(5); + OUString sPrivilege = xCurrentRow->getString(6); + OUString sGrantable = xCurrentRow->getString(7); - nRightsWithGrant = nRights = 0; + if (!m_Name.equalsIgnoreAsciiCase(sGrantee)) + continue; - Reference<XRow> xCurrentRow(xRes, UNO_QUERY); - while (xCurrentRow.is() && xRes->next()) + if (sPrivilege.equalsIgnoreAsciiCase("SELECT")) + { + nRights |= Privilege::SELECT; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::SELECT; + } + else if (sPrivilege.equalsIgnoreAsciiCase("INSERT")) + { + nRights |= Privilege::INSERT; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::INSERT; + } + else if (sPrivilege.equalsIgnoreAsciiCase("UPDATE")) + { + nRights |= Privilege::UPDATE; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::UPDATE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("DELETE")) + { + nRights |= Privilege::DELETE; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::DELETE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("READ")) + { + nRights |= Privilege::READ; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::READ; + } + else if (sPrivilege.equalsIgnoreAsciiCase("CREATE")) + { + nRights |= Privilege::CREATE; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::CREATE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("ALTER")) + { + nRights |= Privilege::ALTER; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::ALTER; + } + else if (sPrivilege.equalsIgnoreAsciiCase("REFERENCES")) { - OUString sGrantee = xCurrentRow->getString(5); - OUString sPrivilege = xCurrentRow->getString(6); - OUString sGrantable = xCurrentRow->getString(7); - - if (!m_Name.equalsIgnoreAsciiCase(sGrantee)) - continue; - - if (sPrivilege.equalsIgnoreAsciiCase("SELECT")) - { - nRights |= Privilege::SELECT; - if (sGrantable.equalsIgnoreAsciiCase(sYes)) - nRightsWithGrant |= Privilege::SELECT; - } - else if (sPrivilege.equalsIgnoreAsciiCase("INSERT")) - { - nRights |= Privilege::INSERT; - if (sGrantable.equalsIgnoreAsciiCase(sYes)) - nRightsWithGrant |= Privilege::INSERT; - } - else if (sPrivilege.equalsIgnoreAsciiCase("UPDATE")) - { - nRights |= Privilege::UPDATE; - if (sGrantable.equalsIgnoreAsciiCase(sYes)) - nRightsWithGrant |= Privilege::UPDATE; - } - else if (sPrivilege.equalsIgnoreAsciiCase("DELETE")) - { - nRights |= Privilege::DELETE; - if (sGrantable.equalsIgnoreAsciiCase(sYes)) - nRightsWithGrant |= Privilege::DELETE; - } - else if (sPrivilege.equalsIgnoreAsciiCase("READ")) - { - nRights |= Privilege::READ; - if (sGrantable.equalsIgnoreAsciiCase(sYes)) - nRightsWithGrant |= Privilege::READ; - } - else if (sPrivilege.equalsIgnoreAsciiCase("CREATE")) - { - nRights |= Privilege::CREATE; - if (sGrantable.equalsIgnoreAsciiCase(sYes)) - nRightsWithGrant |= Privilege::CREATE; - } - else if (sPrivilege.equalsIgnoreAsciiCase("ALTER")) - { - nRights |= Privilege::ALTER; - if (sGrantable.equalsIgnoreAsciiCase(sYes)) - nRightsWithGrant |= Privilege::ALTER; - } - else if (sPrivilege.equalsIgnoreAsciiCase("REFERENCES")) - { - nRights |= Privilege::REFERENCE; - if (sGrantable.equalsIgnoreAsciiCase(sYes)) - nRightsWithGrant |= Privilege::REFERENCE; - } - else if (sPrivilege.equalsIgnoreAsciiCase("DROP")) - { - nRights |= Privilege::DROP; - if (sGrantable.equalsIgnoreAsciiCase(sYes)) - nRightsWithGrant |= Privilege::DROP; - } + nRights |= Privilege::REFERENCE; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::REFERENCE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("DROP")) + { + nRights |= Privilege::DROP; + if (sGrantable.equalsIgnoreAsciiCase(sYes)) + nRightsWithGrant |= Privilege::DROP; } - ::comphelper::disposeComponent(xRes); } + ::comphelper::disposeComponent(xRes); } sal_Int32 SAL_CALL OMySQLUser::getGrantablePrivileges(const OUString& objName, sal_Int32 objType) @@ -219,19 +219,19 @@ void SAL_CALL OMySQLUser::grantPrivileges(const OUString& objName, sal_Int32 obj ::osl::MutexGuard aGuard(m_aMutex); OUString sPrivs = getPrivilegeString(objPrivileges); - if (!sPrivs.isEmpty()) - { - Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); - OUString sGrant = "GRANT " + sPrivs + " ON " - + ::dbtools::quoteTableName(xMeta, objName, - ::dbtools::EComposeRule::InDataManipulation) - + " TO " + m_Name; - - Reference<XStatement> xStmt = m_xConnection->createStatement(); - if (xStmt.is()) - xStmt->execute(sGrant); - ::comphelper::disposeComponent(xStmt); - } + if (sPrivs.isEmpty()) + return; + + Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); + OUString sGrant + = "GRANT " + sPrivs + " ON " + + ::dbtools::quoteTableName(xMeta, objName, ::dbtools::EComposeRule::InDataManipulation) + + " TO " + m_Name; + + Reference<XStatement> xStmt = m_xConnection->createStatement(); + if (xStmt.is()) + xStmt->execute(sGrant); + ::comphelper::disposeComponent(xStmt); } void SAL_CALL OMySQLUser::revokePrivileges(const OUString& objName, sal_Int32 objType, @@ -247,19 +247,19 @@ void SAL_CALL OMySQLUser::revokePrivileges(const OUString& objName, sal_Int32 ob ::osl::MutexGuard aGuard(m_aMutex); checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); OUString sPrivs = getPrivilegeString(objPrivileges); - if (!sPrivs.isEmpty()) - { - Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); - OUString sGrant = "REVOKE " + sPrivs + " ON " - + ::dbtools::quoteTableName(xMeta, objName, - ::dbtools::EComposeRule::InDataManipulation) - + " FROM " + m_Name; - - Reference<XStatement> xStmt = m_xConnection->createStatement(); - if (xStmt.is()) - xStmt->execute(sGrant); - ::comphelper::disposeComponent(xStmt); - } + if (sPrivs.isEmpty()) + return; + + Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); + OUString sGrant + = "REVOKE " + sPrivs + " ON " + + ::dbtools::quoteTableName(xMeta, objName, ::dbtools::EComposeRule::InDataManipulation) + + " FROM " + m_Name; + + Reference<XStatement> xStmt = m_xConnection->createStatement(); + if (xStmt.is()) + xStmt->execute(sGrant); + ::comphelper::disposeComponent(xStmt); } // XUser diff --git a/connectivity/source/drivers/mysql_jdbc/YViews.cxx b/connectivity/source/drivers/mysql_jdbc/YViews.cxx index 4393ba0a566b..4bdeca9596b3 100644 --- a/connectivity/source/drivers/mysql_jdbc/YViews.cxx +++ b/connectivity/source/drivers/mysql_jdbc/YViews.cxx @@ -80,19 +80,19 @@ void OViews::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/) Reference<XInterface> xObject(getObject(_nPos)); bool bIsNew = connectivity::sdbcx::ODescriptor::isNew(xObject); - if (!bIsNew) - { - OUString aSql("DROP VIEW"); + if (bIsNew) + return; - Reference<XPropertySet> xProp(xObject, UNO_QUERY); - aSql += ::dbtools::composeTableName(m_xMetaData, xProp, - ::dbtools::EComposeRule::InTableDefinitions, true); + OUString aSql("DROP VIEW"); - Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection(); - Reference<XStatement> xStmt = xConnection->createStatement(); - xStmt->execute(aSql); - ::comphelper::disposeComponent(xStmt); - } + Reference<XPropertySet> xProp(xObject, UNO_QUERY); + aSql += ::dbtools::composeTableName(m_xMetaData, xProp, + ::dbtools::EComposeRule::InTableDefinitions, true); + + Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection(); + Reference<XStatement> xStmt = xConnection->createStatement(); + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); } void OViews::dropByNameImpl(const OUString& elementName) diff --git a/connectivity/source/drivers/odbc/OResultSet.cxx b/connectivity/source/drivers/odbc/OResultSet.cxx index e17032152433..61e5caecfa77 100644 --- a/connectivity/source/drivers/odbc/OResultSet.cxx +++ b/connectivity/source/drivers/odbc/OResultSet.cxx @@ -1745,48 +1745,48 @@ bool OResultSet::moveImpl(IResultSetHelper::Movement _eCursorPosition, sal_Int32 void OResultSet::fillNeededData(SQLRETURN _nRet) { SQLRETURN nRet = _nRet; - if( nRet == SQL_NEED_DATA) + if( nRet != SQL_NEED_DATA) + return; + + void* pColumnIndex = nullptr; + nRet = N3SQLParamData(m_aStatementHandle,&pColumnIndex); + + do { - void* pColumnIndex = nullptr; - nRet = N3SQLParamData(m_aStatementHandle,&pColumnIndex); + if (nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO && nRet != SQL_NEED_DATA) + break; - do + sal_IntPtr nColumnIndex ( reinterpret_cast<sal_IntPtr>(pColumnIndex)); + Sequence< sal_Int8 > aSeq; + switch(m_aRow[nColumnIndex].getTypeKind()) { - if (nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO && nRet != SQL_NEED_DATA) + case DataType::BINARY: + case DataType::VARBINARY: + case DataType::LONGVARBINARY: + case DataType::BLOB: + aSeq = m_aRow[nColumnIndex]; + N3SQLPutData (m_aStatementHandle, aSeq.getArray(), aSeq.getLength()); break; - - sal_IntPtr nColumnIndex ( reinterpret_cast<sal_IntPtr>(pColumnIndex)); - Sequence< sal_Int8 > aSeq; - switch(m_aRow[nColumnIndex].getTypeKind()) + case SQL_WLONGVARCHAR: { - case DataType::BINARY: - case DataType::VARBINARY: - case DataType::LONGVARBINARY: - case DataType::BLOB: - aSeq = m_aRow[nColumnIndex]; - N3SQLPutData (m_aStatementHandle, aSeq.getArray(), aSeq.getLength()); - break; - case SQL_WLONGVARCHAR: - { - OUString const & sRet = m_aRow[nColumnIndex].getString(); - N3SQLPutData (m_aStatementHandle, static_cast<SQLPOINTER>(const_cast<sal_Unicode *>(sRet.getStr())), sizeof(sal_Unicode)*sRet.getLength()); - break; - } - case DataType::LONGVARCHAR: - case DataType::CLOB: - { - OUString sRet = m_aRow[nColumnIndex].getString(); - OString aString(OUStringToOString(sRet,m_nTextEncoding)); - N3SQLPutData (m_aStatementHandle, static_cast<SQLPOINTER>(const_cast<char *>(aString.getStr())), aString.getLength()); - break; - } - default: - SAL_WARN( "connectivity.odbc", "Not supported at the moment!"); + OUString const & sRet = m_aRow[nColumnIndex].getString(); + N3SQLPutData (m_aStatementHandle, static_cast<SQLPOINTER>(const_cast<sal_Unicode *>(sRet.getStr())), sizeof(sal_Unicode)*sRet.getLength()); + break; } - nRet = N3SQLParamData(m_aStatementHandle,&pColumnIndex); + case DataType::LONGVARCHAR: + case DataType::CLOB: + { + OUString sRet = m_aRow[nColumnIndex].getString(); + OString aString(OUStringToOString(sRet,m_nTextEncoding)); + N3SQLPutData (m_aStatementHandle, static_cast<SQLPOINTER>(const_cast<char *>(aString.getStr())), aString.getLength()); + break; + } + default: + SAL_WARN( "connectivity.odbc", "Not supported at the moment!"); } - while (nRet == SQL_NEED_DATA); + nRet = N3SQLParamData(m_aStatementHandle,&pColumnIndex); } + while (nRet == SQL_NEED_DATA); } SWORD OResultSet::impl_getColumnType_nothrow(sal_Int32 columnIndex) diff --git a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx index 63255f562dc3..0452324a16cb 100644 --- a/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx +++ b/connectivity/source/drivers/postgresql/pq_resultsetmetadata.cxx @@ -153,69 +153,68 @@ ResultSetMetaData::ResultSetMetaData( void ResultSetMetaData::checkForTypes() { - if( ! m_checkedForTypes ) + if( m_checkedForTypes ) + return; + + Reference< XStatement > stmt = + extractConnectionFromStatement( m_origin->getStatement() )->createStatement(); + DisposeGuard guard( stmt ); + OUStringBuffer buf(128); + buf.append( "SELECT oid, typname, typtype FROM pg_type WHERE "); + for( int i = 0 ; i < m_colCount ; i ++ ) { - Reference< XStatement > stmt = - extractConnectionFromStatement( m_origin->getStatement() )->createStatement(); - DisposeGuard guard( stmt ); - OUStringBuffer buf(128); - buf.append( "SELECT oid, typname, typtype FROM pg_type WHERE "); - for( int i = 0 ; i < m_colCount ; i ++ ) - { - if( i > 0 ) - buf.append( " OR " ); - int oid = m_colDesc[i].typeOid; - buf.append( "oid=" ); - buf.append( static_cast<sal_Int32>(oid) ); - } - Reference< XResultSet > rs = stmt->executeQuery( buf.makeStringAndClear() ); - Reference< XRow > xRow( rs, UNO_QUERY ); - while( rs->next() ) - { - Oid oid = xRow->getInt( 1 ); - OUString typeName = xRow->getString( 2 ); - OUString typType = xRow->getString( 3 ); + if( i > 0 ) + buf.append( " OR " ); + int oid = m_colDesc[i].typeOid; + buf.append( "oid=" ); + buf.append( static_cast<sal_Int32>(oid) ); + } + Reference< XResultSet > rs = stmt->executeQuery( buf.makeStringAndClear() ); + Reference< XRow > xRow( rs, UNO_QUERY ); + while( rs->next() ) + { + Oid oid = xRow->getInt( 1 ); + OUString typeName = xRow->getString( 2 ); + OUString typType = xRow->getString( 3 ); - sal_Int32 type = typeNameToDataType( typeName, typType ); + sal_Int32 type = typeNameToDataType( typeName, typType ); - for( sal_Int32 j = 0; j < m_colCount ; j ++ ) + for( sal_Int32 j = 0; j < m_colCount ; j ++ ) + { + if( m_colDesc[j].typeOid == oid ) { - if( m_colDesc[j].typeOid == oid ) - { - m_colDesc[j].typeName = typeName; - m_colDesc[j].type = type; - } + m_colDesc[j].typeName = typeName; + m_colDesc[j].type = type; } } - m_checkedForTypes = true; } + m_checkedForTypes = true; } void ResultSetMetaData::checkTable() { - if( ! m_checkedForTable ) - { - m_checkedForTable = true; - if( m_tableName.getLength() ) - { + if( m_checkedForTable ) + return; - Reference< css::container::XNameAccess > tables = (*m_ppSettings)->tables; - if( ! tables.is() ) - { + m_checkedForTable = true; + if( !m_tableName.getLength() ) + return; - Reference< XTablesSupplier > supplier( - extractConnectionFromStatement( m_origin->getStatement() ), UNO_QUERY); - if( supplier.is() ) - tables = supplier->getTables(); - } - if( tables.is() ) - { - const OUString name (getTableName ( 1 )); - const OUString schema (getSchemaName( 1 )); - const OUString composedName( schema.isEmpty() ? name : (schema + "." + name) ); - tables->getByName( composedName ) >>= m_table; - } - } + Reference< css::container::XNameAccess > tables = (*m_ppSettings)->tables; + if( ! tables.is() ) + { + + Reference< XTablesSupplier > supplier( + extractConnectionFromStatement( m_origin->getStatement() ), UNO_QUERY); + if( supplier.is() ) + tables = supplier->getTables(); + } + if( tables.is() ) + { + const OUString name (getTableName ( 1 )); + const OUString schema (getSchemaName( 1 )); + const OUString composedName( schema.isEmpty() ? name : (schema + "." + name) ); + tables->getByName( composedName ) >>= m_table; } } diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx index 37f6cb575c22..bece8a806f29 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.cxx +++ b/connectivity/source/drivers/postgresql/pq_tools.cxx @@ -1036,45 +1036,45 @@ void bufferKey2TableConstraint( } buf.append( ") " ); - if( foreign ) + if( !foreign ) + return; + + buf.append( "REFERENCES " ); + OUString schema; + OUString tableName; + splitConcatenatedIdentifier( referencedTable, &schema, &tableName ); + bufferQuoteQualifiedIdentifier(buf , schema, tableName, settings ); + if(columns.is() ) { - buf.append( "REFERENCES " ); - OUString schema; - OUString tableName; - splitConcatenatedIdentifier( referencedTable, &schema, &tableName ); - bufferQuoteQualifiedIdentifier(buf , schema, tableName, settings ); - if(columns.is() ) + Reference< XEnumerationAccess > colEnumAccess( columns->getColumns(), UNO_QUERY); + if( colEnumAccess.is() ) { - Reference< XEnumerationAccess > colEnumAccess( columns->getColumns(), UNO_QUERY); - if( colEnumAccess.is() ) + buf.append( " (" ); + Reference< XEnumeration > colEnum(colEnumAccess->createEnumeration()); + bool first = true; + while(colEnum.is() && colEnum->hasMoreElements() ) { - buf.append( " (" ); - Reference< XEnumeration > colEnum(colEnumAccess->createEnumeration()); - bool first = true; - while(colEnum.is() && colEnum->hasMoreElements() ) + if( first ) { - if( first ) - { - first = false; - } - else - { - buf.append( ", " ); - } - Reference< XPropertySet > keyColumn( colEnum->nextElement(), UNO_QUERY_THROW ); - bufferQuoteIdentifier( - buf, extractStringProperty( keyColumn, st.RELATED_COLUMN ), settings ); + first = false; } - buf.append( ") " ); + else + { + buf.append( ", " ); + } + Reference< XPropertySet > keyColumn( colEnum->nextElement(), UNO_QUERY_THROW ); + bufferQuoteIdentifier( + buf, extractStringProperty( keyColumn, st.RELATED_COLUMN ), settings ); } + buf.append( ") " ); } - - buf.append( "ON DELETE " ); - keyType2String( buf, deleteRule ); - buf.append( " ON UPDATE " ); - keyType2String( buf, updateRule ); } + buf.append( "ON DELETE " ); + keyType2String( buf, deleteRule ); + buf.append( " ON UPDATE " ); + keyType2String( buf, updateRule ); + } void extractNameValuePairsFromInsert( String2StringMap & map, const OString & lastQuery ) @@ -1084,57 +1084,57 @@ void extractNameValuePairsFromInsert( String2StringMap & map, const OString & la int nSize = vec.size(); // printf( "1 %d\n", nSize ); - if( nSize > 6 && + if( !(nSize > 6 && vec[0].equalsIgnoreAsciiCase( "insert" ) && - vec[1].equalsIgnoreAsciiCase( "into" ) ) - { - int n = 2; + vec[1].equalsIgnoreAsciiCase( "into" )) ) + return; + + int n = 2; // printf( "1a\n" ); - // skip table name - if( vec[n+1].equalsIgnoreAsciiCase( "." ) ) + // skip table name + if( vec[n+1].equalsIgnoreAsciiCase( "." ) ) + { + n +=2; + } + + n ++; + if( !vec[n].equalsIgnoreAsciiCase( "(" ) ) + return; + + std::vector< OString> names; +// printf( "2\n" ); + // extract names + n++; + while( nSize > n && ! vec[n].equalsIgnoreAsciiCase( ")" ) ) + { + names.push_back( vec[n] ); + if( nSize > n+1 && vec[n+1].equalsIgnoreAsciiCase( "," ) ) { - n +=2; + n ++; } + n++; + } + n++; - n ++; - if( vec[n].equalsIgnoreAsciiCase( "(" ) ) - { - std::vector< OString> names; -// printf( "2\n" ); - // extract names - n++; - while( nSize > n && ! vec[n].equalsIgnoreAsciiCase( ")" ) ) - { - names.push_back( vec[n] ); - if( nSize > n+1 && vec[n+1].equalsIgnoreAsciiCase( "," ) ) - { - n ++; - } - n++; - } - n++; + // now read the values + if( !(nSize > n +1 && vec[n].equalsIgnoreAsciiCase("VALUES") && + vec[n+1].equalsIgnoreAsciiCase( "(" )) ) + return; - // now read the values - if( nSize > n +1 && vec[n].equalsIgnoreAsciiCase("VALUES") && - vec[n+1].equalsIgnoreAsciiCase( "(" ) ) - { - n +=2; + n +=2; // printf( "3\n" ); - for (auto& name : names) - { - if (n >= nSize) - break; + for (auto& name : names) + { + if (n >= nSize) + break; - map[name] = vec[n]; - if( nSize > n+1 && vec[n+1].equalsIgnoreAsciiCase(",") ) - { - n ++; - } - n++; - } - } + map[name] = vec[n]; + if( nSize > n+1 && vec[n+1].equalsIgnoreAsciiCase(",") ) + { + n ++; } + n++; } } diff --git a/connectivity/source/drivers/postgresql/pq_xcontainer.cxx b/connectivity/source/drivers/postgresql/pq_xcontainer.cxx index b7c1537eed04..06323615f4b7 100644 --- a/connectivity/source/drivers/postgresql/pq_xcontainer.cxx +++ b/connectivity/source/drivers/postgresql/pq_xcontainer.cxx @@ -378,26 +378,26 @@ void Container::removeContainerListener( void Container::fire( const EventBroadcastHelper &helper ) { cppu::OInterfaceContainerHelper *container = rBHelper.getContainer( helper.getType() ); - if( container ) + if( !container ) + return; + + cppu::OInterfaceIteratorHelper iterator( * container ); + while( iterator.hasMoreElements() ) { - cppu::OInterfaceIteratorHelper iterator( * container ); - while( iterator.hasMoreElements() ) + try + { + helper.fire( static_cast<XEventListener *>(iterator.next()) ); + } + catch ( css::uno::RuntimeException & ) + { + OSL_ENSURE( false, "exception caught" ); + // loose coupling, a runtime exception shall not break anything + // TODO: log away as warning ! + } + catch( css::uno::Exception & ) { - try - { - helper.fire( static_cast<XEventListener *>(iterator.next()) ); - } - catch ( css::uno::RuntimeException & ) - { - OSL_ENSURE( false, "exception caught" ); - // loose coupling, a runtime exception shall not break anything - // TODO: log away as warning ! - } - catch( css::uno::Exception & ) - { - OSL_ENSURE( false, "exception from listener flying through" ); - throw; - } + OSL_ENSURE( false, "exception from listener flying through" ); + throw; } } diff --git a/connectivity/source/drivers/postgresql/pq_xtables.cxx b/connectivity/source/drivers/postgresql/pq_xtables.cxx index 1d9b9fd3b13c..83758208b203 100644 --- a/connectivity/source/drivers/postgresql/pq_xtables.cxx +++ b/connectivity/source/drivers/postgresql/pq_xtables.cxx @@ -151,83 +151,83 @@ void Tables::refresh() static void appendColumnList( OUStringBuffer &buf, const Reference< XColumnsSupplier > & columnSupplier, ConnectionSettings *settings ) { - if( columnSupplier.is() ) - { - Reference< XEnumerationAccess > columns( columnSupplier->getColumns(),UNO_QUERY ); - if( columns.is() ) - { - Reference< XEnumeration > xEnum( columns->createEnumeration() ); - bool first = true; - Statics & st = getStatics(); + if( !columnSupplier.is() ) + return; - while( xEnum.is() && xEnum->hasMoreElements() ) - { - if( first ) - { - first = false; - } - else - { - buf.append( ", " ); - } - Reference< XPropertySet > column( xEnum->nextElement(), UNO_QUERY ); - OUString name = extractStringProperty( column, st.NAME ); - OUString defaultValue = extractStringProperty( column, st.DEFAULT_VALUE ); - bool isNullable = extractBoolProperty( column, st.IS_NULLABLE ); - bool isAutoIncrement = extractBoolProperty( column, st.IS_AUTO_INCREMENT ); + Reference< XEnumerationAccess > columns( columnSupplier->getColumns(),UNO_QUERY ); + if( !columns.is() ) + return; - bufferQuoteIdentifier( buf, name, settings ); + Reference< XEnumeration > xEnum( columns->createEnumeration() ); + bool first = true; + Statics & st = getStatics(); - OUString type = sqltype2string( column ); - if( isAutoIncrement ) - { - sal_Int32 dataType = 0; - column->getPropertyValue( st.TYPE ) >>= dataType; - if( css::sdbc::DataType::INTEGER == dataType ) - { - buf.append( " serial "); - isNullable = false; - } - else if( css::sdbc::DataType::BIGINT == dataType ) - { - buf.append( " serial8 " ); - isNullable = false; - } - else - buf.append( type ); - } - else - { - buf.append( type ); - } - if( !defaultValue.isEmpty() ) - { - bufferQuoteConstant( buf, defaultValue, settings ); - } + while( xEnum.is() && xEnum->hasMoreElements() ) + { + if( first ) + { + first = false; + } + else + { + buf.append( ", " ); + } + Reference< XPropertySet > column( xEnum->nextElement(), UNO_QUERY ); + OUString name = extractStringProperty( column, st.NAME ); + OUString defaultValue = extractStringProperty( column, st.DEFAULT_VALUE ); + bool isNullable = extractBoolProperty( column, st.IS_NULLABLE ); + bool isAutoIncrement = extractBoolProperty( column, st.IS_AUTO_INCREMENT ); - if( ! isNullable ) - buf.append( " NOT NULL " ); + bufferQuoteIdentifier( buf, name, settings ); + OUString type = sqltype2string( column ); + if( isAutoIncrement ) + { + sal_Int32 dataType = 0; + column->getPropertyValue( st.TYPE ) >>= dataType; + if( css::sdbc::DataType::INTEGER == dataType ) + { + buf.append( " serial "); + isNullable = false; + } + else if( css::sdbc::DataType::BIGINT == dataType ) + { + buf.append( " serial8 " ); + isNullable = false; } + else + buf.append( type ); } + else + { + buf.append( type ); + } + if( !defaultValue.isEmpty() ) + { + bufferQuoteConstant( buf, defaultValue, settings ); + } + + if( ! isNullable ) + buf.append( " NOT NULL " ); + } } static void appendKeyList( OUStringBuffer & buf, const Reference< XKeysSupplier > &keySupplier, ConnectionSettings *settings ) { - if( keySupplier.is() ) + if( !keySupplier.is() ) + return; + + Reference< XEnumerationAccess > keys( keySupplier->getKeys(), UNO_QUERY ); + if(keys.is() ) { - Reference< XEnumerationAccess > keys( keySupplier->getKeys(), UNO_QUERY ); - if(keys.is() ) + Reference< XEnumeration > xEnum = keys->createEnumeration(); + while( xEnum.is() && xEnum->hasMoreElements() ) { - Reference< XEnumeration > xEnum = keys->createEnumeration(); - while( xEnum.is() && xEnum->hasMoreElements() ) - { - buf.append( ", " ); - Reference< XPropertySet > key( xEnum->nextElement(), UNO_QUERY ); - bufferKey2TableConstraint( buf, key, settings ); - } + buf.append( ", " ); + Reference< XPropertySet > key( xEnum->nextElement(), UNO_QUERY ); + bufferKey2TableConstraint( buf, key, settings ); } } } |