[Dbix-class] Issue converting select/insert from DBI to DBIx::Class
Steve Bertrand
steve at ibctech.ca
Tue Dec 22 14:28:41 GMT 2009
Hi all,
I've been working on converting much of my DBI code to DBIx::Class, and
am a tad bit stuck.
This particular issue is one that I've worked on for quite a few hours,
while testing out different combinations I've found in the great number
of docs. I'm at the point now where I could use an experienced set of eyes.
My original code:
my $insert_sth = $dbh->prepare("
INSERT INTO aggregate_daily
( UserName, AcctDate, ConnNum,
ConnTotDuration, ConnMaxDuration, ConnMinDuration,
InputOctets, OutputOctets, NASIPAddress
)
SELECT UserName, '$day', COUNT(*), SUM(AcctSessionTime),
MAX(AcctSessionTime), MIN(AcctSessionTime),
SUM(AcctInputOctets),
SUM(AcctOutputOctets), NASIPAddress
FROM radacct
WHERE AcctStopTime like '$day%'
GROUP BY UserName,NASIPAddress
") or die $DBI::errstr;
...and the new code (albeit unfinished, as I am just trying to get the
basics of a select down first). Although it runs without error, I have
no indication that I'm doing things properly. When I dump the $rs with
Data::Dumper, I do not see the expected data.
Can someone let me know if I'm on the right track?
my $rs = $schema->resultset( 'Radacct' )->search( undef, {
select => [
'username',
{ count => 'radacctid' },
{ sum => 'acctsessiontime' },
{ max => 'acctsessiontime' },
{ min => 'acctsessiontime' },
{ sum => 'acctinputoctets' }, { {
sum => 'acctoutputoctets' },
'nasipaddress',
],
group_by => [ qw/ username nasipaddress / ],
as => [ 'daily' ],
});
Steve
More information about the DBIx-Class
mailing list