Accord to the DB API the return value of cur.execute
is undefined. So if you use
logincheck = cur.execute(loadname, login)
then your code will be relying on the particular behavior of your database adapter. MySQLdb
for example, returns the primary key of the row selected (if it exists), or 0L
if there is no such row. Nevertheless, I think it is better not to rely on this.
Your code will be a little more general if you instead stick to only those behaviors guaranteed by the DB API.
Instead you could use
cur.execute(loadname, login)
logincheck = cur.fetchone()
This will make logincheck
a tuple (if a row exists) or the value None
.
If login
is an ID
in CharactersDB
, then logincheck
will look like the tuple (login, )
, not the string login
.
If login
is not an ID, then logincheck
will be None.
So the if-statement
could then look like this:
if logincheck is None:
print("Sorry, could not find you in the database\nOr it just isn't working")
else:
print("pass\nSuccessfully loaded {} from the database".format(login))