python - 无法在 python 中执行长 sql 语句?
问题描述
我已将我的 sql 语句定义如下(注意换行符)
def getTankSystemIds():
sql='select tt.TankSystemId,ts.sitecode,tt.productid ' \
'from [dbo].[TankSystems] tt' \
'left join [dbo].sites ts on tt.siteid=ts.siteid where ts.companyid=8' \
'and ProductId in (10,4,2,3,11,4)'
cursor = connectDB()
cursor.execute(sql)
records = cursor.fetchall()
调用此方法时,出现以下错误。我将单引号更改为 " 和 ''',""" 但都给出了相同的错误我在这里做错了什么?我也尝试在一条长行中提供 sql 语句。但同样的错误
SyntaxError: Non-ASCII character '\xef' in file /Users/ratha/PycharmProjects/Processor/Utilities/DbConnector.py on line 86, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
解决方案
SQL 查询是从某处复制/粘贴还是被另一个程序保存为 UTF-8 编码?它有一个字节顺序标记(BOM),这就是\xef
字符。ASCII 不喜欢这样,因为它是 Unicode 的东西。
推荐阅读
- python - 如何通过一个 SeparableConv2D 传递多张图像?
- node.js - 如何将 React 发送到 Express 服务器获取请求传递 id
- python - 将输入分配给变量
- visual-studio-app-center - 使用 API 或 CLI 从 AppCenter 下载 Appium 日志
- ios - 二元运算符“>”不能应用于两个“Int?” 尝试排序时
- docker - 无法在 docker 中优雅地停止应用程序
- objective-c - 为什么我在 Xcode 单元测试中遇到错误的浮点运算问题?
- vba - 使用表格检查导入 Excel - access 2016
- vue.js - 每页的 Vuejs MPA 和 indexPath
- mongodb - Spring-boot + Mongodb 手册参考不起作用,找不到我的错误,查询 Mongodb 工作正常