Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Sql in dbman globals

Quote Reply
Sql in dbman globals
I am going to make a global for dbman sql including a sql-statment like this:

"select sum(sum_ff) from table_name where field_name like 'foobar' and sum_ff > 0"

How to do this is not documented.

Do someone have any idea on how to do this?
Kjetil Palmquist
Quote Reply
Re: [kjetilpa] Sql in dbman globals In reply to
The code should be:

sub {

my $db = $DB->table('table_name');

require GT::SQL::Condition;

my $cd = GT::SQL::Condition->new('field_name', 'like', '%foobar%');

my $total = $db->select($cd, ['SUM(sum_ff) as total'])->fetchrow_array;
return $total;