مراجعة الأسبوع الماضي: دوال fetch

وش ترجع؟

صف الحصة
الأسبوع التاسع: تحديث البيانات

Fahad تطوّر...
وكرته لسه 85!

تقييمه الحقيقي صار 87، والجدول مكتوب فيه قديم 🤔نحتاج نعدّل بيانات موجودة: الأمر UPDATE (ص85)
ص85

صيغة الأمر
UPDATE

صيغة التعليمة البرمجية لتحديث البيانات
1cursor.execute('UPDATE players SET rating = ? WHERE id = ?',
2 (87, 2))
ص85-86

خطوات تحديث
البيانات

ص85

بدون WHERE؟
كل الصفوف!

انتبه ⚠️
1cursor.execute('UPDATE players SET price = ?',
2 (0,))
ص86-87

المثال 1:
عمود واحد

update_data.py · مثال الكتاب: price = 2 للصف id = 5
1import sqlite3
2connection = sqlite3.connect('fut_club.db')
3cursor = connection.cursor()
4# Update data
5cursor.execute('''UPDATE players
6 SET rating = ?
7 WHERE id = ?''', (87, 2))
8print('Number of rows updated:', connection.total_changes)
9connection.commit()
10connection.close()
ص87-88

كم صف
تغيّر؟

السطر 8
1import sqlite3
2connection = sqlite3.connect('fut_club.db')
3cursor = connection.cursor()
4# Update data
5cursor.execute('''UPDATE players
6 SET rating = ?
7 WHERE id = ?''', (87, 2))
8print('Number of rows updated:', connection.total_changes)
9connection.commit()
10connection.close()
▶ Run: main
Number of rows updated: 1
Process finished with exit code 0
ص88-89

المثال 2:
أكثر من عمود

update_data.py · مثال الكتاب: price و year للفئة Art
1import sqlite3
2connection = sqlite3.connect('fut_club.db')
3cursor = connection.cursor()
4# Update data
5cursor.execute('''UPDATE players
6 SET club = ?, price = ?
7 WHERE name = ?''',
8 ('Red FC', 9.5, 'Yousef'))
9print('Number of rows updated:', connection.total_changes)
10connection.commit()
11connection.close()
▶ Run: main
Number of rows updated: 1
Process finished with exit code 0
ص90

شروط
أذكى

تحديث بشرط IS NULL وبشرط مركب
1# 1) price is empty
2cursor.execute('''UPDATE players SET price = ?
3 WHERE price IS NULL''', (5.0,))
4
5# 2) compound condition
6cursor.execute('''UPDATE players SET price = ?
7 WHERE rating > ? AND price < ?''',
8 (40, 84, 30))
ص91-92

ورقة العمل 8:
تحديث صف

update_data1.py · المشروع update_landmark
1import sqlite3
2connection = sqlite3.connect('landmarks_Kuwait.db')
3cursor = connection.cursor()
4# Update Data
5cursor.execute()
6print('Number of rows updated:', connection.total_changes)
7connection.commit()
8connection.close()
ص93-94

ورقة العمل 9:
دخول مجاني

update_data2.py · المشروع update_landmark
1import sqlite3
2connection = sqlite3.connect('landmarks_Kuwait.db')
3cursor = connection.cursor()
4# Update Data
5cursor.execute()
6print('Number of rows updated:', connection.total_changes)
7connection.commit()
8connection.close()
الملخص

الكود كامل،
قطعة قطعة

main.py — PyCharm
1import sqlite3
2connection = sqlite3.connect('fut_club.db')
3cursor = connection.cursor()
4cursor.execute('UPDATE players SET rating = ? WHERE id = ?', (87, 2))
5print('Number of rows updated:', connection.total_changes)
6connection.commit()
7connection.close()
▶ Run: main
Number of rows updated: 1
Process finished with exit code 0
ص127-131

المنتجات الرقمية:
مشروعك

وحدة المشروعاتص127
الهدف: الاستفادة من المهارات اللي طبقتوها في أوراق العمل، وتنمية العمل الجماعي والابتكار.
الخطوات: تحديد المشكلة ← الخوارزمية ← خريطة التدفق ← الكود ← الاختبار والتصحيح ← العرض ← التحسين ← بناء البرنامج
مهام فريق العملص129
الفريق من 4 إلى 5 أعضاء:
قائد الفريق · مُعد قاعدة البيانات · المبرمج · مُعد العرض التقديمي
فكرة المشروعص131
مشروع تقني تعليمي بسيط (تطبيق، لعبة، أداة تحليل بيانات...) بشرط: واضحة وقابلة للتطبيق، لها فئة مستفادة، قابلة لنموذج برمجي، لها مصادر خارجية، وتعتمد على الذكاء الاصطناعي
🏆 لوحة النقاط
↩ رجوع للشريحة 1
⬇ تصدير Excel
💾 نسخة احتياطية
📂 استرجاع نسخة
كل ضغطة = نص نقطة · خذ 💾 بنهاية كل حصة
1 / 14
‹
›
↻
🏆 النقاط