You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (Created) (JIRA)" <ji...@apache.org> on 2011/12/14 11:32:30 UTC

[jira] [Created] (DERBY-5537) Casting to a shorter string type does not warn about truncation

Casting to a shorter string type does not warn about truncation
---------------------------------------------------------------

                 Key: DERBY-5537
                 URL: https://issues.apache.org/jira/browse/DERBY-5537
             Project: Derby
          Issue Type: Bug
          Components: SQL
    Affects Versions: 10.8.2.2
            Reporter: Knut Anders Hatlen


SQL:2003, part 2, 6.12 <cast specification> specifies that a truncation warning should be raised when casting from one (character or binary) string data type to another. Derby does truncate, but it doesn't raise a warning:

ij> values cast('abc' as char(2));
1 
--
ab

1 row selected
ij> values cast(x'cafebabe' as char(2) for bit data);
1   
----
cafe

1 row selected

We should generate a warning in order to be compliant.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (DERBY-5537) Casting to a shorter string type does not warn about truncation

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5537?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen resolved DERBY-5537.
---------------------------------------

    Resolution: Duplicate

Resolving as duplicate of DERBY-129.
                
> Casting to a shorter string type does not warn about truncation
> ---------------------------------------------------------------
>
>                 Key: DERBY-5537
>                 URL: https://issues.apache.org/jira/browse/DERBY-5537
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.8.2.2
>            Reporter: Knut Anders Hatlen
>              Labels: derby_triage10_9
>         Attachments: warn.diff
>
>
> SQL:2003, part 2, 6.12 <cast specification> specifies that a truncation warning should be raised when casting from one (character or binary) string data type to another. Derby does truncate, but it doesn't raise a warning:
> ij> values cast('abc' as char(2));
> 1 
> --
> ab
> 1 row selected
> ij> values cast(x'cafebabe' as char(2) for bit data);
> 1   
> ----
> cafe
> 1 row selected
> We should generate a warning in order to be compliant.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5537) Casting to a shorter string type does not warn about truncation

Posted by "Mamta A. Satoor (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5537?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mamta A. Satoor updated DERBY-5537:
-----------------------------------

    Issue & fix info: Release Note Needed,Repro attached
             Urgency: Normal
              Labels: derby_triage10_9  (was: )
    
> Casting to a shorter string type does not warn about truncation
> ---------------------------------------------------------------
>
>                 Key: DERBY-5537
>                 URL: https://issues.apache.org/jira/browse/DERBY-5537
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.8.2.2
>            Reporter: Knut Anders Hatlen
>              Labels: derby_triage10_9
>         Attachments: warn.diff
>
>
> SQL:2003, part 2, 6.12 <cast specification> specifies that a truncation warning should be raised when casting from one (character or binary) string data type to another. Derby does truncate, but it doesn't raise a warning:
> ij> values cast('abc' as char(2));
> 1 
> --
> ab
> 1 row selected
> ij> values cast(x'cafebabe' as char(2) for bit data);
> 1   
> ----
> cafe
> 1 row selected
> We should generate a warning in order to be compliant.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (DERBY-5537) Casting to a shorter string type does not warn about truncation

Posted by "Knut Anders Hatlen (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-5537?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13169254#comment-13169254 ] 

Knut Anders Hatlen commented on DERBY-5537:
-------------------------------------------

SQLChar.java has this comment:

            /*
            ** Check whether any non-blank characters will be truncated.
            */
            if (errorOnTrunc)
                hasNonBlankChars(getString(), desiredWidth, sourceWidth);
            //RESOLVE: should issue a warning instead

Similar in SQLBit.java:

			if (errorOnTrunc)
			{
				// error if truncating non pad characters.
				for (int i = desiredWidth; i < dataValue.length; i++) {

					if (dataValue[i] != SQLBinary.PAD)
						throw StandardException.newException(SQLState.LANG_STRING_TRUNCATION, getTypeName(), 
									StringUtil.formatForPrint(this.toString()),
									String.valueOf(desiredWidth));
				}
			}
			//else
			//{
			// RESOLVE: when we have warnings, issue a warning if
			// truncation of non-zero bits will occur
			//}

One thing to note is that SQLBit is silent about the truncation, also in the cases where truncation should cause an exception, if all the truncated bytes are equal to SQLBinary.PAD (0x20). According to 6.12 <cast specification>, general rule 12, we should always generate a warning on truncation of binary string types. For character string types, on the other hand, it is correct not to warn if all the truncated characters are <space>s.
                
> Casting to a shorter string type does not warn about truncation
> ---------------------------------------------------------------
>
>                 Key: DERBY-5537
>                 URL: https://issues.apache.org/jira/browse/DERBY-5537
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.8.2.2
>            Reporter: Knut Anders Hatlen
>
> SQL:2003, part 2, 6.12 <cast specification> specifies that a truncation warning should be raised when casting from one (character or binary) string data type to another. Derby does truncate, but it doesn't raise a warning:
> ij> values cast('abc' as char(2));
> 1 
> --
> ab
> 1 row selected
> ij> values cast(x'cafebabe' as char(2) for bit data);
> 1   
> ----
> cafe
> 1 row selected
> We should generate a warning in order to be compliant.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (DERBY-5537) Casting to a shorter string type does not warn about truncation

Posted by "Knut Anders Hatlen (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-5537?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen updated DERBY-5537:
--------------------------------------

    Attachment: warn.diff

For the binary string data types, there are similar comments about the need to generate warnings in SQLVarbit.java and SQLBlob.java, in addition to SQLBit.java. (For the character string data types, SQLVarchar and SQLClob inherit the affected code from SQLChar.)

I've experimented with the attached warn.diff patch (not ready for commit), which adds a java.sql.DataTruncation warning to the ResultSet (or Statement if the query doesn't return a ResultSet) when a value has been truncated. The warnings seem to appear at the right place:

ij> create table t(x varchar(10));
0 rows inserted/updated/deleted
ij> insert into t values 'abcde', 'fghi  j', 'klmn   ', 'opqr';
4 rows inserted/updated/deleted
ij> select x, cast(x as char(4)) from t;
X         |2   
---------------
abcde     |abcd
WARNING 01004: Data truncation
fghi  j   |fghi
WARNING 01004: Data truncation
klmn      |klmn
opqr      |opqr

4 rows selected
                
> Casting to a shorter string type does not warn about truncation
> ---------------------------------------------------------------
>
>                 Key: DERBY-5537
>                 URL: https://issues.apache.org/jira/browse/DERBY-5537
>             Project: Derby
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 10.8.2.2
>            Reporter: Knut Anders Hatlen
>         Attachments: warn.diff
>
>
> SQL:2003, part 2, 6.12 <cast specification> specifies that a truncation warning should be raised when casting from one (character or binary) string data type to another. Derby does truncate, but it doesn't raise a warning:
> ij> values cast('abc' as char(2));
> 1 
> --
> ab
> 1 row selected
> ij> values cast(x'cafebabe' as char(2) for bit data);
> 1   
> ----
> cafe
> 1 row selected
> We should generate a warning in order to be compliant.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira