-
Notifications
You must be signed in to change notification settings - Fork 359
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
integers are being inserted instead of floats using executemany #241
Comments
I am able to replicate the behaviour you are seeing and that is definitely incorrect. I'll look at correcting that. Thanks for the clear example and explanation! |
I've taken a quick peek at this. The reason for the difference between Python 2 and Python 3 is that Python 3 has unified "integers" and "long integers" so cx_Oracle just uses a string representation for all integers rather than attempt to determine whether it can fit in a native integer (and incur the overhead of doing so). In Python 2 I have still been using native integers where applicable but there was no check for the type on the mistaken assumption that PyLong_AsLong() would raise an error if a floating point number was passed. It actually performs int() on the object in question which is what you are seeing. I'll add the code to raise the exception "expecting integer" so that the silent truncation no longer occurs. I'll also consider switching the Python 2 behaviour to match Python 3 behaviour. |
Won't raising the error just bring back #82? I would prefer matching it to Python 3 as it would not involve a code change on my end. Though I have tracked down where the integers came from if necessary. |
Raising the error will indeed cause #82 to occur again -- but not sure if there is any solution to that now that this issue has been noted -- beyond switching the behaviour to the same as Python 3. I'll give it some thought. In the meantime, you have a workaround for the issue. |
NATIVE_FLOAT or NATIVE_DOUBLE types, all numbers are converted to strings and passed through to ODPI-C in all Python versions; improved error message when a value cannot be represented by an Oracle number value; improved test suite to verify that calling executemany() with integers, floats and decimal values intermixed with each other works as expected (#241).
I just pushed a set of changes that should resolve this issue as well as permit integers, floats and decimals to be intermixed in executemany(). Let me know what you think. |
It seems to be working as desired with my example. |
Great. Thanks for confirming. This will become part of version 7.1 when it is released. |
Corrected in cx_Oracle 7.1 which was released yesterday. |
I have an issue where using executemany in python 2.7 with an integer in the very first row of the very first executemany, causes all subsequent rows to be inserted as integers. Sample:
create table test_bug (ID NUMBER(10,0), testnum NUMBER(20,2));
Results:
I expected ID=5 to be 14.95, but it is 14. This does not happen in python 3, nor cx_Oracle 5.3.0. This appears to be related to the fix for #82 and #75
Answer the following questions:
What is your version of Python? Is it 32-bit or 64-bit?
Python 2.7.12
What is your cx_Oracle version?
6.2.0, 6.3.0, 7.0.0
What error(s) you are seeing?
Data incorrect
What OS (and version) is Python executing on?
Ubuntu 16.4
What is your version of the Oracle client (e.g. Instant Client)? How was it installed? Where is it installed?
I tried both Instant Client 11.2 and 12.2
What is your Oracle Database version?
Oracle 12c
The text was updated successfully, but these errors were encountered: