简体   繁体   English

这有什么问题? (sqlite3的)

[英]What is wrong with this? (sqlite3)

recordCheck = c.execute("SELECT * FROM Student, Behaviour WHERE Forename=:oldForename, Surname=:oldSurname,     YearGroup=:oldYearGroup, FormNumber=:oldFormNumber, Date=:oldDate, BehaviourType=:oldBehaviourType", {"oldForename":oldForename,    "oldSurname":oldSurname, "oldYearGroup":oldYearGroup, "oldFormNumber":oldFormNumber,"oldDate":oldDate,"oldBehaviourType":oldBehaviourType})

This returns this error: 这会返回此错误:

OperationalError: near ",": syntax error

But I can't see what is wrong with it. 但我看不出它有什么问题。 Can anyone help? 有人可以帮忙吗?

Comma is not valid in a where clause. 逗号在where子句中无效。 Conditions are normally separated by AND or OR . 条件通常由ANDOR分隔。 So, this is invalid: 所以,这是无效的:

WHERE Forename=:oldForename, Surname=:oldSurname

One of these would be valid: 其中一个是有效的:

WHERE Forename=:oldForename AND Surname=:oldSurname

WHERE Forename=:oldForename OR Surname=:oldSurname

使用WHERE X=Y AND Y=Z而不是WHERE X=Y, Y=Z

recordCheck = c.execute("SELECT * FROM Student, Behaviour WHERE Forename=:oldForename AND Surname=:oldSurname AND YearGroup=:oldYearGroup AND FormNumber=:oldFormNumber AND Date=:oldDate AND BehaviourType=:oldBehaviourType", {"oldForename":oldForename,    "oldSurname":oldSurname, "oldYearGroup":oldYearGroup, "oldFormNumber":oldFormNumber,"oldDate":oldDate,"oldBehaviourType":oldBehaviourType})

您在WHERE子句中使用逗号,您应该使用AND。

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

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