简体   繁体   English

sqlite3.OperationalError:接近“<”:语法错误

[英]sqlite3.OperationalError: near "<": syntax error

Can Anyone Help Me to solve this i had error sqlite3.OperationalError: near "<": syntax error i think that from the sql but still stucking there任何人都可以帮我解决这个问题我有错误 sqlite3.OperationalError: near "<": syntax error 我认为从 sql 但仍然卡在那里

def getProfile(id):
       connect = sqlite3.connect('C:///Users///Marvin///Desktop///Opencv-face-detection-python-master///SQL///sql.db')
       cur = connect.cursor()
       connect.execute("SELECT * FROM user WHERE id="+str(id))
       profile=None
       for row in cur:
         profile=row
       cur.close()
       return profile

I cannot replicate your error in my testing.我无法在测试中复制您的错误。

While I was testing your code, I notice a problem with当我测试你的代码时,我注意到一个问题

connect.execute("SELECT * FROM user WHERE id="+str(id))

I think it should be我认为应该是

cur.execute("SELECT * FROM user WHERE id="+str(id))

That works during my testing.这在我的测试期间有效。 Please let me know if this works or not.请让我知道这是否有效。 By changing this, the function returns a result and I was able to get the result.通过改变这个,函数返回一个结果,我能够得到结果。

If you don't mind, I have one extra piece of advice for you.如果你不介意,我还有一个额外的建议给你。 The way you wrote your query is very prone to SQL Injection attacks as shown here .你写你的查询方式很容易出现SQL注入攻击如图所示这里 I would recommend you to structure your query in the following way.我建议您按以下方式构建查询。

cur.execute("SELECT * FROM user WHERE id=?",str(id))

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

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