Fix queries like /*!40000 SHOW ENGINES */ to be recognized as "result"-queries while not breaking getFirstWord calls in situations where the second or later char can be a number (fx the collation in createdatabase).

This commit is contained in:
Ansgar Becker
2007-10-04 20:31:31 +00:00
parent 94f1d6035f
commit f0db5d8497

View File

@@ -1942,18 +1942,23 @@ end;
function getFirstWord( text: String ): String;
var
i : Integer;
wordChars : Set of Char;
wordChars, wordCharsFirst : Set of Char;
begin
result := '';
text := trim( text );
// First char in word must not be numerical. Fixes queries like
// /*!40000 SHOW ENGINES */ to be recognized as "result"-queries
// while not breaking getFirstWord in situations where the second
// or later char can be a number (fx the collation in createdatabase).
wordChars := ['a'..'z', 'A'..'Z', '0'..'9', '_', '-'];
wordCharsFirst := wordChars - ['0'..'9'];
i := 1;
// Find beginning of the first word, ignoring non-alphanumeric chars at the very start
// @see bug #1692828
while i < Length(text) do
begin
if (text[i] in wordChars) then
if (text[i] in wordCharsFirst) then
begin
// Found beginning of word!
break;
@@ -1971,7 +1976,7 @@ begin
// Add chars as long as they're alpha-numeric
while i <= Length(text) do
begin
if (text[i] in wordChars) then
if ((result = '') and (text[i] in wordCharsFirst)) or (text[i] in wordChars) then
begin
result := result + text[i];
end