I attached a function to the REGEXP keyword in PHP and I discovered that SQLite3Result::fetchArray re-executes the query! What inefficiency!
function _sqliteRegexp($pattern, $string)
{
echo $pattern . ' - ' . $string . '<br/>';
return preg_match('/' . $pattern . '/', $string);
}
$handle = new SQLite3($filename);
$handle->createFunction('regexp', '_sqliteRegexp', 2);
// (1)
$result = $handle->query("SELECT * FROM pages WHERE '" . $request_uri . "' REGEXP request LIMIT 1;");
// (2)
$result->fetchArray();
Giving, for example:
(1)
\/ - /admin/settings/1
\/sqlite - /admin/settings/1
\/admin - /admin/settings/1
\/admin\/logout - /admin/settings/1
\/admin\/settings(\/[0-9]+)? - /admin/settings/1
(2)
\/ - /admin/settings/1
\/sqlite - /admin/settings/1
\/admin - /admin/settings/1
\/admin\/logout - /admin/settings/1
\/admin\/settings(\/[0-9]+)? - /admin/settings/1
Both (1) and (2) echo the pattern and string the very same. I highly suspect the query is re-executed, which would be quite redundant. Is this a bug or just me being hastily concluding?
LIMIT 3?