我正在尝试执行以下代码:
conn = sqlite3.connect("./Databases/Functions/He.db")
cursor = conn.cursor()
sql = "SELECT * FROM Requests WHERE Request like ?"
cursor.execute(sql, [(msg)])
results = cursor.fetchall()[0]
print results
if((results)[1] == "True"):
GPIO = (results)[2]
Direction = (results)[3]
print "GPIO Setup ready.."
我收到以下错误:
File "./Functions/doFunctions.py", line 29, in enRequests
results = cursor.fetchall()[0]
IndexError: list index out of range
我总是搞乱数据库,最后解决了这些问题,我不知道为什么它们从一开始就弹出..
获取 msg 字符串的代码,搜索它是否存在于数据库中,如果存在则获取 GPIO 引脚并发送信号(请求位于0
数据库行的索引处,而 GPIO 引脚位于索引处2
)。