Issue Details (XML | Word | Printable)

Key: CORE-2361
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Adriano dos Santos Fernandes
Reporter: Richard Wesley
Votes: 0
Watchers: 0
Operations

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

String truncation reading 8859-1 Spanish column using isc_dsql_fetch with UTF-8 connection..

Created: 09/Mar/09 07:58 PM   Updated: 31/May/11 01:15 PM
Component/s: Charsets/Collation
Affects Version/s: 2.1.1, 2.1.2
Fix Version/s: 2.5 Beta 2

Time Tracking:
Issue & Sub-Tasks
Issue Only
Not Specified

Environment: Win XP 32 bit
Issue Links:
Relate
 

Planning Status: Unspecified

Sub-Tasks  All   Open   

 Description  « Hide
Database script:

create database "setup.B21839.fdb";

create table "'Master by Reseller$'" (
    "Tier" VARCHAR(20) CHARACTER SET ISO8859_1 COLLATE ES_ES_CI_AI
);

commit;

insert into "'Master by Reseller$'" ( "Tier" ) VALUES ('(blank)');
insert into "'Master by Reseller$'" ( "Tier" ) VALUES ('Approved');
insert into "'Master by Reseller$'" ( "Tier" ) VALUES ('Bronze');
insert into "'Master by Reseller$'" ( "Tier" ) VALUES ('DMR');
insert into "'Master by Reseller$'" ( "Tier" ) VALUES ('Domestic Distributor');
insert into "'Master by Reseller$'" ( "Tier" ) VALUES ('End-User');
insert into "'Master by Reseller$'" ( "Tier" ) VALUES ('Evaluation');
insert into "'Master by Reseller$'" ( "Tier" ) VALUES ('Gold');
insert into "'Master by Reseller$'" ( "Tier" ) VALUES ('New');
insert into "'Master by Reseller$'" ( "Tier" ) VALUES ('Silver');
insert into "'Master by Reseller$'" ( "Tier" ) VALUES ('VAM');

commit;

We then connect to it using the API:

    dpb.SetParam( isc_dpb_user_name, attr[ DataConnection::attrUsername ] );
    dpb.SetParam( isc_dpb_password, pwd );
    dpb.SetParam( isc_dpb_lc_ctype, _T("UTF8") );
    dpb.SetParam( isc_dpb_sql_dialect, (ISC_SCHAR) SQL_DIALECT_V6 );

and attempt to run the following query:

SELECT DISTINCT ((CASE WHEN "'Master by Reseller$'"."Tier" IN ( '(blank)', 'Domestic Distributor', 'End-User', 'Evaluation', 'New') THEN '(blank)' ELSE "'Master by Reseller$'"."Tier" END)) AS "Tier (group)"
FROM "'Master by Reseller$'"
ORDER BY 1 ASC

The XSQLDA structure comes back from isc_dsql_describe with a single record having a length of 0x01c. We multiply this by 4 to make sure we allocate enough space. for the returning string. We then call isc_dsql_execute and isc_dsql_fetch. The isc_dsql_fetch call fails with:

Status: 335544321
arithmetic exception, numeric overflow, or string truncation

Adding the string 'Approved' to the IN list in the query seems to solve the problem. Most notably, it reduces the maximum length of the return string to be less than '(blank)'.

The problem does not reproduce with the UTF8 character set.


 All   Comments   Work Log   Change History   Version Control   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Richard Wesley added a comment - 09/Mar/09 08:06 PM
Sorry, it is the isc_dsql_execute call that fails (we have seen both with this expression).

Richard Wesley added a comment - 09/Mar/09 08:07 PM
Also happens in 2.1.2.

Adriano dos Santos Fernandes added a comment - 14/Apr/09 08:07 AM
Simple test case:
select case when 1 = 0 then '(blank)' else "'Master by Reseller$'"."Tier" end from "'Master by Reseller$'";

Pavel Cisar added a comment - 31/May/11 01:15 PM
QA test added.