fork download
  1. import sqlite3
  2.  
  3. # إنشاء اتصال بقاعدة بيانات SQLite (سيتم إنشاء ملف قاعدة البيانات إذا لم يكن موجودًا)
  4. conn = sqlite3.connect('patients.db')
  5. cursor = conn.cursor()
  6.  
  7. # 1. إنشاء جدول المرضى
  8. cursor.execute('''
  9. CREATE TABLE IF NOT EXISTS Patients (
  10. ID INTEGER PRIMARY KEY,
  11. Name VARCHAR(100),
  12. Age INTEGER,
  13. Issue VARCHAR(100)
  14. )
  15. ''')
  16.  
  17. # 2. إدراج بيانات المرضى
  18. patients_data = [
  19. (2580000, 'Malak', 24, 'pressure'),
  20. (567778, 'Ahmed', 30, 'sugar'),
  21. (78999865, 'mina', 40, 'migraine'),
  22. (777666, 'Mariam', 40, 'sugar')
  23. ]
  24. cursor.executemany('INSERT OR IGNORE INTO Patients (ID, Name, Age, Issue) VALUES (?, ?, ?, ?)', patients_data)
  25.  
  26. # 3. تحديث بيانات مريض (تحديث المشكلة للمريض أحمد)
  27. cursor.execute('UPDATE Patients SET Issue = ? WHERE ID = ?', ('pressure', 567778))
  28.  
  29. # 4. حذف بيانات مريض (حذف المريض mina)
  30. cursor.execute('DELETE FROM Patients WHERE Name = ?', ('mina',))
  31.  
  32. # 5. إضافة مريض جديد اسمه Abanoub
  33. cursor.execute('INSERT OR IGNORE INTO Patients (ID, Name, Age, Issue) VALUES (?, ?, ?, ?)', (56788, 'Abanoub', 28, 'Covid'))
  34.  
  35. # 6. عرض جميع بيانات المرضى
  36. cursor.execute('SELECT * FROM Patients')
  37. all_patients = cursor.fetchall()
  38. for patient in all_patients:
  39. print(patient)
  40.  
  41. # حفظ (commit) التغييرات وإغلاق الاتصال
  42. conn.commit()
  43. conn.close()
Success #stdin #stdout 0.03s 25408KB
stdin
Standard input is empty
stdout
import sqlite3

# إنشاء اتصال بقاعدة بيانات SQLite (سيتم إنشاء ملف قاعدة البيانات إذا لم يكن موجودًا)
conn = sqlite3.connect('patients.db')
cursor = conn.cursor()

# 1. إنشاء جدول المرضى
cursor.execute('''
CREATE TABLE IF NOT EXISTS Patients (
    ID INTEGER PRIMARY KEY,
    Name VARCHAR(100),
    Age INTEGER,
    Issue VARCHAR(100)
)
''')

# 2. إدراج بيانات المرضى
patients_data = [
    (2580000, 'Malak', 24, 'pressure'),
    (567778, 'Ahmed', 30, 'sugar'),
    (78999865, 'mina', 40, 'migraine'),
    (777666, 'Mariam', 40, 'sugar')
]
cursor.executemany('INSERT OR IGNORE INTO Patients (ID, Name, Age, Issue) VALUES (?, ?, ?, ?)', patients_data)

# 3. تحديث بيانات مريض (تحديث المشكلة للمريض أحمد)
cursor.execute('UPDATE Patients SET Issue = ? WHERE ID = ?', ('pressure', 567778))

# 4. حذف بيانات مريض (حذف المريض mina)
cursor.execute('DELETE FROM Patients WHERE Name = ?', ('mina',))

# 5. إضافة مريض جديد اسمه Abanoub
cursor.execute('INSERT OR IGNORE INTO Patients (ID, Name, Age, Issue) VALUES (?, ?, ?, ?)', (56788, 'Abanoub', 28, 'Covid'))

# 6. عرض جميع بيانات المرضى
cursor.execute('SELECT * FROM Patients')
all_patients = cursor.fetchall()
for patient in all_patients:
    print(patient)

# حفظ (commit) التغييرات وإغلاق الاتصال
conn.commit()
conn.close()