Issue Details (XML | Word | Printable)

Key: ODBC-149
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Alexander Potapchenko
Reporter: Vadim Zeitlin
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
ODBC Driver

Input double parameters are modified when saving them as NUMERIC values

Created: 22/Jun/12 01:23 PM   Updated: 09/Jul/13 11:01 AM
Component/s: None
Affects Version/s: 2.0.1
Fix Version/s: 2.0.2

Environment: 32-bit ODBC driver under Windows 7 however the issue should affect all platforms.


 Description  « Hide
Binding an input parameter of C type "double" to an SQL INSERT statement that writes it to a NUMERIC column in the database completely unexpectedly changes the value of the input parameter.

This happens because OdbcConvert::convDoubleToLong(), which is called from OdbcStatement::inputParam() in turn called by executeStatement() and sqlExecute(), uses a non-const reference to the from value that it then proceeds to modify. The following trivial patch fixes the problem:

diff --git a/cygdrive/d/src/3rdparty/ODBCFb-2.0.1.152/OdbcConvert.cpp b/cygdrive/d/src/3rdparty/ODBCFb-2.0.1.152.my/OdbcConvert.cpp
index e92754e..3975dbf 100755
--- a/cygdrive/d/src/3rdparty/ODBCFb-2.0.1.152/OdbcConvert.cpp
+++ b/cygdrive/d/src/3rdparty/ODBCFb-2.0.1.152.my/OdbcConvert.cpp
@@ -1217,7 +1217,7 @@ int OdbcConvert::conv##TYPE_FROM##To##TYPE_TO(DescRecord * from, DescRecord * to

                                                \
        ODBCCONVERT_CHECKNULL_COMMON(C_TYPE_TO);
        \

                                                \
- C_TYPE_FROM &valFrom = *(C_TYPE_FROM*)getAdressBindDataFrom((char*)from->dataPtr); \
+ C_TYPE_FROM valFrom = *(C_TYPE_FROM*)getAdressBindDataFrom((char*)from->dataPtr); \
        if ( to->scale )
                                \
                valFrom *= (C_TYPE_FROM)(QUAD)listScale[to->scale]; \
        if ( valFrom < 0 )valFrom -= 0.5;
                \

IOW simple make a copy of the input value instead of modifying it in place.

I hope this can be applied soon because this is really unexpected and none of the other ODBC drivers I tested (PostgreSQL, MS SQL Server, Oracle) behaves in this way.

Thanks!

 All   Comments   Change History   Subversion Commits      Sort Order: Descending order - Click to sort in ascending order
Alexander Potapchenko added a comment - 04/Aug/12 09:10 AM
Fixed in CVS