Replies: 2 comments 1 reply
-
|
The instructions on page 485 are incomplete/unclear (and I'll add an errata entry to the book's O'Reilly page to confirm). In the Test Drive, the line before the output should read: "When we press Ctrl+Enter to rerun the code cell shown at the bottom of page 481 - displaying all the data - we see this:" The reason you are seeing no output with your code is that db.fetchall() needs to be associated with a SELECT statement (which returns data), whereas the code on page 485 uses INSERT (which updates the database with data, but does not produce any fetch-able results). Sorry for the trouble, and thanks for bringing this to my attention. --Paul. |
Beta Was this translation helpful? Give feedback.
-
|
Your code (as is, above) only INSERTs data into the database table. In order to read the just inserted data back out from the database, you need to SELECT the data before you call db.fetchall(). On its own, db.fetchall() does nothing if it is not immediately proceeded by a SELECT statement. If you are running the code in the book but seeing no output, make sure you aren't performing a DELETE query (which removes all the data from the database table). Additionally, after you run your INSERT code, check that the "CoachDB.sqlite3" file is being created in your current folder and that it is not empty (i.e., it has a file-size greater than a few bytes). If there's no file, or the file is empty, then there's something up with your data insertion code. --Paul. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
chap 10 test drive on p.485 and p.489 i cannot get the output
as on the book. this is my code(duplicate the book code)
i am using shift(crtl) + enter to run the code, the output is an empty list
i m using windows 10 VScode with py notebook
i tried restart several times with no good result
i tried book resource chap10 with no output either.
can anyone help me to resolve this problem
thanks
bill
import os
import DBcm
db_details = "CoachDB.sqlite3"
FOLDER = "swimdata/"
files = os.listdir(FOLDER)
files.remove(".DS_Store")
SQL_INSERT = """
insert into swimmers
(name, age)
values
(?, ?)
"""
with DBcm.UseDatabase(db_details) as db:
for fn in files:
results
Beta Was this translation helpful? Give feedback.
All reactions