mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-26 03:01:07 +08:00
Allow digits and dot in word characters so ReformatSQL does not split known keywords from database, table or column names. Fixes issue #1944.
This commit is contained in:
@ -84,8 +84,6 @@ type
|
||||
procedure ExplodeQuotedList(Text: String; var List: TStringList);
|
||||
procedure ensureValidIdentifier(name: String);
|
||||
function getEnumValues(str: String): String;
|
||||
function IsWhitespace(const c: Char): Boolean;
|
||||
function IsLetter(const c: Char): Boolean;
|
||||
function GetSQLSplitMarkers(const SQL: String): TSQLBatch;
|
||||
function SplitSQL(const SQL: String): TSQLBatch;
|
||||
function sstr(str: String; len: Integer) : String;
|
||||
@ -363,26 +361,6 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
{***
|
||||
Return true if given character represents whitespace.
|
||||
Limitations: only recognizes ANSI whitespace.
|
||||
Eligible for inlining, hope the compiler does this automatically.
|
||||
}
|
||||
function IsWhitespace(const c: Char): Boolean;
|
||||
begin
|
||||
Result := (c = #9) or (c = #10) or (c = #13) or (c = #32);
|
||||
end;
|
||||
|
||||
|
||||
function IsLetter(const c: Char): Boolean;
|
||||
var
|
||||
o: Integer;
|
||||
begin
|
||||
o := Ord(c);
|
||||
Result := ((o >= 65) and (o <= 90)) or ((o >= 97) and (o <= 122)) or (o = 95);
|
||||
end;
|
||||
|
||||
|
||||
function GetSQLSplitMarkers(const SQL: String): TSQLBatch;
|
||||
var
|
||||
i, AllLen, DelimLen, DelimStart, LastLeftOffset, RightOffset, LastNewLineOffset: Integer;
|
||||
@ -2814,6 +2792,9 @@ var
|
||||
IsEsc, IsQuote, InComment, InBigComment, InString, InKeyword, InIdent, LastWasComment: Boolean;
|
||||
c, p: Char;
|
||||
Keyword, PreviousKeyword, TestPair: String;
|
||||
const
|
||||
WordChars = ['a'..'z', 'A'..'Z', '0'..'9', '_', '.'];
|
||||
WhiteSpaces = [#9, #10, #13, #32];
|
||||
begin
|
||||
// Known SQL keywords, get converted to UPPERCASE
|
||||
AllKeywords := TStringList.Create;
|
||||
@ -2863,7 +2844,7 @@ begin
|
||||
end;
|
||||
if (c = '*') and (p = '/') and (not InComment) and (not InString) then InBigComment := True;
|
||||
if (c = '/') and (p = '*') and (not InComment) and (not InString) then InBigComment := False;
|
||||
InKeyword := (not InComment) and (not InBigComment) and (not InString) and (not InIdent) and IsLetter(c);
|
||||
InKeyword := (not InComment) and (not InBigComment) and (not InString) and (not InIdent) and CharInSet(c, WordChars);
|
||||
|
||||
// Creation of returning text
|
||||
if InKeyword then begin
|
||||
@ -2871,7 +2852,7 @@ begin
|
||||
end else begin
|
||||
if Keyword <> '' then begin
|
||||
if AllKeywords.IndexOf(KeyWord) > -1 then begin
|
||||
while (Run > 1) and IsWhitespace(Result[Run-1]) do
|
||||
while (Run > 1) and CharInSet(Result[Run-1], WhiteSpaces) do
|
||||
Dec(Run);
|
||||
Keyword := UpperCase(Keyword);
|
||||
if Run > 1 then begin
|
||||
|
Reference in New Issue
Block a user