Welcome Guest, Not a member yet? Register   Sign In
$this->db->where bug?
#1

[eluser]Darkroom Dave[/eluser]
I just upgraded from 1.7.0 to 1.7.1 and a few of my queries no longer work.

$this->db->where("highlight=1");

but will work if I change it to

$this->db->where("highlight = 1");
#2

[eluser]Dam1an[/eluser]
What error do you get with the no space version?
Does it fail to create the query, or just not return the expected results?

If you turn on the profiler, what is the generarated query for both cases? (there is also a function to return the SQL query, but can't remember its name, as I've never needed it)
#3

[eluser]warrennz[/eluser]
Or just pass in 2 params

Code:
$this->db->where('highlight',1);

This way it should never break regardless of CI version
#4

[eluser]Dam1an[/eluser]
[quote author="warrennz" date="1240631645"]Or just pass in 2 params

Code:
$this->db->where('highlight',1);

This way it should never break regardless of CI version[/quote]

Yeah, thats a good way to do, as it future proofs you, but doesn't explain why his/her code has broken
#5

[eluser]wiredesignz[/eluser]
[quote author="Dam1an" date="1240668453"]... but doesn't explain why his/her code has broken[/quote]

CI active record adds backticks to the entire string causing the error, the spaces allow it to add backticks correctly.
#6

[eluser]darkroomdave[/eluser]
I ran the profiler on it to see what it was doing

SELECT * FROM (`categories`) WHERE `highlight=1` ORDER BY `orderid`

So it does break my existing code. Maybe it shouldn't back tick if there is a operator like = in there?

Obliviously it didn't before 1.7.1

I do usually use the array method but the same problem also broke this

$this->db->where(sprintf("parent_id=%s OR highlight=1", $id));

And yes I could of used or_where but I didn't
#7

[eluser]Dam1an[/eluser]
[quote author="darkroomdave" date="1240956248"]
$this->db->where(sprintf("parent_id=%s OR highlight=1", $id));[/quote]
I think its because you have nested logic, try setting the second parameter to false
#8

[eluser]darkroomdave[/eluser]
To be clear. I am not trying to fixed this. Already fix days ago.

I am pointing out there was a change some place before 1.7.1 that breaks existing code.

Just trying to be helpful to others...




Theme © iAndrew 2016 - Forum software by © MyBB