I'm using SQLite3 with python in JetBrains PyCharm Community Edition 4.0.4.
I have a table that looks like this. ID is integer, name and content are text.
ID Name Content
1 Matt oirefasd aifsfnib if ib @John sefuhrg wefirwgf
2 John sdfwre frwgfwg wegfhtr @Patsfrwg
3 Pat asjgre wurgjnsow wouregjeo @Johnsfbwufaeovnwo
4 John sfgoe eriogner weogfib
So here is my question, Assume a user John, is logged in. How do I write the sqlite query such that I receive the rows that contain messages starting with @ symbol followed by the user that is logged in (John) in the Content column.
I should receive the answer as a tuple.(ID, Name, Content)
So the solution should be:
ID Name Content
1 Matt oirefasd aifsfnib if ib @John sefuhrg wefirwgf
3 Pat asjgre wurgjnsow wouregjeo @Johnsfbwufaeovnwo
This is my current sql query. currentuser stores the name of the current logged in user in this case John.
str = '%'+ currentuser + '%'
c = db.cursor()
sql = "SELECT id, Name, content FROM myusers WHERE myusers.content LIKE ? LiMIT ?"
c.execute(sql,(str,limit))
return [x[0] for x in c]
I keep getting an error which says "'int' object is not subscriptable"
Aucun commentaire:
Enregistrer un commentaire