[Date Prev][Date Next] [Chronological] [Thread] [Top]

RE: Any sample on sorting?



Hi Charles,
Thanks for replying.
 
I have tried what you said - and I tried sorting on "cn" itself. But the results remain unsorted. I am not sure if sorting itself is supported by AD or not. Have you got successful sorted results EVER? If yes, I will have hope on my side.
 
Here is the code.
 
bool LDAPH_ObjectSet::SortSelectedObjects( const _TSTR strKeyAttribute )
{
    LDAPSortKey **ppSortKeys = new LDAPSortKey *[2];
    ppSortKeys[0] = new LDAPSortKey;
    ppSortKeys[0]->sk_attrtype = (_TCHAR*)strKeyAttribute.c_str();
    ppSortKeys[0]->sk_matchruleoid = LDAP_SERVER_SORT_OID_W;
    ppSortKeys[0]->sk_reverseorder = false;
    ppSortKeys[1] = NULL;
   
    LDAPControl *pLdapSortControl;
 
    ULONG ulRes = ldap_create_sort_control( m_pLdapSession->GetSessionHandle(),
                                            ppSortKeys,
                                            1,
                                            &pLdapSortControl );
 
    LDAPH_EXPECT_LDAP_SUCCESS( ulRes );
 
    LDAPControl **ppLdapControls = new LDAPControl*[2];
    ppLdapControls[0] = pLdapSortControl;
    ppLdapControls[1] = NULL;
 
    // Erase previous Search results.
        if ( NULL != m_pSelectedObjects )
        {
            ldap_msgfree(m_pSelectedObjects);
            m_pSelectedObjects = NULL;
        }
 
    ulRes = ldap_search_ext_s( m_pLdapSession->GetSessionHandle(),
                               (_TCHAR *) m_strBaseObjectDN.c_str(),
                               m_Level,
                               (_TCHAR*)m_strFilter.c_str(),
                               m_pptcsAttrs,
                               m_bAttribValues,
                               ppLdapControls,
                               NULL,
                               NULL,
                               0,
                               &m_pSelectedObjects );
 
    ldap_control_free( pLdapSortControl );
    delete ppSortKeys[0];
    delete [] ppSortKeys;
    delete [] ppLdapControls;
 
    LDAPH_EXPECT_LDAP_SUCCESS( ulRes );
 
    return true;
}
-sanju
-----Original Message-----
From: Charles Oppermann [mailto:Charles@coppersoftware.com]
Sent: Wednesday, January 03, 2001 3:06 PM
To: openldap-general@OpenLDAP.org
Subject: RE: Any sample on sorting?

RE: Any sample on sorting? Active Directory only supports one sort key, but = the samples I've seen of using sort keys uses an array of pointers, with = a NULL terminator: LDAPSortKey ldapSortKey = { "cn", /* Attribute to sort on */ NULL, = /* Pointer to matching rule OID string (use NULL) */ FALSE,/* FALSE for regular sort order, TRUE for reverse order = */ }; PLDAPSortKey pldapSortKeys[] = { = &ldapSortKey, NULL }; You should be aware that you cannot sort on a = multivalued attribute - I don't know if that's a limitation of Active = Directory or the LDAP API. Charles Oppermann Copper Software Active Directory information at http://w= ww.coppersoftware.com/software/activedirectory/ charles@coppersoftware.com -----Original Message----- From: Burkule, Sanju [mailto:sanju.burkule@unisys.com<= /A>] Sent: Tuesday, January 02, 2001 3:57 = PM To: openldap-general@OpenLDAP.org Subject: Any sample on sorting? Hi, Could anyone point me to a C++ sample which does = ldap sorting? An example related to Active Directory would be great. I am = not able to get ldap_create_sort_control to work. It throws some = exception. Its not clear whether the first parameter - LDAPSortKey list - = ends with a NULL or not. Any help is appreciated. Thanks, -sanju