Assignment 12-03

 

 

1.viewing the customer based on customer id :

''' Write a Program for Customer Management:
Create a Customerdetails ⇒ id,name,city,tickets
Options :
1.viewing the customer based on customer id
2. Total count of tickets sold
3. City wise ticket sold
4. Information ⇒ based on descending order
5. Update ⇒ customer id ⇒ which detail
6. Delete ⇒ customer id ⇒ delete the record '''

import sqlite3

con = sqlite3.connect('cus.db')

cursor = con.cursor()
sq = '''CREATE TABLE customer_details(
id INTEGER PRIMARY KEY,
name TEXT ,
city TEXT,
tickets INTEGER)'''

cursor.execute(sq)

print('table is created successfully')

con.commit()
con.close()


 

 

 

import sqlite3

def data(dl2):

con = sqlite3.connect('cus.db')
cursor = con.cursor()


ins = '''INSERT INTO customer_details
VALUES (?,?,?,?) '''

cursor.executemany(ins, dl2)

con.commit()
print("no of records inserted: ",cursor.rowcount)
con.commit()
con.close()

dl2 = [(1,'raj','banglore',4),(2,'raju','chennai',3),(3,'rajesh','mumbai',5),(4,'martha','delhi',2),(5,'ulrich','delhi',4),(6,'jonas','delhi',5),(7,'anna','pune',6),(8,'hanna','kolkata',10),(9,'charlotte','pune',2),(10,'thomas','kolkata',3)]

data(dl2)


 

import sqlite3

def show(n):
c = sqlite3.connect('cus.db')

cur = c.cursor()

cur.execute("SELECT * FROM customer_details WHERE id = (?)",(n,))

rec = cur.fetchall()

for i in rec:
print(i)

c.commit()
c.close()


import bhshjb

#k = int(input("enter the id : "))

bhshjb.show()

2. Total count of tickets sold :

import sqlite3

def show():
c = sqlite3.connect('cus.db')

cur = c.cursor()

cur.execute("SELECT SUM(tickets) FROM customer_details ")

rec = cur.fetchall()

for i in rec:
print(i)

c.commit()
c.close()


 

3. City wise ticket sold :

 

import sqlite3


def show(n):

c = sqlite3.connect('cus.db')

cur = c.cursor()

cur.execute("SELECT * FROM customer_details WHERE city = (?)", (n,))

rec = cur.fetchall()
print(rec)
j=0
for i in rec:
j=i[-1]+j

print(j)
c.commit()
c.close()



 

import bhshjb

#k = int(input("enter the id : "))

bhshjb.show('delhi')

 

4. Information ⇒ based on descending order :

def show(n):

c = sqlite3.connect('cus.db')

cur = c.cursor()

cur.execute("SELECT * FROM customer_details ORDER BY id DESC")

rec = cur.fetchall()
print(rec)

for i in rec:
print(i)
c.commit()
c.close()


 

5. Update ⇒ customer id ⇒ which detail :

 


def show():

c = sqlite3.connect('cus.db')

cur = c.cursor()

cur.execute("UPDATE customer_details SET name = 'suman' WHERE id = 1")

rec = cur.fetchall()
print(rec)

for i in rec:
print(i)
c.commit()
c.close()


 

6. Delete ⇒ customer id ⇒ delete the record :

 

import sqlite3


def show():

c = sqlite3.connect('cus.db')

cur = c.cursor()

cur.execute("DELETE FROM customer_details WHERE id = 10")

rec = cur.fetchall()
print(rec)

for i in rec:
print(i)
c.commit()
c.close()


 

 

 

 

 

 

Comments

Popular posts from this blog

Using lists , tuples, sets, dictionaries

Method Over riding in Java

introduction to SQL