[eluser]ascotan[/eluser]
There is currently no way to switch the collation type "on the fly" for a search (at least that i could easily find).
I'd like to do to following with MySQL:
SELECT x
FROM y
WHERE z = limiter
AND a LIKE '%searchterm%' COLLATE latin1_general_ci
ORDER BY b
LIMIT c
This is because my table default is "latin1_general_cs". I need CS in the db, however I want particular searches to be CI. (case sensitive/insensitive).
Anywho. I went about adding a 4th parameter to the LIKE queries:
Code:
function like($field, $match = '', $side = 'both', $collation=NULL)
{
return $this->_like($field, $match, 'AND ', $side, NULL, $collation);
}
.....
function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '', $collation)
{
......
if ($side == 'before')
{
$like_statement = $prefix." $k $not LIKE '%{$v}'";
if ($collation){
$like_statement = $like_statement." COLLATE ".$collation;
}
}
.....
So I can run:
Code:
if ($filter_type->modifier_type == "text"){
switch($filter->modifier){
case 0:
$this->db->where($selector, $filter->text, NULL, 'latin1_general_ci');
break;
case 1:
$this->db->like($selector, $filter->text, NULL, 'latin1_general_ci');
break;
case 2;
$this->db->like($selector, $filter->text, 'before', 'latin1_general_ci');
break;
case 3;
$this->db->like($selector, $filter->text, 'after', 'latin1_general_ci');
break;
}
}
I'd like to "hook" this or something but the DB modules are not "hookable". Wondering if there was another way to do this or if not, that this might be a nice feature for peeps that use CS collation types on their tables.