Issue Details (XML | Word | Printable)

Key: CORE-6340
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Adriano dos Santos Fernandes
Reporter: Pavel Zotov
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Firebird Core

Alternate quoting does not work on some particular cases

Created: 23/Jun/20 02:53 PM   Updated: 30/Jun/20 06:39 PM
Component/s: Engine, ISQL
Affects Version/s: 4.0 Beta 2
Fix Version/s: 4.0 RC 1, 3.0.7

QA Status: Done successfully


 Description  « Hide
1) select q'{} }' from rdb$database; -- works OK
2) select q'{{}' from rdb$database; -- also OK
3) select q'{}}' from rdb$database; -- note: there is no space between "}}"
   
 Last statement raises:
=======
 Invalid token.
 Dynamic SQL Error.
 SQL error code = -104.
 Token unknown - line 1, column 9.
 '{}}'.
=======

Checked on 4.0.0.2070; 3.0.6.33322


 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Pavel Zotov added a comment - 24/Jun/20 04:36 AM
It seems that <alternate START char> (see "README.alternate_string_quoting.txt") must differ from <alternate END char> when single quote ( ' ) is used as text to be printed:

select q'!That's a string!' from rdb$database; -- works OK (this is example from doc)
select q'! ' !' from rdb$database; -- also works OK (all letters were replaced with spaces)
select q'!'!' from rdb$database; -- FAILS with "Expected end of statement, encountered EOF"
select q'!' !' from rdb$database; -- also FAILS (the same)
select q'!'' !' from rdb$database; -- passed (output is two single quotes)
select q'!''' !' from rdb$database; -- fails.

No such problems with:

select q'< ' >' from rdb$database;
select q'<' '>' from rdb$database;
select q'<'>' from rdb$database;
select q'<' >' from rdb$database;
select q'<'>' from rdb$database;
select q'<''' >' from rdb$database;

Adriano dos Santos Fernandes added a comment - 24/Jun/20 01:17 PM
That was another problem in ISQL. Please test again.

Pavel Zotov added a comment - 24/Jun/20 03:17 PM
echo set heading off; select q'!#'!' from rdb$database; | isql /:e40 -q
Database: /:e40, User: SYSDBA
SQL>
#'

(OK, expected)
############

echo set heading off; select q'!''!' from rdb$database; | isql /:e40 -q
Database: /:e40, User: SYSDBA
SQL>
''

(OK, expected)
############

echo set heading off; select q'!'!!' from rdb$database; | isql /:e40 -q
Database: /:e40, User: SYSDBA
SQL>
'!

(OK, expected)
############

But:
====

C:\FBTESTING\qa\misc>echo set heading off; select q'!!'!' from rdb$database; | isql /:e40 -q
Database: /:e40, User: SYSDBA
SQL> CON> Expected end of statement, encountered EOF

The same for
echo set heading off; select q'!!'!'!' from rdb$database; | isql /:e40 -q
echo set heading off; select q'!!!!!'!' from rdb$database; | isql /:e40 -q
... etc ...

-- i.e. wher sequence <alternate END char> + single_quote presents within string.

Checked on build 4.0.0.2073 with timestamp 24.06.2020 13:40.

Adriano dos Santos Fernandes added a comment - 24/Jun/20 04:01 PM
> -- i.e. wher sequence <alternate END char> + single_quote presents within string.

<alternate END char> + single_quote defines end of string. How could it be within a string?

Pavel Zotov added a comment - 24/Jun/20 04:13 PM
IMO, end of string which starts with q'! must be defined by !' which are LAST two characters of this string literal.
It is the almost the same as when we write SINGLE_QUOTE + <S> + SINGLE_QUOTE where <S> is arbitrary set of characters including SINGLE_QUOTE (but it must be duplicated in this case).

Adriano dos Santos Fernandes added a comment - 24/Jun/20 04:29 PM - edited
It's different case. Double single quote in single quote string is like a escape.

In Oracle the alternate string literal works like our current behavior. It stops in first <alternate END char> + single_quote.

There is no escape on it. You can choose a start/end character to not need escapes.