Bio::DB::Query::SqlGenerator - Object representing an SQL Query
use Bio::DB::Query::BioQuery; use Bio::DB::Query::SqlGenerator; # get a Bio::DB::Query::AbstractQuery or derived query somehow my $query = Bio::DB::Query::BioQuery->new(-tables => ["table1, table2"]); $query->where(["and", ["or", "col4 = ?", "col5 = 'somevalue'"], ["col2 = col4", "col6 not like 'abcd*'"]]); # use the generator to turn a query object into SQL my $sqlgen = Bio::DB::Query::SqlGenerator->new(-query => $query); my $sql = $sqlgen->generate_sql(); print "SQL: $SQL\n"; # then bind as necessary, and execute ...
This represents the strategy pattern for generating a SQL statement given a Query object.
Eventually there should be interfaces for this pattern as well as for the Query.
Chris Mungall, firstname.lastname@example.org Hilmar Lapp, hlapp at gmx.net
This is essentially code ripped out of SqlQuery.pm and AbstractQuery.pm (both by Chris Mungall), put into its own module as a strategy pattern.
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
Title : query Usage : $obj->query($newval) Function: Get/set query object (a Bio::DB::Query::AbstractQuery or derived instance). Example : Returns : value of query (a Bio::DB::Query::AbstractQuery or derived) Args : new value (a Bio::DB::Query::AbstractQuery or derived, optional)
Usage: $sqlstmt = $sqlgen->generate_sql; $dbh->do($sqlstmt); $sqlstmt = $sqlgen->generate_sql($query); $dbh->do($sqlstmt);
Flattens query object into a SQL statement.