Skip to content

sqlite3

jasper-zanjani edited this page Aug 6, 2020 · 1 revision

Create a Connect connection object and employee.db (binary) if it doesn't exist

conn = sqlite.connect('employee.db')

Create a Connect.Cursor object

c = conn.cursor()

Perform SQL commands with Connect.Cursor.execute(). Create tablename with fields field of type type (null, integer, real, text, blob); never use Python's native string operations (f-strings, etc) to form commands, because this method is vulnerable to SQL injection. YouTube

c.execute('''CREATE TABLE {tablename} ({field} {type}, {field} {type} ...))

Save changes

conn.commit()

Close connection

conn.close()

Clone this wiki locally