-
Notifications
You must be signed in to change notification settings - Fork 357
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
cx_Oracle.NotSupportedError: Python value of type WindowsPath not supported #171
Comments
Sure. You can do the following: rows = [ ('01787440110', 'Rakin','22-04-2017', my_file.open("rb").read() )] That will open the file and read its contents. This will work effectively for files that readily fit in memory and for those types of files this is the most efficient way to do that. For very large files you will need to use a LOB locator and stream the data instead. |
Many thanks @anthony-tuininga As you said I have induced the following update in my code:
Will the updated code work perfectly for very large files ? Or, is there any other performant option for production while dealing with very large files?
I didn't get the point. What I have done is to read the contents from the file and write it to the LOB. Could you please clarify me how I could stream the data directly using the lob locator ? Thanks in advance!! |
The code will work for any file less than 1 GB provided you have the contiguous memory available to keep the file contents in memory! If you need to stream, you can do something like the following: lobVar = cursor.var(cx_Oracle.CLOB)
cursor.execute("INSERT INTO CHAT_HISTORY(MOBILE_NUMBER,USER_NAME,CHAT_DATE,USER_TRANSCRIPTS) values (:1, :2, :3, empty_clob()) returning USER_TRANSCRIPTS into :4", ['01787440110', 'Rakin', '22-04-2017', lobVar)
lob = lobVar.getvalue()
offset = 1
lob.write(firstPart, offset)
offset += len(firstPart)
lob.write(secondPart, offset)
offset += len(secondPart)
# and so forth |
Great!! But do I have to split the original content into firstPart, secondPart.... manually ? The thing is that I have to save chat history of different user programmatically and concurrently. And, chat history file size will be different for different users. And, Many thanks for your time @anthony-tuininga |
Not at all! Generally, if you're reading from a file you would do something like this: offset = 1
size = 8388608 # or some value that makes sense to you or is optimal for your configuration
with open(fileName, "rb") as f:
while True:
data = f.read(size)
if not data:
break
lob.write(data, offset)
offset += len(data)
That is because lobVar is a variable, not a LOB value! This documentation is what you want! |
Thanks @anthony-tuininga .... Things are now absolutely clear to me. I am closing the issue as well. |
Hello,
I am using cx_Oracle to insert binary files from a directory as BLOB in a column of a table.
So, I am intended to use the PATH module of python3 and then insert the binary file by fetching the file using WindowsPath
Configurations:-
Here's the cdoe:-
Then, I am getting the following errors:-
Traceback (most recent call last): File "F:/Python with ORACLE/orapy.py", line 53, in print(cursor.executemany('insert into CHAT_HISTORY(MOBILE_NUMBER,USER_NAME,CHAT_DATE,USER_TRANSCRIPTS) values (:1, :2, :3, :4)', rows)) cx_Oracle.NotSupportedError: Python value of type WindowsPath not supported.
Is there any way to export binary files from a directory and then directly insert the file in as BLOB using cx_Oracle ??
The text was updated successfully, but these errors were encountered: