ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/branches/udr/client/IBUtils.pas
(Generate patch)

Comparing ibx/trunk/fbintf/IBUtils.pas (file contents):
Revision 265 by tony, Sat Dec 8 11:22:27 2018 UTC vs.
Revision 270 by tony, Fri Jan 18 11:10:37 2019 UTC

# Line 258 | Line 258 | type
258    sqltPlaceholder,
259    sqltSingleQuotes,
260    sqltDoubleQuotes,
261 +  sqltBackslash,
262    sqltComma,
263    sqltPeriod,
264    sqltEquals,
# Line 592 | Line 593 | type
593      function TokenFound(var token: TSQLTokens): boolean; override;
594    end;
595  
596 +    { TSQLParamProcessor }
597 +
598 +  TSQLParamProcessor = class(TSQLwithNamedParamsTokeniser)
599 +  private
600 +  const
601 +    sIBXParam = 'IBXParam';  {do not localize}
602 +  private
603 +    FInString: AnsiString;
604 +    FIndex: integer;
605 +    function DoExecute(GenerateParamNames: boolean;
606 +        var slNames: TStrings): AnsiString;
607 +  protected
608 +    function GetChar: AnsiChar; override;
609 +  public
610 +    class function Execute(sSQL: AnsiString; GenerateParamNames: boolean;
611 +        var slNames: TStrings): AnsiString;
612 +  end;
613 +
614 +
615   function Max(n1, n2: Integer): Integer;
616   function Min(n1, n2: Integer): Integer;
617   function RandomString(iLength: Integer): AnsiString;
# Line 974 | Line 994 | begin
994    Result := StringReplace(s,'''','''''',[rfReplaceAll]);
995   end;
996  
997 + { TSQLParamProcessor }
998 +
999 + function TSQLParamProcessor.DoExecute(GenerateParamNames: boolean;
1000 +  var slNames: TStrings): AnsiString;
1001 + var token: TSQLTokens;
1002 +    iParamSuffix: Integer;
1003 + begin
1004 +  Result := '';
1005 +  iParamSuffix := 0;
1006 +
1007 +  while not EOF do
1008 +  begin
1009 +    token := GetNextToken;
1010 +    case token of
1011 +    sqltParam,
1012 +    sqltQuotedParam:
1013 +      begin
1014 +        Result := Result + '?';
1015 +        slNames.Add(TokenText);
1016 +      end;
1017 +
1018 +    sqltPlaceHolder:
1019 +      if GenerateParamNames then
1020 +      begin
1021 +        Inc(iParamSuffix);
1022 +        slNames.AddObject(sIBXParam + IntToStr(iParamSuffix),self); //Note local convention
1023 +                                            //add pointer to self to mark entry
1024 +        Result := Result + '?';
1025 +      end
1026 +      else
1027 +        IBError(ibxeSQLParseError, [SParamNameExpected]);
1028 +
1029 +    sqltQuotedString:
1030 +      Result := Result + '''' + SQLSafeString(TokenText) + '''';
1031 +
1032 +    sqltIdentifierInDoubleQuotes:
1033 +      Result := Result + '"' + StringReplace(TokenText,'"','""',[rfReplaceAll]) + '"';
1034 +
1035 +    sqltComment:
1036 +      Result := Result + '/*' + TokenText + '*/';
1037 +
1038 +    sqltCommentLine:
1039 +      Result := Result + '//' + TokenText + LineEnding;
1040 +
1041 +    sqltEOL:
1042 +      Result := Result + LineEnding;
1043 +
1044 +    else
1045 +      Result := Result + TokenText;
1046 +    end;
1047 +  end;
1048 + end;
1049 +
1050 + function TSQLParamProcessor.GetChar: AnsiChar;
1051 + begin
1052 +  if FIndex <= Length(FInString) then
1053 +  begin
1054 +    Result := FInString[FIndex];
1055 +    Inc(FIndex);
1056 +  end
1057 +  else
1058 +    Result := #0;
1059 + end;
1060 +
1061 + class function TSQLParamProcessor.Execute(sSQL: AnsiString;
1062 +  GenerateParamNames: boolean; var slNames: TStrings): AnsiString;
1063 + begin
1064 +  with self.Create do
1065 +  try
1066 +    FInString := sSQL;
1067 +    FIndex := 1;
1068 +    Result := DoExecute(GenerateParamNames,slNames);
1069 +  finally
1070 +    Free;
1071 +  end;
1072 + end;
1073 +
1074   { TSQLwithNamedParamsTokeniser }
1075  
1076   procedure TSQLwithNamedParamsTokeniser.Assign(source: TSQLTokeniser);
# Line 1093 | Line 1190 | begin
1190        Result := sqltSingleQuotes;
1191      '/':
1192        Result := sqltForwardSlash;
1193 +    '\':
1194 +      Result := sqltBackslash;
1195      '*':
1196        Result := sqltAsterisk;
1197      '(':

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines