mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-26 22:00:16 +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 ExplodeQuotedList(Text: String; var List: TStringList);
|
||||||
procedure ensureValidIdentifier(name: String);
|
procedure ensureValidIdentifier(name: String);
|
||||||
function getEnumValues(str: String): 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 GetSQLSplitMarkers(const SQL: String): TSQLBatch;
|
||||||
function SplitSQL(const SQL: String): TSQLBatch;
|
function SplitSQL(const SQL: String): TSQLBatch;
|
||||||
function sstr(str: String; len: Integer) : String;
|
function sstr(str: String; len: Integer) : String;
|
||||||
@ -363,26 +361,6 @@ begin
|
|||||||
end;
|
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;
|
function GetSQLSplitMarkers(const SQL: String): TSQLBatch;
|
||||||
var
|
var
|
||||||
i, AllLen, DelimLen, DelimStart, LastLeftOffset, RightOffset, LastNewLineOffset: Integer;
|
i, AllLen, DelimLen, DelimStart, LastLeftOffset, RightOffset, LastNewLineOffset: Integer;
|
||||||
@ -2814,6 +2792,9 @@ var
|
|||||||
IsEsc, IsQuote, InComment, InBigComment, InString, InKeyword, InIdent, LastWasComment: Boolean;
|
IsEsc, IsQuote, InComment, InBigComment, InString, InKeyword, InIdent, LastWasComment: Boolean;
|
||||||
c, p: Char;
|
c, p: Char;
|
||||||
Keyword, PreviousKeyword, TestPair: String;
|
Keyword, PreviousKeyword, TestPair: String;
|
||||||
|
const
|
||||||
|
WordChars = ['a'..'z', 'A'..'Z', '0'..'9', '_', '.'];
|
||||||
|
WhiteSpaces = [#9, #10, #13, #32];
|
||||||
begin
|
begin
|
||||||
// Known SQL keywords, get converted to UPPERCASE
|
// Known SQL keywords, get converted to UPPERCASE
|
||||||
AllKeywords := TStringList.Create;
|
AllKeywords := TStringList.Create;
|
||||||
@ -2863,7 +2844,7 @@ begin
|
|||||||
end;
|
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 := True;
|
||||||
if (c = '/') and (p = '*') and (not InComment) and (not InString) then InBigComment := False;
|
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
|
// Creation of returning text
|
||||||
if InKeyword then begin
|
if InKeyword then begin
|
||||||
@ -2871,7 +2852,7 @@ begin
|
|||||||
end else begin
|
end else begin
|
||||||
if Keyword <> '' then begin
|
if Keyword <> '' then begin
|
||||||
if AllKeywords.IndexOf(KeyWord) > -1 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);
|
Dec(Run);
|
||||||
Keyword := UpperCase(Keyword);
|
Keyword := UpperCase(Keyword);
|
||||||
if Run > 1 then begin
|
if Run > 1 then begin
|
||||||
|
Reference in New Issue
Block a user