Python Forum
How to Check if something inside a Database exists? 3.6.0
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Check if something inside a Database exists? 3.6.0
#1
I am creating a quiz with a log in system and I'm using a sqlite3 database to store the data on each account. I was wondering if there is anyway to have the user input their, for example, Username and have the system check if that Username exists and then either let them continue or close the system. Sorry for such a basic question but this is my first time using databases so I'm really confused.
Reply
#2
Yes, you can use query like this:

Quote:SELECT COUNT(*) FROM users WHERE username = '[USERNAME]'

You replace the [USERNAME] in a query with username which the user has used and you'll get the number of existing users with it. If it equals 0, there is no user in DB.
Reply
#3
don't forget to run the interactive sqlite3 program, syntax: sqlite3 dbname
Run this from the directory containing the database, if you want a fancier way
to do this, I highly recommend downloading sqliteman: https://sourceforge.net/p/sqliteman/wiki/Home/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Check if a file exists. Pedroski55 5 3,251 Sep-08-2020, 10:01 AM
Last Post: Pedroski55
  p]Why os.path.exists("abc/d") and os.path.exists("abc/D") treat same rajeev1729 1 2,140 May-27-2020, 08:34 AM
Last Post: DeaD_EyE
  Check table exists in Database ARV 0 1,911 Oct-03-2019, 02:37 PM
Last Post: ARV
  How to check if class instance exists in a list of class instance objects? sonicblind 23 20,083 May-27-2018, 05:44 AM
Last Post: buran
  How do you check if something exists or doesn't in the conditions of an if? Klar 1 2,479 Dec-15-2017, 03:47 PM
Last Post: sparkz_alot
  How to check if the data is empty in a database? chris0147 8 20,030 Aug-28-2017, 12:03 AM
Last Post: Fran_3
  check if file exists. ian 6 8,334 Jul-15-2017, 09:34 AM
Last Post: wavic
  Check Python version from inside script? Run Pythons script in v2 compatibility mode? pstein 2 9,790 Jul-07-2017, 08:59 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020