+our @values;
+our @limits;
+
+sub __ldap_search_to_sql {
+ my ( $how, $what ) = @_;
+ warn "### how $how\n";
+ if ( $how eq 'equalityMatch' && defined $what ) {
+ my $name = $what->{attributeDesc} || warn "ERROR: no attributeDesc?";
+ my $value = $what->{assertionValue} || warn "ERROR: no assertionValue?";
+ if ( ! $ldap_ignore->{ $name } ) {
+ push @limits, __sql_column($name) . ' = ?';
+ push @values, $value;
+ }
+ } elsif ( $how eq 'substrings' ) {
+ foreach my $substring ( @{ $what->{substrings} } ) {
+ my $name = $what->{type} || warn "ERROR: no type?";
+ while ( my($op,$value) = each %$substring ) {
+ push @limits, __sql_column($name) . ' LIKE ?';
+ if ( $op eq 'any' ) {
+ $value = '%' . $value . '%';
+ } else {
+ warn "UNSUPPORTED: op $op - using plain $value";
+ }
+ push @values, $value;
+ }
+ }
+ } elsif ( $how eq 'present' ) {
+ my $name = __sql_column( $what );
+ push @limits, "$name IS NOT NULL and length($name) > 1";
+ ## XXX length(foo) > 1 to avoid empty " " strings
+ } else {
+ warn "UNSUPPORTED: how $how what ",dump( $what );
+ }
+}
+