-
Notifications
You must be signed in to change notification settings - Fork 62
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
Insert empty string into Database #135
Comments
I am unable to replicate your issue using the example you showed above. Can you send me the packet output for your case? I don't need everything. I just need the packet containing the SQL statement so I can see what is being sent to the database. Thank you! |
Hi Anthony, thank you for your reply. I tried to debug the call of An alternative way of reproducing my issue is by using the function insert_statement = 'INSERT INTO tmp_table(SHORT_FIELD, LONG_FIELD) VALUES(:SHORT_FIELD, :LONG_FIELD)'
with get_database_connection() as connection:
with connection.cursor() as cursor:
cursor.execute(insert_statement, ['', 'Loooooong string'])
connection.commit() To reproduce the error the order of the parameters is important. Maybe the stack trace helps you:
Kind regards, |
Hi @lihofm i try you code and the code is executed without error cursor.execute('INSERT INTO tmp_table(SHORT_FIELD, LONG_FIELD) VALUES(:SHORT_FIELD, :LONG_FIELD)', ['', 'Loooooong string']) and this will fail cursor.execute('INSERT INTO tmp_table(SHORT_FIELD, LONG_FIELD) VALUES(:LONG_FIELD, :SHORT_FIELD)', ['Loooooong string', '']) also this will fail cursor.execute('INSERT INTO tmp_table(SHORT_FIELD, LONG_FIELD) VALUES(:SHORT_FIELD, :LONG_FIELD)', ['Loooooong string', '']) so i think better to close this issue because it is not an issue of the driver |
@sijms, what you say is correct but I think misses the point! The code supplied by @lihofm is correct. @lihofm, I tried your new code which is much simpler but doesn't fail for me, either! You can enable packet output by setting the environment variable
Note that I renamed my table to If you call |
Hi @anthony-tuininga @sijms , thank you for your reply! This is my packet output using
I tested my code using In my not working program I am connecting to the database using the following code: def get_database_connection(host_name, port, sid, user_name, user_password):
try:
dsn = makedsn(host_name, port, sid)
connection = connect(user=user_name, password=user_password, dsn=dsn)
return connection
except Exception:
print("do something") Is using |
Thanks for supplying the packet output. That looks exactly like mine, except for the differences due to the fact that you are using 12.1.0.2.0, so I'll have to see if I can replicate with that older database. The call to |
Ok. I can replicate the problem with a 12.1.0.2.0 database. Hopefully I can get to the bottom of the issue now! |
Hi @anthony-tuininga , |
I was able to determine the source of the issue! If you are able to build from source you can verify that it corrects your issue as well. Now that I know the source of the issue I can supply a few workarounds:
|
Hi @anthony-tuininga , I tested my code (with |
This has been included in version 1.3.0 which was just released. |
Hi,
1. What versions are you using?
Database version: Oracle Database 12c (12.1.0.2.0)
platform.platform: Windows-10-10.0.19044-SP0
sys.maxsize > 2**32: True
platform.python_version: 3.10.9
oracledb.version: 1.2.1
cx_Oracle.version: 8.3.0
2. Is it an error or a hang or a crash?
error
3. What error(s) or behavior you are seeing?
When I am trying to insert an empty string into my database the input parameters after the empty string are getting shifted by one to the left. This leads to the following strange behavior:
Here is an example of case 3:
On Database:
In Python:
After executing the python code I will get the following error:
oracledb.exceptions.DatabaseError: ORA-12899: value too large for column "TMP_TABLE"."SHORT_FIELD" (actual: 14, maximum: 1)
So the function
executemany
tried to insert the wrong value ('Loooong string'
) into the fieldshort_field
. Even though I defined a value for the field.When executing the code with the function
execute
I get the same error.I also tried to insert an empty string with the python package
cx_oracle
and it works.4. Does your application call init_oracle_client()?
No
5. Include a runnable Python script that shows the problem.
see above
Thank you!
The text was updated successfully, but these errors were encountered: