Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

how to insert string variable into sqlite database

def create_db():
    with con:
        cur = con.cursor()
        cur.execute("DROP TABLE IF EXISTS Contacts")
        cur.execute("CREATE TABLE Contacts (First Name TEXT, Last Name TEXT, Phone TEXT, Email TEXT);")
        cur.execute("INSERT INTO Contacts VALUES (?, ?, ?, ?);", (firstname, lastname, phone, email))

        ## call commit on the connection...
        con.commit()
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #insert #string #variable #sqlite #database
ADD COMMENT
Topic
Name
9+8 =