Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[python] Function specifications. student_report: This function takes an SQLite db filename and a student id. The database contains tables for classes like we've been working

[python]

image text in transcribed

image text in transcribed

Function specifications. student_report: This function takes an SQLite db filename and a student id. The database contains tables for classes like we've been working with through the semester. Each table has columns last, first, middle, email, id, grade, major, level. It goes through each of the tables in the db, generating a string that prints like this: Thompson, Richard, 131000000 ISTA 130 S17: A ISTA 131 F17: A ISTA 331 F18: A Notice that the classes are in order by class number and that the number of dashes is exactly the same as the length of the header. Use this query to get the names of the tables in the db so you can build the query strings to access them: SELECT name FROM sqlite_master WHERE type = 'table'; You opened the db at the beginning of this function, so close it at the end. Here is some pseudocode: do the usual opening SQL stuff transcript = initialize your result string query = given above for row in c.execute (query).fetchall(): query = query to grab desired info FROM row [O] for given id result = c.execute(query).fetchone () if result: # the student is in this table if not transcript: # the header has not been created transcript += header transcript += info for the student properly formatted close your connection return your string In the code above, row [0] will contain each of the tablenames in the database. Since you're building a string, what should you initialize your string variable to (transcript in my code)? Function specifications. student_report: This function takes an SQLite db filename and a student id. The database contains tables for classes like we've been working with through the semester. Each table has columns last, first, middle, email, id, grade, major, level. It goes through each of the tables in the db, generating a string that prints like this: Thompson, Richard, 131000000 ISTA 130 S17: A ISTA 131 F17: A ISTA 331 F18: A Notice that the classes are in order by class number and that the number of dashes is exactly the same as the length of the header. Use this query to get the names of the tables in the db so you can build the query strings to access them: SELECT name FROM sqlite_master WHERE type = 'table'; You opened the db at the beginning of this function, so close it at the end. Here is some pseudocode: do the usual opening SQL stuff transcript = initialize your result string query = given above for row in c.execute (query).fetchall(): query = query to grab desired info FROM row [O] for given id result = c.execute(query).fetchone () if result: # the student is in this table if not transcript: # the header has not been created transcript += header transcript += info for the student properly formatted close your connection return your string In the code above, row [0] will contain each of the tablenames in the database. Since you're building a string, what should you initialize your string variable to (transcript in my code)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions