Feedback
Did this article resolve your question/issue?

   

Article

Fractional truncation returned as SQL_ERROR using the ODBC SQL Server driver.

Information

 
TitleFractional truncation returned as SQL_ERROR using the ODBC SQL Server driver.
URL NameFractional-truncation-reported-as-SQL-ERROR-on-linux64-for-SQLserver-Driver
Article Number000115180
EnvironmentProduct: Connect for ODBC SQL Server driver
Version: 7.0/7.1
OS: Linux
Database: SQL Server
Application: All supported applications
Question/Problem Description
When trying to insert a Decimal value into SQL Server Decimal column, the below error occurs using ODBC 3.x behavior and the insert fails.
Using ODBC 2.x behavior, the SQLExecute() function  will result in SQL_SUCCESS_WITH_INFO and the insert succeeds (with fraction truncated).
Steps to Reproduce-Table DDL :
create table test (col1 Decimal(18,2))

-SQLPrepare(INSERT INTO test(col1) VALUES ( ?))

-SQLBindParameter with value having too many fractional digits like 1254.135 :
SQLBindParameter((SQLHSTMT)hstmt, 1,SQL_PARAM_INPUT, SQL_C_CHAR, SQL_NUMERIC, 18, 2, num, 100, &cb_dsi_key_id_);

-SQLExecute ((SQLHSTMT)hstmt);

-Observed results using ODBC 3.x:

EXIT SQLExecute with return code -1 (SQL_ERROR)
HSTMT 0x00000003f5b2f0

EXIT SQLError with return code 0 (SQL_SUCCESS)
HENV 0x00000003f2fa40
HDBC 0x00000003f38500
HSTMT 0x00000003f5b2f0
UCHAR * 0x007fff742cd400 [ 5] "22001"
SDWORD * 0x007fff742cd3fc (0)
UCHAR * 0x007fff742cd1f0 [ 101] "[DataDirect][ODBC SQL Server Wire Protocol driver]String data, right truncated. Error in parameter 1."
SWORD 511
SWORD * 0x007fff742cd3fa (101)

-Observed results using ODBC 2.x:

EXIT SQLExecute with return code 1 (SQL_SUCCESS_WITH_INFO)
HSTMT 0x000000000079D970

DIAG [01004] [DataDirect][ODBC SQL Server Wire Protocol driver]Fractional truncation. Error in parameter 1. (0)
Clarifying Information
Error Message[DataDirect][ODBC SQL Server Wire Protocol driver]String data, right truncated. Error in parameter 1. (ODBC 3.x)
[DataDirect][ODBC SQL Server Wire Protocol driver]Fractional truncation. Error in parameter 1. (ODBC 2.x)
Defect Number
Enhancement Number
Cause
  • ODBC 3.x behavior:
According Appendix D of the 3.0 ODBC Programmer's Reference, when converting from SQL_C_CHAR to SQL_NUMERIC, the truncation of fractional digits returns SQLSTATE 22001.
see: https://msdn.microsoft.com/en-us/library/ms714651(v=vs.85).aspx

By definition, this SQLSTATE (22001) is an error and not a warning, thus returning SQL_ERROR is the correct behavior for ODBC 3.x.
  • ODBC 2.x behavior :
According Appendix D of the 2.0 ODBC Programmer's Reference, when converting from SQL_C_CHAR to SQL_NUMERIC, the truncation of fractional digits returns SQLSTATE 01004.

By definition, this SQLSTATE (01004) is a warning and not an error, thus SQL_SUCCESS_WITH_INFO is the correct behavior for ODBC 2.0.
Resolution
This is expected behavior since it conforms to the ODBC Specification.

 
Workaround
Notes
Last Modified Date11/6/2017 8:35 PM
Files
Disclaimer The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.