Welcome Guest, Not a member yet? Register   Sign In
Db prefix + dots in the query problem
#1

[eluser]GIN[/eluser]
Hi.

I'm not sure is that bug or not, but here is another similar problem http://ellislab.com/forums/viewthread/77767/
Anyway, my problem is:

I have a db prefix - sg_
I have this active record code:
Code:
$this->db->select('g.id, g.name, g.eng_name, g.price, g.code,
IF(CHAR_LENGTH(g.name)>40, CONCAT(LEFT(g.name, 40), "..."),g.name) as short_name,
gi.filename as preview, CONCAT(g.eng_name,"-",g.id) as nameid',FALSE)
->from('goods as g')
->join('goods_img as gi','g.id = gi.good_id AND gi.type = 0','left')
->where('g.id IN ('.join(',',$good_ids).') AND g.warehouse = 1 AND g.active = 1')
->groupby('g.id')
->orderby('g.priority');
$result = $this->db->get()->result();
And so what I got after $this->db->last_query():
Code:
SELECT g.id, g.name, g.eng_name, g.price, g.opt_price, g.code,
IF(CHAR_LENGTH(g.name)>40, CONCAT(LEFT(g.name, 40), "..sg_."), g.name) as short_name,
gi.filename as preview, CONCAT(g.eng_name, "-", g.id) as nameid FROM (sg_goods as g)
LEFT JOIN sg_goods_img as gi ON g.id = gi.good_id AND gi.type = 0
WHERE `g`.`id` IN (2855,2856,2857,2858,2859,2860,2861) AND g.warehouse = 1 AND g.active = 1
GROUP BY g.id
ORDER BY g.priority

Look at this section IF(CHAR_LENGTH(g.name)>40, CONCAT(LEFT(g.name, 40), "..sg_."), g.name) as short_name

If I have two or more dots - db_prefix appears in short_name (sg_)
If I have one dot there - I got syntax error in sql query:
IF(CHAR_LENGTH(g.name)>40, CONCAT(LEFT(g.name, 40), sg_"."), g.name) as short_name

Other symbols besides dots not makes problem.
I think problem in _protect_identifiers method in CI_DB_driver class, but can't understand what happens.

What do you think?


Messages In This Thread
Db prefix + dots in the query problem - by El Forum - 02-03-2010, 06:48 PM
Db prefix + dots in the query problem - by El Forum - 02-03-2010, 07:21 PM
Db prefix + dots in the query problem - by El Forum - 02-04-2010, 04:05 AM
Db prefix + dots in the query problem - by El Forum - 02-04-2010, 06:14 PM
Db prefix + dots in the query problem - by El Forum - 02-04-2010, 07:02 PM



Theme © iAndrew 2016 - Forum software by © MyBB