Bug 1248489 - DB2 - error getting substring if "from position" is out of range
Summary: DB2 - error getting substring if "from position" is out of range
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: JBoss Data Virtualization 6
Classification: JBoss
Component: Teiid
Version: 6.2.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
: ---
Assignee: Van Halbert
QA Contact: Juraj Duráni
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-07-30 12:00 UTC by Juraj Duráni
Modified: 2017-06-12 15:31 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
When using DB2, if the second argument of a SUBSTRING(x,y,z) function is out of the range of the first argument, users will encounter an exception.
Clone Of:
Environment:
Last Closed: 2017-02-22 17:55:15 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker JDV7-63 0 Major New DB2 - error getting substring if "from position" is out of range 2017-06-12 15:29:45 UTC
Red Hat Issue Tracker TEIID-3600 0 Major Resolved DB2 - error getting substring if "from position" is out of range 2017-06-12 15:29:45 UTC

Description Juraj Duráni 2015-07-30 12:00:10 UTC
Description of problem:
If second argument of a SUBSTRING(x,y,z) function is out of range of first argument an exception is thrown [1]. Source-specific command [2].

[1]
Caused by: com.ibm.db2.jcc.am.SqlDataException: DB2 SQL Error: SQLCODE=-138, SQLSTATE=22011, SQLERRMC=null, DRIVER=4.12.55
at com.ibm.db2.jcc.am.hd.a(hd.java:668)
at com.ibm.db2.jcc.am.hd.a(hd.java:60)
...

[2]
SELECT substr(varchar(g_0.TimestampValue), 40, CASE WHEN 0 > (length(varchar(g_0.TimestampValue)) - (40 - 1)) THEN (length(varchar(g_0.TimestampValue)) - (40 - 1)) ELSE 0 END) FROM SmallA AS g_0 WHERE g_0.IntKey = 1


Steps to Reproduce:
Query:
e.g. SELECT substring(timestampvalue, 40, 0) FROM smalla WHERE intkey = 1;


Additional information:
There is also some inconsistency in result of substring(x,y,z) function of different translators:
1. second argument out of range
Teiid returns NULL by default, but almost every jdbc translator (except oracle and sybase - NULL) returns an empty string (""). I expect that this depends on driver. Excel, solr and salesforce return NULL.

2. third argument is zero
In case of teiid, excel, solr and salesforce the result depends on second argument. If it is out of range, then the result is NULL, otherwise an empty string is returned. JDBC translators return an empty string, except of oracle and sybase - NULL.

Don't you want to consider to unify it?


Document URL: 

Section Number and Name: 

Describe the issue: 

Suggestions for improvement: 

Additional information:

Comment 1 JBoss JIRA Server 2015-08-06 13:45:08 UTC
Steven Hawkins <shawkins> updated the status of jira TEIID-3600 to Resolved

Comment 2 Van Halbert 2015-09-03 18:16:37 UTC
This has bee resolved upstream on the 8.12 Teiid branch.

Comment 3 JBoss JIRA Server 2016-01-26 18:00:55 UTC
Steven Hawkins <shawkins> updated the status of jira TEIID-3600 to Closed

Comment 4 Juraj Duráni 2016-05-09 11:35:57 UTC
The issue is still present. Source-specific command has changed, but exception is thrown anyway.

Source-specific command: SELECT substr(varchar(g_0.TIMESTAMPVALUE), CASE WHEN 40 > 0 THEN 0 ELSE 40 END, CASE WHEN 0 > (length(varchar(g_0.TIMESTAMPVALUE)) - (CASE WHEN 40 > 0 THEN 0 ELSE 40 END - 1)) THEN (length(varchar(g_0.TIMESTAMPVALUE)) - (CASE WHEN 40 > 0 THEN 0 ELSE 40 END - 1)) ELSE 0 END) FROM SMALLA AS g_0 WHERE g_0.INTKEY = 1

Result: Caused by: com.ibm.db2.jcc.am.SqlDataException: DB2 SQL Error: SQLCODE=-138, SQLSTATE=22011, SQLERRMC=null, DRIVER=4.12.55

Comment 5 JBoss JIRA Server 2016-05-24 12:26:05 UTC
Van Halbert <vhalbert> updated the status of jira TEIID-3600 to Reopened

Comment 6 JBoss JIRA Server 2016-05-24 13:16:54 UTC
Steven Hawkins <shawkins> updated the status of jira TEIID-3600 to Resolved

Comment 7 Juraj Duráni 2016-06-09 13:09:50 UTC
The query is still failing. I can see condition in the source-specific command like follows:
CASE WHEN 40 > length(varchar(g_0.TIMESTAMPVALUE)) THEN (length(varchar(g_0.TIMESTAMPVALUE)) + 1)

I believe that this is wrong as (length(varchar(g_0.TIMESTAMPVALUE)) + 1) is obviously greater than length(varchar(g_0.TIMESTAMPVALUE)) which actually causes the exception.

Source-specific command:
SELECT substr(varchar(g_0.TIMESTAMPVALUE), CASE WHEN 40 > length(varchar(g_0.TIMESTAMPVALUE)) THEN (length(varchar(g_0.TIMESTAMPVALUE)) + 1) ELSE 40 END, CASE WHEN 0 > (length(varchar(g_0.TIMESTAMPVALUE)) - (CASE WHEN 40 > length(varchar(g_0.TIMESTAMPVALUE)) THEN (length(varchar(g_0.TIMESTAMPVALUE)) + 1) ELSE 40 END - 1)) THEN (length(varchar(g_0.TIMESTAMPVALUE)) - (CASE WHEN 40 > length(varchar(g_0.TIMESTAMPVALUE)) THEN (length(varchar(g_0.TIMESTAMPVALUE)) + 1) ELSE 40 END - 1)) ELSE 0 END) FROM SMALLA AS g_0 WHERE integer(g_0.INTKEY) = 1

Comment 8 JBoss JIRA Server 2016-06-09 13:11:15 UTC
Juraj Duráni <jdurani> updated the status of jira TEIID-3600 to Reopened

Comment 9 Juraj Duráni 2016-06-09 13:30:41 UTC
I am sorry. Setting to from NEW to ASSIGNED.

Comment 10 JBoss JIRA Server 2016-09-19 18:35:40 UTC
Steven Hawkins <shawkins> updated the status of jira TEIID-3600 to Resolved


Note You need to log in before you can comment on or make changes to this bug.