Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import sqlite 3 conn = sqlite 3 . connect ( test . db ) print ( Database connected. ) conn.execute ( '

import sqlite3
conn = sqlite3.connect("test.db")
print("Database connected.")
conn.execute('''CREATE TABLE IF NOT EXISTS CONTACTS
(ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50));''')
print("Table created.")
conn.execute("INSERT INTO CONTACTS (ID,NAME,AGE,ADDRESS)\
VALUES (18, 'Polly', 32, 'Seattle')");
conn.execute("INSERT INTO CONTACTS (ID,NAME,AGE,ADDRESS)\
VALUES (19, 'Roger', 28, 'Bainbridge')");
conn.commit()
print("Records created.")
cursor = conn.execute("SELECT * from CONTACTS")
for row in cursor:
print ("ID ="+ str(row[0]))
print ("NAME ="+ row[1])
print("AGE ="+ str(row[2]))
print ("ADDRESS ="+ str(row[3])+"
")
print ("Records found.")
cursor = conn.execute("UPDATE CONTACTS SET NAME = 'Mazen' WHERE NAME = 'Polly'")
conn.commit()
cursor = conn.execute("SELECT * from CONTACTS")
for row in cursor:
print ("ID ="+ str(row[0]))
print ("NAME ="+ row[1])
print("AGE ="+ str(row[2]))
print ("ADDRESS ="+ str(row[3])+"
")
print("Records updated.")
cursor = conn.execute("DELETE FROM CONTACTS WHERE NAME = 'Polly'")
conn.commit()
print("Record deieted")
conn.close()
Use this code to:
Create a Python script for managing a server.
Create a Python module to consume data from a public API and reformat the data to present as a web page.
Create a Python module for complex queries to a SQL or NoSQL database.
Create a Python module to search log files for selected content and to generate a report on what is discovered.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Objects And Databases International Symposium Sophia Antipolis France June 13 2000 Revised Papers Lncs 1944

Authors: Klaus R. Dittrich ,Giovanna Guerrini ,Isabella Merlo ,Marta Oliva ,M. Elena Rodriguez

2001st Edition

3540416641, 978-3540416647

More Books

Students also viewed these Databases questions