التابع Connection.executescript()‎ في بايثون

من موسوعة حسوب
< Python‏ | Connection
مراجعة 19:23، 16 سبتمبر 2018 بواسطة Mohammed Taher (نقاش | مساهمات)
(فرق) → مراجعة أقدم | المراجعة الحالية (فرق) | مراجعة أحدث ← (فرق)
اذهب إلى التنقل اذهب إلى البحث


يستدعي هذا التابعُ التابعَ Cursor.executescript()‎ مع تمرير المعاملات المعطاة.

البنية العامة

executescript(sql_script)

‎المعاملات

sql_script

سلسلة نصية تتضمن شيفرة SQL المراد تنفيذها.

القيمة المعادة

هذا التابع هو طريقة مختصرة لإنشاء كائن مؤشر عن طريق استدعاء التابع cursor()‎، حيث يستدعي التابع executescript() في كائن المؤشر مع تمرير قيمة المعامل sql_script، ثم يعيد كائن المؤشر.

أمثلة

يبين المثال التالي آلية عمل التابع:

import sqlite3
conn = sqlite3.connect('example.db')
conn.executescript("""
    insert into recipe (name, ingredients) values ('broccoli stew', 'broccoli peppers cheese tomatoes');
    insert into recipe (name, ingredients) values ('pumpkin stew', 'pumpkin onions garlic celery');
    insert into recipe (name, ingredients) values ('broccoli pie', 'broccoli cheese onions flour');
    insert into recipe (name, ingredients) values ('pumpkin pie', 'pumpkin sugar flour butter');
    """)

انظر أيضًا

مصادر

صفحة DB-API 2.0 interface for SQLite databases في توثيق بايثون الرسمي.