Welcome Guest, Not a member yet? Register   Sign In
Bug with CI 1.7 - Active Record - select_sum
#1

[eluser]maxez[/eluser]
Hey Derek/guys,

I think I found a bug that is unreported. I searched the forum and found nothing, my excuses if this has been already reported though. I am 99% sure it is a bug, but I was wondering if somebody could try to reproduce. Here is the deal for the following code:

Code:
$this->db->select_sum('c.amount', 'total');
$this->db->from('transactions c');
$this->db->where("c.type","Payment");
$query = $this->db->get();
$row = $query->row();
$return['total_payments'] = $row->total;

The query generated by CI is as follows:

Code:
SELECT `SUM(`c`.`amount`)` AS total FROM (`transactions` c) WHERE `c`.`type` = 'Payment'

NOTE the bakticks (or whatever they are called Smile ) around the "SUM" statement. This obviously blows up. Now to the interesting part: If I rewrite the select_sum WITHOUT a table qualifier (Instead of c.amount, I say amount), it works fine. So this works fine:

Code:
$this->db->select_sum('amount', 'total');
$this->db->from('transactions c');
$this->db->where("c.type","Payment");
$query = $this->db->get();
$row = $query->row();
$return['total_payments'] = $row->total;
Code:
SELECT SUM(`amount`) AS total FROM (`transactions` c) WHERE `c`.`type` = 'Payment'
Again, pretty sure is a bug, if anybody could replicate, I will appreciate it.

Database is MySql 5.0.67
I AM 100% SURE THIS WASN'T HAPPENING ON CI 1.6.3.

Thanks!
Max




Theme © iAndrew 2016 - Forum software by © MyBB