[Dbix-class] Issue converting select/insert from DBI to DBIx::Class

Steve Bertrand steve at ibctech.ca
Tue Dec 22 17:41:19 GMT 2009


Rob Kinyon wrote:

> The first problem is that you're ignore AcctDate in the select and
> AcctStopTime in the where clauses. Second is the 'as' element is
> unneeded.

Thanks Rob, you set me on another tangent, so I now have this working
code which simulates exactly what I had before (which hopefully doesn't
get mangled):

    my $daily_fetch_rs = $schema->resultset( 'Radacct' )->search(

            {
                'username' => 'test3',
                'acctstoptime' => { like => "$day%" },
            },{

            select => [
                'username',
                { count => 'radacctid' },
                { sum   => 'acctsessiontime' },
                { max   => 'acctsessiontime' },
                { min   => 'acctsessiontime' },
                { sum   => 'acctinputoctets' },
                { sum   => 'acctoutputoctets' },
                'nasipaddress',
            ],

            group_by => [ qw/ username nasipaddress / ],

            as       => [ qw/
                                UserName
                                ConnNum
                                ConnTotDuration
                                ConnMaxDuration
                                ConnMinDuration
                                InputOctets
                                OutputOctets
                                NASIPAddress
                            /,
                        ],
        });

    $daily_fetch_rs->result_class(
			'DBIx::Class::ResultClass::HashRefInflator'
		);

    my $agg_table = $schema->resultset( 'DailyAgg' );

    while ( my $daily_entry = $daily_fetch_rs->next() ) {

        $daily_entry->{ AcctDate } = $day;
        $agg_table->create( $daily_entry );
    }

> Does that help?

Yep! Thanks ;)

Steve



More information about the DBIx-Class mailing list