简体   繁体   English

PYODBC 使用 sql cursor 中的 where 执行

[英]PYODBC using where in the sql cursor execute

A student of mine is partaking on a piece of coursework where they create a small program / artefact and they have chosen to link Python with a database using pyodbc.我的一个学生正在参加一项课程,他们创建了一个小程序/人工制品,他们选择使用 pyodbc 将 Python 与数据库链接。

So far he can successfully connect and if he uses a select * from statement and then fetchall he can print out the whole database.到目前为止,他可以成功连接,如果他使用 select * from 语句然后 fetchall 他可以打印出整个数据库。 But naturally to extend this work he wants to be able to filter results using where but it doesn't seem to work as intended and my experience in this is very limited.但很自然地,为了扩展这项工作,他希望能够使用 where 过滤结果,但它似乎没有按预期工作,而且我在这方面的经验非常有限。

For example the code:例如代码:

cursor.execute("select * from Films where BBFC = '12'")

Gives this error给出这个错误

pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. (-3010) (SQLExecDirectW)')” pyodbc.Error: ('07002', '[07002] [Microsoft][ODBC Microsoft Access Driver] 参数太少。预期 1. (-3010) (SQLExecDirectW)')”

It is a database of films and wants to filter it by age rating (the bbfc column).它是一个电影数据库,并希望按年龄分级(bbfc 列)对其进行过滤。 I have taken a look myself and cant seem to fix the issue so any help or guidance would be massively appreciated.我自己看了看,似乎无法解决这个问题,所以任何帮助或指导将不胜感激。

The problem here might be some spelling mistakes or maybe a case senstive field name or table name.这里的问题可能是一些拼写错误,或者可能是区分大小写的字段名或表名。 Would you be able to make sure that 'Films' and 'BBFC' are spelt correctly and match the DB?您能否确保“电影”和“BBFC”拼写正确并与数据库匹配?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM