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...

  • Exercise 2: Import a Python Math Module You can find a list of all of the...

    Exercise 2: Import a Python Math Module You can find a list of all of the math functions available in the Python.org Math Functions page found in the Resources. Select any math function(s) that you would like to use in a program. Do the following: Write a program that imports the math module and uses the function that you selected. (Hint: You will need to determine the arguments that must be passed to the function, return the result, and display...

  • 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...

  • 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...

  • 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...

  • 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)?

  • 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,...

  • You are to write a Java program that emulates an “undo” operation in programs like Word...

    You are to write a Java program that emulates an “undo” operation in programs like Word processors. You will need to use the proper data structures as you see fit. Specifically, you will create a data type called, DocumentBuffer, that acts as edit buffer & keeps a list of Line data type. To keep it simple, DocumentBuffer will have these editing operations: add a Line and remove a Line. DocumentBuffer will store its state during any edits. It will need...

  • You are to write a program that emulates an “undo” operation in programs like Word processors....

    You are to write a program that emulates an “undo” operation in programs like Word processors. 2. You will need to use the proper data stuctures as you see fit. 3. Specifically, you will create a data type called, DocumentBuffer, that acts as edit buffer & keeps a list of Line data type. 4. To keep it simple, DocumentBuffer will have these editing operations: add a Line and remove a Line. 5. DocumentBuffer will store its state during any edits....

  • Implement the following problem as a self-contained python module. Write a program that continually prompts the...

    Implement the following problem as a self-contained python module. Write a program that continually prompts the user for positive integer values and stores them in a list. You should stop prompting when the user enters a negative integer value. When the user is done entering values, you should print the list of integers they have provided in sorted order. You should then compute the mean and standard deviation of the values in the list. Recall that the mean is just...

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