SQLite
SQLite
import sqlite3
Create Database
Connect db = sqlite3.connect(“File_Name.db”)
And Connect
cr.execute(“select
Execute(select) Select field from
Table_Name”)
Command info Example
Delete
Execute(Delete) cr.execute(“delete from Table_Name where field = Value”)
Data
# Inserting Data
my_list = ["Ahmed", "Sayed", "Mahmoud", "Ali", "Kamel", "Ibrahim", "Enas"]
for key, user in enumerate(my_list):
cr.execute(f"insert into users(user_id, name) values({key +
1},'{user}')")
# cr.execute(f"insert into users values({key + 1},'{user}')") # we
couldn't write fields
# Update Date
cr.execute("update users set name = 'Mahmoud' where user_id = 1")
# Delete Date
cr.execute("delete from users where user_id = 5")
# Fetch Data
cr.execute("select * from users")
print(cr.fetchone()) # fetchone
print(cr.fetchmany(2)) # fetchmany
print(cr.fetchall()) # fetchall
# Close Database
db.close()
Important Informations
SQL Injection
Select order
Select where