Problems with the "\" character

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
ricardoclaudine
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 04.06.2014, 14:24
Location: Maringá, Paraná, Brasil

Problems with the "\" character

Post 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!
kgizmo
Fresh Boarder
Fresh Boarder
Posts: 6
Joined: 14.05.2010, 10:16
Location: Poland

Re: Problems with the "\" character

Post 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.
miab3
Zeos Test Team
Zeos Test Team
Posts: 1310
Joined: 11.05.2012, 12:32
Location: Poland

Re: Problems with the "\" character

Post by miab3 »

@ kgizmo, All

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

Michal
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1935
Joined: 17.01.2011, 14:17

Re: Problems with the "\" character

Post by marsupilami »

@All:

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

Jan
ricardoclaudine
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 04.06.2014, 14:24
Location: Maringá, Paraná, Brasil

Re: Problems with the "\" character

Post by ricardoclaudine »

Sorry, I forgot to say: use PostgreSQL!
ricardoclaudine
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 04.06.2014, 14:24
Location: Maringá, Paraná, Brasil

Re: Problems with the "\" character

Post 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!
ricardoclaudine
Fresh Boarder
Fresh Boarder
Posts: 5
Joined: 04.06.2014, 14:24
Location: Maringá, Paraná, Brasil

Re: Problems with the "\" character

Post by ricardoclaudine »

Worked perfectly! Thank you very much!
Post Reply