[Dbix-class] Set a MySQL Variable Before Doing SELECT
Websuche :: Felix Antonius Wilhelm Ostmann
ostmann at websuche.de
Wed Mar 16 08:12:10 GMT 2011
I need that behavior for setting special env for some queries and i use
the following (in a resultset-class):
sub latest {
my ($self) = @_;
return $schema->storage->dbh_do(sub {
my ($storage, $dbh, $self) = @_;
local $dbh->{pg_server_prepare} = 0;
return [
$self
->search(...)
->get_column(...)
->all
,
];
}, $self);
}
...
$dbh->do('SET @runtot := 0;');
return $self->search(...)->all;
...
only problem: you have to execute the query when you call that func (you
cannot chain the rs)
Am 15.03.2011 20:23, schrieb Dave Mabe:
> I'm trying to calculate a running total in the query I'm doing with
> DBIx::Class, similar to what is described here:
>
> http://stackoverflow.com/questions/664700/calculate-a-running-total-in-mysql
>
> So basically I'll need to run this command just before running a query
> to get a resultset:
>
> SET @runtot := 0;
> SELECT profit, (@runtot := @runtot + profit) AS rt FROM table;
>
> How can I have that "SET @runtot := 0;" execute just before the SELECT
> statement when I call the resultset method?
>
> Dave
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>
--
Mit freundlichen Grüßen
Felix Antonius Wilhelm Ostmann
-----------------------------------------------------------
Websuche Search Technology GmbH & Co. KG
Martinistraße 3, D-49080 Osnabrück
-----------------------------------------------------------
Tel.: +49 (0) 541 40666 0, Fax: +49 (0) 541 40666 22
Email: info at websuche.de, Web: www.websuche.de
-----------------------------------------------------------
HRA 200252, AG Osnabrück, Ust-IdNr.: DE814737310
-----------------------------------------------------------
Komplementärin: Websuche Search Technology Verwaltungs GmbH
HRB 200359, AG Osnabrück, Geschäftsführer: Ansas Meyer
-----------------------------------------------------------
Die in dieser Email enthaltenen Informationen sind vertrau-
lich zu behandeln und ausschließlich für den Adressaten be-
stimmt. Jegliche Veröffentlichung, Verteilung oder sonstige
in diesem Zusammenhang stehende Handlung wird ausdrücklich
untersagt.
More information about the DBIx-Class
mailing list