Python + SQLite check | HELP | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Python + SQLite check | HELP

I'd like to check if name I set in Python is in SQLite table > Column. How to make it? Example: name = 'John' Table name: Table_name column name: Name Which function should I use? Please help!

5th Mar 2017, 5:55 PM
XENONIUM
XENONIUM - avatar
12 Answers
+ 7
i guess first thing is to insert a name o_O check = c.execute('INSERT into Table_name VALUES (?)', 'John')
5th Mar 2017, 6:48 PM
Burey
Burey - avatar
+ 7
and then: name="John" check = c.execute("SELECT name from Table_name WHERE name="+name)
5th Mar 2017, 6:52 PM
Burey
Burey - avatar
+ 7
might be for the best SQL ain't my strong suite xD
5th Mar 2017, 6:55 PM
Burey
Burey - avatar
+ 6
have you checked the API? https://docs.python.org/3/library/sqlite3.html
5th Mar 2017, 6:11 PM
Burey
Burey - avatar
+ 6
can you post any code you have so far?
5th Mar 2017, 6:19 PM
Burey
Burey - avatar
+ 6
and do you have anything in the table? sorry my SQL is rusty xD http://sebastianraschka.com/Articles/2014_sqlite_in_python_tutorial.html some nice info here
5th Mar 2017, 6:25 PM
Burey
Burey - avatar
+ 6
according to the link i posted: "if we use the .fetchall() method, we return a list of tuples from the database query, where each tuple represents one row entry. " so it shouldn't be an issue that it displays [(0,)] instead of 0
5th Mar 2017, 6:41 PM
Burey
Burey - avatar
+ 1
So, how to pair it with Python? How to check if name is in table?
5th Mar 2017, 6:43 PM
XENONIUM
XENONIUM - avatar
0
Yes, checked. But can't find the right function
5th Mar 2017, 6:17 PM
XENONIUM
XENONIUM - avatar
0
c = conn.cursor() name = 'John' check = c.execute('SELECT count(name) FROM table_name') c.fetchall() >>> ([0,]) I need at least 0 instead of ([0,])
5th Mar 2017, 6:23 PM
XENONIUM
XENONIUM - avatar
0
No, didn't help. Still the output is [(0,)] instead of 0
5th Mar 2017, 6:30 PM
XENONIUM
XENONIUM - avatar
0
I'll check this site
5th Mar 2017, 6:54 PM
XENONIUM
XENONIUM - avatar