[Dbix-class] Help me with subclassing
dreel
dreel at bk.ru
Fri Sep 14 14:19:56 GMT 2007
I wana enhance SQL::Abstract::Limit
It's working wrong with MS SQL Server
if i make sql like this
->search(
{
'rt.net_id' => $c->stash->{net_id},
},
{
alias => 'rt', # alias columns in accordance with "from"
from => [
{ rt => 'vi_route' },
[
{ n_1 => 'vi_nodes', -join_type => 'inner' },
{
'rt.route_beg' => 'n_1.node_id',
'rt.net_id' => 'n_1.net_id'
}
],
[
{ n_2 => 'vi_nodes', -join_type => 'inner' },
{
'rt.route_end' => 'n_2.node_id',
'rt.net_id' => 'n_2.net_id'
}
],
],
'select' => [
{ distinct => ['rt.route_beg']},
'rt.route_end',
\'n_1.node_name AS node_name_beg',
\'n_2.node_name AS node_name_end',
'(SELECT COUNT(v.route_beg) FROM vi_route v WHERE v.net_id = \''.$c->stash->{net_id}.'\' and v.route_beg = rt.route_beg and v.route_end = rt.route_end) as grp_count',
],
'as' => [ qw/ route_beg route_end node_name_beg node_name_end route_grp_count / ],
'order_by' => $order_by,
page => $page, # page to return (defaults to 1)use Data::Dumper; die "SEARCH" . Dumper($new_attrs);
rows => $rows, # number of results per page
},
)
it becomes WRONG syntax in sql:
SELECT * FROM
(
SELECT TOP 10 * FROM
(
SELECT TOP 10 DISTINCT ...sql ORDER BY node_name_beg ASC
) AS foo
ORDER BY node_name_beg DESC
) AS bar
ORDER BY node_name_beg ASC
SQL Server has another syntax: SELECT DISTINCT TOP 10 (DISTINCT BEFORE TOP)
I wana do right sql - it work fine when looks like:
sub _Top {
my ( $self, $sql, $order, $rows, $offset ) = @_;
my $last = $rows + $offset;
my ( $order_by_up, $order_by_down ) = $self->_order_directions( $order );
$sql = <<"";
SELECT * FROM
(
SELECT TOP $rows * FROM
(
SELECT TOP $last * FROM
(
$sql
) AS doo
$order_by_up
) AS foo
$order_by_down
) AS bar
$order_by_up
return $sql;
}
But I don't have enough experience to subclass it - i never do it (
More information about the DBIx-Class
mailing list