@ 2013-12-31T20:20:14Z <?php
/**
* Tokenizes text that looks something like SQL.
*/
function tokenizeSQL( $SQL )
{
$functions = array ( 'concat', 'if' );
$token = '\\(|\\)|[\']|"|\140|[*]|,|<|>|<>|=|[+]';
$terminal = $token.'|;| |\\n';
$result = array();
$string = $SQL;
$string = ltrim($string);
$string = rtrim($string,';').';'; // always ends with a terminal
$string = preg_replace( "/[\n\r]/s", ' ', $string );
while(
preg_match( "/^($token)($terminal)/s", $string, $matches ) ||
preg_match( "/^({$token})./s", $string, $matches ) ||
preg_match( "/^([a-zA-Z0-9_.]+?)($terminal)/s", $string, $matches)
)
{
$t = $matches[1];
if ($t=='\'')
{
// it's a string
$t = tokSingleQuoteString( $string );
array_push($result, $t);
}
else if ($t=="\140")
{
// it's a backtick string (a name)
$t = tokBackQuoteString( $string );
array_push($result, $t);
}
else if ($t=='"')
{
// it's a double quoted string (a name in normal sql)
$t = tokDoubleQuoteString( $string );
array_push($result, $t);
}
else
{
array_push($result, $t);
}
$string = substr( $string, strlen($t) );
$string = ltrim($string);
}
return $result;
}
function tokSingleQuoteString( $string )
{
// matches a single-quoted string in $string
// $string starts with a single quote
preg_match('/^(\'.*?\').*$/s', $string, $matches );
return $matches[1];
}
function tokBackQuoteString( $string )
{
// matches a back-quoted string in $string
// $string starts with a back quote
preg_match('/^([\140].*?[\140]).*$/s', $string, $matches );
return $matches[1];
}
function tokDoubleQuoteString( $string )
{
// matches a back-quoted string in $string
// $string starts with a back quote
preg_match('/^(".*?").*$/s', $string, $matches );
return $matches[1];
}
print "<pre>";
print_r(tokenizeSQL('SELECT name, rew from asdf where id in(select papa from sdfff')));
print "</pre>";
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.4.23 0.014 0.042 12.41 5.4.22 0.010 0.043 12.41 5.4.21 0.011 0.040 12.41 5.4.20 0.016 0.052 12.41 5.4.19 0.012 0.041 12.40 5.4.18 0.012 0.039 12.40 5.4.17 0.013 0.042 12.41 5.4.16 0.008 0.045 12.41 5.4.15 0.010 0.043 12.40 5.4.14 0.012 0.041 12.09 5.4.13 0.014 0.043 12.07 5.4.12 0.012 0.044 12.04 5.4.11 0.010 0.046 12.04 5.4.10 0.010 0.042 12.04 5.4.9 0.012 0.039 12.04 5.4.8 0.015 0.069 12.04 5.4.7 0.013 0.039 12.03 5.4.6 0.013 0.041 12.03 5.4.5 0.014 0.038 12.03 5.4.4 0.012 0.039 12.02 5.4.3 0.012 0.039 12.02 5.4.2 0.011 0.039 12.01 5.4.1 0.012 0.039 12.01 5.4.0 0.020 0.050 11.50 5.3.28 0.013 0.047 12.71 5.3.27 0.016 0.043 12.72 5.3.26 0.013 0.045 12.72 5.3.25 0.020 0.071 12.72 5.3.24 0.012 0.046 12.72 5.3.23 0.018 0.067 12.71 5.3.22 0.012 0.041 12.68 5.3.21 0.021 0.047 12.68 5.3.20 0.013 0.041 12.68 5.3.19 0.012 0.041 12.68 5.3.18 0.016 0.036 12.67 5.3.17 0.012 0.043 12.67 5.3.16 0.007 0.045 12.67 5.3.15 0.016 0.052 12.67 5.3.14 0.011 0.041 12.66 5.3.13 0.014 0.038 12.66 5.3.12 0.022 0.062 12.65 5.3.11 0.012 0.043 12.65 5.3.10 0.012 0.043 12.13 5.3.9 0.013 0.039 12.11 5.3.8 0.012 0.042 12.10 5.3.7 0.012 0.043 12.10 5.3.6 0.011 0.041 12.08 5.3.5 0.012 0.047 12.03 5.3.4 0.013 0.050 12.03 5.3.3 0.012 0.042 12.00 5.3.2 0.018 0.066 11.78 5.3.1 0.011 0.040 11.74 5.3.0 0.014 0.045 11.72
preferences:dark mode live preview
134.28 ms | 1394 KiB | 7 Q