We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
async def execute(sql, args, autocommit = True): .... async with __pool.get() as conn: ... try: async with conn.cursor(aiomysql.DictCursor) as cur: await cur.execute(sql.replace('?','%s'),args) affected = cur.rowcount .... except BaseException: ..... return affected
在这个代码里面 cur.execute(sql.replace('?','%s'),args) 如果执行错误的话(例如重复插入unique key相同的数据),下面的local variable affected 变量不会被申明且赋值,而在try外面 affected 又被返回,此时会报错,且在调用excute函数的外面并没有捕获异常导致程序崩溃.
cur.execute(sql.replace('?','%s'),args)
The text was updated successfully, but these errors were encountered:
首先,如果对unique key插入相同数值的话会报MySQL内部错误IntegrityError(1062, "Duplicate entry 'test2' for key 'idx_email'")。然后这个return affect并不在try...中,也不在finally..中,所以怎么会返回呢?
IntegrityError(1062, "Duplicate entry 'test2' for key 'idx_email'")
return affect
try...
finally..
Sorry, something went wrong.
可能会抛出异常,执行except下面的代码,执行完毕后返回affect。
return语句不在except中,执行完except后无finally则直接退出,怎么会return呢?难道你的报错信息中有到这一句吗?
return
except
finally
No branches or pull requests
在这个代码里面
cur.execute(sql.replace('?','%s'),args)
如果执行错误的话(例如重复插入unique key相同的数据),下面的local variable affected 变量不会被申明且赋值,而在try外面 affected 又被返回,此时会报错,且在调用excute函数的外面并没有捕获异常导致程序崩溃.The text was updated successfully, but these errors were encountered: