Python Using Databases in Python Our Diary App Doing Data Entry

YiSzen Tang
YiSzen Tang
2,221 Points

Sqlite3

I can't do sqlite3 diary.db on python (not on workspaces) the error says: 'sqlite3' is not recognized as an internal or external command, operable program or batch file.

1 Answer

James J. McCombie
James J. McCombie
Python Web Development Techdegree Graduate 20,022 Points

Hello,

you would need to actually download SQlite itself to do this I believe. The python module sqlite3 provides an interface only.

that being said you can still interact with sqlite3 databases, and in fact create them using the module. To do this, you do:

import sqlite3

# this connects to or creates the database
db = sqlite3.connect('diary.db')

# creates a cursor object which you will use to interact with the database
c = db.cursor()

# execute SQL queries as an example
c.execute(INSERT SQL HERE)
# save the changes
db.commit()

you may also consider installing an ORM (object-relational mapping) type package, like pewee, or SQLalchemy. Pewee will be covered if you do the python-flask lessons, and its nice to use - I would recommend reading the docs - https://peewee.readthedocs.io/en/latest - if only to get an idea of what it does.

James