Question: import sqlite 3 from sqlite 3 import Error # Creates connection to sqlite in - memory database def create _ connection ( ) :
import sqlite
from sqlite import Error
# Creates connection to sqlite inmemory database
def createconnection:
Create a connection to inmemory database
:return: Connection object
# YOUR CODE HERE
# Use sqliteconnect:memory:" to create connection object
return conn
# Creates Horse table
def createtableconn:
Create Horse table
:param conn: Connection object
:return: Nothing
# YOUR CODE HERE
# Inserts row to Horse table given data tuple
def inserthorseconn data:
Create a new row in Horse table
:param conn: Connection object
:param data: tuple of values for new row
:return: Nothing
# YOUR CODE HERE
# Use the character as placeholder for SQLite query parameters
# Selects and prints all rows of Horse table
def selectallhorsesconn:
Query all rows in the Horse table
:param conn: the Connection object
:return: Nothing
# YOUR CODE HERE
# DO NOT MODIFY main
if namemain:
# Create connection to sqlite inmemroy database
conn createconnection
if conn is None:
printError cannot create the database connection."
# Create Horse table
createtableconn
# Insert row to Horse table
horsedata "Babe", "Quarter Horse",
inserthorseconn horsedata
# Select and print all Horse table rows
printAll horses:"
selectallhorsesconn 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:
createconnection creates a connection to the database.
createtable creates the Horse table.
inserthorse inserts one row into Horse.
selectallhorses 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:
tableNameData type,Constraints,ValueIdinteger,primary key, not null,Nametext,,'Babe'Breedtext,,'Quarter horse'Heightdouble,,BirthDatetext,,
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
