~ubuntu-branches/ubuntu/intrepid/libdbix-searchbuilder-perl/intrepid

« back to all changes in this revision

Viewing changes to SearchBuilder/Handle/SQLite.pm

  • Committer: Bazaar Package Importer
  • Author(s): Niko Tyni
  • Date: 2007-05-22 22:59:59 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070522225959-85fasy1na0irre21
Tags: 1.48-1
* New upstream release.
* Add build-dependency on libtest-pod-perl, for test coverage.
* Upgrade to debhelper compatibility level 5.
* Update watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
package DBIx::SearchBuilder::Handle::SQLite;
3
 
use DBIx::SearchBuilder::Handle;
4
 
@ISA = qw(DBIx::SearchBuilder::Handle);
5
3
 
6
 
use vars qw($VERSION @ISA $DBIHandle $DEBUG);
7
4
use strict;
 
5
use warnings;
 
6
 
 
7
use base qw(DBIx::SearchBuilder::Handle);
8
8
 
9
9
=head1 NAME
10
10
 
96
96
 
97
97
 
98
98
 
99
 
=head2 _BuildJoins
100
 
 
101
 
Adjusts syntax of join queries for SQLite.
102
 
 
103
 
=cut
104
 
 
105
 
#SQLite can't handle 
106
 
# SELECT DISTINCT main.*     FROM (Groups main          LEFT JOIN Principals Principals_2  ON ( main.id = Principals_2.id)) ,     GroupMembers GroupMembers_1      WHERE ((GroupMembers_1.MemberId = '70'))     AND ((Principals_2.Disabled = '0'))     AND ((main.Domain = 'UserDefined'))     AND ((main.id = GroupMembers_1.GroupId)) 
107
 
#     ORDER BY main.Name ASC
108
 
#     It needs
109
 
# SELECT DISTINCT main.*     FROM Groups main           LEFT JOIN Principals Principals_2  ON ( main.id = Principals_2.id) ,      GroupMembers GroupMembers_1      WHERE ((GroupMembers_1.MemberId = '70'))     AND ((Principals_2.Disabled = '0'))     AND ((main.Domain = 'UserDefined'))     AND ((main.id = GroupMembers_1.GroupId)) ORDER BY main.Name ASC
110
 
 
111
 
sub _BuildJoins {
112
 
    my $self = shift;
113
 
    my $sb   = shift;
114
 
    my %seen_aliases;
115
 
    
116
 
    $seen_aliases{'main'} = 1;
117
 
 
118
 
    # We don't want to get tripped up on a dependency on a simple alias. 
119
 
        foreach my $alias ( @{ $sb->{'aliases'}} ) {
120
 
          if ( $alias =~ /^(.*?)\s+(.*?)$/ ) {
121
 
              $seen_aliases{$2} = 1;
122
 
          }
123
 
    }
124
 
 
125
 
    my $join_clause = $sb->Table . " main ";
126
 
    
127
 
    my @keys = ( keys %{ $sb->{'left_joins'} } );
128
 
    my %seen;
129
 
    
130
 
    while ( my $join = shift @keys ) {
131
 
        if ( ! $sb->{'left_joins'}{$join}{'depends_on'} || $seen_aliases{ $sb->{'left_joins'}{$join}{'depends_on'} } ) {
132
 
           #$join_clause = "(" . $join_clause;
133
 
            $join_clause .=
134
 
              $sb->{'left_joins'}{$join}{'alias_string'} . " ON (";
135
 
            $join_clause .=
136
 
              join ( ') AND( ',
137
 
                values %{ $sb->{'left_joins'}{$join}{'criteria'} } );
138
 
            $join_clause .= ") ";
139
 
            
140
 
            $seen_aliases{$join} = 1;
141
 
        }   
142
 
        else {
143
 
            push ( @keys, $join );
144
 
            die "Unsatisfied dependency chain in Joins @keys"
145
 
              if $seen{"@keys"}++;
146
 
        }     
147
 
        
148
 
    }
149
 
    return ( join ( ", ", ( $join_clause, @{ $sb->{'aliases'} } ) ) );
150
 
    
151
 
}
152
 
 
153
99
1;
154
100
 
155
101
__END__