5.8 LAB - Database programming with Python (SQLite) Complete the Python program to create a Horse table, insert one row,

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

5.8 LAB - Database programming with Python (SQLite) Complete the Python program to create a Horse table, insert one row,

Post by answerhappygod »

5 8 Lab Database Programming With Python Sqlite Complete The Python Program To Create A Horse Table Insert One Row 1
5 8 Lab Database Programming With Python Sqlite Complete The Python Program To Create A Horse Table Insert One Row 1 (110.18 KiB) Viewed 168 times
5 8 Lab Database Programming With Python Sqlite Complete The Python Program To Create A Horse Table Insert One Row 2
5 8 Lab Database Programming With Python Sqlite Complete The Python Program To Create A Horse Table Insert One Row 2 (118.2 KiB) Viewed 168 times
5.8 LAB - Database programming with Python (SQLite) Complete the Python program to create a Horse table, insert one row, and display the row. The main program calls four functions: 1. create_connection() creates a connection to the database. 2. create_table() creates the Horse table. 3. insert_horse() inserts one row into Horse. 4. select_all_horses() outputs all Horse rows. Complete all four functions. Function parameters are described in the template. Do not modify the main program The Horse table should have five columns, with the following names, data types, constraints, and values: Name Data type Constraints Value Id integer primary key, not null 1 Name text 'Babe Breed text Quarter horse Height double 15.3 BirthDate text 2015-02-10 The program output should be: All horses: (1, "Babe', 'Quarter Horse', 15.3, '2015-02-10') This lab uses the SQLite database rather than MySQL. The Python API for SQLite is similar to MySQL Connector/Python. Consequently, the API is as described in the text, with a few exceptions: • Use the import library provided in the program template. Create a connection object with the function sqlite3.connect(": memory:"). • Use the character ? instead of %s as a placeholder for query parameters. • Use data type text instead of char and varchar.

The program output should be: All horses: (1, 'Babe', 'Quarter Horse', 15.3, '2015-02-10') This lab uses the SQLite database rather than MySQL. The Python API for SQLite is similar to MySQL Connector/Python. Consequently, the API is as described in the text, with a few exceptions: • Use the import library provided in the program template. • Create a connection object with the function sqlite3.connect(":memory:") • Use the character ? instead of %s as a placeholder for query parameters. • Use data type text instead of char and varchar. SQLite reference information can be found at SQLite Python Tutorial, but is not necessary to complete this lab. 403894.1874424.qx3zqy7 LAB ACTIVITY 5.8.1: LAB - Database programming with Python (SQLite) 3/ 10 main.py Load default template... 1 import sqlite3 2 from sqlite3 import Error 4 # Creates connection to sqlite in-memory database 5 def create_connection: 7 8 Create a connection to in-memory database return: Connection object 10 11 # YOUR CODE HERE 12 # Use sqlite3.connect(":memory:") to create connection object 13 14 return conn 15 16 17 # Creates Horse table 18 def create_table (conn) : Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the

24 17 # Creates Horse table 18 def create_table conn) : 19 20 Create Horse table 21 param conn: Connection object 22 return: Nothing 23 24 25 # YOUR CODE HERE 26 27 28 # Inserts row to Horse table given data tuple 29 def insert_horse (conn, data): 30 31 Create a new row in Horse table 32 param conn: Connection object 33 param data: tuple of values for new row 34 :return: Nothing 35 36 37 # YOUR CODE HERE 38 # Use the ? character as placeholder for SQLite query parameters 39 40 41 # Selects and prints all rows of Horse table 42 def select_all_horses (conn): 43 Query all rows in the Horse table 45 param conn: the Connection object 46 :return: Nothing 47 48 49 # YOUR CODE HERE 44 50 51
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply