import sqlite3
conn = sqlite3.connect('/Users/macbook/Desktop/lool.db')
c = conn.cursor()
invalid_input = True
def startinglogin(self):
loginmessage = input("To register to the Quizzer, type in 'Register'. To login, type in 'Login'.\n")
while loginmessage != "Login" and loginmessage != "Register":
loginmessage = input("To register to the Quizzer, type in 'Register'. To login, type in 'Login'.\n")
self.loginmessage = loginmessage
studentusername = ' '
studentpassword = ' '
def nameandpass():
global studentusername
studentusername = input('Enter username: ')
global studentpassword
studentpassword = input('Enter password: ')
def start():
def passlength():
while len(studentpassword) < 4 or len(studentpassword) > 16:
print ("ERROR. Your password must be longer than 4 characters and shorter than 16 characters.")
studentpassword = input('Enter password: ')
def usernamechecker():
c.execute("SELECT username FROM studenttest WHERE username=(?)", (studentusername, ))
if c.fetchone() == None:
global usernamecheck
usernamecheck = ' '
else:
c.execute("SELECT username FROM studenttest WHERE username=(?)", (studentusername, ))
usernamecheck = ' '.join(map(str, (c.fetchone())))
def passwordchecker():
c.execute("SELECT password FROM studenttest WHERE password=(?)", (studentpassword, ))
if c.fetchone() == None:
global passcheck
passcheck = ' '
else:
c.execute("SELECT password FROM studenttest WHERE password=(?)", (studentpassword, ))
passcheck = ' '.join(map(str, (c.fetchone())))
def create_db():
c.execute("DROP TABLE IF EXISTS studenttest")
c.execute("CREATE TABLE studenttest (id INTEGER PRIMARY KEY, username TEXT, password TEXT)")
conn.commit()
def loginform():
while usernamecheck != studentusername or passcheck != studentpassword:
print ("Your login info is wrong.")
nameandpass()
usernamechecker()
passwordchecker()
if usernamecheck == studentusername and passcheck == studentpassword:
print ("Access granted!")
global invalid_input
invalid_input = False
else:
print("Access denied!")
def registerform():
while studentusername == useravailable:
print ("That username is already taken!")
global studentusername
studentusername = input("Enter username: ")
if studentusername != useravailable:
c.execute("INSERT INTO studenttest VALUES (NULL,?,?);", (studentusername, studentpassword))
global invalid_input
invalid_input = False
conn.commit()
def sameusername():
c.execute("SELECT username FROM studenttest")
global useravailable
useravailable = ' '.join(map(str, (c.fetchone())))
if startinglogin.loginmessage == "Register":
sameusername()
registerform()
elif startinglogin.loginmessage == "Login":
usernamechecker()
passwordchecker()
loginform()
conn.commit()
while invalid_input:
startinglogin(startinglogin)
nameandpass()
start()
if invalid_input == False:
c.close()
I have no idea why my code is locking the database, can someone help out with that? The error message that is displayed in the shell is:
Traceback (most recent call last):
File "/Users/macbook/Documents/hey draft2.py", line 85, in <module>
start()
File "/Users/macbook/Documents/hey draft2.py", line 75, in start
registerform()
File "/Users/macbook/Documents/hey draft2.py", line 65, in registerform
c.execute("INSERT INTO studenttest VALUES (NULL,?,?);", (studentusername, studentpassword))
sqlite3.OperationalError: database is locked
If this is a noob mistake, I'm really sorry for wasting time. :/
EDIT: Forgot to call passlength() in the code, don't mind that. Adding or taking it out had no effect.