Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input double parameters are modified when saving them as NUMERIC values [ODBC149] #146

Closed
firebird-automations opened this issue Jun 22, 2012 · 3 comments

Comments

@firebird-automations
Copy link

Submitted by: Vadim Zeitlin (vz)

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!

Commits: d5cd549 6d7c3bf

@firebird-automations
Copy link
Author

Commented by: @alexpotapchenko

Fixed in CVS

@firebird-automations
Copy link
Author

Modified by: @alexpotapchenko

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 2.0.2 [ 10465 ]

@firebird-automations
Copy link
Author

Modified by: @alexpotapchenko

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants