Skip to content

Instantly share code, notes, and snippets.

@techsharif
Created November 19, 2017 05:53
Show Gist options
  • Save techsharif/bf72531dc3d034e24f0f118389b3c0cc to your computer and use it in GitHub Desktop.
Save techsharif/bf72531dc3d034e24f0f118389b3c0cc to your computer and use it in GitHub Desktop.
PYTHON3 sqlite basic operation
"""
importent links:
http://sebastianraschka.com/Articles/2014_sqlite_in_python_tutorial.html
http://www.pythoncentral.io/introduction-to-sqlite-in-python/
"""
import sqlite3
# Create a database in RAM
conn = sqlite3.connect('testdb.sqlite')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE student(
id INTEGER PRIMARY KEY,
roll INTEGER,
name TEXT,
phone TEXT
)
''')
cursor.execute('''
INSERT INTO student( roll, name, phone )
VALUES ( '1','hello','01737573157' )
''')
cursor.execute('''
SELECT roll, name, phone
FROM student
''')
all_rows = cursor.fetchall()
for row in all_rows:
print('{0} : {1}, {2}'.format(row[0], row[1], row[2]))
conn.commit()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment