summaryrefslogtreecommitdiff
path: root/connectivity/source/drivers/evoab2/NResultSet.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'connectivity/source/drivers/evoab2/NResultSet.cxx')
-rw-r--r--connectivity/source/drivers/evoab2/NResultSet.cxx155
1 files changed, 17 insertions, 138 deletions
diff --git a/connectivity/source/drivers/evoab2/NResultSet.cxx b/connectivity/source/drivers/evoab2/NResultSet.cxx
index c0b31cc100e4..bc9656337097 100644
--- a/connectivity/source/drivers/evoab2/NResultSet.cxx
+++ b/connectivity/source/drivers/evoab2/NResultSet.cxx
@@ -36,7 +36,7 @@
#include <connectivity/sqlerror.hxx>
#include <rtl/string.hxx>
#include <sal/log.hxx>
-#include <tools/diagnose_ex.h>
+#include <comphelper/diagnose_ex.hxx>
#include <unotools/syslocale.hxx>
#include <unotools/intlwrapper.hxx>
#include <unotools/collatorwrapper.hxx>
@@ -51,7 +51,6 @@ 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;
using namespace com::sun::star::container;
using namespace com::sun::star::io;
namespace ErrorCondition = ::com::sun::star::sdb::ErrorCondition;
@@ -88,7 +87,7 @@ static OUString
valueToOUString( GValue& _rValue )
{
const char *pStr = g_value_get_string( &_rValue );
- OString aStr( pStr ? pStr : "" );
+ std::string_view aStr( pStr ? pStr : "" );
OUString sResult( OStringToOUString( aStr, RTL_TEXTENCODING_UTF8 ) );
g_value_unset( &_rValue );
return sResult;
@@ -308,6 +307,10 @@ static int CompareContacts( gconstpointer _lhs, gconstpointer _rhs, gpointer _us
for ( const auto& sortCol : rCompData.rSortOrder )
{
sal_Int32 nField = sortCol.nField;
+ int nOrder = 1;
+ // if descending sort, reverse order
+ if (!sortCol.bAscending)
+ nOrder = -1;
GType eFieldType = evoab::getGFieldType( nField );
bool success = getValue( lhs, nField, eFieldType, &aLhsValue, bLhsNull )
@@ -317,9 +320,9 @@ static int CompareContacts( gconstpointer _lhs, gconstpointer _rhs, gpointer _us
return 0;
if ( bLhsNull && !bRhsNull )
- return -1;
+ return -1 * nOrder;
if ( !bLhsNull && bRhsNull )
- return 1;
+ return 1 * nOrder;
if ( bLhsNull && bRhsNull )
continue;
@@ -329,16 +332,16 @@ static int CompareContacts( gconstpointer _lhs, gconstpointer _rhs, gpointer _us
sRhs = valueToOUString( aRhsValue );
sal_Int32 nCompResult = rCompData.aIntlWrapper.getCaseCollator()->compareString( sLhs, sRhs );
if ( nCompResult != 0 )
- return nCompResult;
+ return nCompResult * nOrder;
continue;
}
bLhs = valueToBool( aLhsValue );
bRhs = valueToBool( aRhsValue );
if ( bLhs && !bRhs )
- return -1;
+ return -1 * nOrder;
if ( !bLhs && bRhs )
- return 1;
+ return 1 * nOrder;
continue;
}
@@ -398,7 +401,7 @@ public:
break;
}
}
- g_list_foreach (pSources, reinterpret_cast<GFunc>(g_object_unref), nullptr);
+ g_list_foreach (pSources, object_unref, nullptr);
g_list_free (pSources);
if (!id)
return nullptr;
@@ -431,7 +434,7 @@ public:
m_pContacts = nullptr;
}
- virtual void executeQuery (EBook* pBook, EBookQuery* pQuery, OString &/*rPassword*/) override
+ virtual void executeQuery (EBook* pBook, EBookQuery* pQuery) override
{
freeContacts();
char *sexp = e_book_query_to_string( pQuery );
@@ -476,123 +479,7 @@ class OEvoabVersion38Helper : public OEvoabVersion36Helper
protected:
virtual EBookClient * createClient( ESource *pSource ) override
{
- return e_book_client_connect_direct_sync (get_e_source_registry (), pSource, nullptr, nullptr);
- }
-};
-
-ESource * findSource( const char *id )
-{
- ESourceList *pSourceList = nullptr;
-
- g_return_val_if_fail (id != nullptr, nullptr);
-
- if (!e_book_get_addressbooks (&pSourceList, nullptr))
- pSourceList = nullptr;
-
- for ( GSList *g = e_source_list_peek_groups (pSourceList); g; g = g->next)
- {
- for (GSList *s = e_source_group_peek_sources (E_SOURCE_GROUP (g->data)); s; s = s->next)
- {
- ESource *pSource = E_SOURCE (s->data);
- if (!strcmp (e_source_peek_name (pSource), id))
- return pSource;
- }
- }
- return nullptr;
-}
-
-bool isAuthRequired( EBook *pBook )
-{
- return e_source_get_property( e_book_get_source( pBook ),
- "auth" ) != nullptr;
-}
-
-class OEvoabVersion35Helper : public OEvoabVersionHelper
-{
-private:
- GList *m_pContacts;
-
-public:
- OEvoabVersion35Helper()
- : m_pContacts(nullptr)
- {
- }
-
- virtual ~OEvoabVersion35Helper() override
- {
- freeContacts();
- }
-
- virtual EBook* openBook(const char *abname) override
- {
- ESource *pSource = findSource (abname);
- EBook *pBook = pSource ? e_book_new (pSource, nullptr) : nullptr;
- if (pBook && !e_book_open (pBook, true, nullptr))
- {
- g_object_unref (G_OBJECT (pBook));
- pBook = nullptr;
- }
- return pBook;
- }
-
- virtual bool isLDAP( EBook *pBook ) override
- {
- return pBook && !strncmp( "ldap://", e_book_get_uri( pBook ), 6 );
- }
-
- virtual bool isLocal( EBook *pBook ) override
- {
- return pBook && ( !strncmp( "file://", e_book_get_uri( pBook ), 6 ) ||
- !strncmp( "local:", e_book_get_uri( pBook ), 6 ) );
- }
-
- virtual void freeContacts() override final
- {
- g_list_free(m_pContacts);
- m_pContacts = nullptr;
- }
-
- virtual void executeQuery (EBook* pBook, EBookQuery* pQuery, OString &rPassword) override
- {
- freeContacts();
-
- ESource *pSource = e_book_get_source( pBook );
- bool bAuthSuccess = true;
-
- if( isAuthRequired( pBook ) )
- {
- OString aUser( getUserName( pBook ) );
- const char *pAuth = e_source_get_property( pSource, "auth" );
- bAuthSuccess = e_book_authenticate_user( pBook, aUser.getStr(), rPassword.getStr(), pAuth, nullptr );
- }
-
- if (bAuthSuccess)
- e_book_get_contacts( pBook, pQuery, &m_pContacts, nullptr );
- }
-
- virtual EContact *getContact(sal_Int32 nIndex) override
- {
- gpointer pData = g_list_nth_data (m_pContacts, nIndex);
- return pData ? E_CONTACT (pData) : nullptr;
- }
-
- virtual sal_Int32 getNumContacts() override
- {
- return g_list_length( m_pContacts );
- }
-
- virtual bool hasContacts() override
- {
- return m_pContacts != nullptr;
- }
-
- virtual void sortContacts( const ComparisonData& _rCompData ) override
- {
- OSL_ENSURE( !_rCompData.rSortOrder.empty(), "sortContacts: no need to call this without any sort order!" );
- ENSURE_OR_THROW( _rCompData.aIntlWrapper.getCaseCollator(), "no collator for comparing strings" );
-
- m_pContacts = g_list_sort_with_data( m_pContacts, &CompareContacts,
- const_cast< gpointer >( static_cast< gconstpointer >( &_rCompData ) ) );
+ return e_book_client_connect_direct_sync (get_e_source_registry (), pSource, 10, nullptr, nullptr);
}
};
@@ -611,12 +498,7 @@ OEvoabResultSet::OEvoabResultSet( OCommonStatement* pStmt, OEvoabConnection *pCo
,m_nIndex(-1)
,m_nLength(0)
{
- if (eds_check_version( 3, 7, 6 ) == nullptr)
- m_pVersionHelper = std::make_unique<OEvoabVersion38Helper>();
- else if (eds_check_version( 3, 6, 0 ) == nullptr)
- m_pVersionHelper = std::make_unique<OEvoabVersion36Helper>();
- else
- m_pVersionHelper = std::make_unique<OEvoabVersion35Helper>();
+ m_pVersionHelper = std::make_unique<OEvoabVersion38Helper>();
registerProperty(
OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE),
@@ -687,9 +569,7 @@ void OEvoabResultSet::construct( const QueryData& _rData )
}
if ( bExecuteQuery )
{
- OString aPassword = m_pConnection->getPassword();
- m_pVersionHelper->executeQuery(pBook, _rData.getQuery(), aPassword);
- m_pConnection->setPassword( aPassword );
+ m_pVersionHelper->executeQuery(pBook, _rData.getQuery());
if ( m_pVersionHelper->hasContacts() && !_rData.aSortOrder.empty() )
{
@@ -1031,8 +911,7 @@ Reference< XInterface > SAL_CALL OEvoabResultSet::getStatement( )
{
::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
- css::uno::WeakReferenceHelper aStatement(static_cast<OWeakObject*>(m_pStatement));
- return aStatement.get();
+ return cppu::getXWeak(m_pStatement);
}