diff options
Diffstat (limited to 'connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx')
-rw-r--r-- | connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx | 254 |
1 files changed, 94 insertions, 160 deletions
diff --git a/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx b/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx index 5e84a27e13fb..110d01feb213 100644 --- a/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx +++ b/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx @@ -23,6 +23,7 @@ #include <connectivity/dbexception.hxx> #include <connectivity/FValue.hxx> #include <com/sun/star/sdbc/ColumnSearch.hpp> +#include <rtl/ref.hxx> #include <cstddef> #include <string.h> @@ -33,10 +34,7 @@ using namespace connectivity::evoab; using namespace connectivity; using namespace com::sun::star::uno; -using namespace com::sun::star::lang; -using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; -using namespace com::sun::star::sdbcx; namespace { @@ -252,8 +250,14 @@ OEvoabDatabaseMetaData::~OEvoabDatabaseMetaData() } -ODatabaseMetaDataResultSet::ORows OEvoabDatabaseMetaData::getColumnRows( const OUString& columnNamePattern ) +Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getColumns( + const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& /*tableNamePattern*/, + const OUString& columnNamePattern ) { + // this returns an empty resultset where the column-names are already set + // in special the metadata of the resultset already returns the right columns + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumns ); + ODatabaseMetaDataResultSet::ORows aRows; ODatabaseMetaDataResultSet::ORow aRow(19); @@ -293,7 +297,7 @@ ODatabaseMetaDataResultSet::ORows OEvoabDatabaseMetaData::getColumnRows( const O ::osl::MutexGuard aGuard( m_aMutex ); initFields(); - for (sal_Int32 i = 0; i < static_cast<sal_Int32>(nFields); i++) + for (guint i = 0; i < nFields; i++) { if( match( columnNamePattern, getFieldName( i ), '\0' ) ) { @@ -303,12 +307,14 @@ ODatabaseMetaDataResultSet::ORows OEvoabDatabaseMetaData::getColumnRows( const O // COLUMN_NAME aRow[4] = new ORowSetValueDecorator( getFieldName( i ) ); // ORDINAL_POSITION - aRow[17] = new ORowSetValueDecorator( i ); + aRow[17] = new ORowSetValueDecorator( sal_Int32(i) ); aRows.push_back( aRow ); } } - return aRows ; + pResultSet->setRows(std::move(aRows)); + + return pResultSet; } OUString OEvoabDatabaseMetaData::impl_getCatalogSeparator_throw( ) @@ -984,23 +990,19 @@ Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getTableTypes( ) { u"TABLE" // Currently we only support a 'TABLE' nothing more complex }; - ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTableTypes); - Reference< XResultSet > xRef = pResult; + rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTableTypes); // here we fill the rows which should be visible when ask for data from the resultset returned here + auto nNbTypes = std::size(sTableTypes); ODatabaseMetaDataResultSet::ORows aRows; - for(std::size_t i=0;i < SAL_N_ELEMENTS(sTableTypes);++i) + for(std::size_t i=0;i < nNbTypes;++i) { - ODatabaseMetaDataResultSet::ORow aRow; - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(OUString(sTableTypes[i]))); - // bound row - aRows.push_back(aRow); + aRows.push_back( { ODatabaseMetaDataResultSet::getEmptyValue(), new ORowSetValueDecorator(OUString(sTableTypes[i])) }); } // here we set the rows at the resultset - pResult->setRows(aRows); - return xRef; + pResult->setRows(std::move(aRows)); + return pResult; } Reference< XResultSet > OEvoabDatabaseMetaData::impl_getTypeInfo_throw( ) @@ -1009,34 +1011,33 @@ Reference< XResultSet > OEvoabDatabaseMetaData::impl_getTypeInfo_throw( ) * Return the proper type information required by evo driver */ - ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); + rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); - Reference< XResultSet > xResultSet = pResultSet; static ODatabaseMetaDataResultSet::ORows aRows = []() { ODatabaseMetaDataResultSet::ORows tmp; - ODatabaseMetaDataResultSet::ORow aRow; - aRow.reserve(19); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(OUString("VARCHAR"))); - aRow.push_back(new ORowSetValueDecorator(DataType::VARCHAR)); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(s_nCHAR_OCTET_LENGTH))); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - // aRow.push_back(new ORowSetValueDecorator((sal_Int32)ColumnValue::NULLABLE)); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(ColumnSearch::FULL))); - aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); - aRow.push_back(new ORowSetValueDecorator(sal_Int32(10))); + ODatabaseMetaDataResultSet::ORow aRow + { + ODatabaseMetaDataResultSet::getEmptyValue() , + new ORowSetValueDecorator(OUString("VARCHAR")) , + new ORowSetValueDecorator(DataType::VARCHAR) , + new ORowSetValueDecorator(sal_Int32(s_nCHAR_OCTET_LENGTH)) , + ODatabaseMetaDataResultSet::getQuoteValue() , + ODatabaseMetaDataResultSet::getQuoteValue() , + ODatabaseMetaDataResultSet::getEmptyValue() , + ODatabaseMetaDataResultSet::get1Value() , + ODatabaseMetaDataResultSet::get1Value() , + new ORowSetValueDecorator(sal_Int32(ColumnSearch::FULL)) , + ODatabaseMetaDataResultSet::get1Value() , + ODatabaseMetaDataResultSet::get0Value() , + ODatabaseMetaDataResultSet::get0Value() , + ODatabaseMetaDataResultSet::getEmptyValue() , + ODatabaseMetaDataResultSet::get0Value() , + ODatabaseMetaDataResultSet::get0Value() , + ODatabaseMetaDataResultSet::getEmptyValue() , + ODatabaseMetaDataResultSet::getEmptyValue() , + new ORowSetValueDecorator(sal_Int32(10)) + }; tmp.push_back(aRow); @@ -1046,23 +1047,10 @@ Reference< XResultSet > OEvoabDatabaseMetaData::impl_getTypeInfo_throw( ) tmp.push_back(aRow); return tmp; }(); - pResultSet->setRows(aRows); - return xResultSet; -} - -Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getColumns( - const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& /*tableNamePattern*/, - const OUString& columnNamePattern ) -{ - // this returns an empty resultset where the column-names are already set - // in special the metadata of the resultset already returns the right columns - ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumns ); - Reference< XResultSet > xResultSet = pResultSet; - pResultSet->setRows( getColumnRows( columnNamePattern ) ); - return xResultSet; + pResultSet->setRows(std::move(aRows)); + return pResultSet; } - bool isSourceBackend(ESource *pSource, const char *backendname) { if (!pSource || !e_source_has_extension (pSource, E_SOURCE_EXTENSION_ADDRESS_BOOK)) @@ -1078,136 +1066,82 @@ Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getTables( { ::osl::MutexGuard aGuard( m_aMutex ); - ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTableTypes); - Reference< XResultSet > xRef = pResult; + rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables); // check if any type is given // when no types are given then we have to return all tables e.g. TABLE - const OUString aTable("TABLE"); + static constexpr OUString aTable(u"TABLE"_ustr); bool bTableFound = true; sal_Int32 nLength = types.getLength(); if(nLength) - { - bTableFound = false; - - const OUString* pBegin = types.getConstArray(); - const OUString* pEnd = pBegin + nLength; - for(;pBegin != pEnd;++pBegin) - { - if(*pBegin == aTable) - { - bTableFound = true; - break; - } - } - } - if(!bTableFound) - return xRef; - - ODatabaseMetaDataResultSet::ORows aRows; - - if (eds_check_version(3, 6, 0) == nullptr) { - GList *pSources = e_source_registry_list_sources(get_e_source_registry(), E_SOURCE_EXTENSION_ADDRESS_BOOK); + bTableFound = false; - for (GList* liter = pSources; liter; liter = liter->next) + const OUString* pBegin = types.getConstArray(); + const OUString* pEnd = pBegin + nLength; + for(;pBegin != pEnd;++pBegin) { - ESource *pSource = E_SOURCE (liter->data); - bool can = false; - switch (m_pConnection->getSDBCAddressType()) + if(*pBegin == aTable) { - case SDBCAddress::EVO_GWISE: - can = isSourceBackend( pSource, "groupwise"); // not supported in evo/eds 3.6.x+, somehow - break; - case SDBCAddress::EVO_LOCAL: - can = isSourceBackend( pSource, "local"); - break; - case SDBCAddress::EVO_LDAP: - can = isSourceBackend( pSource, "ldap"); - break; - case SDBCAddress::Unknown: - can = true; - break; + bTableFound = true; + break; } - if (!can) - continue; - - OUString aHumanName = OStringToOUString( e_source_get_display_name( pSource ), - RTL_TEXTENCODING_UTF8 ); - OUString aUID = OStringToOUString( e_source_get_uid( pSource ), - RTL_TEXTENCODING_UTF8 ); - ODatabaseMetaDataResultSet::ORow aRow{ - ORowSetValueDecoratorRef(), - ORowSetValueDecoratorRef(), - ORowSetValueDecoratorRef(), - new ORowSetValueDecorator(aHumanName), //tablename - new ORowSetValueDecorator(aTable), - new ORowSetValueDecorator(aUID)}; //comment - //I'd prefer to swap the comment and the human name and - //just use e_source_registry_ref_source(get_e_source_registry(), aUID); - //in open book rather than search for the name again - aRows.push_back(aRow); } - - g_list_foreach (pSources, reinterpret_cast<GFunc>(g_object_unref), nullptr); - g_list_free (pSources); } - else - { - ESourceList *pSourceList; - if( !e_book_get_addressbooks (&pSourceList, nullptr) ) - pSourceList = nullptr; + if(!bTableFound) + return pResult; - GSList *g; - for( g = e_source_list_peek_groups( pSourceList ); g; g = g->next) - { - GSList *s; - const char *p = e_source_group_peek_base_uri(E_SOURCE_GROUP(g->data)); + ODatabaseMetaDataResultSet::ORows aRows; - switch (m_pConnection->getSDBCAddressType()) { + GList *pSources = e_source_registry_list_sources(get_e_source_registry(), E_SOURCE_EXTENSION_ADDRESS_BOOK); + + for (GList* liter = pSources; liter; liter = liter->next) + { + ESource *pSource = E_SOURCE (liter->data); + bool can = false; + switch (m_pConnection->getSDBCAddressType()) + { case SDBCAddress::EVO_GWISE: - if ( !strncmp( "groupwise://", p, 11 )) - break; - else - continue; + can = isSourceBackend( pSource, "groupwise"); // not supported in evo/eds 3.6.x+, somehow + break; case SDBCAddress::EVO_LOCAL: - if ( !strncmp( "file://", p, 6 ) || - !strncmp( "local://", p, 6 ) ) - break; - else - continue; + can = isSourceBackend( pSource, "local"); + break; case SDBCAddress::EVO_LDAP: - if ( !strncmp( "ldap://", p, 6 )) - break; - else - continue; + can = isSourceBackend( pSource, "ldap"); + break; case SDBCAddress::Unknown: + can = true; break; - } - for (s = e_source_group_peek_sources (E_SOURCE_GROUP (g->data)); s; s = s->next) - { - ESource *pSource = E_SOURCE (s->data); - - OUString aName = OStringToOUString( e_source_peek_name( pSource ), - RTL_TEXTENCODING_UTF8 ); - - ODatabaseMetaDataResultSet::ORow aRow{ - ORowSetValueDecoratorRef(), - ORowSetValueDecoratorRef(), - ORowSetValueDecoratorRef(), - new ORowSetValueDecorator(aName), - new ORowSetValueDecorator(aTable), - ODatabaseMetaDataResultSet::getEmptyValue()}; - aRows.push_back(aRow); - } } + if (!can) + continue; + + OUString aHumanName = OStringToOUString( e_source_get_display_name( pSource ), + RTL_TEXTENCODING_UTF8 ); + OUString aUID = OStringToOUString( e_source_get_uid( pSource ), + RTL_TEXTENCODING_UTF8 ); + ODatabaseMetaDataResultSet::ORow aRow{ + ORowSetValueDecoratorRef(), + ORowSetValueDecoratorRef(), + ORowSetValueDecoratorRef(), + new ORowSetValueDecorator(aHumanName), //tablename + new ORowSetValueDecorator(ORowSetValue(aTable)), + new ORowSetValueDecorator(aUID)}; //comment + //I'd prefer to swap the comment and the human name and + //just use e_source_registry_ref_source(get_e_source_registry(), aUID); + //in open book rather than search for the name again + aRows.push_back(aRow); } - pResult->setRows(aRows); + g_list_foreach (pSources, object_unref, nullptr); + g_list_free (pSources); + + pResult->setRows(std::move(aRows)); - return xRef; + return pResult; } Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getUDTs( const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& /*typeNamePattern*/, const Sequence< sal_Int32 >& /*types*/ ) |