diff options
author | Caolán McNamara <caolanm@redhat.com> | 2014-09-11 16:37:00 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-09-11 17:25:43 +0100 |
commit | e7fb96a1c93f57b1ffc6c0bd2af578d6a3e4f78b (patch) | |
tree | 0e945b01a8462ab03f9b36707147a11afae77c0e /connectivity/source/drivers/dbase | |
parent | 8d2818ff987cca3bac84fb66926b94cbc620a54a (diff) |
ODbaseDatabaseMetaData::getColumns dies if throwInvalidDbaseFormat occurs
Change-Id: If649c1cb8f41e8a29afb5ad350664a573cd1102a
Diffstat (limited to 'connectivity/source/drivers/dbase')
-rw-r--r-- | connectivity/source/drivers/dbase/DDatabaseMetaData.cxx | 120 |
1 files changed, 65 insertions, 55 deletions
diff --git a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx index 00f334183cae..bc37bdb13d51 100644 --- a/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx +++ b/connectivity/source/drivers/dbase/DDatabaseMetaData.cxx @@ -18,6 +18,7 @@ */ #include "dbase/DDatabaseMetaData.hxx" +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/sdbc/DataType.hpp> #include <com/sun/star/sdbc/ResultSetType.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> @@ -157,7 +158,6 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( { ::osl::MutexGuard aGuard( m_aMutex ); - Reference< XTablesSupplier > xTables = m_pConnection->createCatalog(); if(!xTables.is()) throw SQLException(); @@ -169,72 +169,82 @@ Reference< XResultSet > SAL_CALL ODbaseDatabaseMetaData::getColumns( ODatabaseMetaDataResultSet::ORows aRows; ODatabaseMetaDataResultSet::ORow aRow(19); - aRow[10] = new ORowSetValueDecorator((sal_Int32)10); - Sequence< OUString> aTabNames(xNames->getElementNames()); - const OUString* pTabBegin = aTabNames.getConstArray(); - const OUString* pTabEnd = pTabBegin + aTabNames.getLength(); - for(;pTabBegin != pTabEnd;++pTabBegin) + try { - if(match(tableNamePattern,*pTabBegin,'\0')) + aRow[10] = new ORowSetValueDecorator((sal_Int32)10); + Sequence< OUString> aTabNames(xNames->getElementNames()); + const OUString* pTabBegin = aTabNames.getConstArray(); + const OUString* pTabEnd = pTabBegin + aTabNames.getLength(); + for(;pTabBegin != pTabEnd;++pTabBegin) { - Reference< XColumnsSupplier> xTable( - xNames->getByName(*pTabBegin), css::uno::UNO_QUERY); - OSL_ENSURE(xTable.is(),"Table not found! Normallya exception had to be thrown here!"); - aRow[3] = new ORowSetValueDecorator(*pTabBegin); + if(match(tableNamePattern,*pTabBegin,'\0')) + { + Reference< XColumnsSupplier> xTable( + xNames->getByName(*pTabBegin), css::uno::UNO_QUERY); + OSL_ENSURE(xTable.is(),"Table not found! Normallya exception had to be thrown here!"); + aRow[3] = new ORowSetValueDecorator(*pTabBegin); - Reference< XNameAccess> xColumns = xTable->getColumns(); - if(!xColumns.is()) - throw SQLException(); + Reference< XNameAccess> xColumns = xTable->getColumns(); + if(!xColumns.is()) + throw SQLException(); - Sequence< OUString> aColNames(xColumns->getElementNames()); + Sequence< OUString> aColNames(xColumns->getElementNames()); - const OUString* pBegin = aColNames.getConstArray(); - const OUString* pEnd = pBegin + aColNames.getLength(); - Reference< XPropertySet> xColumn; - for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i) - { - if(match(columnNamePattern,*pBegin,'\0')) + const OUString* pBegin = aColNames.getConstArray(); + const OUString* pEnd = pBegin + aColNames.getLength(); + Reference< XPropertySet> xColumn; + for(sal_Int32 i=1;pBegin != pEnd;++pBegin,++i) { - aRow[4] = new ORowSetValueDecorator(*pBegin); - - xColumn.set( - xColumns->getByName(*pBegin), css::uno::UNO_QUERY); - OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!"); - aRow[5] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))); - aRow[6] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))); - aRow[7] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))); - aRow[9] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))); - aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))); - aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))); - switch((sal_Int32)aRow[5]->getValue()) + if(match(columnNamePattern,*pBegin,'\0')) { - case DataType::CHAR: - case DataType::VARCHAR: - aRow[16] = new ORowSetValueDecorator((sal_Int32)254); - break; - case DataType::LONGVARCHAR: - aRow[16] = new ORowSetValueDecorator((sal_Int32)65535); - break; - default: - aRow[16] = new ORowSetValueDecorator((sal_Int32)0); + aRow[4] = new ORowSetValueDecorator(*pBegin); + + xColumn.set( + xColumns->getByName(*pBegin), css::uno::UNO_QUERY); + OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!"); + aRow[5] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))); + aRow[6] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))); + aRow[7] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))); + aRow[9] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))); + aRow[11] = new ORowSetValueDecorator(getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))); + aRow[13] = new ORowSetValueDecorator(getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))); + switch((sal_Int32)aRow[5]->getValue()) + { + case DataType::CHAR: + case DataType::VARCHAR: + aRow[16] = new ORowSetValueDecorator((sal_Int32)254); + break; + case DataType::LONGVARCHAR: + aRow[16] = new ORowSetValueDecorator((sal_Int32)65535); + break; + default: + aRow[16] = new ORowSetValueDecorator((sal_Int32)0); + } + aRow[17] = new ORowSetValueDecorator(i); + switch(sal_Int32(aRow[11]->getValue())) + { + case ColumnValue::NO_NULLS: + aRow[18] = new ORowSetValueDecorator(OUString("NO")); + break; + case ColumnValue::NULLABLE: + aRow[18] = new ORowSetValueDecorator(OUString("YES")); + break; + default: + aRow[18] = new ORowSetValueDecorator(OUString()); + } + aRows.push_back(aRow); } - aRow[17] = new ORowSetValueDecorator(i); - switch(sal_Int32(aRow[11]->getValue())) - { - case ColumnValue::NO_NULLS: - aRow[18] = new ORowSetValueDecorator(OUString("NO")); - break; - case ColumnValue::NULLABLE: - aRow[18] = new ORowSetValueDecorator(OUString("YES")); - break; - default: - aRow[18] = new ORowSetValueDecorator(OUString()); - } - aRows.push_back(aRow); } } } } + catch (const WrappedTargetException& e) + { + SQLException aSql; + if (e.TargetException >>= aSql) + throw aSql; + throw WrappedTargetRuntimeException(e.Message, e.Context, e.TargetException); + } ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); Reference< XResultSet > xRef = pResult; pResult->setRows(aRows); |