better handling of children_cond

This commit is contained in:
Pierangelo Masarati 2002-08-31 10:38:29 +00:00
parent 95a99bd522
commit a1bb43946b

View file

@ -288,31 +288,7 @@ backsql_db_open(
} }
if ( si->children_cond.bv_val == NULL ) { if ( si->children_cond.bv_val == NULL ) {
/*
* Prepare concat function for children search condition
*/
struct berval concat;
ber_len_t len = 0; ber_len_t len = 0;
struct berval values[] = {
{ sizeof( "'%,'" ) - 1, "'%,'" },
{ sizeof( "?" ) - 1, "?" },
{ 0, NULL }
};
if ( backsql_prepare_pattern( si->concat_func, values,
&concat ) ) {
Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
"unable to prepare CONCAT pattern", 0, 0, 0 );
return 1;
}
Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
"children search SQL condition not specified "
"(use \"children_cond\" directive in slapd.conf)\n",
0, 0, 0);
si->children_cond.bv_val = NULL;
si->children_cond.bv_len = 0;
if ( si->upper_func.bv_val ) { if ( si->upper_func.bv_val ) {
@ -320,13 +296,12 @@ backsql_db_open(
* UPPER(ldap_entries.dn) LIKE UPPER(CONCAT('%,',?)) * UPPER(ldap_entries.dn) LIKE UPPER(CONCAT('%,',?))
*/ */
backsql_strfcat( &si->children_cond, &len, "blbbb", backsql_strfcat( &si->children_cond, &len, "blbl",
&si->upper_func, &si->upper_func,
(ber_len_t)sizeof( "(ldap_entries.dn) LIKE " ) - 1, (ber_len_t)sizeof( "(ldap_entries.dn)=" ) - 1,
"(ldap_entries.dn) LIKE ", "(ldap_entries.dn)=",
&si->upper_func_open, &si->upper_func,
&concat, (ber_len_t)sizeof( "(?)" ) - 1, "(?)" );
&si->upper_func_close );
} else { } else {
@ -334,10 +309,9 @@ backsql_db_open(
* ldap_entries.dn LIKE CONCAT('%,',?) * ldap_entries.dn LIKE CONCAT('%,',?)
*/ */
backsql_strfcat( &si->children_cond, &len, "lb", backsql_strfcat( &si->children_cond, &len, "l",
(ber_len_t)sizeof( "ldap_entries.dn LIKE " ) - 1, (ber_len_t)sizeof( "ldap_entries.dn=?" ) - 1,
"ldap_entries.dn LIKE ", "ldap_entries.dn=?");
&concat );
} }
Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): " Debug( LDAP_DEBUG_TRACE, "backsql_db_open(): "
@ -446,7 +420,8 @@ backsql_db_open(
bv.bv_val = NULL; bv.bv_val = NULL;
bv.bv_len = 0; bv.bv_len = 0;
backsql_strfcat( &bv, &idq_len, "sb", backsql_strfcat( &bv, &idq_len, "sb",
"select count(*) from ldap_entries where ", "SELECT COUNT(distinct subordinates.id) FROM ldap_entries,ldap_entries AS subordinates WHERE subordinates.parent=ldap_entries.id AND ",
&si->children_cond ); &si->children_cond );
si->has_children_query = bv.bv_val; si->has_children_query = bv.bv_val;