Question

You will be creating a python module that emulates the behavior of the built-in module, "sqlite3"....

You will be creating a python module that emulates the behavior of the built-in module, "sqlite3". Your module will be able to execute SQL statements corresponding to: creating tables, inserting rows, and selecting rows.

Need help starting out on this

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the description given about the sqlite3 module existed in PYTHON PROGRAMMING LANGUAGE.

We can connect to the database using sqlite3 module by creating a connection object and we can execute the SQL statements by creating a cursor object .

Here is the sample program which i have attached below , which consists of creating connection object , creating Table , Inserting rows and finally Selecting rows..

PROGRAM:

#imported sqlite3 module

import sqlite3

conn = sqlite3.connect('test.db') #To open the database

conn.execute('''CREATE TABLE PERSON (ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50));''') # To create the table

conn.execute("INSERT INTO PERSON (ID,NAME,AGE,ADDRESS) \
      VALUES (1, 'Kumar', 32, 'Karnataka' )"); #To Insert the rows into the table

conn.execute("INSERT INTO PERSON (ID,NAME,AGE,ADDRESS) \ VALUES (2, 'Ganesh', 25, 'Telangana' )"); #To Insert the rows into the table

conn.commit() #Once we do the commit rows will get fetched to the table.

#Created Cursor to point to the row , we can move the cursor so that we can fetch all the records

#which we got as result of specific query

cursor = conn.execute("SELECT id, name, address from PERSON")
#To get the each record from the cursor and to move the cursor as well
for row in cursor:
   print "ID = ", row[0]
   print "NAME = ", row[1]
   print "ADDRESS = ", row[2] "\n"
conn.close() #Finally closing the database.

Thanks..

Add a comment
Know the answer?
Add Answer to:
You will be creating a python module that emulates the behavior of the built-in module, "sqlite3"....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello, I'm working on inserting data into a table using MySQL and Python on my Windows...

    Hello, I'm working on inserting data into a table using MySQL and Python on my Windows OS laptop; and I am asked to modify the script so that it executes an insert query in one of my database tables. I am also asked to print the table before and after I execute this query in order to ensure the new information was inserted into the table. I'd like to INSERT INTO my EMPLOYEE table. The columns are employee_id, employee_password, order_id...

  • This problem demonstrates the use of import module. The Python programming language has many strengths, but...

    This problem demonstrates the use of import module. The Python programming language has many strengths, but one of its best is the availability to use many existing modules for various tasks, and you do not need to be an experienced computer programmer to start using these modules. We have given you some incomplete code; note that the very first line of that code contains an import statement as follows: import math This statement enables your program to use a math...

  • Please help as much as you can it’s pretty much just terms What is the main purpose of the python-requests module? What kinds of requests can it make, and what types of responses might be returne...

    Please help as much as you can it’s pretty much just terms What is the main purpose of the python-requests module? What kinds of requests can it make, and what types of responses might be returned? Text? HTML? JSON? Images? What is JSON? How does it compare to CSV? Whern processed using the json.loads) method, what Python data structure does the imported JSON get imported as. What is an HTML Document Object Model (DOM) and how does that relate to...

  • Through the remaining assignments due in this course, you will be creating a simple database for...

    Through the remaining assignments due in this course, you will be creating a simple database for tracking information about volunteers working and raising money for a community organization. This assignment requires that you create the initial table, called PERSON, to hold basic information about volunteers. You will be redefining the design and building the database in the upcoming unit assignments. 1.Use the mysqldump.exe command line tool to backup the data in your volunteer database. To access the mysqldump.exe tool, start...

  • Tables: Create table Item(                 ItemId                 char(5) constraint itmid_unique primar

    Tables: Create table Item(                 ItemId                 char(5) constraint itmid_unique primary key,                 Decription           varchar2(30),                 Unitcost               number(7,2)); Create table Customer(                 custID                   char(5) constraint cid.unique primary key,                 custName          varchar2(20),                 address                                varchar2(50)); Create table Orderdata( orderID                char(5) constraint oid_uniq primary key,                 orderdate           date,                 shipdate              date,                 ItemId                  char(5) references Item.ItemId,                 No_of_items     number(4),                 Unitcost               number(7,2),                 Order_total        number(7,2),                 custID                   char(5) references customer.custID); Insert Into Item values(‘A123’,’Pencil’,2.5); Insert Into Item values(‘B123’,’Pen’,15); Insert Into...

  • Questions: Assume you are creating a database for IS paint store. Suppose you have an ER diagram ...

    Questions: Assume you are creating a database for IS paint store. Suppose you have an ER diagram like the following: Please answer the following questions. Explain your answer. 1. Convert the ER diagrams to relational tables. 2. Specify primary keys and foreign keys in each table. For foreign keys, specify which primary key it references to. 3. Please create the tables in SQL for the relational tables in our ER diagrams. You also need to define primary keys and foreign...

  • The lab for this week addresses taking a logical database design (data model) and transforming it...

    The lab for this week addresses taking a logical database design (data model) and transforming it into a physical model (tables, constraints, and relationships). As part of the lab, you will need to download the zip file titled CIS336Lab3Files from Doc Sharing. This zip file contains the ERD, Data Dictionary, and test data for the tables you create as you complete this exercise. Your job will be to use the ERD Diagram found below as a guide to define the...

  • Learning Objectives: Learn to define constraints on tables Lean to define primary keys and foreign keys...

    Learning Objectives: Learn to define constraints on tables Lean to define primary keys and foreign keys Exercise                                                                                In Lab 09, we will continue the practice of creating tables. You will need to write SQL statements for the tasks specified below. After you complete them, submit your SQL script (in one *.sql file) to Blackboard by 11:59pm Nov. 16 (Friday). Include your name as a comment in the SQL script submitted. The creation statement for each table is worth one point,...

  • What motivates you to study for exams or work hard in your classes? Pick a behavior...

    What motivates you to study for exams or work hard in your classes? Pick a behavior and design your own operant conditioning plan. What kinds of punishment/rewards do you believe would work best for you? Do you think that you could do this for yourself, that is, execute your operant conditioning plan, or would you need external punishment/reward (e.g., like a coach, professional help, or a buddy that would monitor and dish out the rewards/punishments)?

  • You are given a database schema as follows: Transaction(TID, Staff, Shop) Item(ItemCode, Description, Price) TransItem(TID, ItemCode,...

    You are given a database schema as follows: Transaction(TID, Staff, Shop) Item(ItemCode, Description, Price) TransItem(TID, ItemCode, Quantity) Sample data of the tables are shown below: TID Staff Shop 1 Ann 1 2 Ann 1 3 Ben 2 Transaction ItemCode Description Price A1 Milk 6 B1 Bread 10 B2 Chocolate 20 Item TID ItemCode Quantity 1 A1 1 1 B2 2 2 B2 1 3 A1 4 3 B2 1 TransItem Assumptions: TID, Shop and Price are integers ItemCode contains a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT