การจัดการ ResultSet ขนาดใหญ่

Python เบื้องต้นสำหรับฐานข้อมูล

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

การรับมือกับ ResultSet ขนาดใหญ่

  • fetchmany() ให้ระบุจำนวนแถวที่ต้องการดึงได้
  • วนลูปผ่าน fetchmany() ได้
  • คืนค่าเป็น list ว่างเมื่อไม่มีข้อมูลเหลือ
  • ต้องปิด ResultProxy หลังใช้งาน
Python เบื้องต้นสำหรับฐานข้อมูล

การดึงข้อมูลหลายแถว

while more_results:

partial_results = results_proxy.fetchmany(50)
if partial_results == []: more_results = False
for row in partial_results: state_count[row.state] += 1
results_proxy.close()
Python เบื้องต้นสำหรับฐานข้อมูล

มาฝึกกันเถอะ!

Python เบื้องต้นสำหรับฐานข้อมูล

Preparing Video For Download...