Question: Python - I need help with a function I am trying to build. The function is suppose to load a people record with the id

Python - I need help with a function I am trying to build. The function is suppose to load a people record with the id of id. I am completely stuck on the yellow highlights. I honestly don't understand them. Any advise is truly appreciated.

Python - I need help with a function I am trying to

load_person() signature: def load_person(self, id): o This method will attempt to load a "people" record with the id of "id". o Create a sql string to select a specific record from the database: sql = "SELECT * FROM people WHERE id=?" 0 Next, open a cursor and use that cursor to execute the sql command: cursor = self.conn.cursor() cursor.execute(sql, (id)) records = cursor.fetchall() Note: the execute command accepts the sql command string and a tuple of parameters to substitute for the question marks in the command string. Notice the comma with nothing after it? That is to ensure (id,) results in a tuple, not a single evaluated value. Next create a variable called result and assign to it a tuple that represents an empty record if nothing is found in the database: result = (-1,'','') # id = -1, first_name = '', last_name o Finally, check to see if the "records" list contains any data and if it does get the first value out of the list. If you simply return records, you will get a list with one item in it instead of just the one item. if records is not None and len(records) > 0: result = records[0] cursor.close() return result

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!