Created
November 19, 2017 05:53
-
-
Save techsharif/bf72531dc3d034e24f0f118389b3c0cc to your computer and use it in GitHub Desktop.
PYTHON3 sqlite basic operation
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
""" | |
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