Issue Details (XML | Word | Printable)

Key: CORE-3282
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Vlad Khorsun
Reporter: John Kilin
Votes: 0
Watchers: 1

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

EXECUTE STATEMENT parses the SQL text using wrong charset

Created: 16/Dec/10 05:31 PM   Updated: 29/May/15 06:48 PM
Component/s: Engine
Affects Version/s: 2.1.0, 2.0.4, 2.1.1, 2.0.5, 2.1.2, 2.1.3, 3.0 Initial, 2.0.6, 2.5.0
Fix Version/s: 2.5.1, 3.0 Alpha 1

Issue Links:

QA Status: Done successfully
Test Details: Confirmed on 2.5.0: get "Malformed string" when connect with cset=utf8.

 Description  « Hide
EXECUTE STATEMENT implementation simply calls the DSQL layer to do its job, but DSQL considers the input SQL text having the connection charset. In EXECUTE STATEMENT, however, the SQL text has the actual charset defined by the appropriate variable descriptor. If it differs from the connection charset and the SQL text contains non-ASCII characters, we get "malformed string" or "cannot transliterate" errors.

The issue can be seen if some procedure using EXECUTE STATEMENT is created in one charset, but called with another charset. Or if the dynamic SQL text is retrieved from a column which charset differs from the connection one.

I doubt it can be fixed for earlier versions (because of the layering issues), but it seems doable for v2.5 and v3.0.

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Dmitry Yemanov added a comment - 20/Dec/10 10:12 AM
Test case:

set names win1251;

create table TestTable (
 ParamName varchar(100) character set win1251,
 ParamValue varchar(1000) character set win1251

insert into TestTable(ParamName, ParamValue)
  values ('TESTSQL', 'execute block as declare variable bufStr varchar(1024); begin bufStr= ''Тест''; end');

set term ^;

create or alter procedure TESTSP
declare variable SQLText varchar(1024);
 select ParamValue
   from TestTable
   where ParamName='TESTSQL'
   into SQLText;

 execute statement SQLText;

set term ;^

-- connect using WIN1251
execute procedure TESTSP
-- no errors

-- connect using UTF8
execute procedure TESTSP
-- Invalid token.
-- Dynamic SQL Error.
-- SQL error code = -104.
-- Malformed string.
-- At procedure 'TESTSP' line: 10, col: 3.

Vlad Khorsun added a comment - 20/Dec/10 03:08 PM
EXECUTE STATEMENTS have 5 string parameters which could be affected by this "charset issue" :
sql text
connection string
user name

Should we convert all of them into calling attachment charset ?

John Kilin added a comment - 21/Dec/10 06:59 AM
Why not?

Vlad Khorsun added a comment - 23/Dec/10 11:34 AM
Fix is committed into 2.5 source tree.
Please, confirm

Vlad Khorsun added a comment - 02/Jan/11 10:21 PM
It seems to me that only query text should be converted into attachment charset because engine assumed that query text is in attachment charset.

Other parameters (connection string, user name, role and password) should not be coverted into attachment charset because user should be able to set correct charset manually.

New fix is committed.

Vlad Khorsun added a comment - 21/Jan/11 10:04 AM
John confirmed fix privately