fork download
  1. import sqlite3
  2.  
  3. # إنشاء اتصال بقاعدة بيانات في الذاكرة (أو ملف إذا رغبت)
  4. conn = sqlite3.connect(':memory:')
  5. cursor = conn.cursor()
  6.  
  7. # إنشاء جدول المرضى
  8. cursor.execute('''
  9. CREATE TABLE Patients (
  10. ID INTEGER PRIMARY KEY,
  11. Name TEXT,
  12. Age INTEGER,
  13. Issue TEXT
  14. )
  15. ''')
  16.  
  17. # إدراج بيانات المرضى
  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 INTO Patients (ID, Name, Age, Issue) VALUES (?, ?, ?, ?)', patients_data)
  25.  
  26. # تحديث بيانات مريض (تحديث المشكلة للمريض أحمد)
  27. cursor.execute('''
  28. UPDATE Patients
  29. SET Issue = 'pressure'
  30. WHERE ID = 567778
  31. ''')
  32.  
  33. # حذف بيانات مريض (حذف المريض mina)
  34. cursor.execute('''
  35. DELETE FROM Patients
  36. WHERE Name = 'mina'
  37. ''')
  38.  
  39. # إضافة مريض جديد اسمه Abanoub
  40. cursor.execute('''
  41. INSERT INTO Patients (ID, Name, Age, Issue) VALUES (?, ?, ?, ?)
  42. ''', (56788, 'Abanoub', 28, 'Covid'))
  43.  
  44. # عرض جميع بيانات المرضى
  45. cursor.execute('SELECT * FROM Patients')
  46. all_patients = cursor.fetchall()
  47.  
  48. # عرض النتائج
  49. for patient in all_patients:
  50. print(patient)
  51.  
  52. # إغلاق الاتصال
  53. conn.close()
Success #stdin #stdout #stderr 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 1: near "import": syntax error