[英]How to upload a image file to a oracle database using Python Flask
I am trying to update a row in my oracle database with a image file (into a blob column) and the file name (varchar2 column).我正在尝试使用图像文件(到 blob 列)和文件名(varchar2 列)更新我的 oracle 数据库中的一行。
Below is my code, if I put f.filename
in the parenthesis of f.read()
, then I get error " expecting a integer as parameter " and if I put nothing there then I get " cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number " on cur.execute
line.下面是我的代码,如果我将
f.filename
放在f.read()
的括号中,那么我会收到错误“期待 integer 作为参数”,如果我什么都不放在那里,那么我会得到“ cx_Oracle.DatabaseError: ORA-01036: cur.execute
行上的非法变量名称/编号”。
How do I modify the below code update the row with my image file?如何修改下面的代码用我的图像文件更新行? Thanks.
谢谢。 I am new to python and trying to learn on my own.
我是 python 的新手,并试图自学。
v_sql = "update login_table set image_file= %s and binary_file = %s where email_address= %s"
v_binary_file = f.read()
v_current_user = 'abcd@abcd.com'
v_args = (f.filename, v_binary_file, v_current_user)
cur.execute(v_sql, v_args)
cur.commit
Oracle's bind variable syntax uses a colon (':') not a percent ('%') prefix for statement placeholders. Oracle 的绑定变量语法使用冒号 (':') 而不是百分号 ('%') 前缀作为语句占位符。
The cx_Oracle manual LOB documentation has clear LOB examples: cx_Oracle 手册 LOB 文档有明确的 LOB 示例:
with open('example.txt', 'r') as f:
textdata = f.read()
with open('image.png', 'rb') as f:
imgdata = f.read()
cursor.execute("""
insert into lob_tbl (id, c, b)
values (:lobid, :clobdata, :blobdata)""",
lobid=10, clobdata=textdata, blobdata=imgdata)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.