Interaction Python & SQLite3
SQLite est le système de gestion de bases de données relationnelles orienté fichier. Nous verrons connecter se connecter à une base de donnée SQLite et effectuer les opérations CRUD.
Prerequisites
No requirements
Packages
Paths & Config
Connection to database
Interaction with database
0. Create a table
1. CREATE : Insert data
sql3 = """
INSERT INTO customers (DepartmentID, Name, GroupName)
VALUES (1, 'Engineering', 'Research and Development'),
(2, 'Tool Design', 'Research and Development'),
(3, 'Sales', 'Sales and Marketing'),
(4, 'Marketing', 'Sales and Marketing'),
(5, 'Purchasing', 'Inventory Management'),
(6, 'Research and Development', 'Research and Development'),
(7, 'Production', 'Manufacturing'),
(8, 'Production Control', 'Manufacturing'),
(9, 'Human Resources', 'Executive General and Administration'),
(10, 'Finance', 'Executive General and Administration'),
(11, 'Information Services', 'Executive General and Administration'),
(12, 'Document Control', 'Quality Assurance'),
(13, 'Quality Assurance', 'Quality Assurance'),
(14, 'Facilities and Maintenance', 'Executive General and Administration'),
(15, 'Shipping and Receiving', 'Inventory Management'),
(16, 'Executive', 'Executive General and Administration');
"""
conn.execute(sql3)
conn.commit()
2. READ : Read data
3. UPDATE : Update data
4. DELETE : Delete data
Close connection
References
- SQLite: https://www.sqlite.org/index.html
- SQLite3 Docs: https://docs.python.org/3/library/sqlite3.html