TAILIEUCHUNG - Advance Praise for Head First Python Part 8

Tùy thuộc vào những gì xảy ra trong giai đoạn Tương tác của quá trình, bạn có thực hiện bất kỳ thay đổi dữ liệu của bạn thường trực (cam kết) hoặc quyết định hủy bỏ những thay đổi của bạn (rollback). Bạn có thể bao gồm các mã như thế này trong chương trình của bạn. | manage your data The database API as Python code Here s how to implement an interaction with a database using the sqlite3 module This disk tile is used to hold the database and its tables As always wpor the library you need- import sqlite3 Establish a tonnettion to a database- Create a Cursor to the data. Execute Some S L. Commit any changes _ making -them permanent- Close your ionneetion h when you re finished- L connection cursor SELECT DATE NOW Depending on what happens during the Interact phase of the process you either make any changes to your data permanent commit or decide to abort your changes rollback . You can include code like this in your program. It is also possible to interact with you SQLite data from within IDLE s shell. Whichever option you choose you are interacting with your database using Python. It s great that you can use a database to hold your data. But what schema should you use Should you use one table or do you need more What data items go where How will you design your database Let s start working on the answers to these questions. you are here 4 315 design your database A little database design goes a long way Let s consider how the NUAC s data is currently stored within your pickle. Each athlete s data is an AthleteList object instance which is associated with the athlete s name in a dictionary. The entire dictionary is pickled. p-ựịíkled dietary has any MhleteL-ist wiihin it number of Each AthleteList has the following attributes With this arrangement it is pretty obvious which name date of birth and list of times is associated with which individual athlete. But how do you model these relationships within a SQL-compliant database system like SQLite You need to define your schema and create some tables. 316 Chapter 9 manage your data Define your database schema Here is a suggested SQL schema for the NUAC s data. The database is called .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.