Welcome Guest, Not a member yet? Register   Sign In
CI 2.1.0 db error but working ok with CI 2.0.2
#1

[eluser]Unknown[/eluser]
hi i have this:
Code:
$q = $this->db
->select_sum('totale')
->select_sum('iva4')
->select_sum('iva10')
->select_sum('iva20')
->select('cast( (sum(`rci_registro_date`.`iva4`) / (1.04)) AS DECIMAL(12,2) ) AS `scorp_iva4`',FALSE)->where('meseanno',date("mY"))
->from('rci_registro_date, aaa_iva_oriz')->get();

in ci 2.0.2 it's working fine
Switching the framework to 2.1.0 and this is the result:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`2)` ) AS `scorp_iva4` FROM (`rci_registro_date`, `aaa_iva_oriz`) WHERE `meseann' at line 1

SELECT SUM(`totale`) AS totale, SUM(`iva4`) AS iva4, SUM(`iva10`) AS iva10, SUM(`iva20`) AS iva20, cast( (sum(`rci_registro_date`.`iva4`) / (1.04)) AS DECIMAL(12, `2)` ) AS `scorp_iva4` FROM (`rci_registro_date`, `aaa_iva_oriz`) WHERE `meseanno` = '012012'
CI adds the ` even though i've added FALSE as the second parameter in the select

UPDATE
I've simplified the query trying to understand where the problem is
Code:
controller
function testdb(){
  $this->load->model("testdb");
  $q1 = $this->testdb->get1()->result();
  var_dump($q1);
  $q2 = $this->testdb->get2()->result();
  var_dump($q2);die();
}


model
function get1(){
  $q = $this->db->select("cast(sum(`aaa_test`.`test` / 10) AS DECIMAL(12,2)) as pippo",FALSE)->select_sum('test')
  ->from('aaa_test')
  ->get();
  echo $this->db->last_query();
  return $q;
}
function get2(){
  $q = $this->db->select_sum('test')->select("cast(sum(`aaa_test`.`test` / 10) AS DECIMAL(12,2)) as pippo",FALSE)
  ->from('aaa_test')
  ->get();
  echo $this->db->last_query();
  return $q;
}


RESULTS
SELECT cast(sum(`aaa_test`.`test` / 10) AS DECIMAL(12, 2)) as pippo, SUM(`test`) AS test FROM (`aaa_test`)

array
  0 =>
    object(stdClass)[21]
      public 'pippo' => string '23.40' (length=5)
      public 'test' => string '234' (length=3)

A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`2))` as pippo FROM (`aaa_test`)' at line 1

SELECT SUM(`test`) AS test, cast(sum(`aaa_test`.`test` / 10) AS DECIMAL(12, `2))` as pippo FROM (`aaa_test`)

Line Number: 330

In CI 202 both the queries are working
IN CI 210 only the first one works, the difference is the order of the select - select_sum
so, is this a bug?
#2

[eluser]Phil Sturgeon[/eluser]
Try this on the 2.1-stable branch and see what happens. There was a bug that basically made sum, max, etc useless.




Theme © iAndrew 2016 - Forum software by © MyBB