Skip to content

If Statement With SQLite Result Returns False #127479

@kevinwdemarest

Description

@kevinwdemarest

Bug report

Bug description:

# I placed a #flag where the if statement is that is having the trouble.

# Author: Kevin Demarest

try:
    from datetime import datetime
    #import pandas as pd    # when I imported pandas sqlite3 wouldn't import
    import sqlite3
except:
    print("Couldn't import") 

con = sqlite3.connect("time-clock.db")    
cur = con.cursor()

res = cur.execute("SELECT username FROM employee")
print("This is SELECT username FROM employee: ", res.fetchall())

#cur.execute("DROP TABLE employee")
#print(cur.execute("describe employee"))

#res = cur.execute("select name from sqlite_master")
#print("This is res.fetchone(): ", res.fetchone())

#cur.execute("CREATE TABLE employee(id PRIMARY KEY, timeid, firstname, lastname, username, password)")
#cur.execute("CREATE TABLE time(id PRIMARY KEY, employeeid, date, timein, timeout, hoursworked)")

#cur.execute("""
#    INSERT INTO employee VALUES
#        (1, 1, 'Kevin', "Demarest", "kevindemarest", "123456"),
#        (2, 2, "Matthew", NULL, "matthew", "123456")
#""")

#cur.execute("""
#    INSERT INTO time VALUES
#        (1, 1, NULL, NULL, NULL, NULL),
#        (2, 2, NULL, NULL, NULL, NULL)
#""")

#tuple testing
#username = ('kevindemarest',)    # you have to use a tuple, so convert to tuple
#sql = cur.execute("SELECT username FROM employee where username = ?", (username))   
#result = cur.fetchall()
#print(result)

def get_username(prompt, retries=4, reminder='Unknown username.'):
    while True:
        reply = input(prompt)
        username = reply
        usernametup = (reply,)
        sql = cur.execute("SELECT username FROM employee where username = ?", usernametup)
        result = cur.fetchall()    
        print("This is result: ", result)
        if result:    # flag
            return username
        retries = retries - 1
        if retries < 0:
            print("Invalid user response.")
            break
        print(reminder)

get_username("Enter your username: ")

username = 'kevindemarest'    # flag 2

def get_password(prompt, username, retries=4, reminder='Please try again!'):    
    while True:
        reply = input(prompt)
        password = reply
        print(username, password)
        params = [username, password]
        sql = cur.execute("SELECT password FROM employee WHERE username = ? and password = ?", (username, password))
        result = cur.fetchall()
        print(result)
        if result:   
            return True
        retries = retries - 1
        if retries < 0:
            print('Invalid user response.')
            break
        print(reminder)

password = get_password("Please enter your password: ", username)

#def ask_clockin(prompt, retries=4, reminder="Please try again!"):
#    while True:
#        clockin = input(prompt)
#        if user.clockedin == True:
#            return True
#        else:
#            return False
#        retries = retries - 1
#        if retries < 0:
#            raise ValueError('invalid user response')
#        print(reminder)

#clockin = ask_clockin("Clockin? Please enter 'y' or 'n': ")

#if clockin == True:
#    timein = datetime.today()
#    user.clockedin = True

t = datetime.today()    #needed from datetime import datetime
#t = datetime.today(...)   # no periods
#t = datetime.fromtimestamp(timestamp, /)
print("Today is: ", t)

t1 = datetime(2024,10,21,15,00)
t2 = datetime(2024,10,22,8,00)    # no leading zeros

print("You worked: ",t2-t1," hours.")

con.close()

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions