$schema->storage->sql_maker->quote_char('`');
$schema->storage->sql_maker->name_sep('.');
-my ($sql, @bind) = ('');
+my ($sql, @bind);
$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
$schema->storage->debug(1);
{ quote_char => '`', name_sep => '.' },
);
-my ($sql, @bind) = ('');
+my ($sql, @bind);
$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)),
$schema->storage->debug(1);
{
$rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] })->search({}, { where => \"title LIKE ?", bind => [ 'Spoon%' ] });
- my ($sql, @bind) = @${$rs->as_query};
is_same_sql_bind(
- $sql, \@bind,
+ $rs->as_query,
"(SELECT me.artistid, me.name, me.rank, me.charfield FROM (SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year FROM artist a JOIN cd ON cd.artist = a.artistid WHERE cd.year = ?) WHERE title LIKE ?)",
[
[ '!!dummy' => '1999' ],
. 'child.father_id ) JOIN person mother ON ( mother.person_id '
. '= child.mother_id )'
;
-is_same_sql_bind(
- $sa->_recurse_from(@j), [],
- $match, [],
+is_same_sql(
+ $sa->_recurse_from(@j),
+ $match,
'join 1 ok'
);
. ' father.person_id = child.father_id )) ON ( mother.person_id = '
. 'child.mother_id )'
;
-is_same_sql_bind(
- $sa->_recurse_from(@j2), [],
- $match, [],
+is_same_sql(
+ $sa->_recurse_from(@j2),
+ $match,
'join 2 ok'
);
. '= child.mother_id )'
;
-is_same_sql_bind(
- $sa->_recurse_from(@j3), [],
- $match, [],
+is_same_sql(
+ $sa->_recurse_from(@j3),
+ $match,
'join 3 (inner join) ok'
);
. ' father.person_id = child.father_id )) ON ( mother.person_id = '
. 'child.mother_id )'
;
-is_same_sql_bind(
- $sa->_recurse_from(@j4), [],
- $match, [],
+is_same_sql(
+ $sa->_recurse_from(@j4),
+ $match,
'join 4 (nested joins + join types) ok'
);
. 'child.father_id ) JOIN person mother ON ( mother.person_id '
. '= child.mother_id )'
;
-is_same_sql_bind(
- $sa->_recurse_from(@j5), [],
- $match, [],
+is_same_sql(
+ $sa->_recurse_from(@j5),
+ $match,
'join 5 (SCALAR reference for ON statement) ok'
);
}
);
-my ($sql, @bind) = @${$rs->as_query};
is_same_sql_bind (
- $sql,
- \@bind,
+ $rs->as_query,
'(SELECT me.cdid, me.title, artist.name FROM cd me JOIN artist artist ON artist.artistid = me.artist)',
[],
'Use of columns attribute results in proper sql'
}
);
-($sql, @bind) = @${$rs->as_query};
is_same_sql_bind (
- $sql,
- \@bind,
+ $rs->as_query,
'(SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, me.cdid, me.title, artist.name FROM cd me JOIN artist artist ON artist.artistid = me.artist)',
[],
'Use of columns attribute results in proper sql'
# test trace output correctness for bind params
{
- my ($sql, @bind) = ('');
- $schema->storage->debugcb( sub { $sql = $_[1] } );
+ my ($sql, @bind);
+ $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
my @cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
is_same_sql_bind(
- $sql, [],
- "SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( artist = ? AND (cdid BETWEEN ? AND ?) ): '1', '1', '3'", [],
+ $sql, \@bind,
+ "SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE ( artist = ? AND (cdid BETWEEN ? AND ?) ): '1', '1', '3'",
+ [qw/'1' '1' '3'/],
'got correct SQL with all bind parameters (debugcb)'
);
- $schema->storage->debugcb(undef);
- $schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind));
@cds = $schema->resultset('CD')->search( { artist => 1, cdid => { -between => [ 1, 3 ] }, } );
is_same_sql_bind(
$sql, \@bind,
$sql,
\@bind,
'SELECT COUNT( * ) FROM (SELECT cds.cdid FROM artist me LEFT JOIN cd cds ON cds.artist = me.artistid LEFT JOIN track tracks ON tracks.cd = cds.cdid JOIN artist artist ON artist.artistid = cds.artist WHERE tracks.position = ? OR tracks.position = ? GROUP BY cds.cdid ORDER BY tracks.cd) count_subq',
- [ qw/'1' '2'/ ], # wtf? we quote bind vals?
+ [ qw/'1' '2'/ ],
);
}
$sql,
\@bind,
'SELECT COUNT( * ) FROM cd me LEFT JOIN track tracks ON tracks.cd = me.cdid JOIN cd disc ON disc.cdid = tracks.cd LEFT JOIN lyrics lyrics ON lyrics.track_id = tracks.trackid WHERE ( ( position = ? OR position = ? ) )',
- [ qw/'1' '2'/ ], # wtf? we quote bind vals?
+ [ qw/'1' '2'/ ],
);
}
artist_id => { 'in' => $art_rs->search({}, { rows => 1 })->get_column( 'id' )->as_query },
});
- my $arr = $cdrs2->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $cdrs2->as_query,
"(SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE artist_id IN ( SELECT id FROM artist me LIMIT 1 ))",
[],
);
},
);
- my $arr = $rs->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $rs->as_query,
"(SELECT (SELECT id FROM cd me LIMIT 1) FROM artist me)",
[],
);
},
);
- my $arr = $rs->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $rs->as_query,
"(SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT id FROM cd me LIMIT 1) FROM artist me)",
[],
);
},
);
- my $arr = $rs->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $rs->as_query,
"(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE ( id > ? ) ) cd2)",
[
[ 'id', 20 ]
{ 'me.artistid' => 'cds_artist' } ] ]
});
- my $arr = $art_rs2->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $art_rs2->as_query,
"(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me JOIN (SELECT me.artist as cds_artist FROM cd me) cds ON me.artistid = cds_artist)",
[]
);
},
);
- my $arr = $rs->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $rs->as_query,
"(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track
FROM
(SELECT cd3.cdid,cd3.artist,cd3.title,cd3.year,cd3.genreid,cd3.single_track
)->get_column('year')->max_rs->as_query,
},
});
- my $arr = $rs->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $rs->as_query,
"(SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE year = (SELECT MAX(inner.year) FROM cd inner WHERE artistid = me.artistid))",
[],
);
},
);
- my $arr = $rs->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $rs->as_query,
"(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE ( title = ? ) ) cd2)",
[ [ 'title', 'Thriller' ] ],
);
}
-
-__END__
my $cdrs = $schema->resultset('CD');
{
- my $arr = $art_rs->as_query;
- my ($query, @bind) = @{$$arr};
-
is_same_sql_bind(
- $query, \@bind,
+ $art_rs->as_query,
"(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me)", [],
);
}
$art_rs = $art_rs->search({ name => 'Billy Joel' });
{
- my $arr = $art_rs->as_query;
- my ($query, @bind) = @{$$arr};
-
is_same_sql_bind(
- $query, \@bind,
+ $art_rs->as_query,
"(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE ( name = ? ))",
[ [ name => 'Billy Joel' ] ],
);
$art_rs = $art_rs->search({ rank => 2 });
{
- my $arr = $art_rs->as_query;
- my ($query, @bind) = @{$$arr};
-
is_same_sql_bind(
- $query, \@bind,
+ $art_rs->as_query,
"(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me WHERE ( ( ( rank = ? ) AND ( name = ? ) ) ) )",
[ [ rank => 2 ], [ name => 'Billy Joel' ] ],
);
my $rscol = $art_rs->get_column( 'charfield' );
{
- my $arr = $rscol->as_query;
- my ($query, @bind) = @{$$arr};
-
is_same_sql_bind(
- $query, \@bind,
+ $rscol->as_query,
"(SELECT me.charfield FROM artist me WHERE ( ( ( rank = ? ) AND ( name = ? ) ) ) )",
[ [ rank => 2 ], [ name => 'Billy Joel' ] ],
);
artist_id => { 'in' => $art_rs->search({}, { rows => 1 })->get_column( 'id' )->as_query },
});
- my $arr = $cdrs2->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $cdrs2->as_query,
"( SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE artist_id IN ( SELECT id FROM artist me LIMIT 1 ) )",
[],
);
},
);
- my $arr = $rs->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $rs->as_query,
"( SELECT (SELECT id FROM cd me LIMIT 1) FROM artist me )",
[],
);
},
);
- my $arr = $rs->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $rs->as_query,
"( SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT id FROM cd me LIMIT 1) FROM artist me )",
[],
);
},
);
- my $arr = $rs->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $rs->as_query,
"( SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE id > ?) cd2 )",
[
[ 'id', 20 ]
{ 'me.artistid' => 'cds_artist' } ] ]
});
- my $arr = $art_rs2->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $art_rs2->as_query,
"( SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me JOIN (SELECT me.artist as cds_artist FROM cd me) cds ON me.artistid = cds_artist )", []
);
},
);
- my $arr = $rs->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $rs->as_query,
"( SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track
FROM
(SELECT cd3.cdid,cd3.artist,cd3.title,cd3.year,cd3.genreid,cd3.single_track
)->get_column('year')->max_rs->as_query,
},
});
- my $arr = $rs->as_query;
- my ($query, @bind) = @{$$arr};
+
is_same_sql_bind(
- $query, \@bind,
+ $rs->as_query,
"( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE year = (SELECT MAX(inner.year) FROM cd inner WHERE artistid = me.artistid) )",
[],
);
},
);
- my $arr = $rs->as_query;
- my ($query, @bind) = @{$$arr};
is_same_sql_bind(
- $query, \@bind,
+ $rs->as_query,
"(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE title = ?) cd2)",
[
[ 'title',
],
);
}
-
-__END__