Last active
February 2, 2016 21:32
-
-
Save Jbot29/f00f12ccf2ed82a6dc9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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