Skip to content
Permalink
Browse files

Use UnescapeString() to remove more escape sequences than a duplicate…

…d single quote. Move ExtractLiteral() to TDBConnection, as UnescapeString() depends on the connection type. Closes #690.
  • Loading branch information...
ansgarbecker committed Jun 26, 2019
1 parent 5670ba5 commit f2ed7b01a10891227bbd748295cc701771e7a00d
Showing with 33 additions and 33 deletions.
  1. +0 −33 source/apphelpers.pas
  2. +33 −0 source/dbconnection.pas
@@ -277,7 +277,6 @@ TAppSettings = class(TObject)
function ScanLineBreaks(Text: String): TLineBreaks;
function CountLineBreaks(Text: String; LineBreak: TLineBreaks=lbsWindows): Cardinal;
function fixNewlines(txt: String): String;
function ExtractLiteral(var SQL: String; Prefix: String): String;
function GetShellFolder(CSIDL: integer): string;
function goodfilename( str: String ): String;
function ExtractBaseFileName(FileName: String): String;
@@ -774,38 +773,6 @@ function fixNewlines(txt: String): String;
end;


function ExtractLiteral(var SQL: String; Prefix: String): String;
var
i, LitStart: Integer;
InLiteral: Boolean;
rx: TRegExpr;
begin
// Return comment from SQL and remove it from the original string
// Single quotes are escaped by a second single quote
Result := '';
rx := TRegExpr.Create;
if Prefix.IsEmpty then
rx.Expression := '^\s*'''
else
rx.Expression := '^\s*'+QuoteRegExprMetaChars(Prefix)+'\s+''';
rx.ModifierI := True;
if rx.Exec(SQL) then begin
LitStart := rx.MatchLen[0]+1;
InLiteral := True;
for i:=LitStart to Length(SQL) do begin
if SQL[i] = '''' then
InLiteral := not InLiteral
else if not InLiteral then
break;
end;
Result := Copy(SQL, LitStart, i-LitStart-1);
Result := StringReplace(Result, '''''', '''', [rfReplaceAll]);
Delete(SQL, 1, i);
end;
rx.Free;
end;


{***
Get the path of a Windows(r)-shellfolder, specified by an integer or a constant
@@ -392,6 +392,7 @@ TDBConnection = class(TComponent)
function FindObject(DB, Obj: String): TDBObject;
function escChars(const Text: String; EscChar, Char1, Char2, Char3, Char4: Char): String;
function UnescapeString(Text: String): String;
function ExtractLiteral(var SQL: String; Prefix: String): String;
function GetResults(SQL: String): TDBQuery;
function GetCol(SQL: String; Column: Integer=0): TStringList;
function GetVar(SQL: String; Column: Integer=0): String; overload;
@@ -3784,6 +3785,38 @@ function TDBConnection.UnescapeString(Text: String): String;
end;


function TDBConnection.ExtractLiteral(var SQL: String; Prefix: String): String;
var
i, LitStart: Integer;
InLiteral: Boolean;
rx: TRegExpr;
begin
// Return comment from SQL and remove it from the original string
// Single quotes are escaped by a second single quote
Result := '';
rx := TRegExpr.Create;
if Prefix.IsEmpty then
rx.Expression := '^\s*'''
else
rx.Expression := '^\s*'+QuoteRegExprMetaChars(Prefix)+'\s+''';
rx.ModifierI := True;
if rx.Exec(SQL) then begin
LitStart := rx.MatchLen[0]+1;
InLiteral := True;
for i:=LitStart to Length(SQL) do begin
if SQL[i] = '''' then
InLiteral := not InLiteral
else if not InLiteral then
break;
end;
Result := Copy(SQL, LitStart, i-LitStart-1);
Result := UnescapeString(Result);
Delete(SQL, 1, i);
end;
rx.Free;
end;


{**
Add backticks to identifier
Todo: Support ANSI style

0 comments on commit f2ed7b0

Please sign in to comment.
You can’t perform that action at this time.