Commit fb30d9f1 authored by Steve Müller's avatar Steve Müller

fix LOCATE expression offset evaluation on SQLite

parent 168eac3a
......@@ -543,9 +543,16 @@ class SqlitePlatform extends AbstractPlatform
*/
static public function udfLocate($str, $substr, $offset = 0)
{
// SQL's LOCATE function works on 1-based positions, while PHP's strpos works on 0-based positions.
// So we have to make them compatible if an offset is given.
if ($offset > 0) {
$offset--;
}
$pos = strpos($str, $substr, $offset);
if ($pos !== false) {
return $pos+1;
return $pos + 1;
}
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment