Python SQLite ToDo script
Question: I'm trying to make a script that asks the user to input a task, the task is
then stored in a SQLite database. I am having a problem getting my delete
function to work. Also when I input a new task I have to encapsulate in quotes
in order to make it run.

    
    
    import sqlite3
    import sys 
    
    con = sqlite3.connect('taskmgr.db')
    
    def create_db():
        with con:
            c.execute("DROP TABLE IF EXISTS ToDo")
            c.execute("CREATE TABLE ToDo(Id int, Task char20, Due char20)") 
    
    def select_task():
        with con:
            cursor = con.execute("SELECT Id, Task, Due from ToDo")
            for row in cursor:
                print "Id:" ,row[0]
                print "Task:" ,row[1]
                print "Due:" ,row[2]
    
    def insert_task():
        with con:
            print("New Task\n")
            Id = input("Enter Id: ")
            Task = input("Enter Task: ")
            Due = input("Enter Due Date: ")
            c.execute("INSERT INTO ToDo VALUES(?, ?, ?)", (Id, Task, Due))
            con.commit()
    
    def delete_record():
        with con:
            print("Enter task Id to delete:")
            user = int(input())
            c.execute("DELETE FROM ToDo WHERE Id=?",(user))
    
    c = con.cursor()        
    create_db()
    
    target= int(8)
    while target != 9:
        target=int(input("\nGood Morning Curtis!\n \nSelect option:\n 1.New Task\n 2.Select Task\n 3.Delete Task\n 9.Quit\n\nUser: "))
    
        if target ==1:
            insert_task()
    
        elif target ==2:
            select_task()
    
        elif target ==3:
            delete_record()
    
        elif target ==9:
            print("good bye")
    


Answer: Regarding the input requiring quotes, for Python 2 use `raw_input()` instead
of `input()`.

The other problem is with the `execute` statement, specifically the values for
the parameterised query needs to be of type tuple (or list), however, you are
passing in an integer value. Try changing it to this:

    
    
    c.execute("DELETE FROM ToDo WHERE Id=?",(user,))
    

The reason is that wrapping a single value in parentheses does not create a
tuple:

    
    
    >>> for user in 1, (1), (1,):
    ...     print user, type(user)
    ... 
    1 <type 'int'>
    1 <type 'int'>
    (1,) <type 'tuple'>
    

From the above you can see that `(1)` is still `1` and is of type int.
Wrapping it in `()` did not convert it to a tuple. However, `(1,)` is a tuple.
Alternatively you could pass a list of the parameters, e.g.

    
    
    c.execute("DELETE FROM ToDo WHERE Id=?",[user])
    

