Skip to content

Instantly share code, notes, and snippets.

@Jbot29
Last active February 2, 2016 21:32
Show Gist options
  • Save Jbot29/f00f12ccf2ed82a6dc9a to your computer and use it in GitHub Desktop.
Save Jbot29/f00f12ccf2ed82a6dc9a to your computer and use it in GitHub Desktop.
Using
import sqlite3
Open a database
filename = "test.sqlite"
conn = sqlite3.connect(filename)
Create Table
c = conn.cursor()
c.execute('''CREATE TABLE users (id INTEGER PRIMARY KEY, email TEXT,created_at DATE)''')
conn.commit()
Insert Row
c = conn.cursor()
c.execute('''INSERT INTO users (email,created_at) VALUES(?,?)''', (email,today,))
conn.commit()
Update Row
c = conn.cursor()
c.execute('''UPDATE users SET email="[email protected]" WHERE email="[email protected]"''');
newemail = "new"
c.execute('''update users set email=?''',(newemail,))
conn.commit()
Query
c = conn.cursor()
c.execute('''select * from users''')
c.fetchall()
c.execute('''select * from users where email = ?''',(email,))
c.fetchall()
c.execute('''select * from email where created_at = ? and email = ?''',(day,email,))
Close
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment