Page 1 of 1

Problems with the "\" character

Posted: 19.05.2016, 21:04
by ricardoclaudine
Hello gentlemen!

First, forgive my English!
I'm having a problem with 7.2.1-rc version that did not occur in version 7.1.4-stable: SQL statements containing strings with the "\" character.

For example, when opening a ZQuery with this SQL, the parameters are not replaced by values:

SELECT (
        'VALUE1 = ' || :param1 || '\r\n' ||
        'VALUE2 = ' || :param2
       ) AS my_text;

Generating, therefore, the following error:

ERROR: syntax error at or near ":"
LINE 1: SELECT ( 'VALUE1 = ' || :param1 || '\r\n' || 'VALUE2 = ' || ...

For it to work, I'm having to do this:

SELECT (
        'VALUE1 = ' || :param1 || CHR(13) || CHR(10) ||
        'VALUE2 = ' || :param2
       ) AS my_text;

This way works perfectly!

In 7.1.4 version, the first way also worked perfectly.
What I did was just upgrade to the 7.2.1-rc version. I did not ANY changes in the database settings and changed NOTHING in my application.
I've tried on and off the property "standard_conforming_strings" in ZConnection, but the problem persists.
Of course, if I replace this '\r\n' for this '\\r\\n', the error does not occur, but a line break is not generated.

Can someone help me?


Thank you very much!

Re: Problems with the "\" character

Posted: 12.09.2016, 20:22
by kgizmo
Hello,
You didn't write what database server do you use. I had the same problem. I found solution for PostgreSQL. There have to be made changes in ZPostgreSqlToken.pas:

Code: Select all

procedure TZPostgreSQLQuoteState.GetQuotedString(Stream: TStream; QuoteChar: Char;
  EscapeSyntax: Boolean; var Result: String);
const BackSlash = Char('\');
var
  ReadChar: Char;
  LastChar: Char;
  QuoteCount: Integer;
  LastWasEscapeChar: Boolean;
begin
  LastChar := #0;
  Result := '';
  InitBuf(QuoteChar);
  QuoteCount := 1;

  LastWasEscapeChar := False;
  while Stream.Read(ReadChar{%H-}, SizeOf(Char)) > 0 do
  begin
    if ReadChar = QuoteChar then
      Inc(QuoteCount, Ord((not EscapeSyntax) or (not LastWasEscapeChar)))
    else
      LastWasEscapeChar :=(ReadChar=BackSlash) and (not LastWasEscapeChar); //False; //Kamil Giza comment False;

    if (LastChar = QuoteChar) and (ReadChar <> QuoteChar) then
      if QuoteCount mod 2 = 0 then begin
        Stream.Seek(-SizeOf(Char), soFromCurrent);
        Break;
      end;
    ToBuf(ReadChar, Result);
    if (LastChar = BackSlash) and EscapeSyntax then begin
      LastChar := #0;
      //LastWasEscapeChar := True; //Kamil Giza add comment
      //Dec(QuoteCount); nope that doesnt' work @all see the tests
    end
    else if (LastChar = QuoteChar) and (ReadChar = QuoteChar) then
      LastChar := #0
    else
      LastChar := ReadChar;
  end;
  FlushBuf(Result);
end;
I will send it to ZEOS Team.

Re: Problems with the "\" character

Posted: 12.09.2016, 22:49
by miab3
@ kgizmo, All

It looks like that your patch works (for Zeos 7.2 svn 3929 and PostgreSQL).

Michal

Re: Problems with the "\" character

Posted: 19.09.2016, 17:54
by marsupilami
@All:

The patch has been applied. See Zeos 7.2 Rev. 3930.
With Best regards,

Jan

Re: Problems with the "\" character

Posted: 27.09.2016, 13:16
by ricardoclaudine
Sorry, I forgot to say: use PostgreSQL!

Re: Problems with the "\" character

Posted: 27.09.2016, 13:18
by ricardoclaudine
marsupilami wrote:@All:

The patch has been applied. See Zeos 7.2 Rev. 3930.
With Best regards,

Jan
Thank you very much! I'll test right now!

Re: Problems with the "\" character

Posted: 27.09.2016, 19:33
by ricardoclaudine
Worked perfectly! Thank you very much!